From 3bf355e37a50d1f26dee75fdbaf1bd03fc7b3f31 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Fri, 21 Oct 2022 18:46:07 +0100 Subject: [PATCH] MDL-75848 editor_atto: fix console error when clicking toolbar menu. --- .../moodle-editor_atto-plugin-debug.js | 4 ++-- .../moodle-editor_atto-plugin-min.js | 4 ++-- .../moodle-editor_atto-plugin/moodle-editor_atto-plugin.js | 4 ++-- lib/editor/atto/yui/src/editor/js/editor-plugin-buttons.js | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/editor/atto/yui/build/moodle-editor_atto-plugin/moodle-editor_atto-plugin-debug.js b/lib/editor/atto/yui/build/moodle-editor_atto-plugin/moodle-editor_atto-plugin-debug.js index 79359ae24ce..cf612ed6c6c 100644 --- a/lib/editor/atto/yui/build/moodle-editor_atto-plugin/moodle-editor_atto-plugin-debug.js +++ b/lib/editor/atto/yui/build/moodle-editor_atto-plugin/moodle-editor_atto-plugin-debug.js @@ -601,9 +601,9 @@ EditorPluginButtons.prototype = { return; } + // Ensure menu button was clicked, and isn't itself disabled. var menuButton = e.currentTarget.ancestor('button', true); - if (menuButton.hasAttribute(DISABLED)) { - // Exit early if the clicked button was disabled. + if (menuButton === null || menuButton.hasAttribute(DISABLED)) { return; } diff --git a/lib/editor/atto/yui/build/moodle-editor_atto-plugin/moodle-editor_atto-plugin-min.js b/lib/editor/atto/yui/build/moodle-editor_atto-plugin/moodle-editor_atto-plugin-min.js index 7ccd5c7da31..9079bdeb62a 100644 --- a/lib/editor/atto/yui/build/moodle-editor_atto-plugin/moodle-editor_atto-plugin-min.js +++ b/lib/editor/atto/yui/build/moodle-editor_atto-plugin/moodle-editor_atto-plugin-min.js @@ -1,2 +1,2 @@ -YUI.add("moodle-editor_atto-plugin",function(r,s){var i,o,n,u,l,h;function t(){t.superclass.constructor.apply(this,arguments)}function e(){}function a(){}i="_group",r.extend(t,r.Base,{name:null,editor:null,toolbar:null,initializer:function(t){this.name=t.name,this.toolbar=t.toolbar,this.editor=t.editor,this.buttons={},this.buttonNames=[],this.buttonStates={},this.menus={},this._primaryKeyboardShortcut=[],this._buttonHandlers=[],this._menuHideHandlers=[],this._highlightQueue={}},markUpdated:function(){return this.get("host").saveSelection(),this.get("host").updateOriginal()}},{NAME:"editorPlugin",ATTRS:{host:{writeOnce:!0},group:{writeOnce:!0,getter:function(t){var e=this.toolbar.one(".atto_group."+t+i);return e||(e=r.Node.create('
'),this.toolbar.append(e)),e}}}}),r.namespace("M.editor_atto").EditorPlugin=t,o="disabled",n="highlight",u=".editor_atto_content",l=".editor_atto_menu_icon",h=".editor_atto_menu_expand",e.ATTRS={},e.prototype={buttons:null,buttonNames:null,buttonStates:null,menus:null,DISABLED:0,ENABLED:1,_buttonHandlers:null,_menuHideHandlers:null,_primaryKeyboardShortcut:null,_highlightQueue:null,addButton:function(e){var i,n,t=this.get("group"),o=this.name,a="atto_"+o+"_button",s=this.get("host");return e.exec&&(a=a+"_"+e.exec),e.buttonName?a=a+"_"+e.buttonName:e.buttonName=e.exec||o,e.buttonClass=a,(e=this._normalizeIcon(e)).title||(e.title="pluginname"),o=M.util.get_string(e.title,"atto_"+o),(i=r.Node.create('')).setAttribute("title",o),i.setAttribute("aria-label",o),window.require(["core/templates"],function(t){t.renderPix(e.icon,e.iconComponent,"").then(function(t){i.append(t)})}),t.append(i),this.toolbar.getAttribute("aria-activedescendant")||(i.setAttribute("tabindex","0"),this.toolbar.setAttribute("aria-activedescendant",i.generateID()),this.get("host")._tabFocus=i),e=this._normalizeCallback(e),this._buttonHandlers.push(this.toolbar.delegate("click",e.callback,"."+a,this)),e.keys&&("undefined"!=typeof e.keyDescription&&(this._primaryKeyboardShortcut[a]=e.keyDescription),this._addKeyboardListener(e.callback,e.keys,a),this._primaryKeyboardShortcut[a]&&(o=M.util.get_string("plugin_title_shortcut","editor_atto",{title:o,shortcut:this._primaryKeyboardShortcut[a]}),i.setAttribute("title",o),i.setAttribute("aria-label",o))),e.tags&&(n=!0,"boolean"==typeof e.tagMatchRequiresAll&&(n=e.tagMatchRequiresAll),this._buttonHandlers.push(s.on(["atto:selectionchanged","change"],function(t){"undefined"!=typeof this._highlightQueue[e.buttonName]&&this._highlightQueue[e.buttonName].cancel(),this._highlightQueue[e.buttonName]=r.soon(r.bind(function(t){s.selectionFilterMatches(e.tags,t.selectedNodes,n)?this.highlightButtons(e.buttonName):this.unHighlightButtons(e.buttonName)},this,t))},this))),this.buttonNames.push(e.buttonName),this.buttons[e.buttonName]=i,this.buttonStates[e.buttonName]=this.ENABLED,i},addBasicButton:function(t){return t.exec?(t.icon||(t.icon="e/"+t.exec),t.callback=function(){document.execCommand(t.exec,!1,null),this.markUpdated()},this.addButton(t)):null},addToolbarMenu:function(e){var i,t,n,o=this.get("group"),a=this.name,s="atto_"+a+"_button";return e.buttonName?s=s+"_"+e.buttonName:e.buttonName=a,e.buttonClass=s,(e=this._normalizeIcon(e)).title||(e.title="pluginname"),t=M.util.get_string(e.title,"atto_"+a),e.menuColor||(e.menuColor="transparent"),a="atto_"+a+"_menubutton_"+r.stamp(this),n=r.Handlebars.compile(''),i=r.Node.create(n({buttonClass:s,config:e,title:t,id:a})),e.buttonId=a,window.require(["core/templates"],function(t){t.renderPix(e.icon,e.iconComponent,"").then(function(t){i.one(l).append(t)}),t.renderPix("t/expanded","core","").then(function(t){i.one(h).append(t)})}),o.append(i),o.append(r.Node.create('')),e.attachmentPoint="#"+a+"_menu",this.toolbar.getAttribute("aria-activedescendant")||(i.setAttribute("tabindex","0"),this.toolbar.setAttribute("aria-activedescendant",i.generateID())),this._buttonHandlers.push(this.toolbar.delegate("click",this._showToolbarMenu,"."+s,this,e),this.toolbar.delegate("key",this._showToolbarMenuAndFocus,"40, 32, enter","."+s,this,e)),this.buttonNames.push(e.buttonName),this.buttons[e.buttonName]=i,this.buttonStates[e.buttonName]=this.ENABLED,i},_showToolbarMenu:function(t,e){var i,n;t.preventDefault(),this.isEnabled()&&((t=t.currentTarget.ancestor("button",!0)).hasAttribute(o)||(this.menus[e.buttonClass]||(e.overlayWidth||(e.overlayWidth="14"),e.innerOverlayWidth||(e.innerOverlayWidth=parseInt(e.overlayWidth,10)-2+"em"),e.overlayWidth=parseInt(e.overlayWidth,10)+"em",this.menus[e.buttonClass]=new r.M.editor_atto.Menu(e),this.menus[e.buttonClass].get("contentBox").delegate("click",this._chooseMenuItem,".atto_menuentry a",this,e)),r.Array.each(this.get("host").openMenus,function(t){t.set("focusAfterHide",null)}),(n=this.buttons[e.buttonName]).focus(),this.get("host")._setTabFocus(n),(i=this.menus[e.buttonClass]).set("focusAfterHide",n),i.show(),t.setAttribute("aria-expanded",!0),i.align(this.buttons[e.buttonName],[r.WidgetPositionAlign.TL,r.WidgetPositionAlign.BL]),this.get("host").openMenus=[i]))},_showToolbarMenuAndFocus:function(t,e){this._showToolbarMenu(t,e),this.menus[e.buttonClass].get("boundingBox").one("a").focus()},_chooseMenuItem:function(t,e,i){var n=t.target.ancestor("a",!0).getData("index"),n=this._normalizeCallback(e.items[n],e.globalItemConfig);(i=this.menus[e.buttonClass]).set("preventHideMenu",!0),n.callback(t,n._callback,n.callbackArgs),i.set("preventHideMenu",!1),i.set("focusAfterHide",this.get("host").editor),i.hide(t)},_normalizeCallback:function(i,t){return i._callbackNormalized||(t=t||{}, -i.inlineFormat=i.inlineFormat||t.inlineFormat,i._inlineCallback=i.callback||t.callback,i._callback=i.callback||t.callback,i.inlineFormat&&"function"==typeof i._inlineCallback&&(i._callback=function(t,e){this.get("host").applyFormat(t,i._inlineCallback,this,e)}),i.callback=r.rbind(this._callbackWrapper,this,i._callback,i.callbackArgs),i._callbackNormalized=!0),i},_normalizeIcon:function(t){return t.iconurl||(t.iconComponent&&"moodle"!=t.iconComponent||(t.iconComponent="core"),t.iconurl=M.util.image_url(t.icon,t.iconComponent)),t},_callbackWrapper:function(t,e,i){var n;if(t.preventDefault(),this.isEnabled()&&(!(n=t.currentTarget.ancestor("button",!0))||!n.hasAttribute(o)))return YUI.Env.UA.android||this.get("host").isActive()||this.get("host").focus(),this.get("host").saveSelection(),n&&this.get("host")._setTabFocus(n),n=[t,i],this.get("host").restoreSelection(),e.apply(this,n)},_addKeyboardListener:function(i,t,e){var n,o,a="key",s=u;if(r.Lang.isArray(t))return r.Array.each(t,function(t){this._addKeyboardListener(i,t)},this),this;e="object"==typeof t?(t.eventtype&&(a=t.eventtype),t.container&&(s=t.container),n=t.keyCodes,i):(o=this._getDefaultMetaKey(),n=this._getKeyEvent()+t+"+"+o,"undefined"==typeof this._primaryKeyboardShortcut[e]&&(this._primaryKeyboardShortcut[e]=this._getDefaultMetaKeyDescription(t)),r.bind(function(t,e){this._eventUsesExactKeyModifiers(t,e)&&i.apply(this,[e])},this,[o])),this._buttonHandlers.push(this.editor.delegate(a,e,n,s,this))},_eventUsesExactKeyModifiers:function(t,e){var i,n;return"key"===e.type&&(n=-1'),this.toolbar.append(e)),e}}}}),r.namespace("M.editor_atto").EditorPlugin=t,o="disabled",n="highlight",u=".editor_atto_content",l=".editor_atto_menu_icon",h=".editor_atto_menu_expand",e.ATTRS={},e.prototype={buttons:null,buttonNames:null,buttonStates:null,menus:null,DISABLED:0,ENABLED:1,_buttonHandlers:null,_menuHideHandlers:null,_primaryKeyboardShortcut:null,_highlightQueue:null,addButton:function(e){var i,n,t=this.get("group"),o=this.name,a="atto_"+o+"_button",s=this.get("host");return e.exec&&(a=a+"_"+e.exec),e.buttonName?a=a+"_"+e.buttonName:e.buttonName=e.exec||o,e.buttonClass=a,(e=this._normalizeIcon(e)).title||(e.title="pluginname"),o=M.util.get_string(e.title,"atto_"+o),(i=r.Node.create('')).setAttribute("title",o),i.setAttribute("aria-label",o),window.require(["core/templates"],function(t){t.renderPix(e.icon,e.iconComponent,"").then(function(t){i.append(t)})}),t.append(i),this.toolbar.getAttribute("aria-activedescendant")||(i.setAttribute("tabindex","0"),this.toolbar.setAttribute("aria-activedescendant",i.generateID()),this.get("host")._tabFocus=i),e=this._normalizeCallback(e),this._buttonHandlers.push(this.toolbar.delegate("click",e.callback,"."+a,this)),e.keys&&("undefined"!=typeof e.keyDescription&&(this._primaryKeyboardShortcut[a]=e.keyDescription),this._addKeyboardListener(e.callback,e.keys,a),this._primaryKeyboardShortcut[a]&&(o=M.util.get_string("plugin_title_shortcut","editor_atto",{title:o,shortcut:this._primaryKeyboardShortcut[a]}),i.setAttribute("title",o),i.setAttribute("aria-label",o))),e.tags&&(n=!0,"boolean"==typeof e.tagMatchRequiresAll&&(n=e.tagMatchRequiresAll),this._buttonHandlers.push(s.on(["atto:selectionchanged","change"],function(t){"undefined"!=typeof this._highlightQueue[e.buttonName]&&this._highlightQueue[e.buttonName].cancel(),this._highlightQueue[e.buttonName]=r.soon(r.bind(function(t){s.selectionFilterMatches(e.tags,t.selectedNodes,n)?this.highlightButtons(e.buttonName):this.unHighlightButtons(e.buttonName)},this,t))},this))),this.buttonNames.push(e.buttonName),this.buttons[e.buttonName]=i,this.buttonStates[e.buttonName]=this.ENABLED,i},addBasicButton:function(t){return t.exec?(t.icon||(t.icon="e/"+t.exec),t.callback=function(){document.execCommand(t.exec,!1,null),this.markUpdated()},this.addButton(t)):null},addToolbarMenu:function(e){var i,t,n,o=this.get("group"),a=this.name,s="atto_"+a+"_button";return e.buttonName?s=s+"_"+e.buttonName:e.buttonName=a,e.buttonClass=s,(e=this._normalizeIcon(e)).title||(e.title="pluginname"),t=M.util.get_string(e.title,"atto_"+a),e.menuColor||(e.menuColor="transparent"),a="atto_"+a+"_menubutton_"+r.stamp(this),n=r.Handlebars.compile(''),i=r.Node.create(n({buttonClass:s,config:e,title:t,id:a})),e.buttonId=a,window.require(["core/templates"],function(t){t.renderPix(e.icon,e.iconComponent,"").then(function(t){i.one(l).append(t)}),t.renderPix("t/expanded","core","").then(function(t){i.one(h).append(t)})}),o.append(i),o.append(r.Node.create('')),e.attachmentPoint="#"+a+"_menu",this.toolbar.getAttribute("aria-activedescendant")||(i.setAttribute("tabindex","0"),this.toolbar.setAttribute("aria-activedescendant",i.generateID())),this._buttonHandlers.push(this.toolbar.delegate("click",this._showToolbarMenu,"."+s,this,e),this.toolbar.delegate("key",this._showToolbarMenuAndFocus,"40, 32, enter","."+s,this,e)),this.buttonNames.push(e.buttonName),this.buttons[e.buttonName]=i,this.buttonStates[e.buttonName]=this.ENABLED,i},_showToolbarMenu:function(t,e){var i,n;t.preventDefault(),this.isEnabled()&&(null===(t=t.currentTarget.ancestor("button",!0))||t.hasAttribute(o)||(this.menus[e.buttonClass]||(e.overlayWidth||(e.overlayWidth="14"),e.innerOverlayWidth||(e.innerOverlayWidth=parseInt(e.overlayWidth,10)-2+"em"),e.overlayWidth=parseInt(e.overlayWidth,10)+"em",this.menus[e.buttonClass]=new r.M.editor_atto.Menu(e),this.menus[e.buttonClass].get("contentBox").delegate("click",this._chooseMenuItem,".atto_menuentry a",this,e)),r.Array.each(this.get("host").openMenus,function(t){t.set("focusAfterHide",null)}),(n=this.buttons[e.buttonName]).focus(),this.get("host")._setTabFocus(n),(i=this.menus[e.buttonClass]).set("focusAfterHide",n),i.show(),t.setAttribute("aria-expanded",!0),i.align(this.buttons[e.buttonName],[r.WidgetPositionAlign.TL,r.WidgetPositionAlign.BL]),this.get("host").openMenus=[i]))},_showToolbarMenuAndFocus:function(t,e){this._showToolbarMenu(t,e),this.menus[e.buttonClass].get("boundingBox").one("a").focus()},_chooseMenuItem:function(t,e,i){var n=t.target.ancestor("a",!0).getData("index"),n=this._normalizeCallback(e.items[n],e.globalItemConfig);(i=this.menus[e.buttonClass]).set("preventHideMenu",!0),n.callback(t,n._callback,n.callbackArgs),i.set("preventHideMenu",!1),i.set("focusAfterHide",this.get("host").editor),i.hide(t)},_normalizeCallback:function(i,t){return i._callbackNormalized||( +t=t||{},i.inlineFormat=i.inlineFormat||t.inlineFormat,i._inlineCallback=i.callback||t.callback,i._callback=i.callback||t.callback,i.inlineFormat&&"function"==typeof i._inlineCallback&&(i._callback=function(t,e){this.get("host").applyFormat(t,i._inlineCallback,this,e)}),i.callback=r.rbind(this._callbackWrapper,this,i._callback,i.callbackArgs),i._callbackNormalized=!0),i},_normalizeIcon:function(t){return t.iconurl||(t.iconComponent&&"moodle"!=t.iconComponent||(t.iconComponent="core"),t.iconurl=M.util.image_url(t.icon,t.iconComponent)),t},_callbackWrapper:function(t,e,i){var n;if(t.preventDefault(),this.isEnabled()&&(!(n=t.currentTarget.ancestor("button",!0))||!n.hasAttribute(o)))return YUI.Env.UA.android||this.get("host").isActive()||this.get("host").focus(),this.get("host").saveSelection(),n&&this.get("host")._setTabFocus(n),n=[t,i],this.get("host").restoreSelection(),e.apply(this,n)},_addKeyboardListener:function(i,t,e){var n,o,a="key",s=u;if(r.Lang.isArray(t))return r.Array.each(t,function(t){this._addKeyboardListener(i,t)},this),this;e="object"==typeof t?(t.eventtype&&(a=t.eventtype),t.container&&(s=t.container),n=t.keyCodes,i):(o=this._getDefaultMetaKey(),n=this._getKeyEvent()+t+"+"+o,"undefined"==typeof this._primaryKeyboardShortcut[e]&&(this._primaryKeyboardShortcut[e]=this._getDefaultMetaKeyDescription(t)),r.bind(function(t,e){this._eventUsesExactKeyModifiers(t,e)&&i.apply(this,[e])},this,[o])),this._buttonHandlers.push(this.editor.delegate(a,e,n,s,this))},_eventUsesExactKeyModifiers:function(t,e){var i,n;return"key"===e.type&&(n=-1