Simplify `classList` & `className.baseVal` logic.

This commit is contained in:
Jason Davies 2011-05-05 16:25:49 +01:00
Родитель 2280d51c9d
Коммит 8d2bc4b1b3
3 изменённых файлов: 30 добавлений и 24 удалений

25
d3.js поставляемый
Просмотреть файл

@ -1305,33 +1305,36 @@ function d3_selection(groups) {
// If no value is specified, return the first value.
if (arguments.length < 2) {
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;
return re.test(this.className.baseVal != null
? this.className.baseVal : this.className);
return re.test((c = this.className).baseVal != null
? c.baseVal : c);
});
}
/** @this {Element} */
function classedAdd() {
if ("classList" in this) return this.classList.add(name);
var isAnimatedString = this.className.baseVal != null,
classes = isAnimatedString ? this.className.baseVal : this.className;
var c;
if (c = this.classList) return c.add(name);
var isAnimatedString = (c = this.className).baseVal != null,
classes = isAnimatedString ? c.baseVal : c;
re.lastIndex = 0;
if (!re.test(classes)) {
classes = d3_collapse(classes + " " + name);
if (isAnimatedString) this.className.baseVal = classes;
if (isAnimatedString) c.baseVal = classes;
else this.className = classes;
}
}
/** @this {Element} */
function classedRemove() {
if ("classList" in this) return this.classList.remove(name);
var isAnimatedString = this.className.baseVal != null,
classes = isAnimatedString ? this.className.baseVal : this.className;
var c;
if (c = this.classList) return c.remove(name);
var isAnimatedString = (c = this.className).baseVal != null,
classes = isAnimatedString ? c.baseVal : c;
classes = d3_collapse(classes.replace(re, " "));
if (isAnimatedString) this.className.baseVal = classes;
if (isAnimatedString) c.baseVal = classes;
else this.className = classes;
}

4
d3.min.js поставляемый

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -305,33 +305,36 @@ function d3_selection(groups) {
// If no value is specified, return the first value.
if (arguments.length < 2) {
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;
return re.test(this.className.baseVal != null
? this.className.baseVal : this.className);
return re.test((c = this.className).baseVal != null
? c.baseVal : c);
});
}
/** @this {Element} */
function classedAdd() {
if ("classList" in this) return this.classList.add(name);
var isAnimatedString = this.className.baseVal != null,
classes = isAnimatedString ? this.className.baseVal : this.className;
var c;
if (c = this.classList) return c.add(name);
var isAnimatedString = (c = this.className).baseVal != null,
classes = isAnimatedString ? c.baseVal : c;
re.lastIndex = 0;
if (!re.test(classes)) {
classes = d3_collapse(classes + " " + name);
if (isAnimatedString) this.className.baseVal = classes;
if (isAnimatedString) c.baseVal = classes;
else this.className = classes;
}
}
/** @this {Element} */
function classedRemove() {
if ("classList" in this) return this.classList.remove(name);
var isAnimatedString = this.className.baseVal != null,
classes = isAnimatedString ? this.className.baseVal : this.className;
var c;
if (c = this.classList) return c.remove(name);
var isAnimatedString = (c = this.className).baseVal != null,
classes = isAnimatedString ? c.baseVal : c;
classes = d3_collapse(classes.replace(re, " "));
if (isAnimatedString) this.className.baseVal = classes;
if (isAnimatedString) c.baseVal = classes;
else this.className = classes;
}