mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 20:33:32 +08:00
chore(polyfill): break DOM polyfills into external file
This commit is contained in:
@ -95,11 +95,6 @@ task('polyfill.modern', (done) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
task('polyfill.copy-readme', (done) => {
|
task('polyfill.copy-readme', (done) => {
|
||||||
const rename = require('gulp-rename');
|
return src('scripts/polyfill/readme.md')
|
||||||
|
|
||||||
return src('scripts/npm/polyfills.readme.md')
|
|
||||||
.pipe(rename({
|
|
||||||
basename: 'README'
|
|
||||||
}))
|
|
||||||
.pipe(dest('dist/ionic-angular/polyfills/'), done);
|
.pipe(dest('dist/ionic-angular/polyfills/'), done);
|
||||||
});
|
});
|
||||||
|
30
scripts/polyfill/polyfill.dom.js
Normal file
30
scripts/polyfill/polyfill.dom.js
Normal file
@ -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;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
})();
|
@ -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
|
* Get the element offsetWidth and offsetHeight. Values are cached
|
||||||
|
Reference in New Issue
Block a user