change classList fallback for multiple args

This commit is contained in:
Adam Bradley
2014-02-18 22:58:21 -06:00
parent 08dcca9ffb
commit a5471aeeb5
3 changed files with 45 additions and 15 deletions

View File

@@ -44,7 +44,8 @@ angular.module('ionic.ui.scroll')
scrollView.activatePullToRefresh(refresherHeight, function() {
self.refresher.classList.add('active');
}, function() {
self.refresher.classList.remove('refreshing', 'active');
self.refresher.classList.remove('refreshing');
self.refresher.classList.remove('active');
}, function() {
self.refresher.classList.add('refreshing');
$scope.onRefresh && $scope.onRefresh();

View File

@@ -1,9 +1,26 @@
angular.element.prototype.addClass = function(cssClasses) {
var x, y, cssClass, el, splitClasses, existingClasses;
if (cssClasses && cssClasses != 'ng-scope' && cssClasses != 'ng-isolate-scope') {
for(var x=0; x<this.length; x++) {
if(this[x].setAttribute) {
this[x].classList.add.apply(this[x].classList, cssClasses.split(/\s+/));
for(x=0; x<this.length; x++) {
el = this[x];
if(el.setAttribute) {
if(cssClasses.indexOf(' ') < 0) {
el.classList.add(cssClasses);
} else {
existingClasses = (' ' + (el.getAttribute('class') || '') + ' ')
.replace(/[\n\t]/g, " ");
splitClasses = cssClasses.split(' ');
for (y=0; y<splitClasses.length; y++) {
cssClass = splitClasses[y].trim();
if (existingClasses.indexOf(' ' + cssClass + ' ') === -1) {
existingClasses += cssClass + ' ';
}
}
el.setAttribute('class', existingClasses.trim());
}
}
}
}
@@ -11,12 +28,27 @@ angular.element.prototype.addClass = function(cssClasses) {
};
angular.element.prototype.removeClass = function(cssClasses) {
var x, y, splitClasses, cssClass, el;
if (cssClasses) {
for(var x=0; x<this.length; x++) {
if(this[x].setAttribute) {
this[x].classList.remove.apply(this[x].classList, cssClasses.split(/\s+/));
for(x=0; x<this.length; x++) {
el = this[x];
if(el.getAttribute) {
if(cssClasses.indexOf(' ') < 0) {
el.classList.remove(cssClasses);
} else {
splitClasses = cssClasses.split(' ');
for (y=0; y<splitClasses.length; y++) {
cssClass = splitClasses[y];
el.setAttribute('class', (
(" " + (el.getAttribute('class') || '') + " ")
.replace(/[\n\t]/g, " ")
.replace(" " + cssClass.trim() + " ", " ")).trim()
);
}
}
}
}
}
return this;
};
};