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 4e5a062add7..28b4239df79 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 @@ -616,6 +616,9 @@ EditorPluginButtons.prototype = { * @private */ _hideMenu: function(e, menuDialogue) { + if (menuDialogue.get('preventHideMenu') === true) { + return; + } menuDialogue.hide(); new Y.EventHandle(this._menuHideHandlers).detach(); }, @@ -636,11 +639,18 @@ EditorPluginButtons.prototype = { // And the normalized callback configuration. buttonConfig = this._normalizeCallback(config.items[index], config.globalItemConfig); - // Clear the focus after hide so that focus is returned to the editor and changes are made correctly. - menuDialogue.set('focusAfterHide', null); + // Prevent the dialogue to be closed because of some browser weirdness. + menuDialogue.set('preventHideMenu', true); // Call the callback for this button. buttonConfig.callback(e, buttonConfig._callback, buttonConfig.callbackArgs); + + // Cancel the hide menu prevention. + menuDialogue.set('preventHideMenu', false); + + // Set the focus after hide so that focus is returned to the editor and changes are made correctly. + menuDialogue.set('focusAfterHide', this.get('host').editor); + this._hideMenu(e, menuDialogue); }, /** @@ -720,6 +730,7 @@ EditorPluginButtons.prototype = { * @param {EventFacade} e * @param {Function} callback The function to call which makes the relevant changes. * @param {Array} [callbackArgs] The arguments passed to this callback. + * @return {Mixed} The value returned by the callback. * @private */ _callbackWrapper: function(e, callback, callbackArgs) { @@ -750,7 +761,7 @@ EditorPluginButtons.prototype = { var args = [e, callbackArgs]; // Actually call the callback now. - callback.apply(this, args); + return callback.apply(this, args); }, /** @@ -1128,7 +1139,7 @@ EditorPluginDialogue.prototype = { if (focusAfterHide === true) { this._dialogue.set('focusAfterHide', this.buttons[this.buttonNames[0]]); - } else if (typeof setFocusAfter === 'string') { + } else if (typeof focusAfterHide === 'string') { this._dialogue.set('focusAfterHide', this.buttons[focusAfterHide]); } else { 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 30d52c5a8c8..f8d557ee7b1 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(e,t){function n(){n.superclass.constructor.apply(this,arguments)}function c(){}function h(){}var r=".atto_group.",i="_group";e.extend(n,e.Base,{name:null,editor:null,toolbar:null,initializer:function(e){this.name=e.name,this.toolbar=e.toolbar,this.editor=e.editor,this.buttons={},this.buttonNames=[],this.buttonStates={},this.menus={},this._buttonHandlers=[],this._menuHideHandlers=[]},markUpdated:function(){return this.get("host").updateOriginal()}},{NAME:"editorPlugin",ATTRS:{host:{writeOnce:!0},group:{writeOnce:!0,getter:function(t){var n=this.toolbar.one(r+t+i);return n||(n=e.Node.create('
'),this.toolbar.append(n)),n}}}}),e.namespace("M.editor_atto").EditorPlugin=n;var s='',o='
',u="disabled",a="highlight",f="moodle-editor_atto-editor-plugin",l={EDITORWRAPPER:".editor_atto_content"};c.ATTRS={},c.prototype={buttons:null,buttonNames:null,buttonStates:null,menus:null,DISABLED:0,ENABLED:1,_buttonHandlers:null,_menuHideHandlers:null,addButton:function(t){var n=this.get("group"),r=this.name,i="atto_"+r+"_button",s,o=this.get("host");t.exec&&(i=i+"_"+t.exec),t.buttonName?i=i+"_"+t.buttonName:t.buttonName=t.exec||r,t=this._normalizeIcon(t),t.title||(t.title="pluginname");var u=M.util.get_string(t.title,"atto_"+r);s=e.Node.create('"),s.setAttribute("title",u),n.append(s);var a=this.toolbar.getAttribute("aria-activedescendant");a||(s.setAttribute("tabindex","0"),this.toolbar.setAttribute("aria-activedescendant",s.generateID()),this.get("host")._tabFocus=s),t=this._normalizeCallback(t),this._buttonHandlers.push(this.toolbar.delegate("click",t.callback,"."+i,this)),t.keys&&this._addKeyboardListener(t.callback,t.keys,i);if(t.tags){var f=null;typeof t.tagMatchRequiresAll=="boolean"&&(f=t.tagMatchRequiresAll),this._buttonHandlers.push(o.on("atto:selectionchanged",function(e){o.selectionFilterMatches(t.tags,e.selectedNodes,f)?this.highlightButtons(t.buttonName):this.unHighlightButtons(t.buttonName)},this))}return this.buttonNames.push(t.buttonName),this.buttons[t.buttonName]=s,this.buttonStates[t.buttonName]=this.ENABLED,s},addBasicButton:function(e){return e.exec?(e.icon||(e.icon="e/"+e.exec),e.callback=function(){document.execCommand(e.exec,!1,null),this.markUpdated()},this.addButton(e)):null},addToolbarMenu:function(t){var n=this.get("group"),r=this.name,i="atto_"+r+"_button",o,u;t.buttonName?i=i+"_"+t.buttonName:t.buttonName=r,t=this._normalizeIcon(t),t.title||(t.title="pluginname");var a=M.util.get_string(t.title,"atto_"+r);t.menuColor||(t.menuColor="transparent");var f=e.Handlebars.compile(s);return o=e.Node.create(f({buttonClass:i,config:t,title:a})),n.append(o),u=this.toolbar.getAttribute("aria-activedescendant"),u||(o.setAttribute("tabindex","0"),this.toolbar.setAttribute("aria-activedescendant",o.generateID())),this._buttonHandlers.push(this.toolbar.delegate("click",this._showToolbarMenu,"."+i,this,t),this.toolbar.delegate("key",this._showToolbarMenu,"40, 32, enter","."+i,this,t)),this.buttonNames.push(t.buttonName),this.buttons[t.buttonName]=o,this.buttonStates[t.buttonName]=this.ENABLED,o},_showToolbarMenu:function(t,n){t.preventDefault();if(!this.isEnabled())return;if(t.currentTarget.ancestor("button",!0).hasAttribute(u))return;var r;if(!this.menus[n.buttonClass]){n.overlayWidth||(n.overlayWidth="14"),n.innerOverlayWidth||(n.innerOverlayWidth=parseInt(n.overlayWidth,10)-2+"em"),n.overlayWidth=parseInt(n.overlayWidth,10)+"em";var i=e.Handlebars.compile(o),s=e.Node.create(i({config:n}));this.menus[n.buttonClass]=new M.core.dialogue({bodyContent:s,width:null,visible:!1,center:!1,closeButton:!1,responsive:!1,extraClasses:["editor_atto_menu"]}),r=this.menus[n.buttonClass],r.headerNode.hide(),this._buttonHandlers.push(s.delegate("click",this._chooseMenuItem,".atto_menuentry a",this,n,r),s.delegate("key",this._chooseMenuItem,"32, enter",".atto_menuentry",this,n,r),s.delegate("key",this._menuKeyboardNavigation,"down:38,40",".menu",this),s.delegate("key",this._hideMenu,"down:37,39",".menu",this,r))}var a=this.buttons[n.buttonName];this.get("host")._setTabFocus(a),r=this.menus[n.buttonClass],r.set("focusAfterHide",a),r.show(),r.align(this.buttons[n.buttonName],[e.WidgetPositionAlign.TL,e.WidgetPositionAlign.BL]),r.get("boundingBox").one("a").focus(),this._menuHideHandlers.push(r.get("boundingBox").on("focusoutside",this._hideMenu,this,r))},_hideMenu:function(t,n){n.hide(),(new e.EventHandle(this._menuHideHandlers)).detach()},_chooseMenuItem:function(e,t,n){var r=e.target.ancestor("a",!0).getData("index"),i=this._normalizeCallback(t.items[r],t.globalItemConfig);n.set("focusAfterHide",null),i.callback(e,i._callback,i.callbackArgs)},_normalizeCallback:function(t,n){return t._callbackNormalized?t:(n||(n={}),typeof t.wrapCallback=="undefined"&&(t.wrapCallback=n.wrapCallback||!0),t.wrapCallback?(t._callback=t.callback||n.callback,t.callback=e.rbind(this._callbackWrapper,this,t._callback,t.callbackArgs)):t.callback=t.callback||n.callback,t._callbackNormalized=!0,t)},_normalizeIcon:function(e){return e.iconurl||(e.iconComponent||(e.iconComponent="core"),e.iconurl=M.util.image_url(e.icon,e.iconComponent)),e},_callbackWrapper:function(e,t,n){e -.preventDefault();if(!this.isEnabled())return;var r=e.currentTarget.ancestor("button",!0);if(r&&r.hasAttribute(u))return;this.get("host").isActive()||this.get("host").focus(),r&&this.get("host")._setTabFocus(r);var i=[e,n];t.apply(this,i)},_addKeyboardListener:function(t,n,r){var i="key",s=l.EDITORWRAPPER,o;if(e.Lang.isArray(n))return e.Array.each(n,function(e){this._addKeyboardListener(t,e)},this),this;typeof n=="object"?(n.eventtype&&(i=n.eventtype),n.container&&(s=n.container),o=n.keyCodes):o=this._getKeyEvent()+n+this._getDefaultMetaKey(),this._buttonHandlers.push(this.editor.delegate(i,t,o,s,this))},isEnabled:function(){var t=e.Object.some(this.buttonStates,function(e){return e===this.ENABLED},this);return t},disableButtons:function(e){return this._setButtonState(!1,e)},enableButtons:function(e){return this._setButtonState(!0,e)},_setButtonState:function(t,n){var r="setAttribute";return t&&(r="removeAttribute"),n?this.buttons[n]&&(this.buttons[n][r](u,u),this.buttonStates[n]=t?this.ENABLED:this.DISABLED):e.Array.each(this.buttonNames,function(e){this.buttons[e][r](u,u),this.buttonStates[e]=t?this.ENABLED:this.DISABLED},this),this},highlightButtons:function(e){return this._changeButtonHighlight(!0,e)},unHighlightButtons:function(e){return this._changeButtonHighlight(!1,e)},_changeButtonHighlight:function(t,n){var r="addClass";return t||(r="removeClass"),n?this.buttons[n]&&this.buttons[n][r](a):e.Object.each(this.buttons,function(e){e[r](a)},this),this},_menuKeyboardNavigation:function(e){e.preventDefault();var t=e.currentTarget.all('a[role="menuitem"]'),n=!1,r=0,i=1,s=0,o=e.target.ancestor('a[role="menuitem"]',!0);while(!n&&r=t.size()&&(r=0),next=t.item(r),s++;while(s'),this.toolbar.append(n)),n}}}}),e.namespace("M.editor_atto").EditorPlugin=n;var s='',o='
',u="disabled",a="highlight",f="moodle-editor_atto-editor-plugin",l={EDITORWRAPPER:".editor_atto_content"};c.ATTRS={},c.prototype={buttons:null,buttonNames:null,buttonStates:null,menus:null,DISABLED:0,ENABLED:1,_buttonHandlers:null,_menuHideHandlers:null,addButton:function(t){var n=this.get("group"),r=this.name,i="atto_"+r+"_button",s,o=this.get("host");t.exec&&(i=i+"_"+t.exec),t.buttonName?i=i+"_"+t.buttonName:t.buttonName=t.exec||r,t=this._normalizeIcon(t),t.title||(t.title="pluginname");var u=M.util.get_string(t.title,"atto_"+r);s=e.Node.create('"),s.setAttribute("title",u),n.append(s);var a=this.toolbar.getAttribute("aria-activedescendant");a||(s.setAttribute("tabindex","0"),this.toolbar.setAttribute("aria-activedescendant",s.generateID()),this.get("host")._tabFocus=s),t=this._normalizeCallback(t),this._buttonHandlers.push(this.toolbar.delegate("click",t.callback,"."+i,this)),t.keys&&this._addKeyboardListener(t.callback,t.keys,i);if(t.tags){var f=null;typeof t.tagMatchRequiresAll=="boolean"&&(f=t.tagMatchRequiresAll),this._buttonHandlers.push(o.on("atto:selectionchanged",function(e){o.selectionFilterMatches(t.tags,e.selectedNodes,f)?this.highlightButtons(t.buttonName):this.unHighlightButtons(t.buttonName)},this))}return this.buttonNames.push(t.buttonName),this.buttons[t.buttonName]=s,this.buttonStates[t.buttonName]=this.ENABLED,s},addBasicButton:function(e){return e.exec?(e.icon||(e.icon="e/"+e.exec),e.callback=function(){document.execCommand(e.exec,!1,null),this.markUpdated()},this.addButton(e)):null},addToolbarMenu:function(t){var n=this.get("group"),r=this.name,i="atto_"+r+"_button",o,u;t.buttonName?i=i+"_"+t.buttonName:t.buttonName=r,t=this._normalizeIcon(t),t.title||(t.title="pluginname");var a=M.util.get_string(t.title,"atto_"+r);t.menuColor||(t.menuColor="transparent");var f=e.Handlebars.compile(s);return o=e.Node.create(f({buttonClass:i,config:t,title:a})),n.append(o),u=this.toolbar.getAttribute("aria-activedescendant"),u||(o.setAttribute("tabindex","0"),this.toolbar.setAttribute("aria-activedescendant",o.generateID())),this._buttonHandlers.push(this.toolbar.delegate("click",this._showToolbarMenu,"."+i,this,t),this.toolbar.delegate("key",this._showToolbarMenu,"40, 32, enter","."+i,this,t)),this.buttonNames.push(t.buttonName),this.buttons[t.buttonName]=o,this.buttonStates[t.buttonName]=this.ENABLED,o},_showToolbarMenu:function(t,n){t.preventDefault();if(!this.isEnabled())return;if(t.currentTarget.ancestor("button",!0).hasAttribute(u))return;var r;if(!this.menus[n.buttonClass]){n.overlayWidth||(n.overlayWidth="14"),n.innerOverlayWidth||(n.innerOverlayWidth=parseInt(n.overlayWidth,10)-2+"em"),n.overlayWidth=parseInt(n.overlayWidth,10)+"em";var i=e.Handlebars.compile(o),s=e.Node.create(i({config:n}));this.menus[n.buttonClass]=new M.core.dialogue({bodyContent:s,width:null,visible:!1,center:!1,closeButton:!1,responsive:!1,extraClasses:["editor_atto_menu"]}),r=this.menus[n.buttonClass],r.headerNode.hide(),this._buttonHandlers.push(s.delegate("click",this._chooseMenuItem,".atto_menuentry a",this,n,r),s.delegate("key",this._chooseMenuItem,"32, enter",".atto_menuentry",this,n,r),s.delegate("key",this._menuKeyboardNavigation,"down:38,40",".menu",this),s.delegate("key",this._hideMenu,"down:37,39",".menu",this,r))}var a=this.buttons[n.buttonName];this.get("host")._setTabFocus(a),r=this.menus[n.buttonClass],r.set("focusAfterHide",a),r.show(),r.align(this.buttons[n.buttonName],[e.WidgetPositionAlign.TL,e.WidgetPositionAlign.BL]),r.get("boundingBox").one("a").focus(),this._menuHideHandlers.push(r.get("boundingBox").on("focusoutside",this._hideMenu,this,r))},_hideMenu:function(t,n){if(n.get("preventHideMenu")===!0)return;n.hide(),(new e.EventHandle(this._menuHideHandlers)).detach()},_chooseMenuItem:function(e,t,n){var r=e.target.ancestor("a",!0).getData("index"),i=this._normalizeCallback(t.items[r],t.globalItemConfig);n.set("preventHideMenu",!0),i.callback(e,i._callback,i.callbackArgs),n.set("preventHideMenu",!1),n.set("focusAfterHide",this.get("host").editor),this._hideMenu(e,n)},_normalizeCallback:function(t,n){return t._callbackNormalized?t:(n||(n={}),typeof t.wrapCallback=="undefined"&&(t.wrapCallback=n.wrapCallback||!0),t.wrapCallback?(t._callback=t.callback||n.callback,t.callback=e.rbind(this._callbackWrapper,this,t._callback,t.callbackArgs)):t.callback=t.callback||n.callback,t._callbackNormalized=!0,t)},_normalizeIcon:function(e){return e.iconurl|| +(e.iconComponent||(e.iconComponent="core"),e.iconurl=M.util.image_url(e.icon,e.iconComponent)),e},_callbackWrapper:function(e,t,n){e.preventDefault();if(!this.isEnabled())return;var r=e.currentTarget.ancestor("button",!0);if(r&&r.hasAttribute(u))return;this.get("host").isActive()||this.get("host").focus(),r&&this.get("host")._setTabFocus(r);var i=[e,n];return t.apply(this,i)},_addKeyboardListener:function(t,n,r){var i="key",s=l.EDITORWRAPPER,o;if(e.Lang.isArray(n))return e.Array.each(n,function(e){this._addKeyboardListener(t,e)},this),this;typeof n=="object"?(n.eventtype&&(i=n.eventtype),n.container&&(s=n.container),o=n.keyCodes):o=this._getKeyEvent()+n+this._getDefaultMetaKey(),this._buttonHandlers.push(this.editor.delegate(i,t,o,s,this))},isEnabled:function(){var t=e.Object.some(this.buttonStates,function(e){return e===this.ENABLED},this);return t},disableButtons:function(e){return this._setButtonState(!1,e)},enableButtons:function(e){return this._setButtonState(!0,e)},_setButtonState:function(t,n){var r="setAttribute";return t&&(r="removeAttribute"),n?this.buttons[n]&&(this.buttons[n][r](u,u),this.buttonStates[n]=t?this.ENABLED:this.DISABLED):e.Array.each(this.buttonNames,function(e){this.buttons[e][r](u,u),this.buttonStates[e]=t?this.ENABLED:this.DISABLED},this),this},highlightButtons:function(e){return this._changeButtonHighlight(!0,e)},unHighlightButtons:function(e){return this._changeButtonHighlight(!1,e)},_changeButtonHighlight:function(t,n){var r="addClass";return t||(r="removeClass"),n?this.buttons[n]&&this.buttons[n][r](a):e.Object.each(this.buttons,function(e){e[r](a)},this),this},_menuKeyboardNavigation:function(e){e.preventDefault();var t=e.currentTarget.all('a[role="menuitem"]'),n=!1,r=0,i=1,s=0,o=e.target.ancestor('a[role="menuitem"]',!0);while(!n&&r=t.size()&&(r=0),next=t.item(r),s++;while(s