diff --git a/bower.json b/bower.json index a277b0b..a4dfcc4 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "aurelia-pal-browser", - "version": "1.1.0", + "version": "1.2.0", "description": "The browser-specific implementation of Aurelia's platform abstraction layer.", "keywords": [ "aurelia", diff --git a/dist/amd/aurelia-pal-browser.js b/dist/amd/aurelia-pal-browser.js index 39da34e..9a4bde6 100644 --- a/dist/amd/aurelia-pal-browser.js +++ b/dist/amd/aurelia-pal-browser.js @@ -5,12 +5,6 @@ define(['exports', 'aurelia-pal'], function (exports, _aureliaPal) { value: true }); exports._DOM = exports._FEATURE = exports._PLATFORM = undefined; - exports._ensureFunctionName = _ensureFunctionName; - exports._ensureClassList = _ensureClassList; - exports._ensurePerformance = _ensurePerformance; - exports._ensureCustomEvent = _ensureCustomEvent; - exports._ensureElementMatches = _ensureElementMatches; - exports._ensureHTMLTemplateElement = _ensureHTMLTemplateElement; exports.initialize = initialize; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { @@ -35,8 +29,8 @@ define(['exports', 'aurelia-pal'], function (exports, _aureliaPal) { } }; - function _ensureFunctionName() { - function test() {} + if (typeof FEATURE_NO_IE === 'undefined') { + var test = function test() {}; if (!test.name) { Object.defineProperty(Function.prototype, 'name', { @@ -50,7 +44,7 @@ define(['exports', 'aurelia-pal'], function (exports, _aureliaPal) { } } - function _ensureClassList() { + if (typeof FEATURE_NO_IE === 'undefined') { if (!('classList' in document.createElement('_')) || document.createElementNS && !('classList' in document.createElementNS('http://www.w3.org/2000/svg', 'g'))) { (function () { var protoProp = 'prototype'; @@ -214,7 +208,7 @@ define(['exports', 'aurelia-pal'], function (exports, _aureliaPal) { } } - function _ensurePerformance() { + if (typeof FEATURE_NO_IE === 'undefined') { // @license http://opensource.org/licenses/MIT if ('performance' in window === false) { window.performance = {}; @@ -237,7 +231,25 @@ define(['exports', 'aurelia-pal'], function (exports, _aureliaPal) { _PLATFORM.performance = window.performance; } - function _ensureCustomEvent() { + if (typeof FEATURE_NO_IE === 'undefined') { + (function () { + var con = window.console = window.console || {}; + var nop = function nop() {}; + + if (!con.memory) con.memory = {}; + ('assert,clear,count,debug,dir,dirxml,error,exception,group,' + 'groupCollapsed,groupEnd,info,log,markTimeline,profile,profiles,profileEnd,' + 'show,table,time,timeEnd,timeline,timelineEnd,timeStamp,trace,warn').split(',').forEach(function (m) { + if (!con[m]) con[m] = nop; + }); + + if (_typeof(con.log) === 'object') { + 'log,info,warn,error,assert,dir,clear,profile,profileEnd'.split(',').forEach(function (method) { + console[method] = this.bind(console[method], console); + }, Function.prototype.call); + } + })(); + } + + if (typeof FEATURE_NO_IE === 'undefined') { if (!window.CustomEvent || typeof window.CustomEvent !== 'function') { var _CustomEvent = function _CustomEvent(event, params) { params = params || { @@ -256,90 +268,78 @@ define(['exports', 'aurelia-pal'], function (exports, _aureliaPal) { } } - function _ensureElementMatches() { - if (Element && !Element.prototype.matches) { - var proto = Element.prototype; - proto.matches = proto.matchesSelector || proto.mozMatchesSelector || proto.msMatchesSelector || proto.oMatchesSelector || proto.webkitMatchesSelector; - } + if (Element && !Element.prototype.matches) { + var proto = Element.prototype; + proto.matches = proto.matchesSelector || proto.mozMatchesSelector || proto.msMatchesSelector || proto.oMatchesSelector || proto.webkitMatchesSelector; } - var _FEATURE = exports._FEATURE = {}; - - _FEATURE.shadowDOM = function () { - return !!HTMLElement.prototype.attachShadow; - }(); - - _FEATURE.scopedCSS = function () { - return 'scoped' in document.createElement('style'); - }(); - - _FEATURE.htmlTemplateElement = function () { - return 'content' in document.createElement('template'); - }(); - - _FEATURE.mutationObserver = function () { - return !!(window.MutationObserver || window.WebKitMutationObserver); - }(); - - function _ensureHTMLTemplateElement() { - function isSVGTemplate(el) { - return el.tagName === 'template' && el.namespaceURI === 'http://www.w3.org/2000/svg'; + var _FEATURE = exports._FEATURE = { + shadowDOM: !!HTMLElement.prototype.attachShadow, + scopedCSS: 'scoped' in document.createElement('style'), + htmlTemplateElement: 'content' in document.createElement('template'), + mutationObserver: !!(window.MutationObserver || window.WebKitMutationObserver), + ensureHTMLTemplateElement: function ensureHTMLTemplateElement(t) { + return t; } + }; - function fixSVGTemplateElement(el) { - var template = el.ownerDocument.createElement('template'); - var attrs = el.attributes; - var length = attrs.length; - var attr = void 0; + if (typeof FEATURE_NO_IE === 'undefined') { + (function () { + var isSVGTemplate = function isSVGTemplate(el) { + return el.tagName === 'template' && el.namespaceURI === 'http://www.w3.org/2000/svg'; + }; - el.parentNode.insertBefore(template, el); + var fixSVGTemplateElement = function fixSVGTemplateElement(el) { + var template = el.ownerDocument.createElement('template'); + var attrs = el.attributes; + var length = attrs.length; + var attr = void 0; - while (length-- > 0) { - attr = attrs[length]; - template.setAttribute(attr.name, attr.value); - el.removeAttribute(attr.name); - } + el.parentNode.insertBefore(template, el); - el.parentNode.removeChild(el); + while (length-- > 0) { + attr = attrs[length]; + template.setAttribute(attr.name, attr.value); + el.removeAttribute(attr.name); + } - return fixHTMLTemplateElement(template); - } + el.parentNode.removeChild(el); - function fixHTMLTemplateElement(template) { - var content = template.content = document.createDocumentFragment(); - var child = void 0; + return fixHTMLTemplateElement(template); + }; - while (child = template.firstChild) { - content.appendChild(child); - } + var fixHTMLTemplateElement = function fixHTMLTemplateElement(template) { + var content = template.content = document.createDocumentFragment(); + var child = void 0; - return template; - } + while (child = template.firstChild) { + content.appendChild(child); + } - function fixHTMLTemplateElementRoot(template) { - var content = fixHTMLTemplateElement(template).content; - var childTemplates = content.querySelectorAll('template'); + return template; + }; - for (var i = 0, ii = childTemplates.length; i < ii; ++i) { - var child = childTemplates[i]; + var fixHTMLTemplateElementRoot = function fixHTMLTemplateElementRoot(template) { + var content = fixHTMLTemplateElement(template).content; + var childTemplates = content.querySelectorAll('template'); - if (isSVGTemplate(child)) { - fixSVGTemplateElement(child); - } else { - fixHTMLTemplateElement(child); - } - } + for (var i = 0, ii = childTemplates.length; i < ii; ++i) { + var child = childTemplates[i]; - return template; - } + if (isSVGTemplate(child)) { + fixSVGTemplateElement(child); + } else { + fixHTMLTemplateElement(child); + } + } - if (_FEATURE.htmlTemplateElement) { - _FEATURE.ensureHTMLTemplateElement = function (template) { return template; }; - } else { - _FEATURE.ensureHTMLTemplateElement = fixHTMLTemplateElementRoot; - } + + if (!_FEATURE.htmlTemplateElement) { + _FEATURE.ensureHTMLTemplateElement = fixHTMLTemplateElementRoot; + } + })(); } var shadowPoly = window.ShadowDOMPolyfill || null; @@ -452,40 +452,11 @@ define(['exports', 'aurelia-pal'], function (exports, _aureliaPal) { return; } - _ensureCustomEvent(); - _ensureFunctionName(); - _ensureHTMLTemplateElement(); - _ensureElementMatches(); - _ensureClassList(); - _ensurePerformance(); - (0, _aureliaPal.initializePAL)(function (platform, feature, dom) { Object.assign(platform, _PLATFORM); Object.assign(feature, _FEATURE); Object.assign(dom, _DOM); - (function (global) { - global.console = global.console || {}; - var con = global.console; - var prop = void 0; - var method = void 0; - var empty = {}; - var dummy = function dummy() {}; - var properties = 'memory'.split(','); - var methods = ('assert,clear,count,debug,dir,dirxml,error,exception,group,' + 'groupCollapsed,groupEnd,info,log,markTimeline,profile,profiles,profileEnd,' + 'show,table,time,timeEnd,timeline,timelineEnd,timeStamp,trace,warn').split(','); - while (prop = properties.pop()) { - if (!con[prop]) con[prop] = empty; - }while (method = methods.pop()) { - if (!con[method]) con[method] = dummy; - } - })(platform.global); - - if (platform.global.console && _typeof(console.log) === 'object') { - ['log', 'info', 'warn', 'error', 'assert', 'dir', 'clear', 'profile', 'profileEnd'].forEach(function (method) { - console[method] = this.bind(console[method], console); - }, Function.prototype.call); - } - Object.defineProperty(dom, 'title', { get: function get() { return document.title; diff --git a/dist/aurelia-pal-browser.d.ts b/dist/aurelia-pal-browser.d.ts index ddd59b7..6a7ffce 100644 --- a/dist/aurelia-pal-browser.d.ts +++ b/dist/aurelia-pal-browser.d.ts @@ -3,6 +3,15 @@ import { isInitialized } from 'aurelia-pal'; +// DOM polyfills +// Actually inlined by our build because of build/paths.js but `import "m"` is not properly removed!? +// import './console'; +// import './custom-event'; +// import './function-name'; +// import './html-template-element'; +// import './element-matches'; +// import './class-list'; +// import './performance'; /** * Initializes the PAL with the Browser-targeted implementation. */ diff --git a/dist/aurelia-pal-browser.js b/dist/aurelia-pal-browser.js index 26a4c26..c55495f 100644 --- a/dist/aurelia-pal-browser.js +++ b/dist/aurelia-pal-browser.js @@ -15,7 +15,7 @@ export const _PLATFORM = { } }; -export function _ensureFunctionName(): void { +if (typeof FEATURE_NO_IE === 'undefined') { // Fix Function#name on browsers that do not support it (IE): function test() {} @@ -32,7 +32,7 @@ export function _ensureFunctionName(): void { } } -export function _ensureClassList(): void { +if (typeof FEATURE_NO_IE === 'undefined') { /* * classList polyfill. Forked from https://github.com/eligrey/classList.js * @@ -210,7 +210,7 @@ export function _ensureClassList(): void { } } -export function _ensurePerformance(): void { +if (typeof FEATURE_NO_IE === 'undefined') { // performance polyfill. Copied from https://gist.github.com/paulirish/5438650 // https://gist.github.com/paulirish/5438650 @@ -236,7 +236,36 @@ export function _ensurePerformance(): void { _PLATFORM.performance = window.performance; } -export function _ensureCustomEvent(): void { +if (typeof FEATURE_NO_IE === 'undefined') { + // References to IE 9 in this file mean the *real* IE 9 browser, not IE 11 in 9 emulation mode. + // Note that in IE 9, until the F12 are actually opened window.console is undefined! + let con = window.console = window.console || {}; + let nop = function() {}; + // console.memory is actually Chrome-only at this point, + // but Aurelia does not use it so we're cutting down on "polyfills" here. + // Moreover, that object is utterly useless in other browsers, as all stats would actually be 'undefined' + if (!con.memory) con.memory = {}; + ('assert,clear,count,debug,dir,dirxml,error,exception,group,' + + 'groupCollapsed,groupEnd,info,log,markTimeline,profile,profiles,profileEnd,' + + 'show,table,time,timeEnd,timeline,timelineEnd,timeStamp,trace,warn') + .split(',') + .forEach(m => { if (!con[m]) con[m] = nop; }); + + // This is really f***ed up IE 9 stuff. + // You can be in a situation where console.log is an object, not a function. + // And the magic voodoo below that should _not_ work (the Function.prototype.call.bind(object,...) part) + // actually kicks IE 9 into converting that object into a real function that actually logs stuff. + // See http://patik.com/blog/complete-cross-browser-console-log/ + if (typeof con.log === 'object') { + 'log,info,warn,error,assert,dir,clear,profile,profileEnd' + .split(',') + .forEach(function(method) { + console[method] = this.bind(console[method], console); + }, Function.prototype.call); + } +} + +if (typeof FEATURE_NO_IE === 'undefined') { if (!window.CustomEvent || typeof window.CustomEvent !== 'function') { let CustomEvent = function(event, params) { params = params || { @@ -255,34 +284,22 @@ export function _ensureCustomEvent(): void { } } -export function _ensureElementMatches(): void { - if (Element && !Element.prototype.matches) { - let proto = Element.prototype; - proto.matches = proto.matchesSelector || - proto.mozMatchesSelector || proto.msMatchesSelector || - proto.oMatchesSelector || proto.webkitMatchesSelector; - } +if (Element && !Element.prototype.matches) { + let proto = Element.prototype; + proto.matches = proto.matchesSelector || + proto.mozMatchesSelector || proto.msMatchesSelector || + proto.oMatchesSelector || proto.webkitMatchesSelector; } -export const _FEATURE = {}; - -_FEATURE.shadowDOM = (function() { - return !!HTMLElement.prototype.attachShadow; -})(); - -_FEATURE.scopedCSS = (function() { - return 'scoped' in document.createElement('style'); -})(); - -_FEATURE.htmlTemplateElement = (function() { - return 'content' in document.createElement('template'); -})(); - -_FEATURE.mutationObserver = (function() { - return !!(window.MutationObserver || window.WebKitMutationObserver); -})(); +export const _FEATURE = { + shadowDOM: !!HTMLElement.prototype.attachShadow, + scopedCSS: 'scoped' in document.createElement('style'), + htmlTemplateElement: 'content' in document.createElement('template'), + mutationObserver: !!(window.MutationObserver || window.WebKitMutationObserver), + ensureHTMLTemplateElement: t => t, +}; -export function _ensureHTMLTemplateElement(): void { +if (typeof FEATURE_NO_IE === 'undefined') { function isSVGTemplate(el) { return el.tagName === 'template' && el.namespaceURI === 'http://www.w3.org/2000/svg'; @@ -335,9 +352,7 @@ export function _ensureHTMLTemplateElement(): void { return template; } - if (_FEATURE.htmlTemplateElement) { - _FEATURE.ensureHTMLTemplateElement = function(template) { return template; }; - } else { + if (!_FEATURE.htmlTemplateElement) { _FEATURE.ensureHTMLTemplateElement = fixHTMLTemplateElementRoot; } } @@ -450,6 +465,16 @@ export const _DOM = { } }; +// DOM polyfills +// Actually inlined by our build because of build/paths.js but `import "m"` is not properly removed!? +// import './console'; +// import './custom-event'; +// import './function-name'; +// import './html-template-element'; +// import './element-matches'; +// import './class-list'; +// import './performance'; + /** * Initializes the PAL with the Browser-targeted implementation. */ @@ -458,58 +483,22 @@ export function initialize(): void { return; } - _ensureCustomEvent(); - _ensureFunctionName(); - _ensureHTMLTemplateElement(); - _ensureElementMatches(); - _ensureClassList(); - _ensurePerformance(); - initializePAL((platform, feature, dom) => { Object.assign(platform, _PLATFORM); Object.assign(feature, _FEATURE); Object.assign(dom, _DOM); - (function(global) { - global.console = global.console || {}; - let con = global.console; - let prop; - let method; - let empty = {}; - let dummy = function() {}; - let properties = 'memory'.split(','); - let methods = ('assert,clear,count,debug,dir,dirxml,error,exception,group,' + - 'groupCollapsed,groupEnd,info,log,markTimeline,profile,profiles,profileEnd,' + - 'show,table,time,timeEnd,timeline,timelineEnd,timeStamp,trace,warn').split(','); - while (prop = properties.pop()) if (!con[prop]) con[prop] = empty; - while (method = methods.pop()) if (!con[method]) con[method] = dummy; - })(platform.global); - - if (platform.global.console && typeof console.log === 'object') { - ['log', 'info', 'warn', 'error', 'assert', 'dir', 'clear', 'profile', 'profileEnd'].forEach(function(method) { - console[method] = this.bind(console[method], console); - }, Function.prototype.call); - } - Object.defineProperty(dom, 'title', { - get: function() { - return document.title; - }, - set: function(value) { - document.title = value; - } + get: () => document.title, + set: (value) => { document.title = value; } }); Object.defineProperty(dom, 'activeElement', { - get: function() { - return document.activeElement; - } + get: () => document.activeElement }); Object.defineProperty(platform, 'XMLHttpRequest', { - get: function() { - return platform.global.XMLHttpRequest; - } + get: () => platform.global.XMLHttpRequest }); }); } diff --git a/dist/commonjs/aurelia-pal-browser.js b/dist/commonjs/aurelia-pal-browser.js index ac72db2..a571c89 100644 --- a/dist/commonjs/aurelia-pal-browser.js +++ b/dist/commonjs/aurelia-pal-browser.js @@ -7,12 +7,6 @@ exports._DOM = exports._FEATURE = exports._PLATFORM = undefined; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; -exports._ensureFunctionName = _ensureFunctionName; -exports._ensureClassList = _ensureClassList; -exports._ensurePerformance = _ensurePerformance; -exports._ensureCustomEvent = _ensureCustomEvent; -exports._ensureElementMatches = _ensureElementMatches; -exports._ensureHTMLTemplateElement = _ensureHTMLTemplateElement; exports.initialize = initialize; var _aureliaPal = require('aurelia-pal'); @@ -33,8 +27,8 @@ var _PLATFORM = exports._PLATFORM = { } }; -function _ensureFunctionName() { - function test() {} +if (typeof FEATURE_NO_IE === 'undefined') { + var test = function test() {}; if (!test.name) { Object.defineProperty(Function.prototype, 'name', { @@ -48,7 +42,7 @@ function _ensureFunctionName() { } } -function _ensureClassList() { +if (typeof FEATURE_NO_IE === 'undefined') { if (!('classList' in document.createElement('_')) || document.createElementNS && !('classList' in document.createElementNS('http://www.w3.org/2000/svg', 'g'))) { (function () { var protoProp = 'prototype'; @@ -212,7 +206,7 @@ function _ensureClassList() { } } -function _ensurePerformance() { +if (typeof FEATURE_NO_IE === 'undefined') { // @license http://opensource.org/licenses/MIT if ('performance' in window === false) { window.performance = {}; @@ -235,7 +229,25 @@ function _ensurePerformance() { _PLATFORM.performance = window.performance; } -function _ensureCustomEvent() { +if (typeof FEATURE_NO_IE === 'undefined') { + (function () { + var con = window.console = window.console || {}; + var nop = function nop() {}; + + if (!con.memory) con.memory = {}; + ('assert,clear,count,debug,dir,dirxml,error,exception,group,' + 'groupCollapsed,groupEnd,info,log,markTimeline,profile,profiles,profileEnd,' + 'show,table,time,timeEnd,timeline,timelineEnd,timeStamp,trace,warn').split(',').forEach(function (m) { + if (!con[m]) con[m] = nop; + }); + + if (_typeof(con.log) === 'object') { + 'log,info,warn,error,assert,dir,clear,profile,profileEnd'.split(',').forEach(function (method) { + console[method] = this.bind(console[method], console); + }, Function.prototype.call); + } + })(); +} + +if (typeof FEATURE_NO_IE === 'undefined') { if (!window.CustomEvent || typeof window.CustomEvent !== 'function') { var _CustomEvent = function _CustomEvent(event, params) { params = params || { @@ -254,90 +266,78 @@ function _ensureCustomEvent() { } } -function _ensureElementMatches() { - if (Element && !Element.prototype.matches) { - var proto = Element.prototype; - proto.matches = proto.matchesSelector || proto.mozMatchesSelector || proto.msMatchesSelector || proto.oMatchesSelector || proto.webkitMatchesSelector; - } +if (Element && !Element.prototype.matches) { + var proto = Element.prototype; + proto.matches = proto.matchesSelector || proto.mozMatchesSelector || proto.msMatchesSelector || proto.oMatchesSelector || proto.webkitMatchesSelector; } -var _FEATURE = exports._FEATURE = {}; - -_FEATURE.shadowDOM = function () { - return !!HTMLElement.prototype.attachShadow; -}(); - -_FEATURE.scopedCSS = function () { - return 'scoped' in document.createElement('style'); -}(); - -_FEATURE.htmlTemplateElement = function () { - return 'content' in document.createElement('template'); -}(); - -_FEATURE.mutationObserver = function () { - return !!(window.MutationObserver || window.WebKitMutationObserver); -}(); - -function _ensureHTMLTemplateElement() { - function isSVGTemplate(el) { - return el.tagName === 'template' && el.namespaceURI === 'http://www.w3.org/2000/svg'; +var _FEATURE = exports._FEATURE = { + shadowDOM: !!HTMLElement.prototype.attachShadow, + scopedCSS: 'scoped' in document.createElement('style'), + htmlTemplateElement: 'content' in document.createElement('template'), + mutationObserver: !!(window.MutationObserver || window.WebKitMutationObserver), + ensureHTMLTemplateElement: function ensureHTMLTemplateElement(t) { + return t; } +}; - function fixSVGTemplateElement(el) { - var template = el.ownerDocument.createElement('template'); - var attrs = el.attributes; - var length = attrs.length; - var attr = void 0; +if (typeof FEATURE_NO_IE === 'undefined') { + (function () { + var isSVGTemplate = function isSVGTemplate(el) { + return el.tagName === 'template' && el.namespaceURI === 'http://www.w3.org/2000/svg'; + }; - el.parentNode.insertBefore(template, el); + var fixSVGTemplateElement = function fixSVGTemplateElement(el) { + var template = el.ownerDocument.createElement('template'); + var attrs = el.attributes; + var length = attrs.length; + var attr = void 0; - while (length-- > 0) { - attr = attrs[length]; - template.setAttribute(attr.name, attr.value); - el.removeAttribute(attr.name); - } + el.parentNode.insertBefore(template, el); - el.parentNode.removeChild(el); + while (length-- > 0) { + attr = attrs[length]; + template.setAttribute(attr.name, attr.value); + el.removeAttribute(attr.name); + } - return fixHTMLTemplateElement(template); - } + el.parentNode.removeChild(el); - function fixHTMLTemplateElement(template) { - var content = template.content = document.createDocumentFragment(); - var child = void 0; + return fixHTMLTemplateElement(template); + }; - while (child = template.firstChild) { - content.appendChild(child); - } + var fixHTMLTemplateElement = function fixHTMLTemplateElement(template) { + var content = template.content = document.createDocumentFragment(); + var child = void 0; - return template; - } + while (child = template.firstChild) { + content.appendChild(child); + } - function fixHTMLTemplateElementRoot(template) { - var content = fixHTMLTemplateElement(template).content; - var childTemplates = content.querySelectorAll('template'); + return template; + }; - for (var i = 0, ii = childTemplates.length; i < ii; ++i) { - var child = childTemplates[i]; + var fixHTMLTemplateElementRoot = function fixHTMLTemplateElementRoot(template) { + var content = fixHTMLTemplateElement(template).content; + var childTemplates = content.querySelectorAll('template'); - if (isSVGTemplate(child)) { - fixSVGTemplateElement(child); - } else { - fixHTMLTemplateElement(child); - } - } + for (var i = 0, ii = childTemplates.length; i < ii; ++i) { + var child = childTemplates[i]; - return template; - } + if (isSVGTemplate(child)) { + fixSVGTemplateElement(child); + } else { + fixHTMLTemplateElement(child); + } + } - if (_FEATURE.htmlTemplateElement) { - _FEATURE.ensureHTMLTemplateElement = function (template) { return template; }; - } else { - _FEATURE.ensureHTMLTemplateElement = fixHTMLTemplateElementRoot; - } + + if (!_FEATURE.htmlTemplateElement) { + _FEATURE.ensureHTMLTemplateElement = fixHTMLTemplateElementRoot; + } + })(); } var shadowPoly = window.ShadowDOMPolyfill || null; @@ -450,40 +450,11 @@ function initialize() { return; } - _ensureCustomEvent(); - _ensureFunctionName(); - _ensureHTMLTemplateElement(); - _ensureElementMatches(); - _ensureClassList(); - _ensurePerformance(); - (0, _aureliaPal.initializePAL)(function (platform, feature, dom) { Object.assign(platform, _PLATFORM); Object.assign(feature, _FEATURE); Object.assign(dom, _DOM); - (function (global) { - global.console = global.console || {}; - var con = global.console; - var prop = void 0; - var method = void 0; - var empty = {}; - var dummy = function dummy() {}; - var properties = 'memory'.split(','); - var methods = ('assert,clear,count,debug,dir,dirxml,error,exception,group,' + 'groupCollapsed,groupEnd,info,log,markTimeline,profile,profiles,profileEnd,' + 'show,table,time,timeEnd,timeline,timelineEnd,timeStamp,trace,warn').split(','); - while (prop = properties.pop()) { - if (!con[prop]) con[prop] = empty; - }while (method = methods.pop()) { - if (!con[method]) con[method] = dummy; - } - })(platform.global); - - if (platform.global.console && _typeof(console.log) === 'object') { - ['log', 'info', 'warn', 'error', 'assert', 'dir', 'clear', 'profile', 'profileEnd'].forEach(function (method) { - console[method] = this.bind(console[method], console); - }, Function.prototype.call); - } - Object.defineProperty(dom, 'title', { get: function get() { return document.title; diff --git a/dist/es2015/aurelia-pal-browser.js b/dist/es2015/aurelia-pal-browser.js index 529b2e4..d5b4eb0 100644 --- a/dist/es2015/aurelia-pal-browser.js +++ b/dist/es2015/aurelia-pal-browser.js @@ -15,7 +15,7 @@ export const _PLATFORM = { } }; -export function _ensureFunctionName() { +if (typeof FEATURE_NO_IE === 'undefined') { function test() {} if (!test.name) { @@ -30,7 +30,7 @@ export function _ensureFunctionName() { } } -export function _ensureClassList() { +if (typeof FEATURE_NO_IE === 'undefined') { if (!('classList' in document.createElement('_')) || document.createElementNS && !('classList' in document.createElementNS('http://www.w3.org/2000/svg', 'g'))) { let protoProp = 'prototype'; let strTrim = String.prototype.trim; @@ -190,7 +190,7 @@ export function _ensureClassList() { } } -export function _ensurePerformance() { +if (typeof FEATURE_NO_IE === 'undefined') { // @license http://opensource.org/licenses/MIT if ('performance' in window === false) { window.performance = {}; @@ -211,7 +211,23 @@ export function _ensurePerformance() { _PLATFORM.performance = window.performance; } -export function _ensureCustomEvent() { +if (typeof FEATURE_NO_IE === 'undefined') { + let con = window.console = window.console || {}; + let nop = function () {}; + + if (!con.memory) con.memory = {}; + ('assert,clear,count,debug,dir,dirxml,error,exception,group,' + 'groupCollapsed,groupEnd,info,log,markTimeline,profile,profiles,profileEnd,' + 'show,table,time,timeEnd,timeline,timelineEnd,timeStamp,trace,warn').split(',').forEach(m => { + if (!con[m]) con[m] = nop; + }); + + if (typeof con.log === 'object') { + 'log,info,warn,error,assert,dir,clear,profile,profileEnd'.split(',').forEach(function (method) { + console[method] = this.bind(console[method], console); + }, Function.prototype.call); + } +} + +if (typeof FEATURE_NO_IE === 'undefined') { if (!window.CustomEvent || typeof window.CustomEvent !== 'function') { let CustomEvent = function (event, params) { params = params || { @@ -230,32 +246,20 @@ export function _ensureCustomEvent() { } } -export function _ensureElementMatches() { - if (Element && !Element.prototype.matches) { - let proto = Element.prototype; - proto.matches = proto.matchesSelector || proto.mozMatchesSelector || proto.msMatchesSelector || proto.oMatchesSelector || proto.webkitMatchesSelector; - } +if (Element && !Element.prototype.matches) { + let proto = Element.prototype; + proto.matches = proto.matchesSelector || proto.mozMatchesSelector || proto.msMatchesSelector || proto.oMatchesSelector || proto.webkitMatchesSelector; } -export const _FEATURE = {}; - -_FEATURE.shadowDOM = function () { - return !!HTMLElement.prototype.attachShadow; -}(); - -_FEATURE.scopedCSS = function () { - return 'scoped' in document.createElement('style'); -}(); - -_FEATURE.htmlTemplateElement = function () { - return 'content' in document.createElement('template'); -}(); - -_FEATURE.mutationObserver = function () { - return !!(window.MutationObserver || window.WebKitMutationObserver); -}(); +export const _FEATURE = { + shadowDOM: !!HTMLElement.prototype.attachShadow, + scopedCSS: 'scoped' in document.createElement('style'), + htmlTemplateElement: 'content' in document.createElement('template'), + mutationObserver: !!(window.MutationObserver || window.WebKitMutationObserver), + ensureHTMLTemplateElement: t => t +}; -export function _ensureHTMLTemplateElement() { +if (typeof FEATURE_NO_IE === 'undefined') { function isSVGTemplate(el) { return el.tagName === 'template' && el.namespaceURI === 'http://www.w3.org/2000/svg'; } @@ -307,11 +311,7 @@ export function _ensureHTMLTemplateElement() { return template; } - if (_FEATURE.htmlTemplateElement) { - _FEATURE.ensureHTMLTemplateElement = function (template) { - return template; - }; - } else { + if (!_FEATURE.htmlTemplateElement) { _FEATURE.ensureHTMLTemplateElement = fixHTMLTemplateElementRoot; } } @@ -426,56 +426,24 @@ export function initialize() { return; } - _ensureCustomEvent(); - _ensureFunctionName(); - _ensureHTMLTemplateElement(); - _ensureElementMatches(); - _ensureClassList(); - _ensurePerformance(); - initializePAL((platform, feature, dom) => { Object.assign(platform, _PLATFORM); Object.assign(feature, _FEATURE); Object.assign(dom, _DOM); - (function (global) { - global.console = global.console || {}; - let con = global.console; - let prop; - let method; - let empty = {}; - let dummy = function () {}; - let properties = 'memory'.split(','); - let methods = ('assert,clear,count,debug,dir,dirxml,error,exception,group,' + 'groupCollapsed,groupEnd,info,log,markTimeline,profile,profiles,profileEnd,' + 'show,table,time,timeEnd,timeline,timelineEnd,timeStamp,trace,warn').split(','); - while (prop = properties.pop()) if (!con[prop]) con[prop] = empty; - while (method = methods.pop()) if (!con[method]) con[method] = dummy; - })(platform.global); - - if (platform.global.console && typeof console.log === 'object') { - ['log', 'info', 'warn', 'error', 'assert', 'dir', 'clear', 'profile', 'profileEnd'].forEach(function (method) { - console[method] = this.bind(console[method], console); - }, Function.prototype.call); - } - Object.defineProperty(dom, 'title', { - get: function () { - return document.title; - }, - set: function (value) { + get: () => document.title, + set: value => { document.title = value; } }); Object.defineProperty(dom, 'activeElement', { - get: function () { - return document.activeElement; - } + get: () => document.activeElement }); Object.defineProperty(platform, 'XMLHttpRequest', { - get: function () { - return platform.global.XMLHttpRequest; - } + get: () => platform.global.XMLHttpRequest }); }); } \ No newline at end of file diff --git a/dist/native-modules/aurelia-pal-browser.js b/dist/native-modules/aurelia-pal-browser.js index 8ba4271..9a88188 100644 --- a/dist/native-modules/aurelia-pal-browser.js +++ b/dist/native-modules/aurelia-pal-browser.js @@ -18,8 +18,8 @@ export var _PLATFORM = { } }; -export function _ensureFunctionName() { - function test() {} +if (typeof FEATURE_NO_IE === 'undefined') { + var test = function test() {}; if (!test.name) { Object.defineProperty(Function.prototype, 'name', { @@ -33,7 +33,7 @@ export function _ensureFunctionName() { } } -export function _ensureClassList() { +if (typeof FEATURE_NO_IE === 'undefined') { if (!('classList' in document.createElement('_')) || document.createElementNS && !('classList' in document.createElementNS('http://www.w3.org/2000/svg', 'g'))) { (function () { var protoProp = 'prototype'; @@ -197,7 +197,7 @@ export function _ensureClassList() { } } -export function _ensurePerformance() { +if (typeof FEATURE_NO_IE === 'undefined') { // @license http://opensource.org/licenses/MIT if ('performance' in window === false) { window.performance = {}; @@ -220,7 +220,25 @@ export function _ensurePerformance() { _PLATFORM.performance = window.performance; } -export function _ensureCustomEvent() { +if (typeof FEATURE_NO_IE === 'undefined') { + (function () { + var con = window.console = window.console || {}; + var nop = function nop() {}; + + if (!con.memory) con.memory = {}; + ('assert,clear,count,debug,dir,dirxml,error,exception,group,' + 'groupCollapsed,groupEnd,info,log,markTimeline,profile,profiles,profileEnd,' + 'show,table,time,timeEnd,timeline,timelineEnd,timeStamp,trace,warn').split(',').forEach(function (m) { + if (!con[m]) con[m] = nop; + }); + + if (_typeof(con.log) === 'object') { + 'log,info,warn,error,assert,dir,clear,profile,profileEnd'.split(',').forEach(function (method) { + console[method] = this.bind(console[method], console); + }, Function.prototype.call); + } + })(); +} + +if (typeof FEATURE_NO_IE === 'undefined') { if (!window.CustomEvent || typeof window.CustomEvent !== 'function') { var _CustomEvent = function _CustomEvent(event, params) { params = params || { @@ -239,90 +257,78 @@ export function _ensureCustomEvent() { } } -export function _ensureElementMatches() { - if (Element && !Element.prototype.matches) { - var proto = Element.prototype; - proto.matches = proto.matchesSelector || proto.mozMatchesSelector || proto.msMatchesSelector || proto.oMatchesSelector || proto.webkitMatchesSelector; - } +if (Element && !Element.prototype.matches) { + var proto = Element.prototype; + proto.matches = proto.matchesSelector || proto.mozMatchesSelector || proto.msMatchesSelector || proto.oMatchesSelector || proto.webkitMatchesSelector; } -export var _FEATURE = {}; - -_FEATURE.shadowDOM = function () { - return !!HTMLElement.prototype.attachShadow; -}(); - -_FEATURE.scopedCSS = function () { - return 'scoped' in document.createElement('style'); -}(); - -_FEATURE.htmlTemplateElement = function () { - return 'content' in document.createElement('template'); -}(); - -_FEATURE.mutationObserver = function () { - return !!(window.MutationObserver || window.WebKitMutationObserver); -}(); - -export function _ensureHTMLTemplateElement() { - function isSVGTemplate(el) { - return el.tagName === 'template' && el.namespaceURI === 'http://www.w3.org/2000/svg'; +export var _FEATURE = { + shadowDOM: !!HTMLElement.prototype.attachShadow, + scopedCSS: 'scoped' in document.createElement('style'), + htmlTemplateElement: 'content' in document.createElement('template'), + mutationObserver: !!(window.MutationObserver || window.WebKitMutationObserver), + ensureHTMLTemplateElement: function ensureHTMLTemplateElement(t) { + return t; } +}; - function fixSVGTemplateElement(el) { - var template = el.ownerDocument.createElement('template'); - var attrs = el.attributes; - var length = attrs.length; - var attr = void 0; +if (typeof FEATURE_NO_IE === 'undefined') { + (function () { + var isSVGTemplate = function isSVGTemplate(el) { + return el.tagName === 'template' && el.namespaceURI === 'http://www.w3.org/2000/svg'; + }; - el.parentNode.insertBefore(template, el); + var fixSVGTemplateElement = function fixSVGTemplateElement(el) { + var template = el.ownerDocument.createElement('template'); + var attrs = el.attributes; + var length = attrs.length; + var attr = void 0; - while (length-- > 0) { - attr = attrs[length]; - template.setAttribute(attr.name, attr.value); - el.removeAttribute(attr.name); - } + el.parentNode.insertBefore(template, el); - el.parentNode.removeChild(el); + while (length-- > 0) { + attr = attrs[length]; + template.setAttribute(attr.name, attr.value); + el.removeAttribute(attr.name); + } - return fixHTMLTemplateElement(template); - } + el.parentNode.removeChild(el); - function fixHTMLTemplateElement(template) { - var content = template.content = document.createDocumentFragment(); - var child = void 0; + return fixHTMLTemplateElement(template); + }; - while (child = template.firstChild) { - content.appendChild(child); - } + var fixHTMLTemplateElement = function fixHTMLTemplateElement(template) { + var content = template.content = document.createDocumentFragment(); + var child = void 0; - return template; - } + while (child = template.firstChild) { + content.appendChild(child); + } - function fixHTMLTemplateElementRoot(template) { - var content = fixHTMLTemplateElement(template).content; - var childTemplates = content.querySelectorAll('template'); + return template; + }; - for (var i = 0, ii = childTemplates.length; i < ii; ++i) { - var child = childTemplates[i]; + var fixHTMLTemplateElementRoot = function fixHTMLTemplateElementRoot(template) { + var content = fixHTMLTemplateElement(template).content; + var childTemplates = content.querySelectorAll('template'); - if (isSVGTemplate(child)) { - fixSVGTemplateElement(child); - } else { - fixHTMLTemplateElement(child); - } - } + for (var i = 0, ii = childTemplates.length; i < ii; ++i) { + var child = childTemplates[i]; - return template; - } + if (isSVGTemplate(child)) { + fixSVGTemplateElement(child); + } else { + fixHTMLTemplateElement(child); + } + } - if (_FEATURE.htmlTemplateElement) { - _FEATURE.ensureHTMLTemplateElement = function (template) { return template; }; - } else { - _FEATURE.ensureHTMLTemplateElement = fixHTMLTemplateElementRoot; - } + + if (!_FEATURE.htmlTemplateElement) { + _FEATURE.ensureHTMLTemplateElement = fixHTMLTemplateElementRoot; + } + })(); } var shadowPoly = window.ShadowDOMPolyfill || null; @@ -435,40 +441,11 @@ export function initialize() { return; } - _ensureCustomEvent(); - _ensureFunctionName(); - _ensureHTMLTemplateElement(); - _ensureElementMatches(); - _ensureClassList(); - _ensurePerformance(); - initializePAL(function (platform, feature, dom) { Object.assign(platform, _PLATFORM); Object.assign(feature, _FEATURE); Object.assign(dom, _DOM); - (function (global) { - global.console = global.console || {}; - var con = global.console; - var prop = void 0; - var method = void 0; - var empty = {}; - var dummy = function dummy() {}; - var properties = 'memory'.split(','); - var methods = ('assert,clear,count,debug,dir,dirxml,error,exception,group,' + 'groupCollapsed,groupEnd,info,log,markTimeline,profile,profiles,profileEnd,' + 'show,table,time,timeEnd,timeline,timelineEnd,timeStamp,trace,warn').split(','); - while (prop = properties.pop()) { - if (!con[prop]) con[prop] = empty; - }while (method = methods.pop()) { - if (!con[method]) con[method] = dummy; - } - })(platform.global); - - if (platform.global.console && _typeof(console.log) === 'object') { - ['log', 'info', 'warn', 'error', 'assert', 'dir', 'clear', 'profile', 'profileEnd'].forEach(function (method) { - console[method] = this.bind(console[method], console); - }, Function.prototype.call); - } - Object.defineProperty(dom, 'title', { get: function get() { return document.title; diff --git a/dist/system/aurelia-pal-browser.js b/dist/system/aurelia-pal-browser.js index c6cdd45..efed58c 100644 --- a/dist/system/aurelia-pal-browser.js +++ b/dist/system/aurelia-pal-browser.js @@ -3,348 +3,18 @@ System.register(['aurelia-pal'], function (_export, _context) { "use strict"; - var initializePAL, isInitialized, _typeof, _PLATFORM, _FEATURE, shadowPoly, _DOM; - - function _ensureFunctionName() { - function test() {} - - if (!test.name) { - Object.defineProperty(Function.prototype, 'name', { - get: function get() { - var name = this.toString().match(/^\s*function\s*(\S*)\s*\(/)[1]; - - Object.defineProperty(this, 'name', { value: name }); - return name; - } - }); - } - } - - _export('_ensureFunctionName', _ensureFunctionName); - - function _ensureClassList() { - if (!('classList' in document.createElement('_')) || document.createElementNS && !('classList' in document.createElementNS('http://www.w3.org/2000/svg', 'g'))) { - (function () { - var protoProp = 'prototype'; - var strTrim = String.prototype.trim; - var arrIndexOf = Array.prototype.indexOf; - var emptyArray = []; - - var DOMEx = function DOMEx(type, message) { - this.name = type; - this.code = DOMException[type]; - this.message = message; - }; - - var checkTokenAndGetIndex = function checkTokenAndGetIndex(classList, token) { - if (token === '') { - throw new DOMEx('SYNTAX_ERR', 'An invalid or illegal string was specified'); - } - - if (/\s/.test(token)) { - throw new DOMEx('INVALID_CHARACTER_ERR', 'String contains an invalid character'); - } - - return arrIndexOf.call(classList, token); - }; - - var ClassList = function ClassList(elem) { - var trimmedClasses = strTrim.call(elem.getAttribute('class') || ''); - var classes = trimmedClasses ? trimmedClasses.split(/\s+/) : emptyArray; - - for (var i = 0, ii = classes.length; i < ii; ++i) { - this.push(classes[i]); - } - - this._updateClassName = function () { - elem.setAttribute('class', this.toString()); - }; - }; - - var classListProto = ClassList[protoProp] = []; - - DOMEx[protoProp] = Error[protoProp]; - - classListProto.item = function (i) { - return this[i] || null; - }; - - classListProto.contains = function (token) { - token += ''; - return checkTokenAndGetIndex(this, token) !== -1; - }; - - classListProto.add = function () { - var tokens = arguments; - var i = 0; - var ii = tokens.length; - var token = void 0; - var updated = false; - - do { - token = tokens[i] + ''; - if (checkTokenAndGetIndex(this, token) === -1) { - this.push(token); - updated = true; - } - } while (++i < ii); - - if (updated) { - this._updateClassName(); - } - }; - - classListProto.remove = function () { - var tokens = arguments; - var i = 0; - var ii = tokens.length; - var token = void 0; - var updated = false; - var index = void 0; - - do { - token = tokens[i] + ''; - index = checkTokenAndGetIndex(this, token); - while (index !== -1) { - this.splice(index, 1); - updated = true; - index = checkTokenAndGetIndex(this, token); - } - } while (++i < ii); - - if (updated) { - this._updateClassName(); - } - }; - - classListProto.toggle = function (token, force) { - token += ''; - - var result = this.contains(token); - var method = result ? force !== true && 'remove' : force !== false && 'add'; - - if (method) { - this[method](token); - } - - if (force === true || force === false) { - return force; - } - - return !result; - }; - - classListProto.toString = function () { - return this.join(' '); - }; - - Object.defineProperty(Element.prototype, 'classList', { - get: function get() { - return new ClassList(this); - }, - enumerable: true, - configurable: true - }); - })(); - } else { - var testElement = document.createElement('_'); - testElement.classList.add('c1', 'c2'); - - if (!testElement.classList.contains('c2')) { - var createMethod = function createMethod(method) { - var original = DOMTokenList.prototype[method]; - - DOMTokenList.prototype[method] = function (token) { - for (var i = 0, ii = arguments.length; i < ii; ++i) { - token = arguments[i]; - original.call(this, token); - } - }; - }; - - createMethod('add'); - createMethod('remove'); - } - - testElement.classList.toggle('c3', false); - - if (testElement.classList.contains('c3')) { - (function () { - var _toggle = DOMTokenList.prototype.toggle; - - DOMTokenList.prototype.toggle = function (token, force) { - if (1 in arguments && !this.contains(token) === !force) { - return force; - } - - return _toggle.call(this, token); - }; - })(); - } - - testElement = null; - } - } - - _export('_ensureClassList', _ensureClassList); - - function _ensurePerformance() { - // @license http://opensource.org/licenses/MIT - if ('performance' in window === false) { - window.performance = {}; - } - - if ('now' in window.performance === false) { - (function () { - var nowOffset = Date.now(); - - if (performance.timing && performance.timing.navigationStart) { - nowOffset = performance.timing.navigationStart; - } - - window.performance.now = function now() { - return Date.now() - nowOffset; - }; - })(); - } - - _PLATFORM.performance = window.performance; - } - - _export('_ensurePerformance', _ensurePerformance); - - function _ensureCustomEvent() { - if (!window.CustomEvent || typeof window.CustomEvent !== 'function') { - var _CustomEvent = function _CustomEvent(event, params) { - params = params || { - bubbles: false, - cancelable: false, - detail: undefined - }; - - var evt = document.createEvent('CustomEvent'); - evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail); - return evt; - }; - - _CustomEvent.prototype = window.Event.prototype; - window.CustomEvent = _CustomEvent; - } - } - - _export('_ensureCustomEvent', _ensureCustomEvent); - - function _ensureElementMatches() { - if (Element && !Element.prototype.matches) { - var proto = Element.prototype; - proto.matches = proto.matchesSelector || proto.mozMatchesSelector || proto.msMatchesSelector || proto.oMatchesSelector || proto.webkitMatchesSelector; - } - } - - _export('_ensureElementMatches', _ensureElementMatches); - - function _ensureHTMLTemplateElement() { - function isSVGTemplate(el) { - return el.tagName === 'template' && el.namespaceURI === 'http://www.w3.org/2000/svg'; - } - - function fixSVGTemplateElement(el) { - var template = el.ownerDocument.createElement('template'); - var attrs = el.attributes; - var length = attrs.length; - var attr = void 0; - - el.parentNode.insertBefore(template, el); - - while (length-- > 0) { - attr = attrs[length]; - template.setAttribute(attr.name, attr.value); - el.removeAttribute(attr.name); - } - - el.parentNode.removeChild(el); - - return fixHTMLTemplateElement(template); - } - - function fixHTMLTemplateElement(template) { - var content = template.content = document.createDocumentFragment(); - var child = void 0; - - while (child = template.firstChild) { - content.appendChild(child); - } - - return template; - } - - function fixHTMLTemplateElementRoot(template) { - var content = fixHTMLTemplateElement(template).content; - var childTemplates = content.querySelectorAll('template'); - - for (var i = 0, ii = childTemplates.length; i < ii; ++i) { - var child = childTemplates[i]; - - if (isSVGTemplate(child)) { - fixSVGTemplateElement(child); - } else { - fixHTMLTemplateElement(child); - } - } - - return template; - } - - if (_FEATURE.htmlTemplateElement) { - _FEATURE.ensureHTMLTemplateElement = function (template) { - return template; - }; - } else { - _FEATURE.ensureHTMLTemplateElement = fixHTMLTemplateElementRoot; - } - } - - _export('_ensureHTMLTemplateElement', _ensureHTMLTemplateElement); + var initializePAL, isInitialized, _typeof, _PLATFORM, test, testElement, createMethod, _CustomEvent, proto, _FEATURE, shadowPoly, _DOM; function initialize() { if (isInitialized) { return; } - _ensureCustomEvent(); - _ensureFunctionName(); - _ensureHTMLTemplateElement(); - _ensureElementMatches(); - _ensureClassList(); - _ensurePerformance(); - initializePAL(function (platform, feature, dom) { Object.assign(platform, _PLATFORM); Object.assign(feature, _FEATURE); Object.assign(dom, _DOM); - (function (global) { - global.console = global.console || {}; - var con = global.console; - var prop = void 0; - var method = void 0; - var empty = {}; - var dummy = function dummy() {}; - var properties = 'memory'.split(','); - var methods = ('assert,clear,count,debug,dir,dirxml,error,exception,group,' + 'groupCollapsed,groupEnd,info,log,markTimeline,profile,profiles,profileEnd,' + 'show,table,time,timeEnd,timeline,timelineEnd,timeStamp,trace,warn').split(','); - while (prop = properties.pop()) { - if (!con[prop]) con[prop] = empty; - }while (method = methods.pop()) { - if (!con[method]) con[method] = dummy; - } - })(platform.global); - - if (platform.global.console && _typeof(console.log) === 'object') { - ['log', 'info', 'warn', 'error', 'assert', 'dir', 'clear', 'profile', 'profileEnd'].forEach(function (method) { - console[method] = this.bind(console[method], console); - }, Function.prototype.call); - } - Object.defineProperty(dom, 'title', { get: function get() { return document.title; @@ -400,25 +70,322 @@ System.register(['aurelia-pal'], function (_export, _context) { _export('_PLATFORM', _PLATFORM); - _export('_FEATURE', _FEATURE = {}); + if (typeof FEATURE_NO_IE === 'undefined') { + test = function test() {}; + + if (!test.name) { + Object.defineProperty(Function.prototype, 'name', { + get: function get() { + var name = this.toString().match(/^\s*function\s*(\S*)\s*\(/)[1]; + + Object.defineProperty(this, 'name', { value: name }); + return name; + } + }); + } + } + + if (typeof FEATURE_NO_IE === 'undefined') { + if (!('classList' in document.createElement('_')) || document.createElementNS && !('classList' in document.createElementNS('http://www.w3.org/2000/svg', 'g'))) { + (function () { + var protoProp = 'prototype'; + var strTrim = String.prototype.trim; + var arrIndexOf = Array.prototype.indexOf; + var emptyArray = []; + + var DOMEx = function DOMEx(type, message) { + this.name = type; + this.code = DOMException[type]; + this.message = message; + }; + + var checkTokenAndGetIndex = function checkTokenAndGetIndex(classList, token) { + if (token === '') { + throw new DOMEx('SYNTAX_ERR', 'An invalid or illegal string was specified'); + } + + if (/\s/.test(token)) { + throw new DOMEx('INVALID_CHARACTER_ERR', 'String contains an invalid character'); + } + + return arrIndexOf.call(classList, token); + }; + + var ClassList = function ClassList(elem) { + var trimmedClasses = strTrim.call(elem.getAttribute('class') || ''); + var classes = trimmedClasses ? trimmedClasses.split(/\s+/) : emptyArray; + + for (var i = 0, ii = classes.length; i < ii; ++i) { + this.push(classes[i]); + } + + this._updateClassName = function () { + elem.setAttribute('class', this.toString()); + }; + }; + + var classListProto = ClassList[protoProp] = []; + + DOMEx[protoProp] = Error[protoProp]; + + classListProto.item = function (i) { + return this[i] || null; + }; + + classListProto.contains = function (token) { + token += ''; + return checkTokenAndGetIndex(this, token) !== -1; + }; + + classListProto.add = function () { + var tokens = arguments; + var i = 0; + var ii = tokens.length; + var token = void 0; + var updated = false; + + do { + token = tokens[i] + ''; + if (checkTokenAndGetIndex(this, token) === -1) { + this.push(token); + updated = true; + } + } while (++i < ii); + + if (updated) { + this._updateClassName(); + } + }; + + classListProto.remove = function () { + var tokens = arguments; + var i = 0; + var ii = tokens.length; + var token = void 0; + var updated = false; + var index = void 0; + + do { + token = tokens[i] + ''; + index = checkTokenAndGetIndex(this, token); + while (index !== -1) { + this.splice(index, 1); + updated = true; + index = checkTokenAndGetIndex(this, token); + } + } while (++i < ii); + + if (updated) { + this._updateClassName(); + } + }; + + classListProto.toggle = function (token, force) { + token += ''; + + var result = this.contains(token); + var method = result ? force !== true && 'remove' : force !== false && 'add'; + + if (method) { + this[method](token); + } + + if (force === true || force === false) { + return force; + } + + return !result; + }; + + classListProto.toString = function () { + return this.join(' '); + }; + + Object.defineProperty(Element.prototype, 'classList', { + get: function get() { + return new ClassList(this); + }, + enumerable: true, + configurable: true + }); + })(); + } else { + testElement = document.createElement('_'); + + testElement.classList.add('c1', 'c2'); + + if (!testElement.classList.contains('c2')) { + createMethod = function createMethod(method) { + var original = DOMTokenList.prototype[method]; + + DOMTokenList.prototype[method] = function (token) { + for (var i = 0, ii = arguments.length; i < ii; ++i) { + token = arguments[i]; + original.call(this, token); + } + }; + }; + + createMethod('add'); + createMethod('remove'); + } + + testElement.classList.toggle('c3', false); + + if (testElement.classList.contains('c3')) { + (function () { + var _toggle = DOMTokenList.prototype.toggle; + + DOMTokenList.prototype.toggle = function (token, force) { + if (1 in arguments && !this.contains(token) === !force) { + return force; + } + + return _toggle.call(this, token); + }; + })(); + } + + testElement = null; + } + } + + if (typeof FEATURE_NO_IE === 'undefined') { + // @license http://opensource.org/licenses/MIT + if ('performance' in window === false) { + window.performance = {}; + } + + if ('now' in window.performance === false) { + (function () { + var nowOffset = Date.now(); + + if (performance.timing && performance.timing.navigationStart) { + nowOffset = performance.timing.navigationStart; + } + + window.performance.now = function now() { + return Date.now() - nowOffset; + }; + })(); + } + + _PLATFORM.performance = window.performance; + } + + if (typeof FEATURE_NO_IE === 'undefined') { + (function () { + var con = window.console = window.console || {}; + var nop = function nop() {}; + + if (!con.memory) con.memory = {}; + ('assert,clear,count,debug,dir,dirxml,error,exception,group,' + 'groupCollapsed,groupEnd,info,log,markTimeline,profile,profiles,profileEnd,' + 'show,table,time,timeEnd,timeline,timelineEnd,timeStamp,trace,warn').split(',').forEach(function (m) { + if (!con[m]) con[m] = nop; + }); + + if (_typeof(con.log) === 'object') { + 'log,info,warn,error,assert,dir,clear,profile,profileEnd'.split(',').forEach(function (method) { + console[method] = this.bind(console[method], console); + }, Function.prototype.call); + } + })(); + } + + if (typeof FEATURE_NO_IE === 'undefined') { + if (!window.CustomEvent || typeof window.CustomEvent !== 'function') { + _CustomEvent = function _CustomEvent(event, params) { + params = params || { + bubbles: false, + cancelable: false, + detail: undefined + }; + + var evt = document.createEvent('CustomEvent'); + evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail); + return evt; + }; + + _CustomEvent.prototype = window.Event.prototype; + window.CustomEvent = _CustomEvent; + } + } + + if (Element && !Element.prototype.matches) { + proto = Element.prototype; + + proto.matches = proto.matchesSelector || proto.mozMatchesSelector || proto.msMatchesSelector || proto.oMatchesSelector || proto.webkitMatchesSelector; + } + + _export('_FEATURE', _FEATURE = { + shadowDOM: !!HTMLElement.prototype.attachShadow, + scopedCSS: 'scoped' in document.createElement('style'), + htmlTemplateElement: 'content' in document.createElement('template'), + mutationObserver: !!(window.MutationObserver || window.WebKitMutationObserver), + ensureHTMLTemplateElement: function ensureHTMLTemplateElement(t) { + return t; + } + }); _export('_FEATURE', _FEATURE); - _FEATURE.shadowDOM = function () { - return !!HTMLElement.prototype.attachShadow; - }(); + if (typeof FEATURE_NO_IE === 'undefined') { + (function () { + var isSVGTemplate = function isSVGTemplate(el) { + return el.tagName === 'template' && el.namespaceURI === 'http://www.w3.org/2000/svg'; + }; + + var fixSVGTemplateElement = function fixSVGTemplateElement(el) { + var template = el.ownerDocument.createElement('template'); + var attrs = el.attributes; + var length = attrs.length; + var attr = void 0; + + el.parentNode.insertBefore(template, el); + + while (length-- > 0) { + attr = attrs[length]; + template.setAttribute(attr.name, attr.value); + el.removeAttribute(attr.name); + } + + el.parentNode.removeChild(el); + + return fixHTMLTemplateElement(template); + }; + + var fixHTMLTemplateElement = function fixHTMLTemplateElement(template) { + var content = template.content = document.createDocumentFragment(); + var child = void 0; - _FEATURE.scopedCSS = function () { - return 'scoped' in document.createElement('style'); - }(); + while (child = template.firstChild) { + content.appendChild(child); + } + + return template; + }; - _FEATURE.htmlTemplateElement = function () { - return 'content' in document.createElement('template'); - }(); + var fixHTMLTemplateElementRoot = function fixHTMLTemplateElementRoot(template) { + var content = fixHTMLTemplateElement(template).content; + var childTemplates = content.querySelectorAll('template'); + + for (var i = 0, ii = childTemplates.length; i < ii; ++i) { + var child = childTemplates[i]; + + if (isSVGTemplate(child)) { + fixSVGTemplateElement(child); + } else { + fixHTMLTemplateElement(child); + } + } - _FEATURE.mutationObserver = function () { - return !!(window.MutationObserver || window.WebKitMutationObserver); - }(); + return template; + }; + + if (!_FEATURE.htmlTemplateElement) { + _FEATURE.ensureHTMLTemplateElement = fixHTMLTemplateElementRoot; + } + })(); + } shadowPoly = window.ShadowDOMPolyfill || null; diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index b9156e3..139aebc 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -1,3 +1,10 @@ + +# [1.2.0](https://github.com/aurelia/pal-browser/compare/1.1.0...v1.2.0) (2017-03-23) + +### Features + +* add flag to opt-out of IE support + # [1.1.0](https://github.com/aurelia/pal-browser/compare/1.0.0...v1.1.0) (2016-12-07) diff --git a/doc/api.json b/doc/api.json index 86d148d..f10b3bb 100644 --- a/doc/api.json +++ b/doc/api.json @@ -1 +1 @@ -{"name":"aurelia-pal-browser","children":[{"id":2,"name":"initialize","kind":64,"kindString":"Function","flags":{"isExported":true},"signatures":[{"id":3,"name":"initialize","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Initializes the PAL with the Browser-targeted implementation."},"type":{"type":"instrinct","name":"void"}}],"sources":[{"fileName":"aurelia-pal-browser.d.ts","line":9,"character":34}]}],"groups":[{"title":"Functions","kind":64,"children":[2]}]} \ No newline at end of file +{"name":"aurelia-pal-browser","children":[{"id":2,"name":"initialize","kind":64,"kindString":"Function","flags":{"isExported":true},"signatures":[{"id":3,"name":"initialize","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Initializes the PAL with the Browser-targeted implementation."},"type":{"type":"instrinct","name":"void"}}],"sources":[{"fileName":"aurelia-pal-browser.d.ts","line":18,"character":34}]}],"groups":[{"title":"Functions","kind":64,"children":[2]}]} \ No newline at end of file diff --git a/package.json b/package.json index 88edf02..dcd3284 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aurelia-pal-browser", - "version": "1.1.0", + "version": "1.2.0", "description": "The browser-specific implementation of Aurelia's platform abstraction layer.", "keywords": [ "aurelia",