I don't think these are worth making into full blown plugins, but I do
think they're useful. Feel free to use these and credit me if you wan
:) I wrote them as utility plugins for a promo rotator I was working
on. I was fading and showing list items in the order they appeared in
the jQuery object, so I needed to mess with said order. If this has
already been done, then consider this an update. Please let me know if
you find any bugs, and if you know of an easier/better/more succinct
way to do this, then I'd love to hear it. I'm always interested in
optimization.
Enjoy,
Paul
--
(function($){
/**
* $().randomize();
* @desc This will random sort the DOM elements in a jQuery object.
* @param bool abort if "true" will cause nothing to happen. This is
there so that you can
* easily have this in a jQuery chain, but turn it off via plugin settings.
* NOTE: This does not change the order of elements in the DOM, just
in the jQuery object
*/
$.fn.randomize = function(abort){
if(!abort)
[].sort.call(this,function(){return
(Math.round(Math.random())-0.5);});
return this;
};
/**
* $().firstToLast();
* @desc This will move the first element in the jQuery object to the last and
* adjust the indices accordingly
*/
$.fn.firstToLast = function(){
[].push.call(this,[].shift.call(this));
return this;
};
/**
* $().lastToFirst();
* @desc This will move the last element in the jQuery object to the first and
* adjust the indices accordingly
*/
$.fn.lastToFirst = function(){
[].unshift.call(this,[].pop.call(this));
return this;
};
})(jQuery);
--
"I don't know karate, but I know KA-RAZY!!!!"
-- James Brown
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/