From 6f9cf841c937a8ea0c31545cc29ed832a0ff7fc0 Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Fri, 20 Sep 2013 14:16:47 +0800 Subject: [PATCH] MDL-41870 atto: keyboard navigation for toolbar (arrows) --- .../moodle-editor_atto-editor-debug.js | 93 ++++++++++++++++--- .../moodle-editor_atto-editor-min.js | 3 +- .../moodle-editor_atto-editor.js | 93 ++++++++++++++++--- lib/editor/atto/yui/src/editor/js/editor.js | 91 ++++++++++++++++-- .../atto/yui/src/editor/meta/editor.json | 1 + 5 files changed, 248 insertions(+), 33 deletions(-) diff --git a/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-debug.js b/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-debug.js index 2ebeb90b866..96ccd495ef5 100644 --- a/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-debug.js +++ b/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-debug.js @@ -159,19 +159,29 @@ M.editor_atto = M.editor_atto || { */ add_toolbar_menu : function(elementid, plugin, icon, groupname, entries) { var toolbar = Y.one('#' + elementid + '_toolbar'), - group = Y.one('#' + elementid + '_toolbar .atto_group.' + groupname + '_group'); + group = Y.one('#' + elementid + '_toolbar .atto_group.' + groupname + '_group'), + currentfocus, + button; + if (!group) { group = Y.Node.create('
'); toolbar.append(group); } - var button = Y.Node.create(''); group.append(button); + currentfocus = toolbar.getAttribute('aria-activedescendant'); + if (!currentfocus) { + button.setAttribute('tabindex', '0'); + toolbar.setAttribute('aria-activedescendant', button.generateID()); + } + // Save the name of the plugin. M.editor_atto.widgets[plugin] = plugin; @@ -228,20 +238,30 @@ M.editor_atto = M.editor_atto || { */ add_toolbar_button : function(elementid, plugin, icon, groupname, handler) { var toolbar = Y.one('#' + elementid + '_toolbar'), - group = Y.one('#' + elementid + '_toolbar .atto_group.' + groupname + '_group'); + group = Y.one('#' + elementid + '_toolbar .atto_group.' + groupname + '_group'), + button, + currentfocus; + if (!group) { group = Y.Node.create('
'); toolbar.append(group); } - var button = Y.Node.create(''); + button = Y.Node.create(''); group.append(button); + currentfocus = toolbar.getAttribute('aria-activedescendant'); + if (!currentfocus) { + button.setAttribute('tabindex', '0'); + toolbar.setAttribute('aria-activedescendant', button.generateID()); + } + // We only need to attach this once. if (!M.editor_atto.buttonhandlers[plugin]) { Y.one('body').delegate('click', M.editor_atto.buttonclicked_handler, '.atto_' + plugin + '_button'); @@ -294,7 +314,7 @@ M.editor_atto = M.editor_atto || { 'spellcheck="true" ' + 'class="editor_atto"/>'); var cssfont = ''; - var toolbar = Y.Node.create('
'); + var toolbar = Y.Node.create('")),M.editor_atto.buttonhandlers[n+"_action_"+l]||(e.one("body").delegate("click",M.editor_atto.buttonclicked_handler,".atto_"+n+"_action_"+l),M.editor_atto.buttonhandlers[n+"_action_"+l]=c.handler);M.editor_atto.buttonhandlers[n]||(e.one("body").delegate("click",M.editor_atto.showhide_menu_handler,".atto_"+n+"_button"),M.editor_atto.buttonhandlers[n]=!0);var h=new M.core.dialogue({bodyContent:f,visible:!1,width:"14em",zindex:100,lightbox:!1,closeButton:!1,centered:!1,align:{node:a,points:[e.WidgetPositionAlign.TL,e.WidgetPositionAlign.BL]}});M.editor_atto.menus[n+"_"+t]=h,h.render(),h.hide(),h.headerNode.hide()},add_toolbar_button:function(t,n,r,i,s){var o=e.one("#"+t+"_toolbar"),u=e.one("#"+t+"_toolbar .atto_group."+i+"_group");u||(u=e.Node.create('
'),o.append(u));var a=e.Node.create('");u.append(a),M.editor_atto.buttonhandlers[n]||(e.one("body").delegate("click",M.editor_atto.buttonclicked_handler,".atto_"+n+"_button"),M.editor_atto.buttonhandlers[n]=s),M.editor_atto.widgets[n]=n},is_active:function(t){var n=M.editor_atto.get_selection();n.length&&(n=n.pop());var r=null;return n.parentElement?r=e.one(n.parentElement()):r=e.one(n.startContainer),r&&r.ancestor("#"+t+"editable")!==null},focus:function(t){e.one("#"+t+"editable").focus()},init:function(t){var n=e.one("#"+t.elementid),r=e.Node.create('
'),i="",s=e.Node.create('
'),o=e.io(t.content_css,{sync:!0}),u=o.responseText.indexOf("font:");u&&(i=o.responseText.substring(u+"font:".length,o.responseText.length-1),r.setStyle("font",i)),r.setStyle("minHeight",1.2*(n.getAttribute("rows")-1)+"em"),r.append(n.get("value")),n.get("parentNode").insert(s,n),n.get("parentNode").insert(r,n),r.setStyle("color",n.getStyle("color")),r.setStyle("lineHeight",n.getStyle("lineHeight")),r.setStyle("fontSize",n.getStyle("fontSize")),n.hide(),r.on("blur",function(){n.set("value",r.getHTML())}),M.editor_atto.filepickeroptions[t.elementid]=t.filepickeroptions},show_filepicker:function(t,n,r){e.use("core_filepicker",function(e){var i=M.editor_atto.filepickeroptions[t][n];i.formcallback=r,i.editor_target=e.one(t),M.core_filepicker.show(e,i)})},get_selection_from_node:function(e){var t;return window.getSelection?(t=document.createRange(),t.setStartBefore(e.getDOMNode()),t.setEndAfter(e.getDOMNode()),[t]):document.selection?(t=document.body.createTextRange(),t.moveToElementText(e.getDOMNode()),t):!1},get_selection:function(){if(window.getSelection){var e=window.getSelection(),t=[],n=0;for(n=0;n0)return e[0].commonAncestorContainer},get_selection_text:function(){var e=M.editor_atto.get_selection();if(e.length>0&&e[0].cloneContents)return e[0].cloneContents()},set_selection:function(e){var t,n;if(window.getSelection){t=window.getSelection(),t.removeAllRanges();for(n=0;n
'),o.append(u)),f=e.Node.create('"),u.append(f),a=o.getAttribute("aria-activedescendant"),a||(f.setAttribute("tabindex","0"),o.setAttribute("aria-activedescendant",f.generateID())),M.editor_atto.widgets[n]=n;var l=e.Node.create('
'),c=0,h={};for(c=0;c'+h.text+""+"
")),M.editor_atto.buttonhandlers[n+"_action_"+c]||(e.one("body").delegate("click",M.editor_atto.buttonclicked_handler,".atto_"+n+"_action_"+c),M.editor_atto.buttonhandlers[n+"_action_"+c]=h.handler);M.editor_atto.buttonhandlers[n]||(e.one("body").delegate("click",M.editor_atto.showhide_menu_handler,".atto_"+n+"_button"),M.editor_atto.buttonhandlers[n]=!0);var p=new M.core.dialogue({bodyContent:l,visible:!1,width:"14em",zindex:100,lightbox:!1,closeButton:!1,centered:!1,align:{node:f,points:[e.WidgetPositionAlign.TL,e.WidgetPositionAlign.BL]}});M.editor_atto.menus[n+"_"+t]=p,p.render(),p.hide(),p.headerNode.hide()},add_toolbar_button:function(t,n,r,i,s){var o=e.one("#"+t+"_toolbar"),u=e.one("#"+t+"_toolbar .atto_group."+i+"_group"),a,f;u||(u=e.Node.create('
'),o.append(u)),a=e.Node.create('"),u.append(a),f=o.getAttribute("aria-activedescendant"),f||(a.setAttribute("tabindex","0"),o.setAttribute("aria-activedescendant",a.generateID())),M.editor_atto.buttonhandlers[n]||(e.one("body").delegate("click",M.editor_atto.buttonclicked_handler,".atto_"+n+"_button"),M.editor_atto.buttonhandlers[n]=s),M.editor_atto.widgets[n]=n},is_active:function(t){var n=M.editor_atto.get_selection();n.length&&(n=n.pop());var r=null;return n.parentElement?r=e.one(n.parentElement()):r=e.one(n.startContainer),r&&r.ancestor("#"+t+"editable")!==null},focus:function(t){e.one("#"+t+"editable").focus()},init:function(t){var n=e.one("#"+t.elementid),r=e.Node.create('
'),i="",s=e.Node.create(''); toolbar.append(group); } - var button = Y.Node.create(''); group.append(button); + currentfocus = toolbar.getAttribute('aria-activedescendant'); + if (!currentfocus) { + button.setAttribute('tabindex', '0'); + toolbar.setAttribute('aria-activedescendant', button.generateID()); + } + // Save the name of the plugin. M.editor_atto.widgets[plugin] = plugin; @@ -228,20 +238,30 @@ M.editor_atto = M.editor_atto || { */ add_toolbar_button : function(elementid, plugin, icon, groupname, handler) { var toolbar = Y.one('#' + elementid + '_toolbar'), - group = Y.one('#' + elementid + '_toolbar .atto_group.' + groupname + '_group'); + group = Y.one('#' + elementid + '_toolbar .atto_group.' + groupname + '_group'), + button, + currentfocus; + if (!group) { group = Y.Node.create('
'); toolbar.append(group); } - var button = Y.Node.create(''); + button = Y.Node.create(''); group.append(button); + currentfocus = toolbar.getAttribute('aria-activedescendant'); + if (!currentfocus) { + button.setAttribute('tabindex', '0'); + toolbar.setAttribute('aria-activedescendant', button.generateID()); + } + // We only need to attach this once. if (!M.editor_atto.buttonhandlers[plugin]) { Y.one('body').delegate('click', M.editor_atto.buttonclicked_handler, '.atto_' + plugin + '_button'); @@ -294,7 +314,7 @@ M.editor_atto = M.editor_atto || { 'spellcheck="true" ' + 'class="editor_atto"/>'); var cssfont = ''; - var toolbar = Y.Node.create('
'); + var toolbar = Y.Node.create('