mirror of
https://github.com/e107inc/e107.git
synced 2025-08-05 14:17:49 +02:00
Updated rating class
This commit is contained in:
@@ -19,7 +19,11 @@ class rater {
|
|||||||
|
|
||||||
function render($table,$id,$options=array())
|
function render($table,$id,$options=array())
|
||||||
{
|
{
|
||||||
|
|
||||||
list($votes,$score,$uvoted) = $this->getrating($table, $id);
|
list($votes,$score,$uvoted) = $this->getrating($table, $id);
|
||||||
|
|
||||||
|
// return "Table=".$table." itmeId=".$id." Votes=".$votes." score=".$score;
|
||||||
|
|
||||||
parse_str($options,$options);
|
parse_str($options,$options);
|
||||||
//
|
//
|
||||||
$label = varset($options['label'],RATELAN_5);
|
$label = varset($options['label'],RATELAN_5);
|
||||||
@@ -34,6 +38,7 @@ class rater {
|
|||||||
$score = ($score / 2);
|
$score = ($score / 2);
|
||||||
// var_dump($readonly);
|
// var_dump($readonly);
|
||||||
|
|
||||||
|
|
||||||
if(!$votes)
|
if(!$votes)
|
||||||
{
|
{
|
||||||
$voteDiz = RATELAN_4;
|
$voteDiz = RATELAN_4;
|
||||||
@@ -54,11 +59,11 @@ class rater {
|
|||||||
$readonly = '1';
|
$readonly = '1';
|
||||||
}
|
}
|
||||||
|
|
||||||
$template = vartrue($options['template'], "STATUS|RATE|VOTES");
|
$template = vartrue($options['template'], " STATUS |RATE|VOTES");
|
||||||
|
|
||||||
$TEMPLATE['STATUS'] = "<div class='e-rate-status e-rate-status-{$table}' id='e-rate-{$table}-{$id}'>".$label."</div>";
|
$TEMPLATE['STATUS'] = " <span class='e-rate-status e-rate-status-{$table}' id='e-rate-{$table}-{$id}'>".$label."</span>";
|
||||||
$TEMPLATE['RATE'] = "<div class='e-rate e-rate-{$table}' id='{$table}-{$id}' data-hint=\"{$datahint}\" data-readonly='{$readonly}' data-score='{$score}' data-url='".e_BASE."rate.php' data-path='{$path}'></div>";
|
$TEMPLATE['RATE'] = "<div class='e-rate e-rate-{$table}' id='{$table}-{$id}' data-hint=\"{$datahint}\" data-readonly='{$readonly}' data-score='{$score}' data-url='".e_BASE."rate.php' data-path='{$path}'></div>";
|
||||||
$TEMPLATE['VOTES'] = "<div class='e-rate-votes e-rate-votes-{$table}' id='e-rate-votes-{$table}-{$id}'>".$this->renderVotes($votes,$score)."</div>";
|
$TEMPLATE['VOTES'] = "<div class='muted e-rate-votes e-rate-votes-{$table}' id='e-rate-votes-{$table}-{$id}'><smalll>".$this->renderVotes($votes,$score)."</small></div>";
|
||||||
|
|
||||||
$tmp = explode("|",$template);
|
$tmp = explode("|",$template);
|
||||||
|
|
||||||
@@ -185,11 +190,16 @@ class rater {
|
|||||||
$sep = chr(1);
|
$sep = chr(1);
|
||||||
|
|
||||||
$sql = new db;
|
$sql = new db;
|
||||||
if (!$sql->db_Select("rate", "*", "rate_table = '{$table}' AND rate_itemid = '{$id}' ")) {
|
if (!$sql->select("rate", "*", "rate_table = '{$table}' AND rate_itemid = '{$id}' "))
|
||||||
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
} else {
|
}
|
||||||
$rowgr = $sql->db_Fetch();
|
else
|
||||||
if($userid==TRUE){
|
{
|
||||||
|
$rowgr = $sql->fetch();
|
||||||
|
|
||||||
|
if($userid==TRUE)
|
||||||
|
{
|
||||||
$rating = "";
|
$rating = "";
|
||||||
$rateusers = explode(".", $rowgr['rate_voters']);
|
$rateusers = explode(".", $rowgr['rate_voters']);
|
||||||
for($i=0;$i<count($rateusers);$i++){
|
for($i=0;$i<count($rateusers);$i++){
|
||||||
@@ -207,14 +217,19 @@ class rater {
|
|||||||
$rating[2] = 0; //no remainder is present, because we have a single users rating
|
$rating[2] = 0; //no remainder is present, because we have a single users rating
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
$rating[0] = $rowgr['rate_votes']; // $rating[0] == number of votes
|
$rating[0] = $rowgr['rate_votes']; // $rating[0] == number of votes
|
||||||
$tmp = $rowgr['rate_rating'] / $rowgr['rate_votes'];
|
$tmp = $rowgr['rate_rating'] / $rowgr['rate_votes'];
|
||||||
$tmp = (strpos($tmp,",")) ? explode(",", $tmp) : explode(".", $tmp);
|
$tmp = (strpos($tmp,",")) ? explode(",", $tmp) : explode(".", $tmp);
|
||||||
$rating[1] = $tmp[0];
|
$rating[1] = $tmp[0];
|
||||||
if(isset($tmp[1])){
|
if(isset($tmp[1]))
|
||||||
|
{
|
||||||
$rating[2] = substr($tmp[1], 0, 1);
|
$rating[2] = substr($tmp[1], 0, 1);
|
||||||
}else{
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
$rating[2] = "0";
|
$rating[2] = "0";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,6 +20,9 @@
|
|||||||
.clear-l { clear: right }
|
.clear-l { clear: right }
|
||||||
.clear-r { clear: left }
|
.clear-r { clear: left }
|
||||||
|
|
||||||
|
i.icon-download { font-size:200%; }
|
||||||
|
|
||||||
|
|
||||||
.e-footer-info { margin-top:10px; padding:20px; text-align: center }
|
.e-footer-info { margin-top:10px; padding:20px; text-align: center }
|
||||||
|
|
||||||
td.text-center { text-align:center; }
|
td.text-center { text-align:center; }
|
||||||
|
@@ -7,9 +7,11 @@ a.e-nav { padding:3px; }
|
|||||||
|
|
||||||
div.e-rate { width:100px; display:inline-block }
|
div.e-rate { width:100px; display:inline-block }
|
||||||
img.e-rate { }
|
img.e-rate { }
|
||||||
.e-rate-status { font-weight:bold;vertical-align:middle; padding-right:4px; width:140px; display:inline-block; text-align:right }
|
|
||||||
|
.e-rate-status { vertical-align:middle; padding-right:4px; display:inline-block; text-align:right }
|
||||||
.e-rate-status-download { text-align:left; }
|
.e-rate-status-download { text-align:left; }
|
||||||
.e-rate-votes { vertical-align:middle; display:inline-block; width:100px }
|
.e-rate-votes { vertical-align:middle; display:inline-block; width:100px }
|
||||||
|
|
||||||
select.e-bb { margin-top:0px; width:100px }
|
select.e-bb { margin-top:0px; width:100px }
|
||||||
.bbcode_buttons { }
|
.bbcode_buttons { }
|
||||||
.bbcode_buttons:hover { }
|
.bbcode_buttons:hover { }
|
||||||
|
@@ -472,8 +472,21 @@ $(document).ready(function()
|
|||||||
var t = tmp.split('-');
|
var t = tmp.split('-');
|
||||||
var table = t[0];
|
var table = t[0];
|
||||||
var id = t[1];
|
var id = t[1];
|
||||||
|
var label = '#e-rate-'+ table + '-' + id;
|
||||||
|
var styles = { 0: ' ', 0.5: 'label-important', 1: 'label-important', 1.5: 'label-warning', 2: 'label-warning', 2.5: 'label-default', 3: 'label-default' , 3.5: 'label-info', 4: 'label-info', 4.5: 'label-success', 5: 'label-success'};
|
||||||
|
|
||||||
|
if($('#e-rate-'+tmp).length == 0)
|
||||||
|
{
|
||||||
|
var target = undefined;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var target = '#e-rate-'+tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$('.e-rate').raty({
|
$('#'+tmp).raty({
|
||||||
path : path,
|
path : path,
|
||||||
half : true,
|
half : true,
|
||||||
score : score,
|
score : score,
|
||||||
@@ -485,11 +498,42 @@ $(document).ready(function()
|
|||||||
// cancelOff : 'cancel-off-big.png',
|
// cancelOff : 'cancel-off-big.png',
|
||||||
// cancelOn : 'cancel-on-big.png',
|
// cancelOn : 'cancel-on-big.png',
|
||||||
// size : 16,
|
// size : 16,
|
||||||
target : '#e-rate-'+tmp,
|
target : target,
|
||||||
|
targetFormat: '{score}',
|
||||||
|
// targetKeep: true,
|
||||||
// targetType : 'number',
|
// targetType : 'number',
|
||||||
targetText : $('#e-rate-'+tmp).text(),
|
targetText : $('#e-rate-'+tmp).text(),
|
||||||
// cancel : true,
|
// cancel : true,
|
||||||
// css : 'e-rate-star',
|
// css : 'e-rate-star',
|
||||||
|
|
||||||
|
mouseover: function(score, evt)
|
||||||
|
{
|
||||||
|
|
||||||
|
// alert(score + ' : '+ styles[score]);
|
||||||
|
|
||||||
|
$(label).removeClass('label-success');
|
||||||
|
$(label).removeClass('label-info');
|
||||||
|
$(label).removeClass('label-warning');
|
||||||
|
$(label).removeClass('label-important');
|
||||||
|
$(label).removeClass('label-default');
|
||||||
|
|
||||||
|
$(label).show();
|
||||||
|
$(label).addClass('label');
|
||||||
|
|
||||||
|
$(label).addClass(styles[score]);
|
||||||
|
// alert('ID: ' + $(this).attr('id') + "\nscore: " + score + "\nevent: " + evt);
|
||||||
|
|
||||||
|
},
|
||||||
|
mouseout: function(score, evt)
|
||||||
|
{
|
||||||
|
$(label).removeClass('label-success');
|
||||||
|
$(label).removeClass('label-info');
|
||||||
|
$(label).removeClass('label-warning');
|
||||||
|
$(label).removeClass('label-important');
|
||||||
|
$(label).removeClass('label-default');
|
||||||
|
$(label).hide();
|
||||||
|
},
|
||||||
|
|
||||||
click: function(score, evt) {
|
click: function(score, evt) {
|
||||||
$(this).find('img').unbind('click');
|
$(this).find('img').unbind('click');
|
||||||
$(this).find('img').unbind();
|
$(this).find('img').unbind();
|
||||||
@@ -500,6 +544,7 @@ $(document).ready(function()
|
|||||||
}).done(function( msg ) {
|
}).done(function( msg ) {
|
||||||
alert(msg);
|
alert(msg);
|
||||||
bla = msg.split('|');
|
bla = msg.split('|');
|
||||||
|
$(label).addClass(styles[score]);
|
||||||
|
|
||||||
$('#e-rate-'+tmp).text(bla[0]);
|
$('#e-rate-'+tmp).text(bla[0]);
|
||||||
if(bla[1])
|
if(bla[1])
|
||||||
|
@@ -1,462 +1,474 @@
|
|||||||
/*!
|
/*!
|
||||||
* jQuery Raty - A Star Rating Plugin - http://wbotelhos.com/raty
|
* jQuery Raty - A Star Rating Plugin
|
||||||
* -------------------------------------------------------------------
|
* ------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* jQuery Raty is a plugin that generates a customizable star rating.
|
* jQuery Raty is a plugin that generates a customizable star rating.
|
||||||
*
|
*
|
||||||
* Licensed under The MIT License
|
* Licensed under The MIT License
|
||||||
*
|
*
|
||||||
* @version 2.4.5
|
* @version 2.5.2
|
||||||
* @since 2010.06.11
|
* @since 2010.06.11
|
||||||
* @author Washington Botelho
|
* @author Washington Botelho
|
||||||
* @documentation wbotelhos.com/raty
|
* @documentation wbotelhos.com/raty
|
||||||
* @twitter twitter.com/wbotelhos
|
*
|
||||||
*
|
* ------------------------------------------------------------------
|
||||||
* Usage:
|
*
|
||||||
* -------------------------------------------------------------------
|
* <div id="star"></div>
|
||||||
* $('#star').raty();
|
*
|
||||||
*
|
* $('#star').raty();
|
||||||
* <div id="star"></div>
|
*
|
||||||
*
|
*/
|
||||||
*/
|
|
||||||
|
;(function($) {
|
||||||
;(function($) {
|
|
||||||
|
var methods = {
|
||||||
var methods = {
|
init: function(settings) {
|
||||||
init: function(settings) {
|
return this.each(function() {
|
||||||
return this.each(function() {
|
methods.destroy.call(this);
|
||||||
var self = this,
|
|
||||||
$this = $(self).empty();
|
this.opt = $.extend(true, {}, $.fn.raty.defaults, settings);
|
||||||
|
|
||||||
self.opt = $.extend(true, {}, $.fn.raty.defaults, settings);
|
var that = $(this),
|
||||||
|
inits = ['number', 'readOnly', 'score', 'scoreName'];
|
||||||
$this.data('settings', self.opt);
|
|
||||||
|
methods._callback.call(this, inits);
|
||||||
self.opt.number = methods.between(self.opt.number, 0, 20);
|
|
||||||
|
if (this.opt.precision) {
|
||||||
if (self.opt.path.substring(self.opt.path.length - 1, self.opt.path.length) != '/') {
|
methods._adjustPrecision.call(this);
|
||||||
self.opt.path += '/';
|
}
|
||||||
}
|
|
||||||
|
this.opt.number = methods._between(this.opt.number, 0, this.opt.numberMax);
|
||||||
if (typeof self.opt.score == 'function') {
|
|
||||||
self.opt.score = self.opt.score.call(self);
|
this.opt.path = this.opt.path || '';
|
||||||
}
|
|
||||||
|
if (this.opt.path && this.opt.path.charAt( this.opt.path.length - 1 ) !== '/') {
|
||||||
if (self.opt.score) {
|
this.opt.path += '/';
|
||||||
self.opt.score = methods.between(self.opt.score, 0, self.opt.number);
|
}
|
||||||
}
|
|
||||||
|
this.stars = methods._createStars.call(this);
|
||||||
for (var i = 1; i <= self.opt.number; i++) {
|
this.score = methods._createScore.call(this);
|
||||||
$('<img />', {
|
|
||||||
src : self.opt.path + ((!self.opt.score || self.opt.score < i) ? self.opt.starOff : self.opt.starOn),
|
methods._apply.call(this, this.opt.score);
|
||||||
alt : i,
|
|
||||||
'class' : self.opt.css,
|
var space = this.opt.space ? 4 : 0,
|
||||||
title : (i <= self.opt.hints.length && self.opt.hints[i - 1] !== null) ? self.opt.hints[i - 1] : i
|
width = this.opt.width || (this.opt.number * this.opt.size + this.opt.number * space);
|
||||||
}).appendTo(self);
|
|
||||||
|
if (this.opt.cancel) {
|
||||||
if (self.opt.space) {
|
this.cancel = methods._createCancel.call(this);
|
||||||
$this.append((i < self.opt.number) ? ' ' : '');
|
|
||||||
}
|
width += (this.opt.size + space);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.stars = $this.children('img:not(".raty-cancel")');
|
if (this.opt.readOnly) {
|
||||||
self.score = $('<input />', { type: 'hidden', name: self.opt.scoreName }).appendTo(self);
|
methods._lock.call(this);
|
||||||
|
} else {
|
||||||
if (self.opt.score && self.opt.score > 0) {
|
that.css('cursor', 'pointer');
|
||||||
self.score.val(self.opt.score);
|
methods._binds.call(this);
|
||||||
methods.roundStar.call(self, self.opt.score);
|
}
|
||||||
}
|
|
||||||
|
if (this.opt.width !== false) {
|
||||||
if (self.opt.iconRange) {
|
that.css('width', width);
|
||||||
methods.fill.call(self, self.opt.score);
|
}
|
||||||
}
|
|
||||||
|
methods._target.call(this, this.opt.score);
|
||||||
methods.setTarget.call(self, self.opt.score, self.opt.targetKeep);
|
|
||||||
|
that.data({ 'settings': this.opt, 'raty': true });
|
||||||
var space = self.opt.space ? 4 : 0,
|
});
|
||||||
width = self.opt.width || (self.opt.number * self.opt.size + self.opt.number * space);
|
}, _adjustPrecision: function() {
|
||||||
|
this.opt.targetType = 'score';
|
||||||
if (self.opt.cancel) {
|
this.opt.half = true;
|
||||||
self.cancel = $('<img />', { src: self.opt.path + self.opt.cancelOff, alt: 'x', title: self.opt.cancelHint, 'class': 'raty-cancel' });
|
}, _apply: function(score) {
|
||||||
|
if (score && score > 0) {
|
||||||
if (self.opt.cancelPlace == 'left') {
|
score = methods._between(score, 0, this.opt.number);
|
||||||
$this.prepend(' ').prepend(self.cancel);
|
this.score.val(score);
|
||||||
} else {
|
}
|
||||||
$this.append(' ').append(self.cancel);
|
|
||||||
}
|
methods._fill.call(this, score);
|
||||||
|
|
||||||
width += (self.opt.size + space);
|
if (score) {
|
||||||
}
|
methods._roundStars.call(this, score);
|
||||||
|
}
|
||||||
if (self.opt.readOnly) {
|
}, _between: function(value, min, max) {
|
||||||
methods.fixHint.call(self);
|
return Math.min(Math.max(parseFloat(value), min), max);
|
||||||
|
}, _binds: function() {
|
||||||
if (self.cancel) {
|
if (this.cancel) {
|
||||||
self.cancel.hide();
|
methods._bindCancel.call(this);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$this.css('cursor', 'pointer');
|
methods._bindClick.call(this);
|
||||||
|
methods._bindOut.call(this);
|
||||||
methods.bindAction.call(self);
|
methods._bindOver.call(this);
|
||||||
}
|
}, _bindCancel: function() {
|
||||||
|
methods._bindClickCancel.call(this);
|
||||||
// $this.css('width', width);
|
methods._bindOutCancel.call(this);
|
||||||
});
|
methods._bindOverCancel.call(this);
|
||||||
}, between: function(value, min, max) {
|
}, _bindClick: function() {
|
||||||
return Math.min(Math.max(parseFloat(value), min), max);
|
var self = this,
|
||||||
}, bindAction: function() {
|
that = $(self);
|
||||||
var self = this,
|
|
||||||
$this = $(self);
|
self.stars.on('click.raty', function(evt) {
|
||||||
|
self.score.val((self.opt.half || self.opt.precision) ? that.data('score') : this.alt);
|
||||||
$this.mouseleave(function() {
|
|
||||||
var score = self.score.val() || undefined;
|
if (self.opt.click) {
|
||||||
|
self.opt.click.call(self, parseFloat(self.score.val()), evt);
|
||||||
methods.initialize.call(self, score);
|
}
|
||||||
methods.setTarget.call(self, score, self.opt.targetKeep);
|
});
|
||||||
|
}, _bindClickCancel: function() {
|
||||||
if (self.opt.mouseover) {
|
var self = this;
|
||||||
self.opt.mouseover.call(self, score);
|
|
||||||
}
|
self.cancel.on('click.raty', function(evt) {
|
||||||
});
|
self.score.removeAttr('value');
|
||||||
|
|
||||||
var action = self.opt.half ? 'mousemove' : 'mouseover';
|
if (self.opt.click) {
|
||||||
|
self.opt.click.call(self, null, evt);
|
||||||
if (self.opt.cancel) {
|
}
|
||||||
self.cancel.mouseenter(function() {
|
});
|
||||||
$(this).attr('src', self.opt.path + self.opt.cancelOn);
|
}, _bindOut: function() {
|
||||||
|
var self = this;
|
||||||
self.stars.attr('src', self.opt.path + self.opt.starOff);
|
|
||||||
|
$(this).on('mouseleave.raty', function(evt) {
|
||||||
methods.setTarget.call(self, null, true);
|
var score = parseFloat(self.score.val()) || undefined;
|
||||||
|
|
||||||
if (self.opt.mouseover) {
|
methods._apply.call(self, score);
|
||||||
self.opt.mouseover.call(self, null);
|
methods._target.call(self, score, evt);
|
||||||
}
|
|
||||||
}).mouseleave(function() {
|
if (self.opt.mouseout) {
|
||||||
$(this).attr('src', self.opt.path + self.opt.cancelOff);
|
self.opt.mouseout.call(self, score, evt);
|
||||||
|
}
|
||||||
if (self.opt.mouseover) {
|
});
|
||||||
self.opt.mouseover.call(self, self.score.val() || null);
|
}, _bindOutCancel: function() {
|
||||||
}
|
var self = this;
|
||||||
}).click(function(evt) {
|
|
||||||
self.score.removeAttr('value');
|
self.cancel.on('mouseleave.raty', function(evt) {
|
||||||
|
$(this).attr('src', self.opt.path + self.opt.cancelOff);
|
||||||
if (self.opt.click) {
|
|
||||||
self.opt.click.call(self, null, evt);
|
if (self.opt.mouseout) {
|
||||||
}
|
self.opt.mouseout.call(self, self.score.val() || null, evt);
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
|
}, _bindOverCancel: function() {
|
||||||
self.stars.bind(action, function(evt) {
|
var self = this;
|
||||||
var value = parseInt(this.alt, 10);
|
|
||||||
|
self.cancel.on('mouseover.raty', function(evt) {
|
||||||
if (self.opt.half) {
|
$(this).attr('src', self.opt.path + self.opt.cancelOn);
|
||||||
var position = parseFloat((evt.pageX - $(this).offset().left) / self.opt.size),
|
|
||||||
diff = (position > .5) ? 1 : .5;
|
self.stars.attr('src', self.opt.path + self.opt.starOff);
|
||||||
|
|
||||||
value = parseFloat(this.alt) - 1 + diff;
|
methods._target.call(self, null, evt);
|
||||||
|
|
||||||
methods.fill.call(self, value);
|
if (self.opt.mouseover) {
|
||||||
|
self.opt.mouseover.call(self, null);
|
||||||
if (self.opt.precision) {
|
}
|
||||||
value = value - diff + position;
|
});
|
||||||
}
|
}, _bindOver: function() {
|
||||||
|
var self = this,
|
||||||
methods.showHalf.call(self, value);
|
that = $(self),
|
||||||
} else {
|
action = self.opt.half ? 'mousemove.raty' : 'mouseover.raty';
|
||||||
methods.fill.call(self, value);
|
|
||||||
}
|
self.stars.on(action, function(evt) {
|
||||||
|
var score = parseInt(this.alt, 10);
|
||||||
$this.data('score', value);
|
|
||||||
|
if (self.opt.half) {
|
||||||
methods.setTarget.call(self, value, true);
|
var position = parseFloat((evt.pageX - $(this).offset().left) / self.opt.size),
|
||||||
|
plus = (position > .5) ? 1 : .5;
|
||||||
if (self.opt.mouseover) {
|
|
||||||
self.opt.mouseover.call(self, value, evt);
|
score = score - 1 + plus;
|
||||||
}
|
|
||||||
}).click(function(evt) {
|
methods._fill.call(self, score);
|
||||||
self.score.val((self.opt.half || self.opt.precision) ? $this.data('score') : this.alt);
|
|
||||||
|
if (self.opt.precision) {
|
||||||
if (self.opt.click) {
|
score = score - plus + position;
|
||||||
self.opt.click.call(self, self.score.val(), evt);
|
}
|
||||||
}
|
|
||||||
});
|
methods._roundStars.call(self, score);
|
||||||
}, cancel: function(isClick) {
|
|
||||||
return $(this).each(function() {
|
that.data('score', score);
|
||||||
var self = this,
|
} else {
|
||||||
$this = $(self);
|
methods._fill.call(self, score);
|
||||||
|
}
|
||||||
if ($this.data('readonly') === true) {
|
|
||||||
return this;
|
methods._target.call(self, score, evt);
|
||||||
}
|
|
||||||
|
if (self.opt.mouseover) {
|
||||||
if (isClick) {
|
self.opt.mouseover.call(self, score, evt);
|
||||||
methods.click.call(self, null);
|
}
|
||||||
} else {
|
});
|
||||||
methods.score.call(self, null);
|
}, _callback: function(options) {
|
||||||
}
|
for (i in options) {
|
||||||
|
if (typeof this.opt[options[i]] === 'function') {
|
||||||
self.score.removeAttr('value');
|
this.opt[options[i]] = this.opt[options[i]].call(this);
|
||||||
});
|
}
|
||||||
}, click: function(score) {
|
}
|
||||||
return $(this).each(function() {
|
}, _createCancel: function() {
|
||||||
if ($(this).data('readonly') === true) {
|
var that = $(this),
|
||||||
return this;
|
icon = this.opt.path + this.opt.cancelOff,
|
||||||
}
|
cancel = $('<img />', { src: icon, alt: 'x', title: this.opt.cancelHint, 'class': 'raty-cancel' });
|
||||||
|
|
||||||
methods.initialize.call(this, score);
|
if (this.opt.cancelPlace == 'left') {
|
||||||
|
that.prepend(' ').prepend(cancel);
|
||||||
if (this.opt.click) {
|
} else {
|
||||||
this.opt.click.call(this, score);
|
that.append(' ').append(cancel);
|
||||||
} else {
|
}
|
||||||
methods.error.call(this, 'you must add the "click: function(score, evt) { }" callback.');
|
|
||||||
}
|
return cancel;
|
||||||
|
}, _createScore: function() {
|
||||||
methods.setTarget.call(this, score, true);
|
return $('<input />', { type: 'hidden', name: this.opt.scoreName }).appendTo(this);
|
||||||
});
|
}, _createStars: function() {
|
||||||
}, error: function(message) {
|
var that = $(this);
|
||||||
$(this).html(message);
|
|
||||||
|
for (var i = 1; i <= this.opt.number; i++) {
|
||||||
$.error(message);
|
var title = methods._getHint.call(this, i),
|
||||||
}, fill: function(score) {
|
icon = (this.opt.score && this.opt.score >= i) ? 'starOn' : 'starOff';
|
||||||
var self = this,
|
|
||||||
number = self.stars.length,
|
icon = this.opt.path + this.opt[icon];
|
||||||
count = 0,
|
|
||||||
$star ,
|
$('<img />', { src : icon, alt: i, title: title }).appendTo(this);
|
||||||
star ,
|
|
||||||
icon ;
|
if (this.opt.space) {
|
||||||
|
that.append((i < this.opt.number) ? ' ' : '');
|
||||||
for (var i = 1; i <= number; i++) {
|
}
|
||||||
$star = self.stars.eq(i - 1);
|
}
|
||||||
|
|
||||||
if (self.opt.iconRange && self.opt.iconRange.length > count) {
|
return that.children('img');
|
||||||
star = self.opt.iconRange[count];
|
}, _error: function(message) {
|
||||||
|
$(this).html(message);
|
||||||
if (self.opt.single) {
|
|
||||||
icon = (i == score) ? (star.on || self.opt.starOn) : (star.off || self.opt.starOff);
|
$.error(message);
|
||||||
} else {
|
}, _fill: function(score) {
|
||||||
icon = (i <= score) ? (star.on || self.opt.starOn) : (star.off || self.opt.starOff);
|
var self = this,
|
||||||
}
|
hash = 0;
|
||||||
|
|
||||||
if (i <= star.range) {
|
for (var i = 1; i <= self.stars.length; i++) {
|
||||||
$star.attr('src', self.opt.path + icon);
|
var star = self.stars.eq(i - 1),
|
||||||
}
|
select = self.opt.single ? (i == score) : (i <= score);
|
||||||
|
|
||||||
if (i == star.range) {
|
if (self.opt.iconRange && self.opt.iconRange.length > hash) {
|
||||||
count++;
|
var irange = self.opt.iconRange[hash],
|
||||||
}
|
on = irange.on || self.opt.starOn,
|
||||||
} else {
|
off = irange.off || self.opt.starOff,
|
||||||
if (self.opt.single) {
|
icon = select ? on : off;
|
||||||
icon = (i == score) ? self.opt.starOn : self.opt.starOff;
|
|
||||||
} else {
|
if (i <= irange.range) {
|
||||||
icon = (i <= score) ? self.opt.starOn : self.opt.starOff;
|
star.attr('src', self.opt.path + icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
$star.attr('src', self.opt.path + icon);
|
if (i == irange.range) {
|
||||||
}
|
hash++;
|
||||||
}
|
}
|
||||||
}, fixHint: function() {
|
} else {
|
||||||
var $this = $(this),
|
var icon = select ? 'starOn' : 'starOff';
|
||||||
score = parseInt(this.score.val(), 10),
|
|
||||||
hint = this.opt.noRatedMsg;
|
star.attr('src', this.opt.path + this.opt[icon]);
|
||||||
|
}
|
||||||
if (!isNaN(score) && score > 0) {
|
}
|
||||||
hint = (score <= this.opt.hints.length && this.opt.hints[score - 1] !== null) ? this.opt.hints[score - 1] : score;
|
}, _getHint: function(score) {
|
||||||
}
|
var hint = this.opt.hints[score - 1];
|
||||||
|
return (hint === '') ? '' : (hint || score);
|
||||||
$this.data('readonly', true).css('cursor', 'default').attr('title', hint);
|
}, _lock: function() {
|
||||||
|
var score = parseInt(this.score.val(), 10), // TODO: 3.1 >> [['1'], ['2'], ['3', '.1', '.2']]
|
||||||
this.score.attr('readonly', 'readonly');
|
hint = score ? methods._getHint.call(this, score) : this.opt.noRatedMsg;
|
||||||
this.stars.attr('title', hint);
|
|
||||||
}, getScore: function() {
|
$(this).data('readonly', true).css('cursor', '').attr('title', hint);
|
||||||
var score = [],
|
|
||||||
value ;
|
this.score.attr('readonly', 'readonly');
|
||||||
|
this.stars.attr('title', hint);
|
||||||
$(this).each(function() {
|
|
||||||
value = this.score.val();
|
if (this.cancel) {
|
||||||
|
this.cancel.hide();
|
||||||
score.push(value ? parseFloat(value) : undefined);
|
}
|
||||||
});
|
}, _roundStars: function(score) {
|
||||||
|
var rest = (score - Math.floor(score)).toFixed(2);
|
||||||
return (score.length > 1) ? score : score[0];
|
|
||||||
}, readOnly: function(isReadOnly) {
|
if (rest > this.opt.round.down) {
|
||||||
return this.each(function() {
|
var icon = 'starOn'; // Up: [x.76 .. x.99]
|
||||||
var $this = $(this);
|
|
||||||
|
if (this.opt.halfShow && rest < this.opt.round.up) { // Half: [x.26 .. x.75]
|
||||||
if ($this.data('readonly') === isReadOnly) {
|
icon = 'starHalf';
|
||||||
return this;
|
} else if (rest < this.opt.round.full) { // Down: [x.00 .. x.5]
|
||||||
}
|
icon = 'starOff';
|
||||||
|
}
|
||||||
if (this.cancel) {
|
|
||||||
if (isReadOnly) {
|
this.stars.eq(Math.ceil(score) - 1).attr('src', this.opt.path + this.opt[icon]);
|
||||||
this.cancel.hide();
|
} // Full down: [x.00 .. x.25]
|
||||||
} else {
|
}, _target: function(score, evt) {
|
||||||
this.cancel.show();
|
if (this.opt.target) {
|
||||||
}
|
var target = $(this.opt.target);
|
||||||
}
|
|
||||||
|
if (target.length === 0) {
|
||||||
if (isReadOnly) {
|
methods._error.call(this, 'Target selector invalid or missing!');
|
||||||
$this.unbind();
|
}
|
||||||
|
|
||||||
$this.children('img').unbind();
|
if (this.opt.targetFormat.indexOf('{score}') < 0) {
|
||||||
|
methods._error.call(this, 'Template "{score}" missing!');
|
||||||
methods.fixHint.call(this);
|
}
|
||||||
} else {
|
|
||||||
methods.bindAction.call(this);
|
var mouseover = evt && evt.type == 'mouseover';
|
||||||
methods.unfixHint.call(this);
|
|
||||||
}
|
if (score === undefined) {
|
||||||
|
score = this.opt.targetText;
|
||||||
$this.data('readonly', isReadOnly);
|
} else if (score === null) {
|
||||||
});
|
score = mouseover ? this.opt.cancelHint : this.opt.targetText;
|
||||||
}, reload: function() {
|
} else {
|
||||||
return methods.set.call(this, {});
|
if (this.opt.targetType == 'hint') {
|
||||||
}, roundStar: function(score) {
|
score = methods._getHint.call(this, Math.ceil(score));
|
||||||
var diff = (score - Math.floor(score)).toFixed(2);
|
} else if (this.opt.precision) {
|
||||||
|
score = parseFloat(score).toFixed(1);
|
||||||
if (diff > this.opt.round.down) {
|
}
|
||||||
var icon = this.opt.starOn; // Full up: [x.76 .. x.99]
|
|
||||||
|
if (!mouseover && !this.opt.targetKeep) {
|
||||||
if (diff < this.opt.round.up && this.opt.halfShow) { // Half: [x.26 .. x.75]
|
score = this.opt.targetText;
|
||||||
icon = this.opt.starHalf;
|
}
|
||||||
} else if (diff < this.opt.round.full) { // Full down: [x.00 .. x.5]
|
}
|
||||||
icon = this.opt.starOff;
|
|
||||||
}
|
if (score) {
|
||||||
|
score = this.opt.targetFormat.toString().replace('{score}', score);
|
||||||
this.stars.eq(Math.ceil(score) - 1).attr('src', this.opt.path + icon);
|
}
|
||||||
} // Full down: [x.00 .. x.25]
|
|
||||||
}, score: function() {
|
if (target.is(':input')) {
|
||||||
return arguments.length ? methods.setScore.apply(this, arguments) : methods.getScore.call(this);
|
target.val(score);
|
||||||
}, set: function(settings) {
|
} else {
|
||||||
this.each(function() {
|
target.html(score);
|
||||||
var $this = $(this),
|
}
|
||||||
actual = $this.data('settings'),
|
}
|
||||||
clone = $this.clone().removeAttr('style').insertBefore($this);
|
}, _unlock: function() {
|
||||||
|
$(this).data('readonly', false).css('cursor', 'pointer').removeAttr('title');
|
||||||
$this.remove();
|
|
||||||
|
this.score.removeAttr('readonly', 'readonly');
|
||||||
clone.raty($.extend(actual, settings));
|
|
||||||
});
|
for (var i = 0; i < this.opt.number; i++) {
|
||||||
|
this.stars.eq(i).attr('title', methods._getHint.call(this, i + 1));
|
||||||
return $(this.selector);
|
}
|
||||||
}, setScore: function(score) {
|
|
||||||
return $(this).each(function() {
|
if (this.cancel) {
|
||||||
if ($(this).data('readonly') === true) {
|
this.cancel.css('display', '');
|
||||||
return this;
|
}
|
||||||
}
|
}, cancel: function(click) {
|
||||||
|
return this.each(function() {
|
||||||
methods.initialize.call(this, score);
|
if ($(this).data('readonly') !== true) {
|
||||||
methods.setTarget.call(this, score, true);
|
methods[click ? 'click' : 'score'].call(this, null);
|
||||||
});
|
this.score.removeAttr('value');
|
||||||
}, setTarget: function(value, isKeep) {
|
}
|
||||||
if (this.opt.target) {
|
});
|
||||||
var $target = $(this.opt.target);
|
}, click: function(score) {
|
||||||
|
return $(this).each(function() {
|
||||||
if ($target.length == 0) {
|
if ($(this).data('readonly') !== true) {
|
||||||
methods.error.call(this, 'target selector invalid or missing!');
|
methods._apply.call(this, score);
|
||||||
}
|
|
||||||
|
if (!this.opt.click) {
|
||||||
var score = value;
|
methods._error.call(this, 'You must add the "click: function(score, evt) { }" callback.');
|
||||||
|
}
|
||||||
if (!isKeep || score === undefined) {
|
|
||||||
score = this.opt.targetText;
|
|
||||||
} else {
|
this.opt.click.call(this, score, $.Event('click'));
|
||||||
if (this.opt.targetType == 'hint') {
|
|
||||||
score = (score === null && this.opt.cancel)
|
methods._target.call(this, score);
|
||||||
? this.opt.cancelHint
|
}
|
||||||
: this.opt.hints[Math.ceil(score - 1)];
|
});
|
||||||
} else {
|
}, destroy: function() {
|
||||||
score = this.opt.precision
|
return $(this).each(function() {
|
||||||
? parseFloat(score).toFixed(1)
|
var that = $(this),
|
||||||
: parseInt(score, 10);
|
raw = that.data('raw');
|
||||||
}
|
|
||||||
}
|
if (raw) {
|
||||||
|
that.off('.raty').empty().css({ cursor: raw.style.cursor, width: raw.style.width }).removeData('readonly');
|
||||||
if (this.opt.targetFormat.indexOf('{score}') < 0) {
|
} else {
|
||||||
methods.error.call(this, 'template "{score}" missing!');
|
that.data('raw', that.clone()[0]);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
if (value !== null) {
|
}, getScore: function() {
|
||||||
score = this.opt.targetFormat.toString().replace('{score}', score);
|
var score = [],
|
||||||
}
|
value ;
|
||||||
|
|
||||||
if ($target.is(':input')) {
|
$(this).each(function() {
|
||||||
$target.val(score);
|
value = this.score.val();
|
||||||
} else {
|
|
||||||
$target.html(score);
|
score.push(value ? parseFloat(value) : undefined);
|
||||||
}
|
});
|
||||||
}
|
|
||||||
}, showHalf: function(score) {
|
return (score.length > 1) ? score : score[0];
|
||||||
var diff = (score - Math.floor(score)).toFixed(1);
|
}, readOnly: function(readonly) {
|
||||||
|
return this.each(function() {
|
||||||
if (diff > 0 && diff < .6) {
|
var that = $(this);
|
||||||
this.stars.eq(Math.ceil(score) - 1).attr('src', this.opt.path + this.opt.starHalf);
|
|
||||||
}
|
if (that.data('readonly') !== readonly) {
|
||||||
}, initialize: function(score) {
|
if (readonly) {
|
||||||
score = !score ? 0 : methods.between(score, 0, this.opt.number);
|
that.off('.raty').children('img').off('.raty');
|
||||||
|
|
||||||
methods.fill.call(this, score);
|
methods._lock.call(this);
|
||||||
|
} else {
|
||||||
if (score > 0) {
|
methods._binds.call(this);
|
||||||
if (this.opt.halfShow) {
|
methods._unlock.call(this);
|
||||||
methods.roundStar.call(this, score);
|
}
|
||||||
}
|
|
||||||
|
that.data('readonly', readonly);
|
||||||
this.score.val(score);
|
}
|
||||||
}
|
});
|
||||||
}, unfixHint: function() {
|
}, reload: function() {
|
||||||
for (var i = 0; i < this.opt.number; i++) {
|
return methods.set.call(this, {});
|
||||||
this.stars.eq(i).attr('title', (i < this.opt.hints.length && this.opt.hints[i] !== null) ? this.opt.hints[i] : i);
|
}, score: function() {
|
||||||
}
|
return arguments.length ? methods.setScore.apply(this, arguments) : methods.getScore.call(this);
|
||||||
|
}, set: function(settings) {
|
||||||
$(this).data('readonly', false).css('cursor', 'pointer').removeAttr('title');
|
return this.each(function() {
|
||||||
|
var that = $(this),
|
||||||
this.score.attr('readonly', 'readonly');
|
actual = that.data('settings'),
|
||||||
}
|
news = $.extend({}, actual, settings);
|
||||||
};
|
|
||||||
|
that.raty(news);
|
||||||
$.fn.raty = function(method) {
|
});
|
||||||
if (methods[method]) {
|
}, setScore: function(score) {
|
||||||
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
|
return $(this).each(function() {
|
||||||
} else if (typeof method === 'object' || !method) {
|
if ($(this).data('readonly') !== true) {
|
||||||
return methods.init.apply(this, arguments);
|
methods._apply.call(this, score);
|
||||||
} else {
|
methods._target.call(this, score);
|
||||||
$.error('Method ' + method + ' does not exist!');
|
}
|
||||||
}
|
});
|
||||||
};
|
}
|
||||||
|
};
|
||||||
$.fn.raty.defaults = {
|
|
||||||
cancel : false,
|
$.fn.raty = function(method) {
|
||||||
cancelHint : 'cancel this rating!',
|
if (methods[method]) {
|
||||||
cancelOff : 'cancel-off.png',
|
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
|
||||||
cancelOn : 'cancel-on.png',
|
} else if (typeof method === 'object' || !method) {
|
||||||
cancelPlace : 'left',
|
return methods.init.apply(this, arguments);
|
||||||
click : undefined,
|
} else {
|
||||||
half : false,
|
$.error('Method ' + method + ' does not exist!');
|
||||||
halfShow : true,
|
}
|
||||||
hints : ['bad', 'poor', 'regular', 'good', 'gorgeous'],
|
};
|
||||||
iconRange : undefined,
|
|
||||||
mouseover : undefined,
|
$.fn.raty.defaults = {
|
||||||
noRatedMsg : 'not rated yet',
|
cancel : false,
|
||||||
number : 5,
|
cancelHint : 'Cancel this rating!',
|
||||||
path : 'img/',
|
cancelOff : 'cancel-off.png',
|
||||||
precision : false,
|
cancelOn : 'cancel-on.png',
|
||||||
round : { down: .25, full: .6, up: .76 },
|
cancelPlace : 'left',
|
||||||
readOnly : false,
|
click : undefined,
|
||||||
score : undefined,
|
half : false,
|
||||||
scoreName : 'score',
|
halfShow : true,
|
||||||
single : false,
|
hints : ['bad', 'poor', 'regular', 'good', 'gorgeous'],
|
||||||
size : 16,
|
iconRange : undefined,
|
||||||
space : true,
|
mouseout : undefined,
|
||||||
starHalf : 'star-half.png',
|
mouseover : undefined,
|
||||||
starOff : 'star-off.png',
|
noRatedMsg : 'Not rated yet!',
|
||||||
starOn : 'star-on.png',
|
number : 5,
|
||||||
target : undefined,
|
numberMax : 20,
|
||||||
targetFormat : '{score}',
|
path : '',
|
||||||
targetKeep : false,
|
precision : false,
|
||||||
targetText : '',
|
readOnly : false,
|
||||||
targetType : 'hint',
|
round : { down: .25, full: .6, up: .76 },
|
||||||
width : undefined,
|
score : undefined,
|
||||||
css : 'raty'
|
scoreName : 'score',
|
||||||
};
|
single : false,
|
||||||
|
size : 16,
|
||||||
})(jQuery);
|
space : true,
|
||||||
|
starHalf : 'star-half.png',
|
||||||
|
starOff : 'star-off.png',
|
||||||
|
starOn : 'star-on.png',
|
||||||
|
target : undefined,
|
||||||
|
targetFormat : '{score}',
|
||||||
|
targetKeep : false,
|
||||||
|
targetText : '',
|
||||||
|
targetType : 'hint',
|
||||||
|
width : undefined
|
||||||
|
};
|
||||||
|
|
||||||
|
})(jQuery);
|
||||||
|
Reference in New Issue
Block a user