author | Santosh G. Vattam <vattam.santosh@gmail.com> |
Mon, 10 Aug 2009 16:58:36 +0530 | |
changeset 36 | a7c525ec281a |
parent 28 | be65e84e7d03 |
permissions | -rw-r--r-- |
28
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1 |
/* |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2 |
### jQuery Star Rating Plugin v3.12 - 2009-04-16 ### |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
3 |
* Home: http://www.fyneworks.com/jquery/star-rating/ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
4 |
* Code: http://code.google.com/p/jquery-star-rating-plugin/ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
5 |
* |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
6 |
* Dual licensed under the MIT and GPL licenses: |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
7 |
* http://www.opensource.org/licenses/mit-license.php |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
8 |
* http://www.gnu.org/licenses/gpl.html |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
9 |
### |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
10 |
*/ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
11 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
12 |
/*# AVOID COLLISIONS #*/ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
13 |
;if(window.jQuery) (function($){ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
14 |
/*# AVOID COLLISIONS #*/ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
15 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
16 |
// IE6 Background Image Fix |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
17 |
if ($.browser.msie) try { document.execCommand("BackgroundImageCache", false, true)} catch(e) { }; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
18 |
// Thanks to http://www.visualjquery.com/rating/rating_redux.html |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
19 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
20 |
// plugin initialization |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
21 |
$.fn.rating = function(options){ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
22 |
if(this.length==0) return this; // quick fail |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
23 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
24 |
// Handle API methods |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
25 |
if(typeof arguments[0]=='string'){ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
26 |
// Perform API methods on individual elements |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
27 |
if(this.length>1){ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
28 |
var args = arguments; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
29 |
return this.each(function(){ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
30 |
$.fn.rating.apply($(this), args); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
31 |
}); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
32 |
}; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
33 |
// Invoke API method handler |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
34 |
$.fn.rating[arguments[0]].apply(this, $.makeArray(arguments).slice(1) || []); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
35 |
// Quick exit... |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
36 |
return this; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
37 |
}; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
38 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
39 |
// Initialize options for this call |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
40 |
var options = $.extend( |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
41 |
{}/* new object */, |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
42 |
$.fn.rating.options/* default options */, |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
43 |
options || {} /* just-in-time options */ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
44 |
); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
45 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
46 |
// Allow multiple controls with the same name by making each call unique |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
47 |
$.fn.rating.calls++; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
48 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
49 |
// loop through each matched element |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
50 |
this |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
51 |
.not('.star-rating-applied') |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
52 |
.addClass('star-rating-applied') |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
53 |
.each(function(){ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
54 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
55 |
// Load control parameters / find context / etc |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
56 |
var control, input = $(this); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
57 |
var eid = (this.name || 'unnamed-rating').replace(/\[|\]/g, '_').replace(/^\_+|\_+$/g,''); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
58 |
var context = $(this.form || document.body); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
59 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
60 |
// FIX: http://code.google.com/p/jquery-star-rating-plugin/issues/detail?id=23 |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
61 |
var raters = context.data('rating'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
62 |
if(!raters || raters.call!=$.fn.rating.calls) raters = { count:0, call:$.fn.rating.calls }; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
63 |
var rater = raters[eid]; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
64 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
65 |
// if rater is available, verify that the control still exists |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
66 |
if(rater) control = rater.data('rating'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
67 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
68 |
if(rater && control)//{// save a byte! |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
69 |
// add star to control if rater is available and the same control still exists |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
70 |
control.count++; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
71 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
72 |
//}// save a byte! |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
73 |
else{ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
74 |
// create new control if first star or control element was removed/replaced |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
75 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
76 |
// Initialize options for this raters |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
77 |
control = $.extend( |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
78 |
{}/* new object */, |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
79 |
options || {} /* current call options */, |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
80 |
($.metadata? input.metadata(): ($.meta?input.data():null)) || {}, /* metadata options */ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
81 |
{ count:0, stars: [], inputs: [] } |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
82 |
); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
83 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
84 |
// increment number of rating controls |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
85 |
control.serial = raters.count++; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
86 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
87 |
// create rating element |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
88 |
rater = $('<span class="star-rating-control"/>'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
89 |
input.before(rater); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
90 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
91 |
// Mark element for initialization (once all stars are ready) |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
92 |
rater.addClass('rating-to-be-drawn'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
93 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
94 |
// Accept readOnly setting from 'disabled' property |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
95 |
if(input.attr('disabled')) control.readOnly = true; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
96 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
97 |
// Create 'cancel' button |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
98 |
rater.append( |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
99 |
control.cancel = $('<div class="rating-cancel"><a title="' + control.cancel + '">' + control.cancelValue + '</a></div>') |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
100 |
.mouseover(function(){ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
101 |
$(this).rating('drain'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
102 |
$(this).addClass('star-rating-hover'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
103 |
//$(this).rating('focus'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
104 |
}) |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
105 |
.mouseout(function(){ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
106 |
$(this).rating('draw'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
107 |
$(this).removeClass('star-rating-hover'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
108 |
//$(this).rating('blur'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
109 |
}) |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
110 |
.click(function(){ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
111 |
$(this).rating('select'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
112 |
}) |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
113 |
.data('rating', control) |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
114 |
); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
115 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
116 |
}; // first element of group |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
117 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
118 |
// insert rating star |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
119 |
var star = $('<div class="star-rating rater-'+ control.serial +'"><a title="' + (this.title || this.value) + '">' + this.value + '</a></div>'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
120 |
rater.append(star); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
121 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
122 |
// inherit attributes from input element |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
123 |
if(this.id) star.attr('id', this.id); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
124 |
if(this.className) star.addClass(this.className); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
125 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
126 |
// Half-stars? |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
127 |
if(control.half) control.split = 2; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
128 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
129 |
// Prepare division control |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
130 |
if(typeof control.split=='number' && control.split>0){ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
131 |
var stw = ($.fn.width ? star.width() : 0) || control.starWidth; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
132 |
var spi = (control.count % control.split), spw = Math.floor(stw/control.split); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
133 |
star |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
134 |
// restrict star's width and hide overflow (already in CSS) |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
135 |
.width(spw) |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
136 |
// move the star left by using a negative margin |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
137 |
// this is work-around to IE's stupid box model (position:relative doesn't work) |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
138 |
.find('a').css({ 'margin-left':'-'+ (spi*spw) +'px' }) |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
139 |
}; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
140 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
141 |
// readOnly? |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
142 |
if(control.readOnly)//{ //save a byte! |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
143 |
// Mark star as readOnly so user can customize display |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
144 |
star.addClass('star-rating-readonly'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
145 |
//} //save a byte! |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
146 |
else//{ //save a byte! |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
147 |
// Enable hover css effects |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
148 |
star.addClass('star-rating-live') |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
149 |
// Attach mouse events |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
150 |
.mouseover(function(){ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
151 |
$(this).rating('fill'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
152 |
$(this).rating('focus'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
153 |
}) |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
154 |
.mouseout(function(){ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
155 |
$(this).rating('draw'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
156 |
$(this).rating('blur'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
157 |
}) |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
158 |
.click(function(){ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
159 |
$(this).rating('select'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
160 |
}) |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
161 |
; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
162 |
//}; //save a byte! |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
163 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
164 |
// set current selection |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
165 |
if(this.checked) control.current = star; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
166 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
167 |
// hide input element |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
168 |
input.hide(); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
169 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
170 |
// backward compatibility, form element to plugin |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
171 |
input.change(function(){ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
172 |
$(this).rating('select'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
173 |
}); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
174 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
175 |
// attach reference to star to input element and vice-versa |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
176 |
star.data('rating.input', input.data('rating.star', star)); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
177 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
178 |
// store control information in form (or body when form not available) |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
179 |
control.stars[control.stars.length] = star[0]; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
180 |
control.inputs[control.inputs.length] = input[0]; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
181 |
control.rater = raters[eid] = rater; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
182 |
control.context = context; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
183 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
184 |
input.data('rating', control); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
185 |
rater.data('rating', control); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
186 |
star.data('rating', control); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
187 |
context.data('rating', raters); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
188 |
}); // each element |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
189 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
190 |
// Initialize ratings (first draw) |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
191 |
$('.rating-to-be-drawn').rating('draw').removeClass('rating-to-be-drawn'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
192 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
193 |
return this; // don't break the chain... |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
194 |
}; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
195 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
196 |
/*--------------------------------------------------------*/ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
197 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
198 |
/* |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
199 |
### Core functionality and API ### |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
200 |
*/ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
201 |
$.extend($.fn.rating, { |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
202 |
// Used to append a unique serial number to internal control ID |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
203 |
// each time the plugin is invoked so same name controls can co-exist |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
204 |
calls: 0, |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
205 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
206 |
focus: function(){ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
207 |
var control = this.data('rating'); if(!control) return this; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
208 |
if(!control.focus) return this; // quick fail if not required |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
209 |
// find data for event |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
210 |
var input = $(this).data('rating.input') || $( this.tagName=='INPUT' ? this : null ); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
211 |
// focus handler, as requested by focusdigital.co.uk |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
212 |
if(control.focus) control.focus.apply(input[0], [input.val(), $('a', input.data('rating.star'))[0]]); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
213 |
}, // $.fn.rating.focus |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
214 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
215 |
blur: function(){ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
216 |
var control = this.data('rating'); if(!control) return this; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
217 |
if(!control.blur) return this; // quick fail if not required |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
218 |
// find data for event |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
219 |
var input = $(this).data('rating.input') || $( this.tagName=='INPUT' ? this : null ); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
220 |
// blur handler, as requested by focusdigital.co.uk |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
221 |
if(control.blur) control.blur.apply(input[0], [input.val(), $('a', input.data('rating.star'))[0]]); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
222 |
}, // $.fn.rating.blur |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
223 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
224 |
fill: function(){ // fill to the current mouse position. |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
225 |
var control = this.data('rating'); if(!control) return this; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
226 |
// do not execute when control is in read-only mode |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
227 |
if(control.readOnly) return; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
228 |
// Reset all stars and highlight them up to this element |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
229 |
this.rating('drain'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
230 |
this.prevAll().andSelf().filter('.rater-'+ control.serial).addClass('star-rating-hover'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
231 |
},// $.fn.rating.fill |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
232 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
233 |
drain: function() { // drain all the stars. |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
234 |
var control = this.data('rating'); if(!control) return this; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
235 |
// do not execute when control is in read-only mode |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
236 |
if(control.readOnly) return; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
237 |
// Reset all stars |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
238 |
control.rater.children().filter('.rater-'+ control.serial).removeClass('star-rating-on').removeClass('star-rating-hover'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
239 |
},// $.fn.rating.drain |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
240 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
241 |
draw: function(){ // set value and stars to reflect current selection |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
242 |
var control = this.data('rating'); if(!control) return this; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
243 |
// Clear all stars |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
244 |
this.rating('drain'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
245 |
// Set control value |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
246 |
if(control.current){ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
247 |
control.current.data('rating.input').attr('checked','checked'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
248 |
control.current.prevAll().andSelf().filter('.rater-'+ control.serial).addClass('star-rating-on'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
249 |
} |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
250 |
else |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
251 |
$(control.inputs).removeAttr('checked'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
252 |
// Show/hide 'cancel' button |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
253 |
control.cancel[control.readOnly || control.required?'hide':'show'](); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
254 |
// Add/remove read-only classes to remove hand pointer |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
255 |
this.siblings()[control.readOnly?'addClass':'removeClass']('star-rating-readonly'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
256 |
},// $.fn.rating.draw |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
257 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
258 |
select: function(value){ // select a value |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
259 |
var control = this.data('rating'); if(!control) return this; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
260 |
// do not execute when control is in read-only mode |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
261 |
if(control.readOnly) return; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
262 |
// clear selection |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
263 |
control.current = null; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
264 |
// programmatically (based on user input) |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
265 |
if(typeof value!='undefined'){ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
266 |
// select by index (0 based) |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
267 |
if(typeof value=='number') |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
268 |
return $(control.stars[value]).rating('select'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
269 |
// select by literal value (must be passed as a string |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
270 |
if(typeof value=='string') |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
271 |
//return |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
272 |
$.each(control.stars, function(){ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
273 |
if($(this).data('rating.input').val()==value) $(this).rating('select'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
274 |
}); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
275 |
} |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
276 |
else |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
277 |
control.current = this[0].tagName=='INPUT' ? |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
278 |
this.data('rating.star') : |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
279 |
(this.is('.rater-'+ control.serial) ? this : null); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
280 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
281 |
// Update rating control state |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
282 |
this.data('rating', control); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
283 |
// Update display |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
284 |
this.rating('draw'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
285 |
// find data for event |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
286 |
var input = $( control.current ? control.current.data('rating.input') : null ); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
287 |
// click callback, as requested here: http://plugins.jquery.com/node/1655 |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
288 |
if(control.callback) control.callback.apply(input[0], [input.val(), $('a', control.current)[0]]);// callback event |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
289 |
},// $.fn.rating.select |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
290 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
291 |
readOnly: function(toggle, disable){ // make the control read-only (still submits value) |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
292 |
var control = this.data('rating'); if(!control) return this; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
293 |
// setread-only status |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
294 |
control.readOnly = toggle || toggle==undefined ? true : false; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
295 |
// enable/disable control value submission |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
296 |
if(disable) $(control.inputs).attr("disabled", "disabled"); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
297 |
else $(control.inputs).removeAttr("disabled"); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
298 |
// Update rating control state |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
299 |
this.data('rating', control); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
300 |
// Update display |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
301 |
this.rating('draw'); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
302 |
},// $.fn.rating.readOnly |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
303 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
304 |
disable: function(){ // make read-only and never submit value |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
305 |
this.rating('readOnly', true, true); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
306 |
},// $.fn.rating.disable |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
307 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
308 |
enable: function(){ // make read/write and submit value |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
309 |
this.rating('readOnly', false, false); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
310 |
}// $.fn.rating.select |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
311 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
312 |
}); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
313 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
314 |
/*--------------------------------------------------------*/ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
315 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
316 |
/* |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
317 |
### Default Settings ### |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
318 |
eg.: You can override default control like this: |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
319 |
$.fn.rating.options.cancel = 'Clear'; |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
320 |
*/ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
321 |
$.fn.rating.options = { //$.extend($.fn.rating, { options: { |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
322 |
cancel: 'Cancel Rating', // advisory title for the 'cancel' link |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
323 |
cancelValue: '', // value to submit when user click the 'cancel' link |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
324 |
split: 0, // split the star into how many parts? |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
325 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
326 |
// Width of star image in case the plugin can't work it out. This can happen if |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
327 |
// the jQuery.dimensions plugin is not available OR the image is hidden at installation |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
328 |
starWidth: 16//, |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
329 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
330 |
//NB.: These don't need to be pre-defined (can be undefined/null) so let's save some code! |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
331 |
//half: false, // just a shortcut to control.split = 2 |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
332 |
//required: false, // disables the 'cancel' button so user can only select one of the specified values |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
333 |
//readOnly: false, // disable rating plugin interaction/ values cannot be changed |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
334 |
//focus: function(){}, // executed when stars are focused |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
335 |
//blur: function(){}, // executed when stars are focused |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
336 |
//callback: function(){}, // executed when a star is clicked |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
337 |
}; //} }); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
338 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
339 |
/*--------------------------------------------------------*/ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
340 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
341 |
/* |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
342 |
### Default implementation ### |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
343 |
The plugin will attach itself to file inputs |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
344 |
with the class 'multi' when the page loads |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
345 |
*/ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
346 |
$(function(){ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
347 |
$('input[type=radio].star').rating(); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
348 |
}); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
349 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
350 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
351 |
|
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
352 |
/*# AVOID COLLISIONS #*/ |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
353 |
})(jQuery); |
be65e84e7d03
Added star-plugin files.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
354 |
/*# AVOID COLLISIONS #*/ |