Dough.js
Just 3KB when gzipped and minified
/*
* Dough.js is a common yet a bit different JS library.
*
* It supports both collection-wide and granular actions,
* easy CSS transforms, CSS animation and transition
* callbacks, explicit CSS toggling and is generally
* very cute.
*
* It's also super light since it works only on modern
* desktop and mobile browsers :D
*
*
* Check the docs below and have a good time...
*/
Dough supports modern browsers, and should do well on Google Chrome, Firefox, Safari, Internet Explorer 9+, iOS and Android 2+.
What's Different?
Collection Methods
Dough's instance methods are performed collection-wide, that is - they are executed on every element in the Dough object (Except for some obvious exceptions like find()
, next()
and others).
The library could have had lots of polyfills but ultimately it was designed to have methods for actions that have no native alternative, especially for bulk actions.
Hence, it behaves a bit differently than other libraries. For example, executing $("p").html()
will set the HTML contents of every element in the collection to an empty string and won't return the HTML contents of the first element in the collection. The same goes for attr()
.
This happens because there's no need for a polyfill method to get the HTML contents of the first element (or any element) in the collection, one could just use $("p")[0].innerHTML
or $("a")[2].getAttribute("href")
which are already supported on Dough's target browsers and will always be much more performant.
Granular Execution
Every collection-wide Dough method supports executing its action on a specific element in the collection. This means you don't need re-create a Dough object just to play with a specific element, like this:
var buttons = $(".button").removeClass("shiny-base");
// Money money money...
for (var i = 0; i < buttons.length; i++) {
$(buttons[i]).addClass("shiny-" + randomNumber());
}
You could just do this:
for (var i = 0; i < buttons.length; i++) {
buttons.addClass("shiny-" + randomNumber(), i);
}
buttons.off("click", 2); // And this, if it makes sense
Just use the element's index as the last parameter.
Console Printing
The Dough object isn't a true Array
, so printing it using console.log()
won't yeild the same result as jQuery...