eldom
v1.1.0
Published
a super-micro framework for element class manipulation
Downloads
2
Readme
elDom.js
v1.1.0 - A super-micro framework for adding and removing classes to elements.
Install
Download elDom.min.js
and include it in your project.
elDom is used with the $
variable, and follows a very familiar syntax.$('.selector')
returns a new instance of elDom
, allowing you to access
methods directly via chaining.
$('.active').remove('active');
Methods
$el.is(classname)
Checks if $el
has classname
.
The boolean result is saved to the object,
if you want to return the boolean, call $el._hasClass(classname)
$el.isnt(classname)
I feel like this one explains itself.
$el.holds(classname)
Checks if the element has a child with classname.
$el.add(classname)
Adds classname
to $el
.
$el.remove(classname)
Removes classname
from $el
.
$el.delete(callback)
Deletes the element, optionally returns callback.
$el.then(callback(el){})
Simply fires the callback if it's allowed to.el
is the selector. See chaining below.
$el.tick(classname, time)
Automatically toggles classname
on $el
every time
seconds.
Example use case for this is breathing animations.
Chaining
Since elDom
always returns itself, you can chain methods together:$('.selector').add('someclass').remove('otherclass')
Chaining can be combined with has()
and hasnt()
to allow for if/then:$('nav a').has('active').remove('active').add('link')
;
So, with every link in the chain, the state gets reset to null
.
The first link, has()
, sets the state to a boolean value and returns itself.
The next step looks at the state, and only processes if state != false
.
That means in the second example above, if .has('active')
returns false
, then .remove('active')
won't fire. However, since .remove()
still resets the state,
.add('link')
fires as normal.
But what if I want to do things that aren't chainable?
That's where .then()
comes in.
$('nav a').has('active').then(function(el) {
// your custom code here
$(el).remove('active');
// some more custom code here
// whatever you want, really
}).add('link'); // chain is still preserved.
Contribute
Fork me and open up a pull request!
Version guide:
- +0.0.1 for patches/minor things
- +0.1.0 for new feature
- +1.0.0 for something drastic!