From cb57f3453ce3db04fe2d15217bbd2aff084cf0e5 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 24 Jun 2015 19:24:19 +0200 Subject: [PATCH] Fixed object extending and event triggering in `Core` --- wcfsetup/install/files/js/WoltLab/WCF/Core.js | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) 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); } }; -- 2.20.1