skateside / jquery-aria Goto Github PK
View Code? Open in Web Editor NEWFunctions for manipulating WAI-ARIA attributes with the jQuery library
License: MIT License
Functions for manipulating WAI-ARIA attributes with the jQuery library
License: MIT License
I think $().identify()
should just be a getter, similar to $().attr("id")
. This feels a lot more jQuery-esque than the current implementation. Also, $("#--id--")
is just a direct wrapper for document.getElementById("--id--")
as you can see here so there's no benefit in not using it - may as well get the performance boost.
$.fn.identify = function () {
var id = this.attr("id");
if (!id) {
do {
id = IDENTIFY_PREFIX + count;
count += 1;
} while (document.getElementById(id));
this.attr("id", id);
}
return id;
};
Since multiple roles are allowed in the WAI-ARIA specs, helper functions should exist to assist that (similar to .addClass()
and removeClass()
verses .attr("class", )
:
$.fn.extend({
// Already exists
role: function (role) {
return role === undefined
? this.attr("role")
: this.attr("role", role);
},
addRole: function (role) {
var roles = this.role().split(/\s+/);
if (roles.indexOf(role) < 0) {
roles.push(role);
this.role(roles.join(" "));
}
return this;
},
removeRole: function (role) {
return role
? this.role(function (fullRole) {
return fullRole
.split(/\s+/)
.filter(function (r) {
return r !== role;
})
.join(" ");
})
: this.removeAttr("role");
}
});
Just thinking out loud
/* Gulp tasks
# gulp dev
- watch for changes
- concatenate ./tmp/jquery.aria.js
# gulp prod
- delete/empty ./tmp/?
- JSLint
- concatenate ./test/test.js
- unit tests
- concatenate ./dist/jquery.aria.js
- minify ./dist/jquery.aria.min.js
- sourcemaps
# gulp doc
- JSDoc
*/
describe("interpretString", function () {
it("should always return a string", function () {
[
"",
0,
true,
[],
{},
null,
undefined,
function () {}
].forEach(function (type) {
chai.assert.isTrue(typeof interpretString(type) === "string");
});
});
it("should covert object to string", function () {
var o1 = {};
var o2 = {
toString: function () {
return "a";
}
};
chai.assert.equal(interpretString(o1), "[object Object]");
chai.assert.equal(interpretString(o2), "a");
});
it("should convert null and undefined to empty strings", function () {
chai.assert.equal(interpretString(), "");
chai.assert.equal(interpretString(null), "");
chai.assert.equal(interpretString(undefined), "");
});
});
describe("identity", function () {
it("should always return the first argument", function () {
var o = {};
chai.assert.equal(identity(""), "");
chai.assert.equal(identity(0), 0);
chai.assert.equal(identity(o), o);
});
it("should ignore subsequent arguments", function () {
var o = {};
chai.assert.equal(identity(o), o);
chai.assert.equal(identity(o, true), o);
chai.assert.equal(identity(o, 0), o);
});
it("should not be affected by context", function () {
var o = {};
chai.assert.equal(identity(o), o);
chai.assert.equal(identity.call(null, o), o);
chai.assert.equal(identity.apply(null, [o]), o);
});
});
describe("isElement", function () {
it("should detect HTML Elements", function () {
chai.assert.isTrue(isElement(document.createElement("div")));
});
it("should return false for a Node that is not an Element", function () {
chai.assert.isFalse(isElement(document.createTextNode("a")));
chai.assert.isFalse(isElement(document.createComment("a")));
chai.assert.isFalse(isElement(document.createDocumentFragment()));
});
it("should not be fooled but Element-like objects", function () {
chai.assert.isFalse(isElement({
nodeName: "A",
nodeType: 1
}));
chai.assert.isFalse(isElement({
toString: function () {
return "[object HTMLElement]";
}
}));
});
});
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.