MDL-44116 Atto: Improve new accessibility sniffs.
Check for empty text it row, column headers and captions on tables. Link to "Entire document" text instead of repeating the entire document if the text is long and has no headings.
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
*/
|
||||
|
||||
$string['emptytext'] = 'Empty text';
|
||||
$string['entiredocument'] = 'Entire document';
|
||||
$string['imagesmissingalt'] = 'Images require alternative text. To fix this warning, add an alt attribute to your img tags. An empty alt attribute may be used, but only when the image is purely decorative and carries no information.';
|
||||
$string['needsmorecontrast'] = 'The colours of the foreground and background text do not have enough contrast. To fix this warning, change either foreground or background colour of the text so that it is easier to read.';
|
||||
$string['needsmoreheadings'] = 'There is a lot of text with no headings. Headings will allow screen reader users to navigate through the page easily and will make the page more usable for everyone.';
|
||||
|
||||
@@ -39,6 +39,7 @@ function atto_accessibilitychecker_strings_for_js() {
|
||||
'tableswithmergedcells',
|
||||
'tablesmissingcaption',
|
||||
'emptytext',
|
||||
'entiredocument',
|
||||
'tablesmissingheaders'),
|
||||
'atto_accessibilitychecker');
|
||||
}
|
||||
|
||||
+16
-3
@@ -179,7 +179,7 @@ Y.namespace('M.atto_accessibilitychecker').Button = Y.Base.create('button', Y.M.
|
||||
problemNodes = [];
|
||||
this.editor.all('table').each(function (table) {
|
||||
caption = table.one('caption');
|
||||
if (caption === null) {
|
||||
if (caption === null || caption.get('text').trim() === '') {
|
||||
problemNodes.push(table);
|
||||
}
|
||||
}, this);
|
||||
@@ -201,7 +201,8 @@ Y.namespace('M.atto_accessibilitychecker').Button = Y.Base.create('button', Y.M.
|
||||
if (table.one('tr').one('td')) {
|
||||
// First row has a non-header cell, so all rows must have at least one header.
|
||||
table.all('tr').some(function (row) {
|
||||
if (!row.one('th')) {
|
||||
var header = row.one('th');
|
||||
if (!header || (header.get('text').trim() === '')) {
|
||||
problemNodes.push(table);
|
||||
return true;
|
||||
}
|
||||
@@ -209,7 +210,16 @@ Y.namespace('M.atto_accessibilitychecker').Button = Y.Base.create('button', Y.M.
|
||||
}, this);
|
||||
} else {
|
||||
// First row must have at least one header then.
|
||||
if (!table.one('tr').one('th')) {
|
||||
var hasHeader = false;
|
||||
table.one('tr').all('th').some(function (header) {
|
||||
hasHeader = true;
|
||||
if (header.get('text').trim() === '') {
|
||||
problemNodes.push(table);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
if (!hasHeader) {
|
||||
problemNodes.push(table);
|
||||
}
|
||||
}
|
||||
@@ -251,6 +261,9 @@ Y.namespace('M.atto_accessibilitychecker').Button = Y.Base.create('button', Y.M.
|
||||
if (text === '') {
|
||||
text = M.util.get_string('emptytext', COMPONENT);
|
||||
}
|
||||
if (nodes[i] === this.editor) {
|
||||
text = M.util.get_string('entiredocument', COMPONENT);
|
||||
}
|
||||
link = Y.Node.create('<a href="#">' + text + '</a>');
|
||||
}
|
||||
link.setData('sourceNode', nodes[i]);
|
||||
|
||||
+1
-1
@@ -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,[],{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('<div style="word-wrap: break-word;"></div>');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("<div></div>");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<t.length;a++){if(n.ancestors("*").indexOf(t[a])!==-1){f=!0;break}if(t[a].ancestors("*").indexOf(n)!==-1){t[a]=n,f=!0;break}}f||t.push(n)}}},this),this._addWarnings(r,M.util.get_string("needsmorecontrast",n),t,!1),this.editor.get("text").length>1e3&&!this.editor.one("h3, h4, h5")&&this._addWarnings(r,M.util.get_string("needsmoreheadings",n),[this.editor],!1),t=[],this.editor.all("table").each(function(e){caption=e.one("caption"),caption===null&&t.push(e)},this),this._addWarnings(r,M.util.get_string("tablesmissingcaption",n),t,!1),t=[],this.editor.all("table").each(function(e){caption=e.one("[colspan],[rowspan]"),caption!==null&&t.push(e)},this),this._addWarnings(r,M.util.get_string("tableswithmergedcells",n),t,!1),t=[],this.editor.all("table").each(function(e){e.one("tr").one("td")?e.all("tr").some(function(n){return n.one("th")?!1:(t.push(e),!0)},this):e.one("tr").one("th")||t.push(e)},this),this._addWarnings(r,M.util.get_string("tablesmissingheaders",n),t,!1),r.hasChildNodes()||r.append("<p>"+M.util.get_string("nowarnings",n)+"</p>"),r},_addWarnings:function(t,r,i,s){var o,u,a,f,l,c,h,p;if(i.length>0){o=e.Node.create("<p>"+r+"</p>"),u=e.Node.create('<ol class="accessibilitywarnings"></ol>'),a=0;for(a=0;a<i.length;a++)c=e.Node.create("<li></li>"),s?(f=i[a].getAttribute("src"),h=e.Node.create('<a href="#"><img src="'+f+'" /> '+f+"</a>")):(l="innerText"in i[a]?"innerText":"textContent",p=i[a].get(l).trim(),p===""&&(p=M.util.get_string("emptytext",n)),h=e.Node.create('<a href="#">'+p+"</a>")),h.setData("sourceNode",i[a]),c.append(h),u.append(c);o.append(u),t.append(o)}},_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('<div style="word-wrap: break-word;"></div>');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("<div></div>");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<t.length;a++){if(n.ancestors("*").indexOf(t[a])!==-1){f=!0;break}if(t[a].ancestors("*").indexOf(n)!==-1){t[a]=n,f=!0;break}}f||t.push(n)}}},this),this._addWarnings(r,M.util.get_string("needsmorecontrast",n),t,!1),this.editor.get("text").length>1e3&&!this.editor.one("h3, h4, h5")&&this._addWarnings(r,M.util.get_string("needsmoreheadings",n),[this.editor],!1),t=[],this.editor.all("table").each(function(e){caption=e.one("caption"),(caption===null||caption.get("text").trim()==="")&&t.push(e)},this),this._addWarnings(r,M.util.get_string("tablesmissingcaption",n),t,!1),t=[],this.editor.all("table").each(function(e){caption=e.one("[colspan],[rowspan]"),caption!==null&&t.push(e)},this),this._addWarnings(r,M.util.get_string("tableswithmergedcells",n),t,!1),t=[],this.editor.all("table").each(function(e){if(e.one("tr").one("td"))e.all("tr").some(function(n){var r=n.one("th");return!r||r.get("text").trim()===""?(t.push(e),!0):!1},this);else{var n=!1;e.one("tr").all("th").some(function(r){return n=!0,r.get("text").trim()===""?(t.push(e),!0):!1}),n||t.push(e)}},this),this._addWarnings(r,M.util.get_string("tablesmissingheaders",n),t,!1),r.hasChildNodes()||r.append("<p>"+M.util.get_string("nowarnings",n)+"</p>"),r},_addWarnings:function(t,r,i,s){var o,u,a,f,l,c,h,p;if(i.length>0){o=e.Node.create("<p>"+r+"</p>"),u=e.Node.create('<ol class="accessibilitywarnings"></ol>'),a=0;for(a=0;a<i.length;a++)c=e.Node.create("<li></li>"),s?(f=i[a].getAttribute("src"),h=e.Node.create('<a href="#"><img src="'+f+'" /> '+f+"</a>")):(l="innerText"in i[a]?"innerText":"textContent",p=i[a].get(l).trim(),p===""&&(p=M.util.get_string("emptytext",n)),i[a]===this.editor&&(p=M.util.get_string("entiredocument",n)),h=e.Node.create('<a href="#">'+p+"</a>")),h.setData("sourceNode",i[a]),c.append(h),u.append(c);o.append(u),t.append(o)}},_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"]});
|
||||
|
||||
+16
-3
@@ -174,7 +174,7 @@ Y.namespace('M.atto_accessibilitychecker').Button = Y.Base.create('button', Y.M.
|
||||
problemNodes = [];
|
||||
this.editor.all('table').each(function (table) {
|
||||
caption = table.one('caption');
|
||||
if (caption === null) {
|
||||
if (caption === null || caption.get('text').trim() === '') {
|
||||
problemNodes.push(table);
|
||||
}
|
||||
}, this);
|
||||
@@ -196,7 +196,8 @@ Y.namespace('M.atto_accessibilitychecker').Button = Y.Base.create('button', Y.M.
|
||||
if (table.one('tr').one('td')) {
|
||||
// First row has a non-header cell, so all rows must have at least one header.
|
||||
table.all('tr').some(function (row) {
|
||||
if (!row.one('th')) {
|
||||
var header = row.one('th');
|
||||
if (!header || (header.get('text').trim() === '')) {
|
||||
problemNodes.push(table);
|
||||
return true;
|
||||
}
|
||||
@@ -204,7 +205,16 @@ Y.namespace('M.atto_accessibilitychecker').Button = Y.Base.create('button', Y.M.
|
||||
}, this);
|
||||
} else {
|
||||
// First row must have at least one header then.
|
||||
if (!table.one('tr').one('th')) {
|
||||
var hasHeader = false;
|
||||
table.one('tr').all('th').some(function (header) {
|
||||
hasHeader = true;
|
||||
if (header.get('text').trim() === '') {
|
||||
problemNodes.push(table);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
if (!hasHeader) {
|
||||
problemNodes.push(table);
|
||||
}
|
||||
}
|
||||
@@ -246,6 +256,9 @@ Y.namespace('M.atto_accessibilitychecker').Button = Y.Base.create('button', Y.M.
|
||||
if (text === '') {
|
||||
text = M.util.get_string('emptytext', COMPONENT);
|
||||
}
|
||||
if (nodes[i] === this.editor) {
|
||||
text = M.util.get_string('entiredocument', COMPONENT);
|
||||
}
|
||||
link = Y.Node.create('<a href="#">' + text + '</a>');
|
||||
}
|
||||
link.setData('sourceNode', nodes[i]);
|
||||
|
||||
@@ -177,7 +177,7 @@ Y.namespace('M.atto_accessibilitychecker').Button = Y.Base.create('button', Y.M.
|
||||
problemNodes = [];
|
||||
this.editor.all('table').each(function (table) {
|
||||
caption = table.one('caption');
|
||||
if (caption === null) {
|
||||
if (caption === null || caption.get('text').trim() === '') {
|
||||
problemNodes.push(table);
|
||||
}
|
||||
}, this);
|
||||
@@ -199,7 +199,8 @@ Y.namespace('M.atto_accessibilitychecker').Button = Y.Base.create('button', Y.M.
|
||||
if (table.one('tr').one('td')) {
|
||||
// First row has a non-header cell, so all rows must have at least one header.
|
||||
table.all('tr').some(function (row) {
|
||||
if (!row.one('th')) {
|
||||
var header = row.one('th');
|
||||
if (!header || (header.get('text').trim() === '')) {
|
||||
problemNodes.push(table);
|
||||
return true;
|
||||
}
|
||||
@@ -207,7 +208,16 @@ Y.namespace('M.atto_accessibilitychecker').Button = Y.Base.create('button', Y.M.
|
||||
}, this);
|
||||
} else {
|
||||
// First row must have at least one header then.
|
||||
if (!table.one('tr').one('th')) {
|
||||
var hasHeader = false;
|
||||
table.one('tr').all('th').some(function (header) {
|
||||
hasHeader = true;
|
||||
if (header.get('text').trim() === '') {
|
||||
problemNodes.push(table);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
if (!hasHeader) {
|
||||
problemNodes.push(table);
|
||||
}
|
||||
}
|
||||
@@ -249,6 +259,9 @@ Y.namespace('M.atto_accessibilitychecker').Button = Y.Base.create('button', Y.M.
|
||||
if (text === '') {
|
||||
text = M.util.get_string('emptytext', COMPONENT);
|
||||
}
|
||||
if (nodes[i] === this.editor) {
|
||||
text = M.util.get_string('entiredocument', COMPONENT);
|
||||
}
|
||||
link = Y.Node.create('<a href="#">' + text + '</a>');
|
||||
}
|
||||
link.setData('sourceNode', nodes[i]);
|
||||
|
||||
Reference in New Issue
Block a user