aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/utils/elements.js
diff options
context:
space:
mode:
authorSam Potts <sam@potts.es>2020-01-30 14:23:10 +0000
committerGitHub <noreply@github.com>2020-01-30 14:23:10 +0000
commit9d512911252cf4835c2b7364cb4ae392cb277a1d (patch)
tree5e6dcc7647285e49683f05d8a49187e8078d0d2b /src/js/utils/elements.js
parent44d3a17870949e828e5b1a4619a30dfcb626a174 (diff)
parentb2ac730572ad81aa9755e8b7852c53ceba0e8e9f (diff)
downloadplyr-9d512911252cf4835c2b7364cb4ae392cb277a1d.tar.lz
plyr-9d512911252cf4835c2b7364cb4ae392cb277a1d.tar.xz
plyr-9d512911252cf4835c2b7364cb4ae392cb277a1d.zip
Merge pull request #1663 from sampotts/master
Merge back to beta
Diffstat (limited to 'src/js/utils/elements.js')
-rw-r--r--src/js/utils/elements.js29
1 files changed, 12 insertions, 17 deletions
diff --git a/src/js/utils/elements.js b/src/js/utils/elements.js
index 6be634e5..4f10938e 100644
--- a/src/js/utils/elements.js
+++ b/src/js/utils/elements.js
@@ -4,6 +4,7 @@
import { toggleListener } from './events';
import is from './is';
+import { extend } from './objects';
// Wrap an element
export function wrap(elements, wrapper) {
@@ -16,7 +17,6 @@ export function wrap(elements, wrapper) {
.reverse()
.forEach((element, index) => {
const child = index > 0 ? wrapper.cloneNode(true) : wrapper;
-
// Cache the current parent and sibling.
const parent = element.parentNode;
const sibling = element.nextSibling;
@@ -137,30 +137,28 @@ export function getAttributesFromSelector(sel, existingAttributes) {
}
const attributes = {};
- const existing = existingAttributes;
+ const existing = extend({}, existingAttributes);
sel.split(',').forEach(s => {
// Remove whitespace
const selector = s.trim();
const className = selector.replace('.', '');
const stripped = selector.replace(/[[\]]/g, '');
-
// Get the parts and value
const parts = stripped.split('=');
- const key = parts[0];
+ const [key] = parts;
const value = parts.length > 1 ? parts[1].replace(/["']/g, '') : '';
-
// Get the first character
const start = selector.charAt(0);
switch (start) {
case '.':
// Add to existing classname
- if (is.object(existing) && is.string(existing.class)) {
- existing.class += ` ${className}`;
+ if (is.string(existing.class)) {
+ attributes.class = `${existing.class} ${className}`;
+ } else {
+ attributes.class = className;
}
-
- attributes.class = className;
break;
case '#':
@@ -179,7 +177,7 @@ export function getAttributesFromSelector(sel, existingAttributes) {
}
});
- return attributes;
+ return extend(existing, attributes);
}
// Toggle hidden
@@ -194,11 +192,8 @@ export function toggleHidden(element, hidden) {
hide = !element.hidden;
}
- if (hide) {
- element.setAttribute('hidden', '');
- } else {
- element.removeAttribute('hidden');
- }
+ // eslint-disable-next-line no-param-reassign
+ element.hidden = hide;
}
// Mirror Element.classList.toggle, with IE compatibility for "force" argument
@@ -233,14 +228,14 @@ export function matches(element, selector) {
return Array.from(document.querySelectorAll(selector)).includes(this);
}
- const matches =
+ const method =
prototype.matches ||
prototype.webkitMatchesSelector ||
prototype.mozMatchesSelector ||
prototype.msMatchesSelector ||
match;
- return matches.call(element, selector);
+ return method.call(element, selector);
}
// Find all elements