size: 0.5k (minified)
A little utility to attach behavior to the data-role attribute more easily.
See this blog post for some background information.
You can install it easily with yeoman or bower:
yeoman install dataroles.js
or
bower install dataroles.js
$.findByRole('show-alert')
is equivalent to:
$("[data-role~='show-alert']")
$("body").findByRole('show-alert')
is equivalent to
$("body").find("[data-role~='show-alert']")
parentsByRole('role')
->parents("[data-role~='role']")
siblingsByRole('role')
->siblings("[data-role~='role']")
- etc..
All standard jQuery traversal methods are wrapped like this.
.hasRole(role)
is quivalent to .is("[data-role~='role']")
multiple roles per data-role attribute are supported (uses the ~=
operator internally)