Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal RTL support #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/css/editor.styl
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ editor-input-fgcolor ?= #000
&.{editor-class-prefix}menu span.{editor-class-prefix}menu-arrow
color lighten(editor-fgcolor, -50%)

.{editor-class-prefix}controls.rtl li,
html[dir='rtl'] .{editor-class-prefix}controls li
float right

li button
text-align right


.{editor-class-prefix}dialog
padding 6px
font-size 12px
Expand Down
6 changes: 3 additions & 3 deletions src/lib/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ var BaseControl = Class(Object, {
}

var text = document.createTextNode(label);
var span = document.createElement('span');
span.appendChild(text);
if (this.toolbar.options.fontAwesomeEnabled && fontAwesomeID) {
var fa = this.getFaElement(fontAwesomeID);
var span = document.createElement('span');
span.appendChild(text);
fa.appendChild(span);
this.element.appendChild(fa);
} else {
this.element.appendChild(text);
this.element.appendChild(span);
}
},

Expand Down
22 changes: 13 additions & 9 deletions src/lib/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ var HtmlCleaner = require('./html-cleaner').HtmlCleaner;
var Editor = Class(Object, {
defaults: {
delay: 300,
diffLeft: 2,
diffTop: -10,
offsetX: 2,
offsetY: -10,
classPrefix: 'editor-',
fontAwesomeEnabled: true
fontAwesomeEnabled: true,
rtl: false
},
BLOCK_NODES: 'P H1 H2 H3 H4 H5 H6 UL OL PRE DL DIV NOSCRIPT BLOCKQUOTE FORM HR TABLE FIELDSET ADDRESS'.split(' '),

Expand All @@ -37,6 +38,7 @@ var Editor = Class(Object, {
this.isActive = true;
this.isSelected = false;
this.options = extend({}, this.defaults, options);
this.isRtl = this.options.rtl || document.documentElement.getAttribute('dir') === 'rtl';

// Internal properties
this._currentEditor = null;
Expand Down Expand Up @@ -193,16 +195,18 @@ var Editor = Class(Object, {
// Top position
var top = 0;
if (boundary.top < height) {
top = boundary.bottom - this.options.diffTop + window.pageYOffset;
top = boundary.bottom - this.options.offsetY + window.pageYOffset;
} else {
top = boundary.top + this.options.diffTop + window.pageYOffset - height;
top = boundary.top + this.options.offsetY + window.pageYOffset - height;
}

// Left position
var left = boundary.left - this.options.diffLeft;
if (this._currentEditor.offsetWidth < width + boundary.left) {
left = boundary.right - width + this.options.diffLeft;
}
var left = boundary.left - this.options.offsetX,
right = boundary.right - width + this.options.offsetX,
overflowLeft = boundary.right - width < this._currentEditor.offsetLeft,
overflowRight = this._currentEditor.offsetLeft + this._currentEditor.offsetWidth < width + boundary.left;

if ((this.isRtl && !overflowLeft) || overflowRight) left = right;

this.toolbar.move(top, left);
},
Expand Down
1 change: 1 addition & 0 deletions src/lib/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var Toolbar = Class(Object, {
this.dialog = document.createElement('div');

this.container.classList.add(this._getClassName('controls'));
if (this.editor.isRtl) this.container.classList.add('rtl');
this.element.classList.add(this._getClassName('toolbar'));
document.body.appendChild(this.element);

Expand Down