src/aria/utils/ClassList.js
function (oldClassName, newClassName) {
            var rem = [], add = [];

            if (!!oldClassName) {
                rem = (typeof oldClassName == "string") ? oldClassName.split(" ") : oldClassName;
            }

            if (!!newClassName) {
                add = (typeof newClassName == "string") ? newClassName.split(" ") : newClassName;
            }

            var classString = this.getClassName(), found = false;
            var classes = !!classString ? classString.split(" ") : [];

            // Remove oldClassNames
            for (var j = classes.length - 1; j >= 0; j -= 1) {
                if (!classes[j]) {
                    classes.splice(j, 1);
                    continue;
                }

                // Remove duplicates
                for (var d = add.length - 1; d >= 0; d -= 1) {
                    if (classes[j] == add[d]) {
                        // Remove it from classes as I'm going to add it again
                        classes.splice(j, 1);
                    }
                }

                for (var k = rem.length - 1; k >= 0; k -= 1) {
                    if (classes[j] == rem[k]) {
                        classes.splice(j, 1);
                        found = true; // Iterate for multiple classes
                    }
                }
            }

            if (!found && add.length === 0) {
                return;
            }

            classes.push.apply(classes, add);
            this.setClassName(classes.join(" "));
        }
function (oldClassName, newClassName) {
            var rem = [], add = [];

            if (!!oldClassName) {
                rem = (typeof oldClassName == "string") ? oldClassName.split(" ") : oldClassName;
            }

            if (!!newClassName) {
                add = (typeof newClassName == "string") ? newClassName.split(" ") : newClassName;
            }

            var classString = this.getClassName(), found = false;
            var classes = !!classString ? classString.split(" ") : [];

            // Remove oldClassNames
            for (var j = classes.length - 1; j >= 0; j -= 1) {
                if (!classes[j]) {
                    classes.splice(j, 1);
                    continue;
                }

                // Remove duplicates
                for (var d = add.length - 1; d >= 0; d -= 1) {
                    if (classes[j] == add[d]) {
                        // Remove it from classes as I'm going to add it again
                        classes.splice(j, 1);
                    }
                }

                for (var k = rem.length - 1; k >= 0; k -= 1) {
                    if (classes[j] == rem[k]) {
                        classes.splice(j, 1);
                        found = true; // Iterate for multiple classes
                    }
                }
            }

            if (!found && add.length === 0) {
                return;
            }

            classes.push.apply(classes, add);
            this.setClassName(classes.join(" "));
        }
function ( oldClassName , newClassName ) { var rem = [ ] , add = [ ] ; if ( ! ! oldClassName ) { rem = ( typeof oldClassName == "string" ) ? oldClassName . split ( " " ) : oldClassName ; } if ( ! ! newClassName ) { add = ( typeof newClassName == "string" ) ? newClassName . split ( " " ) : newClassName ; } var classString = this . getClassName ( ) , found = false ; var classes = ! ! classString ? classString . split ( " " ) : [ ] ; // Remove oldClassNames for ( var j = classes . length - 1 ; j >= 0 ; j -= 1 ) { if ( ! classes [ j ] ) { classes . splice ( j , 1 ) ; continue ; } // Remove duplicates for ( var d = add . length - 1 ; d >= 0 ; d -= 1 ) { if ( classes [ j ] == add [ d ] ) { // Remove it from classes as I'm going to add it again classes . splice ( j , 1 ) ; } } for ( var k = rem . length - 1 ; k >= 0 ; k -= 1 ) { if ( classes [ j ] == rem [ k ] ) { classes . splice ( j , 1 ) ; found = true ; // Iterate for multiple classes } } } if ( ! found && add . length === 0 ) { return ; } classes . push . apply ( classes , add ) ; this . setClassName ( classes . join ( " " ) ) ; }
Replaces a class with another class. If no oldClassName is present, the newClassName is simply added.
@param {String|Array} oldClassName The class name or an array of class names to be replaced
@param {String|Array} newClassName The class name or an array of class names that will be replacing the old
class name
Replaces a class with another class . If no oldClassName is present the newClassName is simply added .