From: Alexander Ebert Date: Tue, 19 May 2015 13:42:06 +0000 (+0200) Subject: Merge branch 'next' of github.com:WoltLab/WCF into next X-Git-Tag: 3.0.0_Beta_1~2385 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=8c2bb4f9e91db604a900bfe926c1492c6ce35c4a;p=GitHub%2FWoltLab%2FWCF.git Merge branch 'next' of github.com:WoltLab/WCF into next Conflicts: wcfsetup/install/files/js/WoltLab/WCF/Core.js --- 8c2bb4f9e91db604a900bfe926c1492c6ce35c4a diff --cc wcfsetup/install/files/js/WoltLab/WCF/Core.js index 7f78bb4255,836d1e8a70..b52d5e333b --- a/wcfsetup/install/files/js/WoltLab/WCF/Core.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/Core.js @@@ -70,49 -44,19 +70,62 @@@ define([], function() return out; }, + /** + * Returns the object's class name. + * + * @param {object} obj target object + * @return {string} object class name + */ + getType: function(obj) { + return Object.prototype.toString.call(obj).replace(/^\[object (.+)\]$/, '$1'); + }, + + /** + * Returns a RFC4122 version 4 compilant UUID. + * + * @see http://stackoverflow.com/a/2117523 + * @return {string} + */ + getUuid: function() { + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { + var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); + return v.toString(16); + }); + }, + + /** + * Recursively serializes an object into an encoded URI parameter string. + * + * @param {object} obj target object + * @return encoded parameter string + */ + serialize: function(obj) { + var parameters = []; + + for (var key in obj) { + if (obj.hasOwnProperty(key)) { + var value = obj[key]; + + if (Array.isArray(value)) { + for (var i = 0, length = value.length; i < length; i++) { + parameters.push(key + '[]=' + encodeURIComponent(value[i])); + } + + continue; + } + else if (this.getType(value) === 'Object') { + parameters.push(this.serialize(value)); + + continue; + } + + parameters.push(key + '=' + encodeURIComponent(value)); + } + } + + return parameters.join('&'); + }, + triggerEvent: function(el, eventName) { var ev; if (document.createEvent) {