Skip to content

Randomize Items #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion jquery.quovolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@
groupMethod = 'children';
}

if ( o.random) {
$this[groupMethod](o.children).quovolverRandom();
}

// Initialize element specific variables
var $box = $this.parent('.quovolve-box'),
$items = $this[groupMethod](o.children),
Expand Down Expand Up @@ -303,7 +307,7 @@
// Auto play interface
if (o.autoPlay) {
if (o.autoPlaySpeed == 'auto') {
// get and store # of chars in each quote
// get and store # of chars in each quote
$items.each(function() {
this.textLength = $(this).text().length;
});
Expand Down Expand Up @@ -341,6 +345,15 @@
}); // @end of return this.each()

};

$.fn.quovolverRandom = function(selector) {
(selector ? this.find(selector) : this).parent().each(function(){
$(this).children(selector).sort(function(){
return Math.random() - 0.5;
}).detach().appendTo(this);
});
return this;
};

$.fn.quovolver.defaults = {

Expand All @@ -363,6 +376,8 @@
navNum : false, // Toggle numbered navigation
navText : false, // Toggle navigation description (e.g. display current item # and total item #)

random : false, // Randomize the items on each page load

navPrevText : 'Prev', // Text for the "previous" button
navNextText : 'Next', // Text for the "next" button
navTextContent : '@a / @b' // @a will be replaced with current and @b with total
Expand Down