From 9fca394bdb22fab38b7ae0e2338f792229b31bed Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Mon, 19 Sep 2016 08:56:25 -0500 Subject: [PATCH] chore(polyfill): break DOM polyfills into external file --- scripts/gulp/tasks/polyfill.ts | 7 +---- scripts/polyfill/polyfill.dom.js | 30 +++++++++++++++++++ .../readme.md} | 0 src/util/dom.ts | 26 ---------------- 4 files changed, 31 insertions(+), 32 deletions(-) create mode 100644 scripts/polyfill/polyfill.dom.js rename scripts/{npm/polyfills.readme.md => polyfill/readme.md} (100%) diff --git a/scripts/gulp/tasks/polyfill.ts b/scripts/gulp/tasks/polyfill.ts index a63a43ea77..c314ffe7f6 100644 --- a/scripts/gulp/tasks/polyfill.ts +++ b/scripts/gulp/tasks/polyfill.ts @@ -95,11 +95,6 @@ task('polyfill.modern', (done) => { }); task('polyfill.copy-readme', (done) => { - const rename = require('gulp-rename'); - - return src('scripts/npm/polyfills.readme.md') - .pipe(rename({ - basename: 'README' - })) + return src('scripts/polyfill/readme.md') .pipe(dest('dist/ionic-angular/polyfills/'), done); }); diff --git a/scripts/polyfill/polyfill.dom.js b/scripts/polyfill/polyfill.dom.js new file mode 100644 index 0000000000..7814a95507 --- /dev/null +++ b/scripts/polyfill/polyfill.dom.js @@ -0,0 +1,30 @@ +(function(){ + "use strict"; + + if (typeof Element.prototype.matches !== 'function') { + Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector || function matches(selector) { + var element = this; + var elements = (element.document || element.ownerDocument).querySelectorAll(selector); + var index = 0; + while (elements[index] && elements[index] !== element) { + ++index; + } + return Boolean(elements[index]); + }; + } + + + if (typeof Element.prototype.closest !== 'function') { + Element.prototype.closest = function closest(selector) { + var element = this; + while (element && element.nodeType === 1) { + if (element.matches(selector)) { + return element; + } + element = element.parentNode; + } + return null; + }; + } + +})(); diff --git a/scripts/npm/polyfills.readme.md b/scripts/polyfill/readme.md similarity index 100% rename from scripts/npm/polyfills.readme.md rename to scripts/polyfill/readme.md diff --git a/src/util/dom.ts b/src/util/dom.ts index 9e4022cc71..a3d1b634ae 100644 --- a/src/util/dom.ts +++ b/src/util/dom.ts @@ -247,32 +247,6 @@ export function copyInputAttributes(srcElement: HTMLElement, destElement: HTMLEl } } -// TODO: Add to external polyfill script -if (typeof Element.prototype.matches !== 'function') { - Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector || function matches(selector) { - var element = this; - var elements = (element.document || element.ownerDocument).querySelectorAll(selector); - var index = 0; - while (elements[index] && elements[index] !== element) { - ++index; - } - return Boolean(elements[index]); - }; -} - -if (typeof Element.prototype.closest !== 'function') { - Element.prototype.closest = function closest(selector) { - var element = this; - while (element && element.nodeType === 1) { - if (element.matches(selector)) { - return element; - } - element = element.parentNode; - } - return null; - }; -} - /** * Get the element offsetWidth and offsetHeight. Values are cached