From 1f4f33dd7a31388dee829f0ee4cb4d8bead53acd Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 12 Jul 2013 14:20:16 +0200 Subject: [PATCH] Added proper support for objects passed to $.fn.data() Fixes #1407 --- wcfsetup/install/files/js/WCF.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index cfba8c6a77..93020c1e6a 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -19,10 +19,31 @@ * @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); -- 2.20.1