Code Monkey home page Code Monkey logo

jquery-aria's People

Contributors

james-jlo-long avatar skateside avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

james-jlo-long

jquery-aria's Issues

jQuery#identify should just be a getter

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;

};

Helper functions for multiple roles should be allowed

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");
        
    }
    
});

Some unit tests and gulp task ideas

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]";
            }
        }));

    });

});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.