From d4f7a1038c6ce8b8422b1431269a4d2152822b81 Mon Sep 17 00:00:00 2001 From: Tony Butler Date: Thu, 20 Jul 2017 15:45:10 +0100 Subject: [PATCH] atto_styles: Try parent node if no class attribute when removing styles --- .../moodle-atto_styles-button-debug.js | 5 ++++- .../moodle-atto_styles-button-min.js | 2 +- .../moodle-atto_styles-button/moodle-atto_styles-button.js | 5 ++++- yui/src/button/js/button.js | 5 ++++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/yui/build/moodle-atto_styles-button/moodle-atto_styles-button-debug.js b/yui/build/moodle-atto_styles-button/moodle-atto_styles-button-debug.js index 1bb7695..bdd130f 100644 --- a/yui/build/moodle-atto_styles-button/moodle-atto_styles-button-debug.js +++ b/yui/build/moodle-atto_styles-button/moodle-atto_styles-button-debug.js @@ -116,9 +116,12 @@ Y.namespace('M.atto_styles').Button = Y.Base.create('button', Y.M.editor_atto.Ed return; } for (p = element; p; p = p.parentNode) { - if (p.nodeType !== 1) { + if (p.nodeType !== 1 || !p.getAttribute('class')) { continue; } + if (p.getAttribute('class').search('editor_atto_content') != -1) { + break; + } pstyle = window.getComputedStyle(p, null); if (pstyle) { p.removeAttribute('class'); diff --git a/yui/build/moodle-atto_styles-button/moodle-atto_styles-button-min.js b/yui/build/moodle-atto_styles-button/moodle-atto_styles-button-min.js index 3c4795e..9b178b7 100644 --- a/yui/build/moodle-atto_styles-button/moodle-atto_styles-button-min.js +++ b/yui/build/moodle-atto_styles-button/moodle-atto_styles-button-min.js @@ -1 +1 @@ -YUI.add("moodle-atto_styles-button",function(l,t){l.namespace("M.atto_styles").Button=l.Base.create("button",l.M.editor_atto.EditorPlugin,[],{initializer:function(){var e,s,n,i,o,t=this.get("styles"),t=JSON.parse(t),a=[];l.Array.each(t,function(t){e="",s="",n='',i="","nostyle"===t.type?(e='',s=''):"block"===t.type?(e='',s=''):"inline"==t.type&&(e='',s='',i='
'+M.util.get_string("inlinehint","atto_styles")+""),!0===t.preview&&(n=''),a.push({text:s+e+n+t.title+""+i+"
",callbackArgs:["<"+t.type+">",t.classes]})}),o=this._showToolbarMenu,this._showToolbarMenu=function(t,e){o.call(this,t,e),t=this.hasRangeSelected(),e=this.menus[e.buttonClass].get("contentBox"),t?e.removeClass("disableinline"):e.addClass("disableinline"),this.toolbar.after("click",l.bind(this._setDropdownHeight,this)),l.on("windowresize",l.bind(this._setDropdownHeight,this))},this.addToolbarMenu({icon:"icon",iconComponent:"atto_styles",buttonClass:"styles",globalItemConfig:{callback:this._changeStyle},items:a})},_changeStyle:function(t,e){var s,n,i,o,a,l,r;if(""!==e[0]){if(""===e[0]){if(document.execCommand("formatBlock",!1,"
"),n=window.getSelection().focusNode,!this.editor.contains(n))return;for(i=n;i;i=i.parentNode)if(1===i.nodeType&&(o=window.getComputedStyle(i,null))&&"block"===o.getPropertyValue("display")){s=i;break}s.setAttribute("class",e[1])}else for(a=e[1].split(" "),l=this.get("host"),r=0;r",s="",i='',n="","nostyle"===t.type?(e='',s=''):"block"===t.type?(e='',s=''):"inline"==t.type&&(e='',s='',n='
'+M.util.get_string("inlinehint","atto_styles")+""),!0===t.preview&&(i=''),a.push({text:s+e+i+t.title+""+n+"
",callbackArgs:["<"+t.type+">",t.classes]})}),o=this._showToolbarMenu,this._showToolbarMenu=function(t,e){o.call(this,t,e),t=this.hasRangeSelected(),e=this.menus[e.buttonClass].get("contentBox"),t?e.removeClass("disableinline"):e.addClass("disableinline"),this.toolbar.after("click",l.bind(this._setDropdownHeight,this)),l.on("windowresize",l.bind(this._setDropdownHeight,this))},this.addToolbarMenu({icon:"icon",iconComponent:"atto_styles",buttonClass:"styles",globalItemConfig:{callback:this._changeStyle},items:a})},_changeStyle:function(t,e){var s,i,n,o,a,l,r;if(""!==e[0]){if(""===e[0]){if(document.execCommand("formatBlock",!1,"
"),i=window.getSelection().focusNode,!this.editor.contains(i))return;for(n=i;n;n=n.parentNode)if(1===n.nodeType&&(o=window.getComputedStyle(n,null))&&"block"===o.getPropertyValue("display")){s=n;break}s.setAttribute("class",e[1])}else for(a=e[1].split(" "),l=this.get("host"),r=0;r