The plugins site is currently in development.
We've been looking to provide a higher-quality, spam-free experience at the plugins site for some time, and a major error on our part forced us to shut down the current site before we could put the new one in place. We are developing a new site, and you can follow along with its development on GitHub. For more information about this transition, including steps you can take as a plugin author to prepare, please read our post about what's going on.
Distributed Elements via If, ElseIf, and Else conditions
Aim
This plug-in offers possibility to distribute elements found with a single search over an If, optional ElseIf, and finally Else chain.
Using a couple of bytes, this plug-in lets us create semantic filters with one or more entry points to perform different operations.
$(function(){
$("div")
.If(function(){return $(this).text() == "3" || $(this).text() == "5"})
.text("1 - match the 3 or 5 check")
.ElseIf(oddNumbers)
.text("2 - odd numbers")
.ElseIf(function(){return $(this).text() == 2})
.Do(function(){ // if you need a closure ...
$(this).text("3 - text is equal 2");
})
.ElseIf(function(){return $(this).text() == 6})
.text("4 - match the 6 condition")
.Else()
.text("5 - line 4 or 8")
;
});More Details
Used filter to distribute elements in the correct entry point is the same of jQuery library. This means that you can pass functions or other filters without problems.
The Do option is the equivalent of an each operation, useful both for a meaningful semantic and to create closures runtime in the chain when a jQuery method does not return the object itself or when we need to perform more than an operation.
