Merge "mw.Map: add ability to map over an existing object other than 'window'"
[lhc/web/wiklou.git] / resources / jquery / jquery.getAttrs.js
1 /**
2 * Utility to get all attributes of an element directy as an object.
3 *
4 * @author Timo Tijhof, 2011
5 */
6 jQuery.fn.getAttrs = function ( all ) {
7 var map = this[0].attributes,
8 attrs = {},
9 len = map.length,
10 i, v;
11
12 for ( i = 0; i < len; i++ ) {
13 // IE6 includes *all* allowed attributes for thew element (including those
14 // not set). Those have values like undefined, null, 0, false, "" or "inherit".
15 // However there may be genuine attributes set to that. If you need them,
16 // set all to true. They are excluded by default.
17 v = map[i].nodeValue;
18 if ( all || ( v && v !== 'inherit' ) ) {
19 attrs[ map[i].nodeName ] = v;
20 }
21 }
22
23 return attrs;
24 };