Simplify `classList` & `className.baseVal` logic.
This commit is contained in:
Родитель
2280d51c9d
Коммит
8d2bc4b1b3
|
@ -1305,33 +1305,36 @@ function d3_selection(groups) {
|
||||||
// If no value is specified, return the first value.
|
// If no value is specified, return the first value.
|
||||||
if (arguments.length < 2) {
|
if (arguments.length < 2) {
|
||||||
return first(function() {
|
return first(function() {
|
||||||
if ("classList" in this) return this.classList.contains(name);
|
var c;
|
||||||
|
if (c = this.classList) return c.contains(name);
|
||||||
re.lastIndex = 0;
|
re.lastIndex = 0;
|
||||||
return re.test(this.className.baseVal != null
|
return re.test((c = this.className).baseVal != null
|
||||||
? this.className.baseVal : this.className);
|
? c.baseVal : c);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @this {Element} */
|
/** @this {Element} */
|
||||||
function classedAdd() {
|
function classedAdd() {
|
||||||
if ("classList" in this) return this.classList.add(name);
|
var c;
|
||||||
var isAnimatedString = this.className.baseVal != null,
|
if (c = this.classList) return c.add(name);
|
||||||
classes = isAnimatedString ? this.className.baseVal : this.className;
|
var isAnimatedString = (c = this.className).baseVal != null,
|
||||||
|
classes = isAnimatedString ? c.baseVal : c;
|
||||||
re.lastIndex = 0;
|
re.lastIndex = 0;
|
||||||
if (!re.test(classes)) {
|
if (!re.test(classes)) {
|
||||||
classes = d3_collapse(classes + " " + name);
|
classes = d3_collapse(classes + " " + name);
|
||||||
if (isAnimatedString) this.className.baseVal = classes;
|
if (isAnimatedString) c.baseVal = classes;
|
||||||
else this.className = classes;
|
else this.className = classes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @this {Element} */
|
/** @this {Element} */
|
||||||
function classedRemove() {
|
function classedRemove() {
|
||||||
if ("classList" in this) return this.classList.remove(name);
|
var c;
|
||||||
var isAnimatedString = this.className.baseVal != null,
|
if (c = this.classList) return c.remove(name);
|
||||||
classes = isAnimatedString ? this.className.baseVal : this.className;
|
var isAnimatedString = (c = this.className).baseVal != null,
|
||||||
|
classes = isAnimatedString ? c.baseVal : c;
|
||||||
classes = d3_collapse(classes.replace(re, " "));
|
classes = d3_collapse(classes.replace(re, " "));
|
||||||
if (isAnimatedString) this.className.baseVal = classes;
|
if (isAnimatedString) c.baseVal = classes;
|
||||||
else this.className = classes;
|
else this.className = classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -305,33 +305,36 @@ function d3_selection(groups) {
|
||||||
// If no value is specified, return the first value.
|
// If no value is specified, return the first value.
|
||||||
if (arguments.length < 2) {
|
if (arguments.length < 2) {
|
||||||
return first(function() {
|
return first(function() {
|
||||||
if ("classList" in this) return this.classList.contains(name);
|
var c;
|
||||||
|
if (c = this.classList) return c.contains(name);
|
||||||
re.lastIndex = 0;
|
re.lastIndex = 0;
|
||||||
return re.test(this.className.baseVal != null
|
return re.test((c = this.className).baseVal != null
|
||||||
? this.className.baseVal : this.className);
|
? c.baseVal : c);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @this {Element} */
|
/** @this {Element} */
|
||||||
function classedAdd() {
|
function classedAdd() {
|
||||||
if ("classList" in this) return this.classList.add(name);
|
var c;
|
||||||
var isAnimatedString = this.className.baseVal != null,
|
if (c = this.classList) return c.add(name);
|
||||||
classes = isAnimatedString ? this.className.baseVal : this.className;
|
var isAnimatedString = (c = this.className).baseVal != null,
|
||||||
|
classes = isAnimatedString ? c.baseVal : c;
|
||||||
re.lastIndex = 0;
|
re.lastIndex = 0;
|
||||||
if (!re.test(classes)) {
|
if (!re.test(classes)) {
|
||||||
classes = d3_collapse(classes + " " + name);
|
classes = d3_collapse(classes + " " + name);
|
||||||
if (isAnimatedString) this.className.baseVal = classes;
|
if (isAnimatedString) c.baseVal = classes;
|
||||||
else this.className = classes;
|
else this.className = classes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @this {Element} */
|
/** @this {Element} */
|
||||||
function classedRemove() {
|
function classedRemove() {
|
||||||
if ("classList" in this) return this.classList.remove(name);
|
var c;
|
||||||
var isAnimatedString = this.className.baseVal != null,
|
if (c = this.classList) return c.remove(name);
|
||||||
classes = isAnimatedString ? this.className.baseVal : this.className;
|
var isAnimatedString = (c = this.className).baseVal != null,
|
||||||
|
classes = isAnimatedString ? c.baseVal : c;
|
||||||
classes = d3_collapse(classes.replace(re, " "));
|
classes = d3_collapse(classes.replace(re, " "));
|
||||||
if (isAnimatedString) this.className.baseVal = classes;
|
if (isAnimatedString) c.baseVal = classes;
|
||||||
else this.className = classes;
|
else this.className = classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче