diff options
author | Benjamin Jones <bjones@galois.com> | 2013-07-23 18:11:28 -0700 |
---|---|---|
committer | Benjamin Jones <bjones@galois.com> | 2013-07-23 18:11:28 -0700 |
commit | 03f6dcbb143849faf318bb6a716aa2e39beb7117 (patch) | |
tree | 8ba465213a74f16a1ff56d92b53de1bfeed33465 /src/js/fiveui/injected | |
parent | 4645e497ef84875c201a2a6d69accf23f6e2d0bb (diff) |
added new jQuery plugin called attrFilter along with unit tests for it
Diffstat (limited to 'src/js/fiveui/injected')
-rw-r--r-- | src/js/fiveui/injected/jquery-plugins.js | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/js/fiveui/injected/jquery-plugins.js b/src/js/fiveui/injected/jquery-plugins.js index 5a32031..1589972 100644 --- a/src/js/fiveui/injected/jquery-plugins.js +++ b/src/js/fiveui/injected/jquery-plugins.js @@ -43,7 +43,8 @@ fiveui.jquery.hasText = function (text) { }; /** - * Filter for elements which lack of the given attribute. + * Filter for elements which lack of the given attribute. (see also + * fiveui.jquery.attrFilter) * * Example: * @@ -133,6 +134,24 @@ fiveui.jquery.cssIsNot = function (prop, set, fn) { } /** + * General attribute filter + * + * @description This plugin filters for elements whose attribute `a` pass + * the predicate `fn`, which should take a string and return true or false. + * Elements that don't have the attribute are automatically filtered out. + * + * @param {String} a element attribute name + * @param {Function} fn a predicate to run on the element attribute + * @returns {Object} jQuery object + */ +fiveui.jquery.attrFilter = function (a, fn) { + return this.filter(function () { + var x = $(this).attr(a); + return x != undefined && fn(x); + }); +} + +/** * Filter out elements that do not contain the attribute * href=`href`. * |