Skip to content

Commit

Permalink
rtl components
Browse files Browse the repository at this point in the history
  • Loading branch information
raikov committed Apr 1, 2022
1 parent 5875014 commit 9696f0f
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 42 deletions.
35 changes: 33 additions & 2 deletions userfiles/modules/microweber/api/editor.js
Expand Up @@ -7,7 +7,6 @@




var EditorPredefinedControls = {
'default': [
[ 'bold', 'italic', 'underline' ],
Expand All @@ -18,6 +17,27 @@ var EditorPredefinedControls = {
};

var MWEditor = function (options) {

;(function (){

var self;
var RtlDetect=self={_regexEscape:/([\.\*\+\^\$\[\]\\\(\)\|\{\}\,\-\:\?])/g,_regexParseLocale:/^([a-zA-Z]*)([_\-a-zA-Z]*)$/,_escapeRegExpPattern:function(str){if(typeof str!=='string'){return str}
return str.replace(self._regexEscape,'\\$1')},_toLowerCase:function(str,reserveReturnValue){if(typeof str!=='string'){return reserveReturnValue&&str}
return str.toLowerCase()},_toUpperCase:function(str,reserveReturnValue){if(typeof str!=='string'){return reserveReturnValue&&str}
return str.toUpperCase()},_trim:function(str,delimiter,reserveReturnValue){var patterns=[];var regexp;var addPatterns=function(pattern){patterns.push('^'+pattern+'+|'+pattern+'+$')};if(typeof delimiter==='boolean'){reserveReturnValue=delimiter;delimiter=null}
if(typeof str!=='string'){return reserveReturnValue&&str}
if(Array.isArray(delimiter)){delimiter.map(function(item){var pattern=self._escapeRegExpPattern(item);addPatterns(pattern)})}
if(typeof delimiter==='string'){var patternDelimiter=self._escapeRegExpPattern(delimiter);addPatterns(patternDelimiter)}
if(!delimiter){addPatterns('\\s')}
var pattern='('+patterns.join('|')+')';regexp=new RegExp(pattern,'g');while(str.match(regexp)){str=str.replace(regexp,'')}
return str},_parseLocale:function(strLocale){var matches=self._regexParseLocale.exec(strLocale);var parsedLocale;var lang;var countryCode;if(!strLocale||!matches){return}
matches[2]=self._trim(matches[2],['-','_']);lang=self._toLowerCase(matches[1]);countryCode=self._toUpperCase(matches[2])||countryCode;parsedLocale={lang:lang,countryCode:countryCode};return parsedLocale},isRtlLang:function(strLocale){var objLocale=self._parseLocale(strLocale);if(!objLocale){return}
return(self._BIDI_RTL_LANGS.indexOf(objLocale.lang)>=0)},getLangDir:function(strLocale){return self.isRtlLang(strLocale)?'rtl':'ltr'}};Object.defineProperty(self,'_BIDI_RTL_LANGS',{value:['ae','ar','arc','bcc','bqi','ckb','dv','fa','glk','he','ku','mzn','nqo','pnb','ps','sd','ug','ur','yi'],writable:!1,enumerable:!0,configurable:!1})

MWEditor.rtlDetect = RtlDetect;

})();

var defaults = {
regions: null,
document: document,
Expand Down Expand Up @@ -47,6 +67,10 @@ var MWEditor = function (options) {
options = options || {};

this.settings = mw.object.extend({}, defaults, options);
if(!this.settings.direction) {
this.settings.direction = 'ltr';
}



if (typeof this.settings.controls === 'string') {
Expand Down Expand Up @@ -397,7 +421,14 @@ var MWEditor = function (options) {
content = this.settings.selectorNode.value;
}
this.area = mw.element({
props: { className: 'mw-editor-area', innerHTML: content }
props: {
className: 'mw-editor-area', innerHTML: content, dir: scope.settings.direction,
style: {
direction: scope.settings.direction,
textAlign: scope.settings.direction === 'ltr' ? 'left' : 'right',
}
},

});
this.area.node.contentEditable = true;
this.area.node.oninput = function() {
Expand Down
Expand Up @@ -106,6 +106,7 @@
$('#'+mwTabContentLocaleId).find('.tab-pane textarea').each(function () {
mw.Editor({
selector: $(this),
lang: this.lang,
mode: 'div',
smallEditor: false,
minHeight: 250,
Expand Down
Expand Up @@ -21,6 +21,12 @@
&.custom-switch {
padding-inline-start: $custom-control-gutter + $custom-control-indicator-size;
}
&.custom-switch {
.custom-control-label{
position: relative;
}

}
}


Expand Down Expand Up @@ -83,7 +89,7 @@
// Build the custom controls out of pseudo-elements.

.custom-control-label {
position: relative;
position: static;
margin-bottom: 0;
color: $custom-control-label-color;
vertical-align: top;
Expand Down Expand Up @@ -181,6 +187,17 @@ html[dir="rtl"] {
}
}

html[dir="rtl"] {
.custom-radio,
.custom-checkbox {
.custom-control-label:before,
.custom-control-label:after{
left: auto !important;
right: 0 !important;
}
}
}

// Radios
//
// Tweak just a few things for radios.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

0 comments on commit 9696f0f

Please sign in to comment.