Namespace fiveui.jquery
Defined in: jquery-plugins.js.
Constructor Attributes | Constructor Name and Description |
---|---|
This module provides several useful jQuery plugins related to checking and reporting UI consistency issues. |
Method Attributes | Method Name and Description |
---|---|
<static> |
fiveui.jquery.attrFilter(a, fn)
General attribute filter This plugin filters for elements whose attribute `a` pass the predicate `fn`, which should take a string and return true or false. |
<static> |
fiveui.jquery.cssIs(prop, set, fn)
General CSS property checker plugin This plugin filters elements, keeping only elements whose CSS property `prop` is a member of the given array `cset`. |
<static> |
fiveui.jquery.cssIsNot(prop, set, fn)
Negated version of fiveui.jquery.cssIs Behaves exactly like fiveui.jquery.cssIs - except that this version excludes elements that have CSS properties and values that match. |
<static> |
fiveui.jquery.hasText(text)
Wrapper for the :contains('text') selector |
<static> |
fiveui.jquery.highlight(hint)
Visually highlight elements in the jQuery object. |
<static> |
fiveui.jquery.linksTo(href)
Filter out elements that do not contain the attribute href=`href`. |
<static> |
fiveui.jquery.noAttr(attribute)
Filter for elements which lack of the given attribute. |
<static> |
fiveui.jquery.noSubElt(sel, A)
Filter for elements having no sub-elements matching the given selector. |
<static> |
fiveui.jquery.notColorSet(cset)
Color checker plugin: filters for elements whose CSS color property is not in the given set. |
<static> |
fiveui.jquery.propDist(prop, log)
Returns a list of css properties that element in the jQuery object have. |
This module provides several useful jQuery plugins related to checking and reporting UI consistency issues.
General attribute filter
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.
$('input').attrFilter('type', function(t) { return t === 'checkbox'; });
- Parameters:
- {string} a
- element attribute name
- {Function} fn
- a predicate to run on the element attribute
- Returns:
- {Object} jQuery object
General CSS property checker plugin
This plugin filters elements, keeping only elements whose CSS property `prop` is a member of the given array `cset`. The names in `cset` and the CSS values that are checked are transformed using the optional given function `fn`. This may be used to normalize values that the browser returns so they can be compared to values in `cset`.
var div = $('<div style="visibility:hidden"></div>') div.cssIs('visibility', ['hidden', 'visible']) // returns the same div
- Parameters:
- {string} prop
- CSS property selector
- {string|string[]} set
- allowable values (either a string or an array of strings)
- {function(string):string} fn Optional
- Function to apply to return values of $(this).css(prop), fn defaults to the identity function.
- Returns:
- {Object} jQuery object
Negated version of fiveui.jquery.cssIs
Behaves exactly like fiveui.jquery.cssIs - except that this version excludes elements that have CSS properties and values that match.
var div = $('<div style="visibility:hidden"></div>') div.cssIsNot('visibility', ['hidden', 'visible']) // returns empty result
- Parameters:
- {string} prop
- CSS property selector
- {string|string[]} set
- allowable values (either a string or an array of strings)
- {function(string):string} fn Optional
- Function to apply to return values of $(this).css(prop), fn defaults to the identity function.
- Returns:
- {Object} jQuery object
Wrapper for the :contains('text') selector
$('div').hasText('to remove').remove();
- Parameters:
- {!string} text
- Text to select for
- Returns:
- {!Object} A modified jQuery object
Visually highlight elements in the jQuery object.
This plugin is useful mostly in the process of writing guidelines, for example the guideline developer can load a page, click the "Break" button on the FiveUI window, enter the browser's Javascript console, and run:
> $5("p").hasText("foo").highlight();
- Parameters:
- {string} hint Optional
- Highlighted border color, defaults to "red"
- Returns:
- {!Object} A modified jQuery object
Filter out elements that do not contain the attribute href=`href`.
- Parameters:
- {string} href
- the href to look for
- Returns:
- {Object} jQuery object
Filter for elements which lack of the given attribute. (see also fiveui.jquery.attrFilter)
$('<table></table>').noAttr('summary').each(function(idx, table) { // `table` is a table element that does not have a "summary" // attribute or that has a "summary" attribute that is empty. });
- Parameters:
- {!string} attribute
- name
- Returns:
- {!Object} a filtered jQuery object
Filter for elements having no sub-elements matching the given selector.
Example: the following should contain no elements// Returns an empty result because the <div> contains a <p> element. $('<div><p>hello</p></div>').noSubElt('p')
- Parameters:
- {!string} sel
- a jQuery selector
- {!Object} A
- filtered jQuery object
Color checker plugin: filters for elements whose CSS color property is not in the given set.
Note: This is a special case of fiveui.jquery.cssIsNot, i.e. $(..).notColorSet(set) == $(..).cssIsNot("color", set, fiveui.color.colorToHex)
- Parameters:
- {string[]} cset
- An array of allowable color strings
- Returns:
- {!Object} A modified jQuery object
- See:
Returns a list of css properties that element in the jQuery object have.
This plugin is useful for analysis of a given page when writing guielines. For example if the guideline developer wants to know what font sizes are used on a loaded page, they can run from the Javascript console:
> $5("*").propDist("font-size", true);
- Parameters:
- {string} prop
- CSS property to be inspected
- {boolean} log Optional
- Boolean which enables console logging of the result; default is `false`.
- Returns:
- {Object} A frequence map { "property": frequency }