mirror of
https://github.com/moodle/moodle.git
synced 2025-08-08 10:26:40 +02:00
MDL-46497 Atto: Fix adding redundant p elements in rtl/ltr actions
This commit is contained in:
parent
74fad2ce3d
commit
2209309e2c
4 changed files with 19 additions and 7 deletions
|
@ -65,7 +65,9 @@ Y.namespace('M.atto_rtl').Button = Y.Base.create('button', Y.M.editor_atto.Edito
|
||||||
*/
|
*/
|
||||||
_toggleRTL: function(e, direction) {
|
_toggleRTL: function(e, direction) {
|
||||||
var host = this.get('host'),
|
var host = this.get('host'),
|
||||||
selection = host.getSelection();
|
sourceSelection = rangy.saveSelection(),
|
||||||
|
selection = host.getSelection(),
|
||||||
|
newDirection = { rtl: 'ltr', ltr: 'rtl' };
|
||||||
if (selection) {
|
if (selection) {
|
||||||
// Format the selection to be sure it has a tag parent (not the contenteditable).
|
// Format the selection to be sure it has a tag parent (not the contenteditable).
|
||||||
var parentNode = host.formatSelectionBlock(),
|
var parentNode = host.formatSelectionBlock(),
|
||||||
|
@ -73,11 +75,13 @@ Y.namespace('M.atto_rtl').Button = Y.Base.create('button', Y.M.editor_atto.Edito
|
||||||
|
|
||||||
var currentDirection = parentDOMNode.getAttribute('dir');
|
var currentDirection = parentDOMNode.getAttribute('dir');
|
||||||
if (currentDirection === direction) {
|
if (currentDirection === direction) {
|
||||||
parentDOMNode.removeAttribute("dir");
|
parentDOMNode.setAttribute("dir", newDirection[direction]);
|
||||||
} else {
|
} else {
|
||||||
parentDOMNode.setAttribute("dir", direction);
|
parentDOMNode.setAttribute("dir", direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Change selection from the containing paragraph to the original one.
|
||||||
|
rangy.restoreSelection(sourceSelection);
|
||||||
// Mark the text as having been updated.
|
// Mark the text as having been updated.
|
||||||
this.markUpdated();
|
this.markUpdated();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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}),e="rtl",this.addButton({icon:"e/right_to_left",title:e,buttonName:e,callback:this._toggleRTL,callbackArgs:e})},_toggleRTL:function(e,t){var n=this.get("host"),r=n.getSelection();if(r){var i=n.formatSelectionBlock(),s=i.getDOMNode(),o=s.getAttribute("dir");o===t?s.removeAttribute("dir"):s.setAttribute("dir",t),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}),e="rtl",this.addButton({icon:"e/right_to_left",title:e,buttonName:e,callback:this._toggleRTL,callbackArgs:e})},_toggleRTL:function(e,t){var n=this.get("host"),r=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),rangy.restoreSelection(r),this.markUpdated()}}})},"@VERSION@",{requires:["moodle-editor_atto-plugin"]});
|
||||||
|
|
|
@ -65,7 +65,9 @@ Y.namespace('M.atto_rtl').Button = Y.Base.create('button', Y.M.editor_atto.Edito
|
||||||
*/
|
*/
|
||||||
_toggleRTL: function(e, direction) {
|
_toggleRTL: function(e, direction) {
|
||||||
var host = this.get('host'),
|
var host = this.get('host'),
|
||||||
selection = host.getSelection();
|
sourceSelection = rangy.saveSelection(),
|
||||||
|
selection = host.getSelection(),
|
||||||
|
newDirection = { rtl: 'ltr', ltr: 'rtl' };
|
||||||
if (selection) {
|
if (selection) {
|
||||||
// Format the selection to be sure it has a tag parent (not the contenteditable).
|
// Format the selection to be sure it has a tag parent (not the contenteditable).
|
||||||
var parentNode = host.formatSelectionBlock(),
|
var parentNode = host.formatSelectionBlock(),
|
||||||
|
@ -73,11 +75,13 @@ Y.namespace('M.atto_rtl').Button = Y.Base.create('button', Y.M.editor_atto.Edito
|
||||||
|
|
||||||
var currentDirection = parentDOMNode.getAttribute('dir');
|
var currentDirection = parentDOMNode.getAttribute('dir');
|
||||||
if (currentDirection === direction) {
|
if (currentDirection === direction) {
|
||||||
parentDOMNode.removeAttribute("dir");
|
parentDOMNode.setAttribute("dir", newDirection[direction]);
|
||||||
} else {
|
} else {
|
||||||
parentDOMNode.setAttribute("dir", direction);
|
parentDOMNode.setAttribute("dir", direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Change selection from the containing paragraph to the original one.
|
||||||
|
rangy.restoreSelection(sourceSelection);
|
||||||
// Mark the text as having been updated.
|
// Mark the text as having been updated.
|
||||||
this.markUpdated();
|
this.markUpdated();
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,9 @@ Y.namespace('M.atto_rtl').Button = Y.Base.create('button', Y.M.editor_atto.Edito
|
||||||
*/
|
*/
|
||||||
_toggleRTL: function(e, direction) {
|
_toggleRTL: function(e, direction) {
|
||||||
var host = this.get('host'),
|
var host = this.get('host'),
|
||||||
selection = host.getSelection();
|
sourceSelection = rangy.saveSelection(),
|
||||||
|
selection = host.getSelection(),
|
||||||
|
newDirection = { rtl: 'ltr', ltr: 'rtl' };
|
||||||
if (selection) {
|
if (selection) {
|
||||||
// Format the selection to be sure it has a tag parent (not the contenteditable).
|
// Format the selection to be sure it has a tag parent (not the contenteditable).
|
||||||
var parentNode = host.formatSelectionBlock(),
|
var parentNode = host.formatSelectionBlock(),
|
||||||
|
@ -71,11 +73,13 @@ Y.namespace('M.atto_rtl').Button = Y.Base.create('button', Y.M.editor_atto.Edito
|
||||||
|
|
||||||
var currentDirection = parentDOMNode.getAttribute('dir');
|
var currentDirection = parentDOMNode.getAttribute('dir');
|
||||||
if (currentDirection === direction) {
|
if (currentDirection === direction) {
|
||||||
parentDOMNode.removeAttribute("dir");
|
parentDOMNode.setAttribute("dir", newDirection[direction]);
|
||||||
} else {
|
} else {
|
||||||
parentDOMNode.setAttribute("dir", direction);
|
parentDOMNode.setAttribute("dir", direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Change selection from the containing paragraph to the original one.
|
||||||
|
rangy.restoreSelection(sourceSelection);
|
||||||
// Mark the text as having been updated.
|
// Mark the text as having been updated.
|
||||||
this.markUpdated();
|
this.markUpdated();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue