Browse Source

Add support for multiple class names in utils add/remove class methods. (#3079)

* Add support for multiple class names in utils add/remove class methods.
Reset subgroup heights in resetSubgroups method.

* Adjust to better process class names
gemini
Ben Morton 7 years ago
committed by yotamberk
parent
commit
421e361350
2 changed files with 13 additions and 11 deletions
  1. +1
    -0
      lib/timeline/component/Group.js
  2. +12
    -11
      lib/util.js

+ 1
- 0
lib/timeline/component/Group.js View File

@ -534,6 +534,7 @@ Group.prototype.resetSubgroups = function() {
for (var subgroup in this.subgroups) { for (var subgroup in this.subgroups) {
if (this.subgroups.hasOwnProperty(subgroup)) { if (this.subgroups.hasOwnProperty(subgroup)) {
this.subgroups[subgroup].visible = false; this.subgroups[subgroup].visible = false;
this.subgroups[subgroup].height = 0;
} }
} }
}; };

+ 12
- 11
lib/util.js View File

@ -621,12 +621,13 @@ exports.getAbsoluteTop = function (elem) {
* @param {Element} elem * @param {Element} elem
* @param {String} className * @param {String} className
*/ */
exports.addClassName = function (elem, className) {
exports.addClassName = function (elem, classNames) {
var classes = elem.className.split(' '); var classes = elem.className.split(' ');
if (classes.indexOf(className) == -1) {
classes.push(className); // add the class to the array
elem.className = classes.join(' ');
}
var newClasses = classNames.split(' ');
classes = classes.concat(newClasses.filter(function(className) {
return classes.indexOf(className) < 0;
}));
elem.className = classes.join(' ');
}; };
/** /**
@ -634,13 +635,13 @@ exports.addClassName = function (elem, className) {
* @param {Element} elem * @param {Element} elem
* @param {String} className * @param {String} className
*/ */
exports.removeClassName = function (elem, className) {
exports.removeClassName = function (elem, classNames) {
var classes = elem.className.split(' '); var classes = elem.className.split(' ');
var index = classes.indexOf(className);
if (index != -1) {
classes.splice(index, 1); // remove the class from the array
elem.className = classes.join(' ');
}
var oldClasses = classNames.split(' ');
classes = classes.filter(function(className) {
return oldClasses.indexOf(className) < 0;
});
elem.className = classes.join(' ');
}; };
/** /**

Loading…
Cancel
Save