From 3bc1e345ca7bb57ed2da206f668dd1fdb47918da Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Wed, 18 Jun 2014 16:33:55 +0800 Subject: [PATCH] MDL-44773 atto_accessibilitychecker: Set focus on clicked warnings --- ...-atto_accessibilitychecker-button-debug.js | 37 ++++++------------- ...le-atto_accessibilitychecker-button-min.js | 2 +- ...moodle-atto_accessibilitychecker-button.js | 37 ++++++------------- .../yui/src/button/js/button.js | 37 ++++++------------- 4 files changed, 34 insertions(+), 79 deletions(-) diff --git a/lib/editor/atto/plugins/accessibilitychecker/yui/build/moodle-atto_accessibilitychecker-button/moodle-atto_accessibilitychecker-button-debug.js b/lib/editor/atto/plugins/accessibilitychecker/yui/build/moodle-atto_accessibilitychecker-button/moodle-atto_accessibilitychecker-button-debug.js index 4a8faaeee7c..cbdb87b56bc 100644 --- a/lib/editor/atto/plugins/accessibilitychecker/yui/build/moodle-atto_accessibilitychecker-button/moodle-atto_accessibilitychecker-button-debug.js +++ b/lib/editor/atto/plugins/accessibilitychecker/yui/build/moodle-atto_accessibilitychecker-button/moodle-atto_accessibilitychecker-button-debug.js @@ -36,14 +36,6 @@ YUI.add('moodle-atto_accessibilitychecker-button', function (Y, NAME) { var COMPONENT = 'atto_accessibilitychecker'; Y.namespace('M.atto_accessibilitychecker').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], { - /** - * The warnings which are displayed. - * - * @property _displayedWarnings - * @type Object - * @private - */ - _displayedWarnings: {}, initializer: function() { this.addButton({ @@ -86,18 +78,12 @@ Y.namespace('M.atto_accessibilitychecker').Button = Y.Base.create('button', Y.M. e.preventDefault(); var host = this.get('host'), - index = e.target.getAttribute("data-index"), - node = this._displayedWarnings[index], + node = e.currentTarget.getData('sourceNode'), dialogue = this.getDialogue(); - if (node) { - // Clear the dialogue's focusAfterHide to ensure we focus - // on the selection. - dialogue.set('focusAfterHide', null); - - // Hide the dialogue. - dialogue.hide(); + // Focus on the editor as we hide the dialogue. + dialogue.set('focusAfterHide', this.editor).hide(); // Then set the selection. host.setSelection(host.getSelectionFromNode(node)); @@ -201,25 +187,24 @@ Y.namespace('M.atto_accessibilitychecker').Button = Y.Base.create('button', Y.M. * @param {boolean} imagewarnings true if the warnings are related to images, false if text. */ _addWarnings: function(list, description, nodes, imagewarnings) { - var warning, fails, i, key, src, textfield; + var warning, fails, i, src, textfield, li, link; if (nodes.length > 0) { warning = Y.Node.create('

' + description + '

'); fails = Y.Node.create('
    '); i = 0; for (i = 0; i < nodes.length; i++) { + li = Y.Node.create('
  1. '); if (imagewarnings) { - key = 'image_'+i; src = nodes[i].getAttribute('src'); - - fails.append(Y.Node.create('
  2. '+src+'
  3. ')); + link = Y.Node.create(' ' + src + ''); } else { - key = 'text_' + i; - - textfield = ('innerText' in nodes[i])? 'innerText' : 'textContent'; - fails.append(Y.Node.create('
  4. ' + nodes[i].get(textfield) + '
  5. ')); + textfield = ('innerText' in nodes[i]) ? 'innerText' : 'textContent'; + link = Y.Node.create('' + nodes[i].get(textfield) + ''); } - this._displayedWarnings[key] = nodes[i]; + link.setData('sourceNode', nodes[i]); + li.append(link); + fails.append(li); } warning.append(fails); diff --git a/lib/editor/atto/plugins/accessibilitychecker/yui/build/moodle-atto_accessibilitychecker-button/moodle-atto_accessibilitychecker-button-min.js b/lib/editor/atto/plugins/accessibilitychecker/yui/build/moodle-atto_accessibilitychecker-button/moodle-atto_accessibilitychecker-button-min.js index 0769b530dc1..026e26b7f43 100644 --- a/lib/editor/atto/plugins/accessibilitychecker/yui/build/moodle-atto_accessibilitychecker-button/moodle-atto_accessibilitychecker-button-min.js +++ b/lib/editor/atto/plugins/accessibilitychecker/yui/build/moodle-atto_accessibilitychecker-button/moodle-atto_accessibilitychecker-button-min.js @@ -1 +1 @@ -YUI.add("moodle-atto_accessibilitychecker-button",function(e,t){var n="atto_accessibilitychecker";e.namespace("M.atto_accessibilitychecker").Button=e.Base.create("button",e.M.editor_atto.EditorPlugin,[],{_displayedWarnings:{},initializer:function(){this.addButton({icon:"e/accessibility_checker",callback:this._displayDialogue})},_displayDialogue:function(){var e=this.getDialogue({headerContent:M.util.get_string("pluginname",n),width:"500px",focusAfterHide:!0});e.set("bodyContent",this._getDialogueContent()).show()},_getDialogueContent:function(){var t=e.Node.create('
    ');return t.append(this._getWarnings()),t.delegate("click",function(e){e.preventDefault();var t=this.get("host"),n=e.target.getAttribute("data-index"),r=this._displayedWarnings[n],i=this.getDialogue();r?(i.set("focusAfterHide",null),i.hide(),t.setSelection(t.getSelectionFromNode(r))):i.hide()},"a",this),t},_getWarnings:function(){var t,r=e.Node.create("
    ");return t=[],this.editor.all("img").each(function(e){alt=e.getAttribute("alt"),(typeof alt=="undefined"||alt==="")&&e.getAttribute("role")!=="presentation"&&t.push(e)},this),this._addWarnings(r,M.util.get_string("imagesmissingalt",n),t,!0),t=[],this.editor.all("*").each(function(n){var r,i,s,o,u;if(e.Lang.trim(n.get("text"))!==""){r=n.getComputedStyle("color"),i=n.getComputedStyle("backgroundColor"),o=this._getLuminanceFromCssColor(r),u=this._getLuminanceFromCssColor(i),o>u?s=(o+.05)/(u+.05):s=(u+.05)/(o+.05);if(s<=4.5){var a=0,f=!1;for(a=0;a"+M.util.get_string("nowarnings",n)+"

    "),r},_addWarnings:function(t,n,r,i){var s,o,u,a,f,l;if(r.length>0){s=e.Node.create("

    "+n+"

    "),o=e.Node.create('
      '),u=0;for(u=0;u '+f+""))):(a="text_"+u,l="innerText"in r[u]?"innerText":"textContent",o.append(e.Node.create('
    1. '+r[u].get(l)+"
    2. "))),this._displayedWarnings[a]=r[u];s.append(o),t.append(s)}},_getLuminanceFromCssColor:function(t){var n;t==="transparent"&&(t="#ffffff"),n=e.Color.toArray(e.Color.toRGB(t));var r=function(e){return e=parseInt(e,10)/255,e<=.03928?e/=12.92:e=Math.pow((e+.055)/1.055,2.4),e},i=r(n[0]),s=r(n[1]),o=r(n[2]);return.2126*i+.7152*s+.0722*o}})},"@VERSION@",{requires:["color-base","moodle-editor_atto-plugin"]}); +YUI.add("moodle-atto_accessibilitychecker-button",function(e,t){var n="atto_accessibilitychecker";e.namespace("M.atto_accessibilitychecker").Button=e.Base.create("button",e.M.editor_atto.EditorPlugin,[],{initializer:function(){this.addButton({icon:"e/accessibility_checker",callback:this._displayDialogue})},_displayDialogue:function(){var e=this.getDialogue({headerContent:M.util.get_string("pluginname",n),width:"500px",focusAfterHide:!0});e.set("bodyContent",this._getDialogueContent()).show()},_getDialogueContent:function(){var t=e.Node.create('
      ');return t.append(this._getWarnings()),t.delegate("click",function(e){e.preventDefault();var t=this.get("host"),n=e.currentTarget.getData("sourceNode"),r=this.getDialogue();n?(r.set("focusAfterHide",this.editor).hide(),t.setSelection(t.getSelectionFromNode(n))):r.hide()},"a",this),t},_getWarnings:function(){var t,r=e.Node.create("
      ");return t=[],this.editor.all("img").each(function(e){alt=e.getAttribute("alt"),(typeof alt=="undefined"||alt==="")&&e.getAttribute("role")!=="presentation"&&t.push(e)},this),this._addWarnings(r,M.util.get_string("imagesmissingalt",n),t,!0),t=[],this.editor.all("*").each(function(n){var r,i,s,o,u;if(e.Lang.trim(n.get("text"))!==""){r=n.getComputedStyle("color"),i=n.getComputedStyle("backgroundColor"),o=this._getLuminanceFromCssColor(r),u=this._getLuminanceFromCssColor(i),o>u?s=(o+.05)/(u+.05):s=(u+.05)/(o+.05);if(s<=4.5){var a=0,f=!1;for(a=0;a"+M.util.get_string("nowarnings",n)+"

      "),r},_addWarnings:function(t,n,r,i){var s,o,u,a,f,l,c;if(r.length>0){s=e.Node.create("

      "+n+"

      "),o=e.Node.create('
        '),u=0;for(u=0;u"),i?(a=r[u].getAttribute("src"),c=e.Node.create(' '+a+"")):(f="innerText"in r[u]?"innerText":"textContent",c=e.Node.create(''+r[u].get(f)+"")),c.setData("sourceNode",r[u]),l.append(c),o.append(l);s.append(o),t.append(s)}},_getLuminanceFromCssColor:function(t){var n;t==="transparent"&&(t="#ffffff"),n=e.Color.toArray(e.Color.toRGB(t));var r=function(e){return e=parseInt(e,10)/255,e<=.03928?e/=12.92:e=Math.pow((e+.055)/1.055,2.4),e},i=r(n[0]),s=r(n[1]),o=r(n[2]);return.2126*i+.7152*s+.0722*o}})},"@VERSION@",{requires:["color-base","moodle-editor_atto-plugin"]}); diff --git a/lib/editor/atto/plugins/accessibilitychecker/yui/build/moodle-atto_accessibilitychecker-button/moodle-atto_accessibilitychecker-button.js b/lib/editor/atto/plugins/accessibilitychecker/yui/build/moodle-atto_accessibilitychecker-button/moodle-atto_accessibilitychecker-button.js index d77ab253b3d..9a4c1774cb5 100644 --- a/lib/editor/atto/plugins/accessibilitychecker/yui/build/moodle-atto_accessibilitychecker-button/moodle-atto_accessibilitychecker-button.js +++ b/lib/editor/atto/plugins/accessibilitychecker/yui/build/moodle-atto_accessibilitychecker-button/moodle-atto_accessibilitychecker-button.js @@ -36,14 +36,6 @@ YUI.add('moodle-atto_accessibilitychecker-button', function (Y, NAME) { var COMPONENT = 'atto_accessibilitychecker'; Y.namespace('M.atto_accessibilitychecker').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], { - /** - * The warnings which are displayed. - * - * @property _displayedWarnings - * @type Object - * @private - */ - _displayedWarnings: {}, initializer: function() { this.addButton({ @@ -86,18 +78,12 @@ Y.namespace('M.atto_accessibilitychecker').Button = Y.Base.create('button', Y.M. e.preventDefault(); var host = this.get('host'), - index = e.target.getAttribute("data-index"), - node = this._displayedWarnings[index], + node = e.currentTarget.getData('sourceNode'), dialogue = this.getDialogue(); - if (node) { - // Clear the dialogue's focusAfterHide to ensure we focus - // on the selection. - dialogue.set('focusAfterHide', null); - - // Hide the dialogue. - dialogue.hide(); + // Focus on the editor as we hide the dialogue. + dialogue.set('focusAfterHide', this.editor).hide(); // Then set the selection. host.setSelection(host.getSelectionFromNode(node)); @@ -196,25 +182,24 @@ Y.namespace('M.atto_accessibilitychecker').Button = Y.Base.create('button', Y.M. * @param {boolean} imagewarnings true if the warnings are related to images, false if text. */ _addWarnings: function(list, description, nodes, imagewarnings) { - var warning, fails, i, key, src, textfield; + var warning, fails, i, src, textfield, li, link; if (nodes.length > 0) { warning = Y.Node.create('

        ' + description + '

        '); fails = Y.Node.create('
          '); i = 0; for (i = 0; i < nodes.length; i++) { + li = Y.Node.create('
        1. '); if (imagewarnings) { - key = 'image_'+i; src = nodes[i].getAttribute('src'); - - fails.append(Y.Node.create('
        2. '+src+'
        3. ')); + link = Y.Node.create(' ' + src + ''); } else { - key = 'text_' + i; - - textfield = ('innerText' in nodes[i])? 'innerText' : 'textContent'; - fails.append(Y.Node.create('
        4. ' + nodes[i].get(textfield) + '
        5. ')); + textfield = ('innerText' in nodes[i]) ? 'innerText' : 'textContent'; + link = Y.Node.create('' + nodes[i].get(textfield) + ''); } - this._displayedWarnings[key] = nodes[i]; + link.setData('sourceNode', nodes[i]); + li.append(link); + fails.append(li); } warning.append(fails); diff --git a/lib/editor/atto/plugins/accessibilitychecker/yui/src/button/js/button.js b/lib/editor/atto/plugins/accessibilitychecker/yui/src/button/js/button.js index 89ec9bc7829..5797448e9b9 100644 --- a/lib/editor/atto/plugins/accessibilitychecker/yui/src/button/js/button.js +++ b/lib/editor/atto/plugins/accessibilitychecker/yui/src/button/js/button.js @@ -34,14 +34,6 @@ var COMPONENT = 'atto_accessibilitychecker'; Y.namespace('M.atto_accessibilitychecker').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], { - /** - * The warnings which are displayed. - * - * @property _displayedWarnings - * @type Object - * @private - */ - _displayedWarnings: {}, initializer: function() { this.addButton({ @@ -84,18 +76,12 @@ Y.namespace('M.atto_accessibilitychecker').Button = Y.Base.create('button', Y.M. e.preventDefault(); var host = this.get('host'), - index = e.target.getAttribute("data-index"), - node = this._displayedWarnings[index], + node = e.currentTarget.getData('sourceNode'), dialogue = this.getDialogue(); - if (node) { - // Clear the dialogue's focusAfterHide to ensure we focus - // on the selection. - dialogue.set('focusAfterHide', null); - - // Hide the dialogue. - dialogue.hide(); + // Focus on the editor as we hide the dialogue. + dialogue.set('focusAfterHide', this.editor).hide(); // Then set the selection. host.setSelection(host.getSelectionFromNode(node)); @@ -199,25 +185,24 @@ Y.namespace('M.atto_accessibilitychecker').Button = Y.Base.create('button', Y.M. * @param {boolean} imagewarnings true if the warnings are related to images, false if text. */ _addWarnings: function(list, description, nodes, imagewarnings) { - var warning, fails, i, key, src, textfield; + var warning, fails, i, src, textfield, li, link; if (nodes.length > 0) { warning = Y.Node.create('

          ' + description + '

          '); fails = Y.Node.create('
            '); i = 0; for (i = 0; i < nodes.length; i++) { + li = Y.Node.create('
          1. '); if (imagewarnings) { - key = 'image_'+i; src = nodes[i].getAttribute('src'); - - fails.append(Y.Node.create('
          2. '+src+'
          3. ')); + link = Y.Node.create(' ' + src + ''); } else { - key = 'text_' + i; - - textfield = ('innerText' in nodes[i])? 'innerText' : 'textContent'; - fails.append(Y.Node.create('
          4. ' + nodes[i].get(textfield) + '
          5. ')); + textfield = ('innerText' in nodes[i]) ? 'innerText' : 'textContent'; + link = Y.Node.create('' + nodes[i].get(textfield) + ''); } - this._displayedWarnings[key] = nodes[i]; + link.setData('sourceNode', nodes[i]); + li.append(link); + fails.append(li); } warning.append(fails);