{"_id":"jquery.role","_rev":"3-8ae2ecbc5366ee05fd080f1b6c115a7b","name":"jquery.role","description":"This project uses [Semantic Versioning](http://semver.org/) for release numbering.","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"jquery.role","version":"1.0.0","description":"This project uses [Semantic Versioning](http://semver.org/) for release numbering.","main":"lib/role.js","directories":{"test":"test"},"scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"https://github.com/aburkut/role.git"},"author":"","license":"ISC","bugs":{"url":"https://github.com/aburkut/role/issues"},"homepage":"https://github.com/aburkut/role","gitHead":"de1a0bd7cc7909c498720262503cf30f2b6e3d0d","_id":"jquery.role@1.0.0","_shasum":"1cfaf338dfd06f75677b15c509157c3227049255","_from":".","_npmVersion":"2.10.1","_nodeVersion":"0.12.4","_npmUser":{"name":"aburkut","email":"a.burkut90@gmail.com"},"dist":{"shasum":"1cfaf338dfd06f75677b15c509157c3227049255","tarball":"https://registry.npmjs.org/jquery.role/-/jquery.role-1.0.0.tgz","integrity":"sha512-YHCRPfxGr69xbpt9HQPdEP+lqGS2M+KnkjDaUJ4VyvkYGoynCDWSoIfKbD9781i9SJFQzYkJwBULIRnnyDLP9Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC61fN8bPNmU3RnTUa4KHdysViSZY1na4geEeF7dMbShQIhAIfT65/vKFYSEfpXO7Y+e7AkQiwdOnxNsZa2uVu028V8"}]},"maintainers":[{"name":"aburkut","email":"a.burkut90@gmail.com"}]}},"readme":"# ![jQuery Role](http://f.cl.ly/items/3L1b2G1M1z0O3p3m3Y1z/role_logo.png)\n## jQuery Role — jQuery plugin to provide easy way to handle DOM elements by role attribute [![Build Status](https://travis-ci.org/kossnocorp/role.png)](https://travis-ci.org/kossnocorp/role])\n\nThis project uses [Semantic Versioning](http://semver.org/) for release numbering.\n\nSponsored by [Evil Martians](http://evilmartians.com/).\n\n## Downloads\n\n* [jquery.role.min.js](https://raw.github.com/kossnocorp/role/master/lib/jquery.role.min.js)\n* [role.min.js](https://raw.github.com/kossnocorp/role/master/lib/jquery.role.min.js)\n* [jquery.role.js](https://raw.github.com/kossnocorp/role/master/lib/jquery.role.js)\n* [role.js](https://raw.github.com/kossnocorp/role/master/lib/role.js)\n\nAlso you can add jquery.role.js and role.js by bundle `role-rails` gem. For further details see *installation* section below.\n\n## Use `role` attribute FTW\n\n```\nUse cases for a role attribute for HTML5, include:\n\n* accessibility,\n* device adaptation,\n* server-side processing, and\n* complex data description.\n```\n\nThis is a quote from [W3C Specification on Role attribute](http://www.w3.org/wiki/PF/XTech/HTML5/RoleAttribute#A_Role_Attribute_for_HTML5).\n\nIn [Evil Martians](http://evilmartians.com/) we came up with a way to use this attribute for our own purposes.\n\nSay you have to update your website page design. HTML markup is done and you have to apply it to the existing site. Of course this marvelous page is crammed with Javascript code tied to an existing structure.\n\n``` javascript\n$('.list .item img')\n    .mouseenter(function () {\n        $(this).rotateTo(30, 300)\n    })\n    .mouseleave(function () {\n        $(this).rotateTo(0, 300)\n    });\n```\n\nObviously, you'll have to rewrite all the selectors for the new layout. And it would be nice if you had to fix only one (or even ten) of these selectors. In reality, most likely, there will be several dozen of them.\n\nAnother issue is that refactoring process requires you to change the names or a number of classes. You'll have to muddle through every JS file to find all classes you are going to change.\n\nAnd, of course, in both cases the end result is absolutely unpredictable, because layout alone is not enough to figure out if a class is actually used in JS.\n\nThe `.js-class_name` prefix use may seem like a good idea, except that someone will surely add styles to this class in a future... Let alone the difficulty to spot, among a large of number of classes, one with a prefix.\n\nIn order to avoid this problems, we can \"attach\" JS to DOM elements by a `role` attribute.\n\nIt's a lot safer then prefixes, because it's much harder to attach styles to `role` and it feels morally difficult to break the `role` use convention.\n\nWith the use of `role`, layout update becomes very straightforward: you just have to add roles to a new element, and if you are not tied to the \"magic numbers\" -- it will work with no further hassle.\n\nTo make life easier (shoutout to [@alex_chrome](https://twitter.com/#!/alex_chrome) for the great idea) we also extended jQuery selector syntax:\n\n``` javascript\n$('@list @item @image')\n    .mouseenter(function () {\n        $(this).rotateTo(30, 300)\n    })\n    .mouseleave(function () {\n        $(this).rotateTo(0, 300)\n    });\n```\n\n`$('@list @item @image')` is the same as `$('[role=\"list\"] [role=\"item] [role=\"image\"]')` and you can use \"multirole\": `$('@list@coupons')`.\n\nIn addition to the jQuery plug-in, I also wrote a version that extends `querySelectorAll` of [Zepto.js](http://zeptojs.com/) with a Role functionality.\n\nUsing of 'role' in a query may work a bit slower compared to usual selectors, but it's neglectable even in a large number of queries.\n\nIn addition to `role`, I sometimes use `id`, but only in very extraordinary cases — because if there is only single element on a page today, it may happen that there will be a few tomorrow, even if that wasn't planned.\n\n## Usage\n\n### Using selectors\n\nYou can use shortcut `@` in jQuery selectors to find elements with roles.\n\nWill select all elements in document with `role=\"ajax-link\"`:\n\n``` js\n$('@ajax-link')\n```\n\nAlso you can combinate roles:\n\n`<form role=\"form login_form\"></form>`:\n\n``` js\n$('@form@login_form')\n```\n\nWill select all forms with \"form\" as role `<form role=\"form login_form\"></form><form role=\"form registration_form\"></form>`:\n\n``` js\n$('@form')\n```\n\nYou can combine role with other selectors as well:\n\n`<form class=\"dark\" role=\"login_form\" method=\"post\"></form>`:\n\n``` js\n$('form.dark@login_form[method=post]')\n```\n\n## Installation\n\nComing soon.\n\n## Changelog\n\n### 1.3.1 (August 24, 2012)\n\n* Override matchesSelector in role.js.\n\n### 1.3.0 (August 18, 2012)\n\n* Added roles, hasRole, addRole, removeRole and toggleRole jQuery methods.\n* jQuery 1.8 compatibility confirmed.\n\n### 1.2.0 (April 19, 2012)\n\n* Total rewrite. jQuery versions 1.2-1.7 compatibility (@rwz)\n\n### 1.0.2 (March 14, 2012)\n\n* Fixes problem in Internet Explorer 8 in jquery.role.js and role.js (issue #11) (thanks @igor-alexandrov for help)\n\n### 1.0.1 (January 27, 2012)\n\n* Fixes problem with multiple roles in Firefox 8 and later (issue #9)\n\n### 1.0.0 (December 26, 2011)\n\n* Remove deprecated function\n* Rewrite in CoffeeScript\n\n### 0.4.1 (December 8, 2011)\n\n* Fix issue #8\n\n### 0.4.0 (December 8, 2011)\n\n* Added specs for jQuery Role\n* Selectors performance improvement for modern browsers (also covers #6)\n* Role extension for querySelectorAll function (`src/role.coffee`)\n\n### 0.3.2 (June 2, 2011)\n\n* Reverted changes made in 0.3.1 because issue #6\n\n### 0.3.1 (May 24, 2011)\n\n* Selectors performance improvement for modern browsers\n\n### 0.3.0 (May 23, 2011)\n\n* Added native Sizzle selectors support (`$('@ajax_link')`)\n\n### 0.2.0 (May 20, 2011)\n\n* Added mechanism to pick roles by element id\n\n### 0.1.0 (May 05, 2011)\n\n* Initial release\n\n## Contributors\n\nOriginal idea by @kossnocorp and @ai.\n\n* @kossnocorp\n* @chrome\n* @rwz\n* @yury\n* @igor-alexandrov\n* @kirs\n\nSpecial thanks to @skfd and @yaroslav for helping with this README.\n\n## License\n\nThe MIT License\n\nCopyright (c) 2011 Sasha Koss\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","maintainers":[{"name":"aburkut","email":"a.burkut90@gmail.com"}],"time":{"modified":"2022-06-19T05:23:21.243Z","created":"2015-06-25T20:36:52.917Z","1.0.0":"2015-06-25T20:36:52.917Z"},"homepage":"https://github.com/aburkut/role","repository":{"type":"git","url":"https://github.com/aburkut/role.git"},"bugs":{"url":"https://github.com/aburkut/role/issues"},"license":"ISC","readmeFilename":"README.md"}