Skip to content

Commit

Permalink
fix #76 removeClass
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Feb 7, 2014
1 parent be74193 commit 4fdeba5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,12 @@ var utils = module.exports = {
if (hasClassList) {
el.classList.remove(cls)
} else {
el.className = (' ' + el.className + ' ')
.replace(' ' + cls + ' ', '')
.trim()
var cur = ' ' + el.className + ' ',
tar = ' ' + cls + ' '
while (cur.indexOf(tar) >= 0) {
cur = cur.replace(tar, ' ')
}
el.className = cur.trim()
}
}
}
4 changes: 3 additions & 1 deletion test/unit/specs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,10 @@ describe('UNIT: Utils', function () {

it('should work', function () {
var el = document.createElement('div')
el.className = 'hihi hi'
el.className = 'hihi hi ha'
utils.removeClass(el, 'hi')
assert.strictEqual(el.className, 'hihi ha')
utils.removeClass(el, 'ha')
assert.strictEqual(el.className, 'hihi')
})

Expand Down

0 comments on commit 4fdeba5

Please sign in to comment.