Created
December 10, 2009 06:17
-
-
Save nojimage/253161 to your computer and use it in GitHub Desktop.
jquery.alternation.js
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
/** | |
* jQuery Alternation Markup Plugin | |
* | |
* Copyright 2009, nojimage (http://php-tips.com/) | |
* | |
* Licensed under The MIT License Redistributions of files must retain the above | |
* copyright notice. | |
* | |
* @filesource | |
* @version 1.0 | |
* @author nojimage <nojimage at gmail.com> | |
* @copyright 2009 nojimage | |
* @license http://www.opensource.org/licenses/mit-license.php The MIT License | |
* @link http://php-tips.com/jquery/2009/12/jquery-alternation-js | |
* @modifiedby nojimage <nojimage at gmail.com> | |
* | |
*/ | |
(function($) | |
{ | |
jQuery.fn.alternation = function(params) | |
{ | |
var options = { | |
classname : 'alter', | |
each : 2, | |
callback : null | |
}; | |
options = jQuery.extend( {}, options, params); | |
var idx = 0; | |
jQuery(this).children().each(function() | |
{ | |
if (idx++ % options.each == (options.each - 1)) { | |
jQuery(this).addClass(options.classname); | |
if (typeof options.callback == "function") { | |
options.callback(this); | |
} | |
} | |
}); | |
} | |
jQuery.extend( { | |
"alternation" : function(params) | |
{ | |
var options = { | |
selector : '.alternation' | |
}; | |
options = jQuery.extend( {}, options, params); | |
jQuery(options.selector).each(function() | |
{ | |
jQuery(this).alternation(options); | |
}); | |
} | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment