]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - resources/src/jquery/jquery.getAttrs.js
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / resources / src / jquery / jquery.getAttrs.js
1 /**
2  * @class jQuery.plugin.getAttrs
3  */
4 ( function ( $ ) {
5         function serializeControls( controls ) {
6                 var i,
7                         data = {},
8                         len = controls.length;
9
10                 for ( i = 0; i < len; i++ ) {
11                         data[ controls[ i ].name ] = controls[ i ].value;
12                 }
13
14                 return data;
15         }
16
17         /**
18          * Get the attributes of an element directy as a plain object.
19          *
20          * If there is more than one element in the collection, similar to most other jQuery getter methods,
21          * this will use the first element in the collection.
22          *
23          * @return {Object}
24          */
25         $.fn.getAttrs = function () {
26                 return serializeControls( this[ 0 ].attributes );
27         };
28
29         /**
30          * Get form data as a plain object mapping form control names to their values.
31          *
32          * @return {Object}
33          */
34         $.fn.serializeObject = function () {
35                 return serializeControls( this.serializeArray() );
36         };
37 }( jQuery ) );