diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:12:12 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:12:12 -0400 |
commit | c9aa36da061816dee256a979c2ff8d2ee41824d9 (patch) | |
tree | 29f7002b80ee984b488bd047dbbd80b36bf892e9 /resources/src/jquery/jquery.getAttrs.js | |
parent | b4274e0e33eafb5e9ead9d949ebf031a9fb8363b (diff) | |
parent | d1ba966140d7a60cd5ae4e8667ceb27c1a138592 (diff) |
Merge branch 'archwiki'
# Conflicts:
# skins/ArchLinux.php
# skins/ArchLinux/archlogo.gif
Diffstat (limited to 'resources/src/jquery/jquery.getAttrs.js')
-rw-r--r-- | resources/src/jquery/jquery.getAttrs.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/resources/src/jquery/jquery.getAttrs.js b/resources/src/jquery/jquery.getAttrs.js new file mode 100644 index 00000000..c44831c4 --- /dev/null +++ b/resources/src/jquery/jquery.getAttrs.js @@ -0,0 +1,42 @@ +/** + * @class jQuery.plugin.getAttrs + */ + +/** + * Get the attributes of an element directy as a plain object. + * + * If there are more elements in the collection, like most jQuery get/read methods, + * this method will use the first element in the collection. + * + * In IE6, the `attributes` map of a node includes *all* allowed attributes + * for an element (including those not set). Those will have values like + * `undefined`, `null`, `0`, `false`, `""` or `"inherit"`. + * + * However there may be attributes genuinely set to one of those values, and there + * is no way to distinguish between attributes set to that and those not set and + * it being the default. If you need them, set `all` to `true`. They are filtered out + * by default. + * + * @param {boolean} [all=false] + * @return {Object} + */ +jQuery.fn.getAttrs = function ( all ) { + var map = this[0].attributes, + attrs = {}, + len = map.length, + i, v; + + for ( i = 0; i < len; i++ ) { + v = map[i].nodeValue; + if ( all || ( v && v !== 'inherit' ) ) { + attrs[ map[i].nodeName ] = v; + } + } + + return attrs; +}; + +/** + * @class jQuery + * @mixins jQuery.plugin.getAttrs + */ |