From 31d62654a68291c413dfc9f296d661d8ff8a152a Mon Sep 17 00:00:00 2001 From: Shamim Rezaie Date: Wed, 4 Mar 2020 22:59:21 +1100 Subject: [PATCH] MDL-45227 atto_rtl: Automatically set alignment when direction changes --- .../moodle-atto_rtl-button/moodle-atto_rtl-button-debug.js | 6 ++++++ .../moodle-atto_rtl-button/moodle-atto_rtl-button-min.js | 2 +- .../build/moodle-atto_rtl-button/moodle-atto_rtl-button.js | 6 ++++++ lib/editor/atto/plugins/rtl/yui/src/button/js/button.js | 6 ++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/editor/atto/plugins/rtl/yui/build/moodle-atto_rtl-button/moodle-atto_rtl-button-debug.js b/lib/editor/atto/plugins/rtl/yui/build/moodle-atto_rtl-button/moodle-atto_rtl-button-debug.js index 10f02f577e7..1a7e8f1f0ec 100644 --- a/lib/editor/atto/plugins/rtl/yui/build/moodle-atto_rtl-button/moodle-atto_rtl-button-debug.js +++ b/lib/editor/atto/plugins/rtl/yui/build/moodle-atto_rtl-button/moodle-atto_rtl-button-debug.js @@ -72,6 +72,10 @@ Y.namespace('M.atto_rtl').Button = Y.Base.create('button', Y.M.editor_atto.Edito newDirection = { rtl: 'ltr', ltr: 'rtl' + }, + directionAlignment = { + rtl: 'right', + ltr: 'left' }; if (selection) { // Format the selection to be sure it has a tag parent (not the contenteditable). @@ -81,8 +85,10 @@ Y.namespace('M.atto_rtl').Button = Y.Base.create('button', Y.M.editor_atto.Edito var currentDirection = parentDOMNode.getAttribute('dir'); if (currentDirection === direction) { parentDOMNode.setAttribute("dir", newDirection[direction]); + parentDOMNode.style.textAlign = directionAlignment[newDirection[direction]]; } else { parentDOMNode.setAttribute("dir", direction); + parentDOMNode.style.textAlign = directionAlignment[direction]; } // Change selection from the containing paragraph to the original one. diff --git a/lib/editor/atto/plugins/rtl/yui/build/moodle-atto_rtl-button/moodle-atto_rtl-button-min.js b/lib/editor/atto/plugins/rtl/yui/build/moodle-atto_rtl-button/moodle-atto_rtl-button-min.js index 687aea1c1bd..b74d11056b7 100644 --- a/lib/editor/atto/plugins/rtl/yui/build/moodle-atto_rtl-button/moodle-atto_rtl-button-min.js +++ b/lib/editor/atto/plugins/rtl/yui/build/moodle-atto_rtl-button/moodle-atto_rtl-button-min.js @@ -1 +1 @@ -YUI.add("moodle-atto_rtl-button",function(e,t){e.namespace("M.atto_rtl").Button=e.Base.create("button",e.M.editor_atto.EditorPlugin,[],{initializer:function(){var e;e="ltr",this.addButton({icon:"e/left_to_right",title:e,buttonName:e,callback:this._toggleRTL,callbackArgs:e,tags:"[dir=ltr]"}),e="rtl",this.addButton({icon:"e/right_to_left",title:e,buttonName:e,callback:this._toggleRTL,callbackArgs:e,tags:"[dir=rtl]"})},_toggleRTL:function(e,t){var n=this.get("host"),r=window.rangy.saveSelection(),i=n.getSelection(),s={rtl:"ltr",ltr:"rtl"};if(i){var o=n.formatSelectionBlock(),u=o.getDOMNode(),a=u.getAttribute("dir");a===t?u.setAttribute("dir",s[t]):u.setAttribute("dir",t),window.rangy.restoreSelection(r),this.markUpdated()}}})},"@VERSION@",{requires:["moodle-editor_atto-plugin"]}); +YUI.add("moodle-atto_rtl-button",function(e,t){e.namespace("M.atto_rtl").Button=e.Base.create("button",e.M.editor_atto.EditorPlugin,[],{initializer:function(){var e;e="ltr",this.addButton({icon:"e/left_to_right",title:e,buttonName:e,callback:this._toggleRTL,callbackArgs:e,tags:"[dir=ltr]"}),e="rtl",this.addButton({icon:"e/right_to_left",title:e,buttonName:e,callback:this._toggleRTL,callbackArgs:e,tags:"[dir=rtl]"})},_toggleRTL:function(e,t){var n=this.get("host"),r=window.rangy.saveSelection(),i=n.getSelection(),s={rtl:"ltr",ltr:"rtl"},o={rtl:"right",ltr:"left"};if(i){var u=n.formatSelectionBlock(),a=u.getDOMNode(),f=a.getAttribute("dir");f===t?(a.setAttribute("dir",s[t]),a.style.textAlign=o[s[t]]):(a.setAttribute("dir",t),a.style.textAlign=o[t]),window.rangy.restoreSelection(r),this.markUpdated()}}})},"@VERSION@",{requires:["moodle-editor_atto-plugin"]}); diff --git a/lib/editor/atto/plugins/rtl/yui/build/moodle-atto_rtl-button/moodle-atto_rtl-button.js b/lib/editor/atto/plugins/rtl/yui/build/moodle-atto_rtl-button/moodle-atto_rtl-button.js index 10f02f577e7..1a7e8f1f0ec 100644 --- a/lib/editor/atto/plugins/rtl/yui/build/moodle-atto_rtl-button/moodle-atto_rtl-button.js +++ b/lib/editor/atto/plugins/rtl/yui/build/moodle-atto_rtl-button/moodle-atto_rtl-button.js @@ -72,6 +72,10 @@ Y.namespace('M.atto_rtl').Button = Y.Base.create('button', Y.M.editor_atto.Edito newDirection = { rtl: 'ltr', ltr: 'rtl' + }, + directionAlignment = { + rtl: 'right', + ltr: 'left' }; if (selection) { // Format the selection to be sure it has a tag parent (not the contenteditable). @@ -81,8 +85,10 @@ Y.namespace('M.atto_rtl').Button = Y.Base.create('button', Y.M.editor_atto.Edito var currentDirection = parentDOMNode.getAttribute('dir'); if (currentDirection === direction) { parentDOMNode.setAttribute("dir", newDirection[direction]); + parentDOMNode.style.textAlign = directionAlignment[newDirection[direction]]; } else { parentDOMNode.setAttribute("dir", direction); + parentDOMNode.style.textAlign = directionAlignment[direction]; } // Change selection from the containing paragraph to the original one. diff --git a/lib/editor/atto/plugins/rtl/yui/src/button/js/button.js b/lib/editor/atto/plugins/rtl/yui/src/button/js/button.js index 724c21d7f61..7cca17ced50 100644 --- a/lib/editor/atto/plugins/rtl/yui/src/button/js/button.js +++ b/lib/editor/atto/plugins/rtl/yui/src/button/js/button.js @@ -70,6 +70,10 @@ Y.namespace('M.atto_rtl').Button = Y.Base.create('button', Y.M.editor_atto.Edito newDirection = { rtl: 'ltr', ltr: 'rtl' + }, + directionAlignment = { + rtl: 'right', + ltr: 'left' }; if (selection) { // Format the selection to be sure it has a tag parent (not the contenteditable). @@ -79,8 +83,10 @@ Y.namespace('M.atto_rtl').Button = Y.Base.create('button', Y.M.editor_atto.Edito var currentDirection = parentDOMNode.getAttribute('dir'); if (currentDirection === direction) { parentDOMNode.setAttribute("dir", newDirection[direction]); + parentDOMNode.style.textAlign = directionAlignment[newDirection[direction]]; } else { parentDOMNode.setAttribute("dir", direction); + parentDOMNode.style.textAlign = directionAlignment[direction]; } // Change selection from the containing paragraph to the original one.