From: Alexander Ebert Date: Wed, 24 Jun 2015 17:24:19 +0000 (+0200) Subject: Fixed object extending and event triggering in `Core` X-Git-Tag: 3.0.0_Beta_1~2254 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=cb57f3453ce3db04fe2d15217bbd2aff084cf0e5;p=GitHub%2FWoltLab%2FWCF.git Fixed object extending and event triggering in `Core` --- diff --git a/wcfsetup/install/files/js/WoltLab/WCF/Core.js b/wcfsetup/install/files/js/WoltLab/WCF/Core.js index eab4c836d8..da79e37438 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/Core.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/Core.js @@ -10,24 +10,20 @@ define([], function() { "use strict"; var _clone = function(variable) { - if (typeof variable === 'object' && variable !== null) { + if (typeof variable === 'object' && (Array.isArray(variable) || Core.isPlainObject(variable))) { return _cloneObject(variable); } return variable; }; - var _cloneArray = function(oldArray) { - return oldArray.slice(); - }; - var _cloneObject = function(obj) { if (!obj) { return null; } if (Array.isArray(obj)) { - return _cloneArray(obj); + return obj.slice(); } var newObj = {}; @@ -181,16 +177,27 @@ define([], function() { return parameters.join('&'); }, - triggerEvent: function(el, eventName) { - var ev; - if (document.createEvent) { - ev = new Event(eventName); - el.dispatchEvent(ev); + /** + * Triggers a custom or built-in event. + * + * @param {Element} element target element + * @param {string} eventName event name + */ + triggerEvent: function(element, eventName) { + var event; + + try { + event = new Event(eventName, { + bubbles: true, + cancelable: true + }); } - else { - ev = document.createEventObject(); - el.fireEvent('on' + eventName, ev); + catch (e) { + event = document.createEvent('Event'); + event.initEvent(eventName, true, true); } + + element.dispatchEvent(event); } };