diff options
author | Sam Potts <sam@potts.es> | 2017-11-18 19:30:26 +1100 |
---|---|---|
committer | Sam Potts <sam@potts.es> | 2017-11-18 19:30:26 +1100 |
commit | 6984d6fb1606a71edd35ac043ac1116b6de8e98b (patch) | |
tree | 1dc18a90bb2870b3c4665e40a3dcaeb75f3bb831 /src/js/utils.js | |
parent | d7a1c4428138d2dd5af09e41e998d1e08dafe76e (diff) | |
download | plyr-6984d6fb1606a71edd35ac043ac1116b6de8e98b.tar.lz plyr-6984d6fb1606a71edd35ac043ac1116b6de8e98b.tar.xz plyr-6984d6fb1606a71edd35ac043ac1116b6de8e98b.zip |
Controls cleanup, work on captions bug, click to invert time
Diffstat (limited to 'src/js/utils.js')
-rw-r--r-- | src/js/utils.js | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/src/js/utils.js b/src/js/utils.js index 53a16e4b..bb576576 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -31,6 +31,9 @@ const utils = { htmlElement(input) { return !this.undefined(input) && input instanceof HTMLElement; }, + textNode(input) { + return this.getConstructor(input) === Text; + }, event(input) { return !this.undefined(input) && input instanceof Event; }, @@ -49,8 +52,8 @@ const utils = { return ( input === null || typeof input === 'undefined' || - ((this.string(input) || this.array(input) || this.nodeList(input)) && input.length === 0) || - (this.object(input) && Object.keys(input).length === 0) + ((this.string(input) || this.array(input) || this.nodeList(input)) && !input.length) || + (this.object(input) && !Object.keys(input).length) ); }, getConstructor(input) { @@ -140,8 +143,12 @@ const utils = { // Get the sprite fetch(url) - .then(response => response.text()) + .then(response => (response.ok ? response.text() : null)) .then(text => { + if (text === null) { + return; + } + if (support.storage) { window.localStorage.setItem( prefix + id, @@ -152,7 +159,8 @@ const utils = { } updateSprite.call(container, text); - }); + }) + .catch(() => {}); } }, @@ -201,22 +209,6 @@ const utils = { }); }, - // Remove an element - removeElement(element) { - if (!utils.is.htmlElement(element) || !utils.is.htmlElement(element.parentNode)) { - return null; - } - - element.parentNode.removeChild(element); - - return element; - }, - - // Inaert an element after another - insertAfter(element, target) { - target.parentNode.insertBefore(element, target.nextSibling); - }, - // Create a DocumentFragment createElement(type, attributes, text) { // Create a new <element> @@ -236,12 +228,28 @@ const utils = { return element; }, + // Inaert an element after another + insertAfter(element, target) { + target.parentNode.insertBefore(element, target.nextSibling); + }, + // Insert a DocumentFragment insertElement(type, parent, attributes, text) { // Inject the new <element> parent.appendChild(utils.createElement(type, attributes, text)); }, + // Remove an element + removeElement(element) { + if (!utils.is.htmlElement(element) || !utils.is.htmlElement(element.parentNode)) { + return null; + } + + element.parentNode.removeChild(element); + + return element; + }, + // Remove all child elements emptyElement(element) { let { length } = element.childNodes; @@ -433,9 +441,9 @@ const utils = { // Trap focus inside container trapFocus() { - const tabbables = utils.getElements.call(this, 'button:not(:disabled), input:not(:disabled), [tabindex]'); - const first = tabbables[0]; - const last = tabbables[tabbables.length - 1]; + const focusable = utils.getElements.call(this, 'button:not(:disabled), input:not(:disabled), [tabindex]'); + const first = focusable[0]; + const last = focusable[focusable.length - 1]; utils.on( this.elements.container, |