Skip to content

Commit

Permalink
Add rotation option and functionality
Browse files Browse the repository at this point in the history
When the option rotateTime is given, it should be an integer of ms for time to rotate between review items.
  • Loading branch information
bpedroza committed Mar 29, 2016
1 parent 15ad63f commit 9b6fde7
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion google-places.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* https://github.com/peledies/google-places */
(function($) {

$.googlePlaces = function(element, options) {
Expand All @@ -7,7 +8,8 @@
, render: ['reviews']
, min_rating: 0
, max_rows: 0
}
, rotateTime: false
};

var plugin = this;

Expand All @@ -24,6 +26,9 @@
// render specified sections
if(plugin.settings.render.indexOf('reviews') > -1){
renderReviews(plugin.place_data.reviews);
if(!!plugin.settings.rotateTime) {
initRotation();
}
}
});
}
Expand Down Expand Up @@ -79,6 +84,22 @@
};
$element.append(html);
}

var initRotation = function() {
var $reviewEls = $element.children('.review-item');
var currentIdx = $reviewEls.length > 0 ? 0 : false;
$reviewEls.hide();
if(currentIdx !== false) {
$($reviewEls[currentIdx]).show();
setInterval(function(){
if(++currentIdx >= $reviewEls.length) {
currentIdx = 0;
}
$reviewEls.hide();
$($reviewEls[currentIdx]).fadeIn('slow');
}, plugin.settings.rotateTime);
}
}

var renderStars = function(rating){
var stars = "<div class='review-stars'><ul>";
Expand Down

0 comments on commit 9b6fde7

Please sign in to comment.