Added proper support for objects passed to $.fn.data()
authorAlexander Ebert <ebert@woltlab.com>
Fri, 12 Jul 2013 12:20:16 +0000 (14:20 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 12 Jul 2013 12:20:16 +0000 (14:20 +0200)
Fixes #1407

wcfsetup/install/files/js/WCF.js

index cfba8c6a771a10f4eabee8a9ce24ec07305c499c..93020c1e6a5fb7bffa5a37a52b9072d25dc96b9a 100755 (executable)
         * @see jQuery.fn.data()
         */
        jQuery.fn.data = function(key, value) {
-               if (key && key.match(/ID$/)) {
-                       arguments[0] = key.replace(/ID$/, '-id');
+               if (key) {
+                       switch (typeof key) {
+                               case 'object':
+                                       for (var $key in key) {
+                                               if ($key.match(/ID$/)) {
+                                                       var $value = key[$key];
+                                                       delete key[$key];
+                                                       
+                                                       $key = $key.replace(/ID$/, '-id');
+                                                       key[$key] = $value;
+                                               }
+                                       }
+                                       
+                                       arguments[0] = key;
+                               break;
+                               
+                               case 'string':
+                                       if (key.match(/ID$/)) {
+                                               arguments[0] = key.replace(/ID$/, '-id');
+                                       }
+                               break;
+                       } 
                }
                
+               
                // call jQuery's own data method
                var $data = $jQueryData.apply(this, arguments);