diff --git a/libraries/cms/html/behavior.php b/libraries/cms/html/behavior.php index 803e641f02bd6..3fc5f2ca5706b 100644 --- a/libraries/cms/html/behavior.php +++ b/libraries/cms/html/behavior.php @@ -960,4 +960,46 @@ public static function tabstate() JHtml::_('script', 'system/tabs-state.js', false, true); self::$loaded[__METHOD__] = true; } + + /** + * Add javascript polyfills. + * + * @param string|array $polyfillTypes The polyfill type(s). Examples: event, array('event', 'classlist'). + * @param array $conditionalBrowser A IE conditional expression. Example: lt IE 9 (lower than IE 9). + * + * @return void + * + * @since __DEPLOY_VERSION__ + */ + public static function polyfill($polyfillTypes = null, $conditionalBrowser = null) + { + if (is_null($polyfillTypes)) + { + return false; + } + + if (!is_array($polyfillTypes)) + { + $polyfillTypes = array($polyfillTypes); + } + + foreach ($polyfillTypes as $polyfillType) + { + $sig = md5(serialize(array($polyfillType, $conditionalBrowser))); + + // Only load once + if (isset(static::$loaded[__METHOD__][$sig])) + { + continue; + } + + // If include according to browser. + $scriptOptions = !is_null($conditionalBrowser) ? array('relative' => true, 'conditional' => $conditionalBrowser) : array('relative' => true); + + JHtml::_('script', 'system/polyfill.' . $polyfillType . '.js', $scriptOptions); + + // Set static array + static::$loaded[__METHOD__][$sig] = true; + } + } } diff --git a/media/system/js/polyfill.classlist-uncompressed.js b/media/system/js/polyfill.classlist-uncompressed.js new file mode 100644 index 0000000000000..4a7c57ebdca09 --- /dev/null +++ b/media/system/js/polyfill.classlist-uncompressed.js @@ -0,0 +1,379 @@ +/** + * Polyfill service v3.9.2 + * For detailed credits and licence information see http://github.com/financial-times/polyfill-service. + * + * Features requested: Element.prototype.classList + * + * - Object.defineProperty, License: CC0 (required by "Element.prototype.classList") + * - _DOMTokenList, License: CC0 (required by "Element.prototype.classList") + * - Document, License: CC0 (required by "Element", "Element.prototype.classList") + * - Element, License: CC0 (required by "Element.prototype.classList") + * - Element.prototype.classList, License: CC0 + * + * @build https://cdn.polyfill.io/v2/polyfill.js?features=Element.prototype.classList&flags=always,gated + * + * @copyright Copyright (c) 2016 Financial Times + * @license MIT License, https://github.com/Financial-Times/polyfill-service/blob/master/LICENSE.md + */ + +(function(undefined) { +if (!(// In IE8, defineProperty could only act on DOM elements, so full support +// for the feature requires the ability to set a property on an arbitrary object +'defineProperty' in Object && (function() { + try { + var a = {}; + Object.defineProperty(a, 'test', {value:42}); + return true; + } catch(e) { + return false + } +}()))) { + +// Object.defineProperty +(function (nativeDefineProperty) { + + var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__'); + var ERR_ACCESSORS_NOT_SUPPORTED = 'Getters & setters cannot be defined on this javascript engine'; + var ERR_VALUE_ACCESSORS = 'A property cannot both have accessors and be writable or have a value'; + + Object.defineProperty = function defineProperty(object, property, descriptor) { + + // Where native support exists, assume it + if (nativeDefineProperty && (object === window || object === document || object === Element.prototype || object instanceof Element)) { + return nativeDefineProperty(object, property, descriptor); + } + + var propertyString = String(property); + var hasValueOrWritable = 'value' in descriptor || 'writable' in descriptor; + var getterType = 'get' in descriptor && typeof descriptor.get; + var setterType = 'set' in descriptor && typeof descriptor.set; + + if (object === null || !(object instanceof Object || typeof object === 'object')) { + throw new TypeError('Object must be an object (Object.defineProperty polyfill)'); + } + + if (!(descriptor instanceof Object)) { + throw new TypeError('Descriptor must be an object (Object.defineProperty polyfill)'); + } + + // handle descriptor.get + if (getterType) { + if (getterType !== 'function') { + throw new TypeError('Getter expected a function (Object.defineProperty polyfill)'); + } + if (!supportsAccessors) { + throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED); + } + if (hasValueOrWritable) { + throw new TypeError(ERR_VALUE_ACCESSORS); + } + object.__defineGetter__(propertyString, descriptor.get); + } else { + object[propertyString] = descriptor.value; + } + + // handle descriptor.set + if (setterType) { + if (setterType !== 'function') { + throw new TypeError('Setter expected a function (Object.defineProperty polyfill)'); + } + if (!supportsAccessors) { + throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED); + } + if (hasValueOrWritable) { + throw new TypeError(ERR_VALUE_ACCESSORS); + } + object.__defineSetter__(propertyString, descriptor.set); + } + + // OK to define value unconditionally - if a getter has been specified as well, an error would be thrown above + if ('value' in descriptor) { + object[propertyString] = descriptor.value; + } + + return object; + }; +}(Object.defineProperty)); + +} + + +// _DOMTokenList +var _DOMTokenList = (function (global) { + + function tokenize(token) { + if (/^-?[_a-zA-Z]+[_a-zA-Z0-9-]*$/.test(token)) { + return String(token); + } else { + throw new Error('InvalidCharacterError: DOM Exception 5'); + } + } + + function toObject(self) { + for (var index = -1, object = {}, element; element = self[++index];) { + object[element] = true; + } + + return object; + } + + function fromObject(self, object) { + var array = [], token; + + for (token in object) { + if (object[token]) { + array.push(token); + } + } + + [].splice.apply(self, [0, self.length].concat(array)); + } + + var DTL = function() {}; + + DTL.prototype = { + constructor: DTL, + item: function item(index) { + return this[parseFloat(index)] || null; + }, + length: Array.prototype.length, + toString: function toString() { + return [].join.call(this, ' '); + }, + + add: function add() { + for (var object = toObject(this), index = 0, token; index in arguments; ++index) { + token = tokenize(arguments[index]); + + object[token] = true; + } + + fromObject(this, object); + }, + contains: function contains(token) { + return token in toObject(this); + }, + remove: function remove() { + for (var object = toObject(this), index = 0, token; index in arguments; ++index) { + token = tokenize(arguments[index]); + + object[token] = false; + } + + fromObject(this, object); + }, + toggle: function toggle(token) { + var + object = toObject(this), + contains = 1 in arguments ? !arguments[1] : tokenize(token) in object; + + object[token] = !contains; + + fromObject(this, object); + + return !contains; + } + }; + + return DTL; + +})(this); +if (!("Document" in this)) { + +// Document + +if (this.HTMLDocument) { // IE8 + + // HTMLDocument is an extension of Document. If the browser has HTMLDocument but not Document, the former will suffice as an alias for the latter. + this.Document = this.HTMLDocument; + +} else { + + // Create an empty function to act as the missing constructor for the document object, attach the document object as its prototype. The function needs to be anonymous else it is hoisted and causes the feature detect to prematurely pass, preventing the assignments below being made. + this.Document = this.HTMLDocument = document.constructor = (new Function('return function Document() {}')()); + this.Document.prototype = document; +} + +} + +if (!('Element' in this && 'HTMLElement' in this)) { + +// Element +(function () { + + // IE8 + if (window.Element && !window.HTMLElement) { + window.HTMLElement = window.Element; + return; + } + + // create Element constructor + window.Element = window.HTMLElement = new Function('return function Element() {}')(); + + // generate sandboxed iframe + var vbody = document.appendChild(document.createElement('body')); + var frame = vbody.appendChild(document.createElement('iframe')); + + // use sandboxed iframe to replicate Element functionality + var frameDocument = frame.contentWindow.document; + var prototype = Element.prototype = frameDocument.appendChild(frameDocument.createElement('*')); + var cache = {}; + + // polyfill Element.prototype on an element + var shiv = function (element, deep) { + var + childNodes = element.childNodes || [], + index = -1, + key, value, childNode; + + if (element.nodeType === 1 && element.constructor !== Element) { + element.constructor = Element; + + for (key in cache) { + value = cache[key]; + element[key] = value; + } + } + + while (childNode = deep && childNodes[++index]) { + shiv(childNode, deep); + } + + return element; + }; + + var elements = document.getElementsByTagName('*'); + var nativeCreateElement = document.createElement; + var interval; + var loopLimit = 100; + + prototype.attachEvent('onpropertychange', function (event) { + var + propertyName = event.propertyName, + nonValue = !cache.hasOwnProperty(propertyName), + newValue = prototype[propertyName], + oldValue = cache[propertyName], + index = -1, + element; + + while (element = elements[++index]) { + if (element.nodeType === 1) { + if (nonValue || element[propertyName] === oldValue) { + element[propertyName] = newValue; + } + } + } + + cache[propertyName] = newValue; + }); + + prototype.constructor = Element; + + if (!prototype.hasAttribute) { + // .hasAttribute + prototype.hasAttribute = function hasAttribute(name) { + return this.getAttribute(name) !== null; + }; + } + + // Apply Element prototype to the pre-existing DOM as soon as the body element appears. + function bodyCheck(e) { + if (!(loopLimit--)) clearTimeout(interval); + if (document.body && !document.body.prototype && /(complete|interactive)/.test(document.readyState)) { + shiv(document, true); + if (interval && document.body.prototype) clearTimeout(interval); + return (!!document.body.prototype); + } + return false; + } + if (!bodyCheck(true)) { + document.onreadystatechange = bodyCheck; + interval = setInterval(bodyCheck, 25); + } + + // Apply to any new elements created after load + document.createElement = function createElement(nodeName) { + var element = nativeCreateElement(String(nodeName).toLowerCase()); + return shiv(element); + }; + + // remove sandboxed iframe + document.removeChild(vbody); +})(); + +} + +if (!('document' in this && "classList" in document.documentElement)) { + +// Element.prototype.classList +Object.defineProperty(Element.prototype, 'classList', { + configurable: true, + get: function () { + + function pull() { + var className = (typeof element.className === "object" ? element.className.baseVal : element.className); + [].splice.apply(classList, [0, classList.length].concat((className || '').replace(/^\s+|\s+$/g, '').split(/\s+/))); + } + + function push() { + if (element.attachEvent) { + element.detachEvent('onpropertychange', pull); + } + + if (typeof element.className === "object") { + element.className.baseVal = original.toString.call(classList); + } else { + element.className = original.toString.call(classList); + } + + if (element.attachEvent) { + element.attachEvent('onpropertychange', pull); + } + } + + var element = this; + var original = _DOMTokenList.prototype; + var ClassList = function ClassList() {}; + var classList; + + ClassList.prototype = new _DOMTokenList; + + ClassList.prototype.item = function item(index) { + return pull(), original.item.apply(classList, arguments); + }; + + ClassList.prototype.toString = function toString() { + return pull(), original.toString.apply(classList, arguments); + }; + + ClassList.prototype.add = function add() { + return pull(), original.add.apply(classList, arguments), push(); + }; + + ClassList.prototype.contains = function contains(token) { + return pull(), original.contains.apply(classList, arguments); + }; + + ClassList.prototype.remove = function remove() { + return pull(), original.remove.apply(classList, arguments), push(); + }; + + ClassList.prototype.toggle = function toggle(token) { + return pull(), token = original.toggle.apply(classList, arguments), push(), token; + }; + + classList = new ClassList; + + if (element.attachEvent) { + element.attachEvent('onpropertychange', pull); + } + + return classList; + } +}); + +} + + +}) +.call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); diff --git a/media/system/js/polyfill.classlist.js b/media/system/js/polyfill.classlist.js new file mode 100644 index 0000000000000..475d64dea0b04 --- /dev/null +++ b/media/system/js/polyfill.classlist.js @@ -0,0 +1 @@ +(function(){"defineProperty"in Object&&function(){try{var t={};return Object.defineProperty(t,"test",{value:42}),!0}catch(e){return!1}}()||!function(t){var e=Object.prototype.hasOwnProperty("__defineGetter__"),n="Getters & setters cannot be defined on this javascript engine",o="A property cannot both have accessors and be writable or have a value";Object.defineProperty=function(r,i,c){if(t&&(r===window||r===document||r===Element.prototype||r instanceof Element))return t(r,i,c);var a=String(i),u="value"in c||"writable"in c,p="get"in c&&typeof c.get,l="set"in c&&typeof c.set;if(null===r||!(r instanceof Object||"object"==typeof r))throw new TypeError("Object must be an object (Object.defineProperty polyfill)");if(!(c instanceof Object))throw new TypeError("Descriptor must be an object (Object.defineProperty polyfill)");if(p){if("function"!==p)throw new TypeError("Getter expected a function (Object.defineProperty polyfill)");if(!e)throw new TypeError(n);if(u)throw new TypeError(o);r.__defineGetter__(a,c.get)}else r[a]=c.value;if(l){if("function"!==l)throw new TypeError("Setter expected a function (Object.defineProperty polyfill)");if(!e)throw new TypeError(n);if(u)throw new TypeError(o);r.__defineSetter__(a,c.set)}return"value"in c&&(r[a]=c.value),r}}(Object.defineProperty);var t=function(){function t(t){if(/^-?[_a-zA-Z]+[_a-zA-Z0-9-]*$/.test(t))return String(t);throw new Error("InvalidCharacterError: DOM Exception 5")}function e(t){for(var e,n=-1,o={};e=t[++n];)o[e]=!0;return o}function n(t,e){var n,o=[];for(n in e)e[n]&&o.push(n);[].splice.apply(t,[0,t.length].concat(o))}var o=function(){};return o.prototype={constructor:o,item:function(t){return this[parseFloat(t)]||null},length:Array.prototype.length,toString:function(){return[].join.call(this," ")},add:function(){for(var o,r=e(this),i=0;i in arguments;++i)o=t(arguments[i]),r[o]=!0;n(this,r)},contains:function(t){return t in e(this)},remove:function(){for(var o,r=e(this),i=0;i in arguments;++i)o=t(arguments[i]),r[o]=!1;n(this,r)},toggle:function(o){var r=e(this),i=1 in arguments?!arguments[1]:t(o)in r;return r[o]=!i,n(this,r),!i}},o}(this);"Document"in this||(this.HTMLDocument?this.Document=this.HTMLDocument:(this.Document=this.HTMLDocument=document.constructor=new Function("return function Document() {}")(),this.Document.prototype=document)),"Element"in this&&"HTMLElement"in this||!function(){function t(){return l--||clearTimeout(e),document.body&&!document.body.prototype&&/(complete|interactive)/.test(document.readyState)?(a(document,!0),e&&document.body.prototype&&clearTimeout(e),!!document.body.prototype):!1}if(window.Element&&!window.HTMLElement)return void(window.HTMLElement=window.Element);window.Element=window.HTMLElement=new Function("return function Element() {}")();var e,n=document.appendChild(document.createElement("body")),o=n.appendChild(document.createElement("iframe")),r=o.contentWindow.document,i=Element.prototype=r.appendChild(r.createElement("*")),c={},a=function(t,e){var n,o,r,i=t.childNodes||[],u=-1;if(1===t.nodeType&&t.constructor!==Element){t.constructor=Element;for(n in c)o=c[n],t[n]=o}for(;r=e&&i[++u];)a(r,e);return t},u=document.getElementsByTagName("*"),p=document.createElement,l=100;i.attachEvent("onpropertychange",function(t){for(var e,n=t.propertyName,o=!c.hasOwnProperty(n),r=i[n],a=c[n],p=-1;e=u[++p];)1===e.nodeType&&(o||e[n]===a)&&(e[n]=r);c[n]=r}),i.constructor=Element,i.hasAttribute||(i.hasAttribute=function(t){return null!==this.getAttribute(t)}),t(!0)||(document.onreadystatechange=t,e=setInterval(t,25)),document.createElement=function(t){var e=p(String(t).toLowerCase());return a(e)},document.removeChild(n)}(),"document"in this&&"classList"in document.documentElement||Object.defineProperty(Element.prototype,"classList",{configurable:!0,get:function(){function e(){var t="object"==typeof r.className?r.className.baseVal:r.className;[].splice.apply(o,[0,o.length].concat((t||"").replace(/^\s+|\s+$/g,"").split(/\s+/)))}function n(){r.attachEvent&&r.detachEvent("onpropertychange",e),"object"==typeof r.className?r.className.baseVal=i.toString.call(o):r.className=i.toString.call(o),r.attachEvent&&r.attachEvent("onpropertychange",e)}var o,r=this,i=t.prototype,c=function(){};return c.prototype=new t,c.prototype.item=function(){return e(),i.item.apply(o,arguments)},c.prototype.toString=function(){return e(),i.toString.apply(o,arguments)},c.prototype.add=function(){return e(),i.add.apply(o,arguments),n()},c.prototype.contains=function(){return e(),i.contains.apply(o,arguments)},c.prototype.remove=function(){return e(),i.remove.apply(o,arguments),n()},c.prototype.toggle=function(t){return e(),t=i.toggle.apply(o,arguments),n(),t},o=new c,r.attachEvent&&r.attachEvent("onpropertychange",e),o}})}).call("object"==typeof window&&window||"object"==typeof self&&self||"object"==typeof global&&global||{}); diff --git a/media/system/js/polyfill.event-uncompressed.js b/media/system/js/polyfill.event-uncompressed.js new file mode 100644 index 0000000000000..74739534cb6f1 --- /dev/null +++ b/media/system/js/polyfill.event-uncompressed.js @@ -0,0 +1,480 @@ +/** + * Polyfill service v3.9.2 + * For detailed credits and licence information see http://github.com/financial-times/polyfill-service. + * + * Features requested: Event,Event.DOMContentLoaded + * + * - Window, License: CC0 (required by "Event", "Event.DOMContentLoaded") + * - Document, License: CC0 (required by "Element", "Event", "Event.DOMContentLoaded") + * - Element, License: CC0 (required by "Event", "Event.DOMContentLoaded") + * - Object.defineProperty, License: CC0 (required by "Event", "Event.DOMContentLoaded") + * - Event, License: CC0 (required by "Event.DOMContentLoaded") + * - Event.DOMContentLoaded, License: CC0 + * + * @build https://cdn.polyfill.io/v2/polyfill.js?features=Event,Event.DOMContentLoaded&flags=always,gated + * + * @copyright Copyright (c) 2016 Financial Times + * @license MIT License, https://github.com/Financial-Times/polyfill-service/blob/master/LICENSE.md + */ + +(function(undefined) { +if (!('Window' in this)) { + +// Window +(function(global) { + if (global.constructor) { + global.Window = global.constructor; + } else { + (global.Window = global.constructor = new Function('return function Window() {}')()).prototype = this; + } +}(this)); + +} + +if (!("Document" in this)) { + +// Document + +if (this.HTMLDocument) { // IE8 + + // HTMLDocument is an extension of Document. If the browser has HTMLDocument but not Document, the former will suffice as an alias for the latter. + this.Document = this.HTMLDocument; + +} else { + + // Create an empty function to act as the missing constructor for the document object, attach the document object as its prototype. The function needs to be anonymous else it is hoisted and causes the feature detect to prematurely pass, preventing the assignments below being made. + this.Document = this.HTMLDocument = document.constructor = (new Function('return function Document() {}')()); + this.Document.prototype = document; +} + +} + +if (!('Element' in this && 'HTMLElement' in this)) { + +// Element +(function () { + + // IE8 + if (window.Element && !window.HTMLElement) { + window.HTMLElement = window.Element; + return; + } + + // create Element constructor + window.Element = window.HTMLElement = new Function('return function Element() {}')(); + + // generate sandboxed iframe + var vbody = document.appendChild(document.createElement('body')); + var frame = vbody.appendChild(document.createElement('iframe')); + + // use sandboxed iframe to replicate Element functionality + var frameDocument = frame.contentWindow.document; + var prototype = Element.prototype = frameDocument.appendChild(frameDocument.createElement('*')); + var cache = {}; + + // polyfill Element.prototype on an element + var shiv = function (element, deep) { + var + childNodes = element.childNodes || [], + index = -1, + key, value, childNode; + + if (element.nodeType === 1 && element.constructor !== Element) { + element.constructor = Element; + + for (key in cache) { + value = cache[key]; + element[key] = value; + } + } + + while (childNode = deep && childNodes[++index]) { + shiv(childNode, deep); + } + + return element; + }; + + var elements = document.getElementsByTagName('*'); + var nativeCreateElement = document.createElement; + var interval; + var loopLimit = 100; + + prototype.attachEvent('onpropertychange', function (event) { + var + propertyName = event.propertyName, + nonValue = !cache.hasOwnProperty(propertyName), + newValue = prototype[propertyName], + oldValue = cache[propertyName], + index = -1, + element; + + while (element = elements[++index]) { + if (element.nodeType === 1) { + if (nonValue || element[propertyName] === oldValue) { + element[propertyName] = newValue; + } + } + } + + cache[propertyName] = newValue; + }); + + prototype.constructor = Element; + + if (!prototype.hasAttribute) { + // .hasAttribute + prototype.hasAttribute = function hasAttribute(name) { + return this.getAttribute(name) !== null; + }; + } + + // Apply Element prototype to the pre-existing DOM as soon as the body element appears. + function bodyCheck(e) { + if (!(loopLimit--)) clearTimeout(interval); + if (document.body && !document.body.prototype && /(complete|interactive)/.test(document.readyState)) { + shiv(document, true); + if (interval && document.body.prototype) clearTimeout(interval); + return (!!document.body.prototype); + } + return false; + } + if (!bodyCheck(true)) { + document.onreadystatechange = bodyCheck; + interval = setInterval(bodyCheck, 25); + } + + // Apply to any new elements created after load + document.createElement = function createElement(nodeName) { + var element = nativeCreateElement(String(nodeName).toLowerCase()); + return shiv(element); + }; + + // remove sandboxed iframe + document.removeChild(vbody); +})(); + +} + +if (!(// In IE8, defineProperty could only act on DOM elements, so full support +// for the feature requires the ability to set a property on an arbitrary object +'defineProperty' in Object && (function() { + try { + var a = {}; + Object.defineProperty(a, 'test', {value:42}); + return true; + } catch(e) { + return false + } +}()))) { + +// Object.defineProperty +(function (nativeDefineProperty) { + + var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__'); + var ERR_ACCESSORS_NOT_SUPPORTED = 'Getters & setters cannot be defined on this javascript engine'; + var ERR_VALUE_ACCESSORS = 'A property cannot both have accessors and be writable or have a value'; + + Object.defineProperty = function defineProperty(object, property, descriptor) { + + // Where native support exists, assume it + if (nativeDefineProperty && (object === window || object === document || object === Element.prototype || object instanceof Element)) { + return nativeDefineProperty(object, property, descriptor); + } + + var propertyString = String(property); + var hasValueOrWritable = 'value' in descriptor || 'writable' in descriptor; + var getterType = 'get' in descriptor && typeof descriptor.get; + var setterType = 'set' in descriptor && typeof descriptor.set; + + if (object === null || !(object instanceof Object || typeof object === 'object')) { + throw new TypeError('Object must be an object (Object.defineProperty polyfill)'); + } + + if (!(descriptor instanceof Object)) { + throw new TypeError('Descriptor must be an object (Object.defineProperty polyfill)'); + } + + // handle descriptor.get + if (getterType) { + if (getterType !== 'function') { + throw new TypeError('Getter expected a function (Object.defineProperty polyfill)'); + } + if (!supportsAccessors) { + throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED); + } + if (hasValueOrWritable) { + throw new TypeError(ERR_VALUE_ACCESSORS); + } + object.__defineGetter__(propertyString, descriptor.get); + } else { + object[propertyString] = descriptor.value; + } + + // handle descriptor.set + if (setterType) { + if (setterType !== 'function') { + throw new TypeError('Setter expected a function (Object.defineProperty polyfill)'); + } + if (!supportsAccessors) { + throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED); + } + if (hasValueOrWritable) { + throw new TypeError(ERR_VALUE_ACCESSORS); + } + object.__defineSetter__(propertyString, descriptor.set); + } + + // OK to define value unconditionally - if a getter has been specified as well, an error would be thrown above + if ('value' in descriptor) { + object[propertyString] = descriptor.value; + } + + return object; + }; +}(Object.defineProperty)); + +} + +if (!((function(global) { + + if (!('Event' in global)) return false; + if (typeof global.Event === 'function') return true; + + try { + + // In IE 9-11, the Event object exists but cannot be instantiated + new Event('click'); + return true; + } catch(e) { + return false; + } +}(this)))) { + +// Event +(function () { + var unlistenableWindowEvents = { + click: 1, + dblclick: 1, + keyup: 1, + keypress: 1, + keydown: 1, + mousedown: 1, + mouseup: 1, + mousemove: 1, + mouseover: 1, + mouseenter: 1, + mouseleave: 1, + mouseout: 1, + storage: 1, + storagecommit: 1, + textinput: 1 + }; + + function indexOf(array, element) { + var + index = -1, + length = array.length; + + while (++index < length) { + if (index in array && array[index] === element) { + return index; + } + } + + return -1; + } + + var existingProto = (window.Event && window.Event.prototype) || null; + window.Event = Window.prototype.Event = function Event(type, eventInitDict) { + if (!type) { + throw new Error('Not enough arguments'); + } + + // Shortcut if browser supports createEvent + if ('createEvent' in document) { + var event = document.createEvent('Event'); + var bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false; + var cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false; + + event.initEvent(type, bubbles, cancelable); + + return event; + } + + var event = document.createEventObject(); + + event.type = type; + event.bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false; + event.cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false; + + return event; + }; + if (existingProto) { + Object.defineProperty(window.Event, 'prototype', { + configurable: false, + enumerable: false, + writable: true, + value: existingProto + }); + } + + if (!('createEvent' in document)) { + window.addEventListener = Window.prototype.addEventListener = Document.prototype.addEventListener = Element.prototype.addEventListener = function addEventListener() { + var + element = this, + type = arguments[0], + listener = arguments[1]; + + if (element === window && type in unlistenableWindowEvents) { + throw new Error('In IE8 the event: ' + type + ' is not available on the window object. Please see https://github.com/Financial-Times/polyfill-service/issues/317 for more information.'); + } + + if (!element._events) { + element._events = {}; + } + + if (!element._events[type]) { + element._events[type] = function (event) { + var + list = element._events[event.type].list, + events = list.slice(), + index = -1, + length = events.length, + eventElement; + + event.preventDefault = function preventDefault() { + if (event.cancelable !== false) { + event.returnValue = false; + } + }; + + event.stopPropagation = function stopPropagation() { + event.cancelBubble = true; + }; + + event.stopImmediatePropagation = function stopImmediatePropagation() { + event.cancelBubble = true; + event.cancelImmediate = true; + }; + + event.currentTarget = element; + event.relatedTarget = event.fromElement || null; + event.target = event.target || event.srcElement || element; + event.timeStamp = new Date().getTime(); + + if (event.clientX) { + event.pageX = event.clientX + document.documentElement.scrollLeft; + event.pageY = event.clientY + document.documentElement.scrollTop; + } + + while (++index < length && !event.cancelImmediate) { + if (index in events) { + eventElement = events[index]; + + if (indexOf(list, eventElement) !== -1 && typeof eventElement === 'function') { + eventElement.call(element, event); + } + } + } + }; + + element._events[type].list = []; + + if (element.attachEvent) { + element.attachEvent('on' + type, element._events[type]); + } + } + + element._events[type].list.push(listener); + }; + + window.removeEventListener = Window.prototype.removeEventListener = Document.prototype.removeEventListener = Element.prototype.removeEventListener = function removeEventListener() { + var + element = this, + type = arguments[0], + listener = arguments[1], + index; + + if (element._events && element._events[type] && element._events[type].list) { + index = indexOf(element._events[type].list, listener); + + if (index !== -1) { + element._events[type].list.splice(index, 1); + + if (!element._events[type].list.length) { + if (element.detachEvent) { + element.detachEvent('on' + type, element._events[type]); + } + delete element._events[type]; + } + } + } + }; + + window.dispatchEvent = Window.prototype.dispatchEvent = Document.prototype.dispatchEvent = Element.prototype.dispatchEvent = function dispatchEvent(event) { + if (!arguments.length) { + throw new Error('Not enough arguments'); + } + + if (!event || typeof event.type !== 'string') { + throw new Error('DOM Events Exception 0'); + } + + var element = this, type = event.type; + + try { + if (!event.bubbles) { + event.cancelBubble = true; + + var cancelBubbleEvent = function (event) { + event.cancelBubble = true; + + (element || window).detachEvent('on' + type, cancelBubbleEvent); + }; + + this.attachEvent('on' + type, cancelBubbleEvent); + } + + this.fireEvent('on' + type, event); + } catch (error) { + event.target = element; + + do { + event.currentTarget = element; + + if ('_events' in element && typeof element._events[type] === 'function') { + element._events[type].call(element, event); + } + + if (typeof element['on' + type] === 'function') { + element['on' + type].call(element, event); + } + + element = element.nodeType === 9 ? element.parentWindow : element.parentNode; + } while (element && !event.cancelBubble); + } + + return true; + }; + } +})(); + +} + +if (!('createEvent' in document)) { + +// Event.DOMContentLoaded +document.attachEvent('onreadystatechange', function() { + if (document.readyState === 'complete') { + document.dispatchEvent(new Event('DOMContentLoaded', { + bubbles: true + })); + } +}); + +} + + +}) +.call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); diff --git a/media/system/js/polyfill.event.js b/media/system/js/polyfill.event.js new file mode 100644 index 0000000000000..5e343282d008f --- /dev/null +++ b/media/system/js/polyfill.event.js @@ -0,0 +1 @@ +(function(e){"Window"in this||!function(e){e.constructor?e.Window=e.constructor:(e.Window=e.constructor=new Function("return function Window() {}")()).prototype=this}(this),"Document"in this||(this.HTMLDocument?this.Document=this.HTMLDocument:(this.Document=this.HTMLDocument=document.constructor=new Function("return function Document() {}")(),this.Document.prototype=document)),"Element"in this&&"HTMLElement"in this||!function(){function e(){return s--||clearTimeout(t),document.body&&!document.body.prototype&&/(complete|interactive)/.test(document.readyState)?(a(document,!0),t&&document.body.prototype&&clearTimeout(t),!!document.body.prototype):!1}if(window.Element&&!window.HTMLElement)return void(window.HTMLElement=window.Element);window.Element=window.HTMLElement=new Function("return function Element() {}")();var t,n=document.appendChild(document.createElement("body")),o=n.appendChild(document.createElement("iframe")),r=o.contentWindow.document,i=Element.prototype=r.appendChild(r.createElement("*")),c={},a=function(e,t){var n,o,r,i=e.childNodes||[],u=-1;if(1===e.nodeType&&e.constructor!==Element){e.constructor=Element;for(n in c)o=c[n],e[n]=o}for(;r=t&&i[++u];)a(r,t);return e},u=document.getElementsByTagName("*"),l=document.createElement,s=100;i.attachEvent("onpropertychange",function(e){for(var t,n=e.propertyName,o=!c.hasOwnProperty(n),r=i[n],a=c[n],l=-1;t=u[++l];)1===t.nodeType&&(o||t[n]===a)&&(t[n]=r);c[n]=r}),i.constructor=Element,i.hasAttribute||(i.hasAttribute=function(e){return null!==this.getAttribute(e)}),e(!0)||(document.onreadystatechange=e,t=setInterval(e,25)),document.createElement=function(e){var t=l(String(e).toLowerCase());return a(t)},document.removeChild(n)}(),"defineProperty"in Object&&function(){try{var e={};return Object.defineProperty(e,"test",{value:42}),!0}catch(t){return!1}}()||!function(e){var t=Object.prototype.hasOwnProperty("__defineGetter__"),n="Getters & setters cannot be defined on this javascript engine",o="A property cannot both have accessors and be writable or have a value";Object.defineProperty=function(r,i,c){if(e&&(r===window||r===document||r===Element.prototype||r instanceof Element))return e(r,i,c);var a=String(i),u="value"in c||"writable"in c,l="get"in c&&typeof c.get,s="set"in c&&typeof c.set;if(null===r||!(r instanceof Object||"object"==typeof r))throw new TypeError("Object must be an object (Object.defineProperty polyfill)");if(!(c instanceof Object))throw new TypeError("Descriptor must be an object (Object.defineProperty polyfill)");if(l){if("function"!==l)throw new TypeError("Getter expected a function (Object.defineProperty polyfill)");if(!t)throw new TypeError(n);if(u)throw new TypeError(o);r.__defineGetter__(a,c.get)}else r[a]=c.value;if(s){if("function"!==s)throw new TypeError("Setter expected a function (Object.defineProperty polyfill)");if(!t)throw new TypeError(n);if(u)throw new TypeError(o);r.__defineSetter__(a,c.set)}return"value"in c&&(r[a]=c.value),r}}(Object.defineProperty),function(e){if(!("Event"in e))return!1;if("function"==typeof e.Event)return!0;try{return new Event("click"),!0}catch(t){return!1}}(this)||!function(){function t(e,t){for(var n=-1,o=e.length;++n