|
|
@ -66,14 +66,7 @@ $.fn.rating = function(parameters) { |
|
|
|
else { |
|
|
|
module.disable(); |
|
|
|
} |
|
|
|
if(settings.initialRating) { |
|
|
|
module.debug('Setting initial rating'); |
|
|
|
module.setRating(settings.initialRating); |
|
|
|
} |
|
|
|
if( $module.data(metadata.rating) ) { |
|
|
|
module.debug('Rating found in metadata'); |
|
|
|
module.setRating( $module.data(metadata.rating) ); |
|
|
|
} |
|
|
|
module.set.rating( module.get.initialRating() ); |
|
|
|
module.instantiate(); |
|
|
|
}, |
|
|
|
|
|
|
@ -100,11 +93,12 @@ $.fn.rating = function(parameters) { |
|
|
|
setup: { |
|
|
|
layout: function() { |
|
|
|
var |
|
|
|
maxRating = $module.data(metadata.maxRating) || settings.maxRating |
|
|
|
maxRating = module.get.maxRating(), |
|
|
|
html = $.fn.rating.settings.templates.icon(maxRating) |
|
|
|
; |
|
|
|
module.debug('Generating icon html dynamically'); |
|
|
|
$module |
|
|
|
.html($.fn.rating.settings.templates.icon(maxRating)) |
|
|
|
.html(html) |
|
|
|
; |
|
|
|
module.refresh(); |
|
|
|
} |
|
|
@ -139,7 +133,7 @@ $.fn.rating = function(parameters) { |
|
|
|
click: function() { |
|
|
|
var |
|
|
|
$activeIcon = $(this), |
|
|
|
currentRating = module.getRating(), |
|
|
|
currentRating = module.get.rating(), |
|
|
|
rating = $icon.index($activeIcon) + 1, |
|
|
|
canClear = (settings.clearable == 'auto') |
|
|
|
? ($icon.length === 1) |
|
|
@ -149,22 +143,14 @@ $.fn.rating = function(parameters) { |
|
|
|
module.clearRating(); |
|
|
|
} |
|
|
|
else { |
|
|
|
module.setRating( rating ); |
|
|
|
module.set.rating( rating ); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
clearRating: function() { |
|
|
|
module.debug('Clearing current rating'); |
|
|
|
module.setRating(0); |
|
|
|
}, |
|
|
|
|
|
|
|
getRating: function() { |
|
|
|
var |
|
|
|
currentRating = $icon.filter('.' + className.active).length |
|
|
|
; |
|
|
|
module.verbose('Current rating retrieved', currentRating); |
|
|
|
return currentRating; |
|
|
|
module.set.rating(0); |
|
|
|
}, |
|
|
|
|
|
|
|
bind: { |
|
|
@ -203,29 +189,55 @@ $.fn.rating = function(parameters) { |
|
|
|
; |
|
|
|
}, |
|
|
|
|
|
|
|
setRating: function(rating) { |
|
|
|
var |
|
|
|
ratingIndex = (rating - 1 >= 0) |
|
|
|
? (rating - 1) |
|
|
|
: 0, |
|
|
|
$activeIcon = $icon.eq(ratingIndex) |
|
|
|
; |
|
|
|
$module |
|
|
|
.removeClass(className.selected) |
|
|
|
; |
|
|
|
$icon |
|
|
|
.removeClass(className.selected) |
|
|
|
.removeClass(className.active) |
|
|
|
; |
|
|
|
if(rating > 0) { |
|
|
|
module.verbose('Setting current rating to', rating); |
|
|
|
$activeIcon |
|
|
|
.prevAll() |
|
|
|
.andSelf() |
|
|
|
.addClass(className.active) |
|
|
|
get: { |
|
|
|
initialRating: function() { |
|
|
|
if($module.data(metadata.rating) !== undefined) { |
|
|
|
$module.removeData(metadata.rating); |
|
|
|
return $module.data(metadata.rating); |
|
|
|
} |
|
|
|
return settings.initialRating; |
|
|
|
}, |
|
|
|
maxRating: function() { |
|
|
|
if($module.data(metadata.maxRating) !== undefined) { |
|
|
|
$module.removeData(metadata.maxRating); |
|
|
|
return $module.data(metadata.maxRating); |
|
|
|
} |
|
|
|
return settings.maxRating; |
|
|
|
}, |
|
|
|
rating: function() { |
|
|
|
var |
|
|
|
currentRating = $icon.filter('.' + className.active).length |
|
|
|
; |
|
|
|
module.verbose('Current rating retrieved', currentRating); |
|
|
|
return currentRating; |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
set: { |
|
|
|
rating: function(rating) { |
|
|
|
var |
|
|
|
ratingIndex = (rating - 1 >= 0) |
|
|
|
? (rating - 1) |
|
|
|
: 0, |
|
|
|
$activeIcon = $icon.eq(ratingIndex) |
|
|
|
; |
|
|
|
$module |
|
|
|
.removeClass(className.selected) |
|
|
|
; |
|
|
|
$icon |
|
|
|
.removeClass(className.selected) |
|
|
|
.removeClass(className.active) |
|
|
|
; |
|
|
|
if(rating > 0) { |
|
|
|
module.verbose('Setting current rating to', rating); |
|
|
|
$activeIcon |
|
|
|
.prevAll() |
|
|
|
.andSelf() |
|
|
|
.addClass(className.active) |
|
|
|
; |
|
|
|
} |
|
|
|
settings.onRate.call(element, rating); |
|
|
|
} |
|
|
|
settings.onRate.call(element, rating); |
|
|
|
}, |
|
|
|
|
|
|
|
setting: function(name, value) { |
|
|
|