Bug 1354211 - Add element.isReadOnly. r=automatedtester

Introduces new function for testing whether an element is read-only.
This content IDL attribute only applies to <input> and <textarea>
elements.

MozReview-Commit-ID: 1YLizKUYMU6

--HG--
extra : rebase_source : 2d7dcd34d20cf0dd2f0e0087b28e5eeebfa72fad
This commit is contained in:
Andreas Tolfsen 2017-12-31 14:44:02 +00:00
Родитель d5a964bb11
Коммит 20643a5532
2 изменённых файлов: 26 добавлений и 0 удалений

Просмотреть файл

@ -782,6 +782,22 @@ element.isSelected = function(el) {
return false; return false;
}; };
/**
* An element is considered read only if it is an
* <code>&lt;input&gt;</code> or <code>&lt;textarea&gt;</code>
* element whose <code>readOnly</code> content IDL attribute is set.
*
* @param {Element} el
* Element to test is read only.
*
* @return {boolean}
* True if element is read only.
*/
element.isReadOnly = function(el) {
return element.isDOMElement(el) &&
["input", "textarea"].includes(el.localName) && el.readOnly;
};
/** /**
* This function generates a pair of coordinates relative to the viewport * This function generates a pair of coordinates relative to the viewport
* given a target element and coordinates relative to that element's * given a target element and coordinates relative to that element's

Просмотреть файл

@ -194,6 +194,16 @@ add_test(function test_isDOMWindow() {
run_next_test(); run_next_test();
}); });
add_test(function test_isReadOnly() {
ok(!element.isReadOnly(null));
ok(!element.isReadOnly(domEl));
ok(!element.isReadOnly(new DOMElement("p", {readOnly: true})));
ok(element.isReadOnly(new DOMElement("input", {readOnly: true})));
ok(element.isReadOnly(new DOMElement("textarea", {readOnly: true})));
run_next_test();
});
add_test(function test_coordinates() { add_test(function test_coordinates() {
let p = element.coordinates(domEl); let p = element.coordinates(domEl);
ok(p.hasOwnProperty("x")); ok(p.hasOwnProperty("x"));