Last active
August 29, 2015 14:02
-
-
Save dshster/37feec87ce5320b799bb to your computer and use it in GitHub Desktop.
bem classes modifiers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
'use strict'; | |
var delimiter = '--'; | |
DOMTokenList.prototype.modify = function(mod) { | |
if (false === tag.classList.modified(mod)) { | |
this.add([this[0], delimiter, mod].join('')); | |
} | |
}; | |
DOMTokenList.prototype.unmodify = function(mod) { | |
if (true === tag.classList.modified(mod)) { | |
this.remove([this[0], delimiter, mod].join('')); | |
} | |
}; | |
DOMTokenList.prototype.modified = function(mod) { | |
return 'string' === typeof this[0] && this.contains([this[0], delimiter, mod].join('')); | |
}; | |
})(); | |
var tag = document.createElement('div'); | |
tag.classList.add('baseclass'); | |
console.log(tag, tag.classList.modified('mod')); | |
tag.classList.modify('mod'); | |
console.log(tag, tag.classList.modified('mod')); | |
tag.classList.modify('foo'); | |
console.log(tag, tag.classList.modified('foo')); | |
tag.classList.unmodify('mod'); | |
console.log(tag, tag.classList.modified('mod')); | |
tag.classList.unmodify('foo'); | |
console.log(tag, tag.classList.modified('foo')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment