example.htm
30.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
<!DOCTYPE html>
<html>
<head>
<title>RateIt</title>
<link href="../src/rateit.css" rel="stylesheet" type="text/css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
<style>
body
{
font-family: Tahoma;
font-size: 12px;
margin: 1em;
}
h1
{
font-size: 1.7em;
}
h2
{
font-size: 1.5em;
}
h3
{
font-size: 1.2em;
}
ul.nostyle
{
list-style: none;
}
ul.nostyle h3
{
margin-left: -20px;
}
#toc {
-moz-column-count: 3;
-webkit-column-count: 3;
column-count: 3;
max-width: 1100px;
}
</style>
<!-- alternative styles -->
<link href="content/bigstars.css" rel="stylesheet" type="text/css">
<link href="content/antenna.css" rel="stylesheet" type="text/css">
<link href="content/svg.css" rel="stylesheet" type="text/css">
<!-- syntax highlighter -->
<link href="sh/shCore.css" rel="stylesheet" type="text/css">
<link href="sh/shCoreDefault.css" rel="stylesheet" type="text/css">
</head>
<body>
<h1><img src="content/rateit.png" style="height:5.6em; float:right" />
RateIt plugin</h1>
<h2>
Prerequisites</h2>
<p>
In order to use RateIt you'll need:
<ul>
<li><a target="_blank" href="http://www.jquery.com">jQuery 1.6.0</a> or newer.</li>
<li>jquery.rateit.min.js, rateit.css, delete.gif, star.gif - <a href="http://rateit.codeplex.com/releases">
Download RateIt</a></li>
<li>Place a reference to the rateit.css stylesheet into the page head.</li>
<li>Place a script reference to jquery.rateit.js before your </body> tag.
</li>
</ul>
</p>
<h2>
Options</h2>
Go to the <a href="http://rateit.codeplex.com">RateIt project homepage</a> to view
the documentation.
<h2>
Examples</h2>
<div style="font-weight: bold">
<ul id="toc"></ul>
</div>
<ul class="nostyle" id="examples">
<li id="ex_a1">
<h3>
1a) Basic usage</h3>
<div class="rateit">
</div>
<pre class="brush: xml">
<div class="rateit">
</div>
</pre>
</li>
<li id="ex_1b">
<h3>
1a) Basic usage (inline element)</h3>
<span class="rateit">
</span>
<pre class="brush: xml">
<span class="rateit">
</span>
</pre>
</li>
<li id="ex_2a">
<h3>
2a) Progressive enhancement (using input[type=range])
</h3>
<input type="range" min="0" max="7" value="0" step="0.5" id="backing2">
<div class="rateit" data-rateit-backingfld="#backing2">
</div>
<pre class="brush: xml">
<input type="range" min="0" max="7" value="0" step="0.5" id="backing2">
<div class="rateit" data-rateit-backingfld="#backing2"></div>
</pre>
<button onclick="$('#backing2').toggle()">
Toggle Backing Field visibility</button>
</li>
<li id="ex_2b">
<h3>
2b) Progressive enhancement (using select)
</h3>
<select id="backing2b">
<option value="0">Bad</option>
<option value="1" selected="selected">OK</option>
<option value="2">Great</option>
<option value="3">Excellent</option>
</select>
<div class="rateit" data-rateit-backingfld="#backing2b">
</div>
<pre class="brush: xml">
<select id="backing2b">
<option value="0">Bad</option>
<option value="1" selected="selected">OK</option>
<option value="2">Great</option>
<option value="3">Excellent</option>
</select>
<div class="rateit" data-rateit-backingfld="#backing2b"></div>
</pre>
</li>
<li id="ex_2c">
<h3>
2c) Progressive enhancement (using select), and overriding min value
</h3>
<select id="backing2c">
<option value="1">Bad</option>
<option value="2">OK</option>
<option value="3">Great</option>
<option value="4">Excellent</option>
</select>
<div class="rateit" data-rateit-backingfld="#backing2c" data-rateit-min="0">
</div>
<pre class="brush: xml">
<select id="backing2c">
<option value="1">Bad</option>
<option value="2">OK</option>
<option value="3">Great</option>
<option value="4">Excellent</option>
</select>
<div class="rateit" data-rateit-backingfld="#backing2c" data-rateit-min="0"></div>
</pre>
</li>
<li id="ex_3">
<h3>
3) Readonly and preset value</h3>
<div class="rateit" data-rateit-value="2.5" data-rateit-ispreset="true" data-rateit-readonly="true">
</div>
<pre class="brush: xml">
<div class="rateit" data-rateit-value="2.5" data-rateit-ispreset="true" data-rateit-readonly="true"></div>
</pre>
</li>
<li id="ex_4">
<h3>
4) More settings</h3>
<input type="range" value="4" step="0.25" id="backing4">
<div class="rateit" data-rateit-backingfld="#backing4" data-rateit-resetable="false" data-rateit-ispreset="true"
data-rateit-min="0" data-rateit-max="10">
</div>
<pre class="brush: xml">
<input type="range" value="4" step="0.25" id="backing4">
<div class="rateit" data-rateit-backingfld="#backing4" data-rateit-resetable="false" data-rateit-ispreset="true"
data-rateit-min="0" data-rateit-max="10">
</div>
</pre>
</li>
<li id="ex_5">
<h3>
5) Javascript interaction</h3>
<div class="rateit" id="rateit5" data-rateit-min="2">
</div>
<div>
<span id="value5"></span><span id="hover5"></span>
</div>
<script type="text/javascript">
$("#rateit5").bind('rated', function (event, value) { $('#value5').text('You\'ve rated it: ' + value); });
$("#rateit5").bind('reset', function () { $('#value5').text('Rating reset'); });
$("#rateit5").bind('over', function (event, value) { $('#hover5').text('Hovering over: ' + value); });
</script>
<pre class="brush: xml">
<div class="rateit" id="rateit5" data-rateit-min="2">
</div>
<div>
<span id="value5"></span>
<span id="hover5"></span>
</div>
<script type="text/javascript">
$("#rateit5").bind('rated', function (event, value) { $('#value5').text('You\'ve rated it: ' + value); });
$("#rateit5").bind('reset', function () { $('#value5').text('Rating reset'); });
$("#rateit5").bind('over', function (event, value) { $('#hover5').text('Hovering over: ' + value); });
</script>
</pre>
</li>
<li id="ex_6">
<h3>
6) Javascript invocation</h3>
<input type="hidden" id="backing6">
<div id="rateit6">
</div>
<script type="text/javascript">
$(function () { $('#rateit6').rateit({ max: 20, step: 2, backingfld: '#backing6' }); });
</script>
<pre class="brush: xml">
<input type="hidden" id="backing6">
<div id="rateit6">
</div>
<script type="text/javascript">
$(function () { $('#rateit6').rateit({ max: 20, step: 2, backingfld: '#backing6' }); });
</script>
</pre>
</li>
<li id="ex_7a">
<h3>
7a) Styling</h3>
<p>
You can change the styles of the plugin in a two ways.
<ul>
<li>You can change change the star.gif and delete.gif pictures (and perhaps the default
starwidth, and starheight values in the javascript file). This will change the style
everywhere.</li>
<li>You can change individual items, by adding a stylesheet with a few rules.</li>
</ul>
Here I've opted for the second option.
</p>
<div class="rateit bigstars" data-rateit-starwidth="32" data-rateit-starheight="32">
</div>
<h4>
Inline code</h4>
<pre class="brush: xml">
<div class="rateit bigstars" data-rateit-starwidth="32" data-rateit-starheight="32"></div>
</pre>
<h4>
Style sheet</h4>
<pre class="brush: css">
div.bigstars div.rateit-range
{
background: url(star-white32.png);
height: 32px;
}
div.bigstars div.rateit-hover
{
background: url(star-gold32.png);
}
div.bigstars div.rateit-selected
{
background: url(star-red32.png);
}
div.bigstars div.rateit-reset
{
background: url(star-black32.png);
width: 32px;
height: 32px;
}
div.bigstars div.rateit-reset:hover
{
background: url(star-white32.png);
}
</pre>
</li>
<li id="ex_7b">
<h3>
7b) More styling</h3>
<p>
Here we use one big image (actually 3), with different dimensions. Not very pretty,
but it conveys the message I hope.</p>
<div class="rateit antenna" data-rateit-starwidth="11" data-rateit-starheight="25">
</div>
<h4>
Inline code</h4>
<pre class="brush: xml">
<div class="rateit antenna" data-rateit-starwidth="11" data-rateit-starheight="25"></div>
</pre>
<h4>
Style sheet</h4>
<pre class="brush: css">
div.antenna div.rateit-range
{
background: url(antenna-black.png) no-repeat;
height: 25px;
}
div.antenna div.rateit-hover
{
background: url(antenna-yellow.png) no-repeat;
}
div.antenna div.rateit-selected
{
background: url(antenna-red.png) no-repeat;
}
</pre>
</li>
<li id="ex_7c">
<h3>
7c) SVG icons
</h3>
<p>
Since SVG can be set as a background image (either through setting the URL to an svg file or by using the Data URI scheme), we can use it as an image inside our RateIt plugin.<br />
This could allow us even to create the image on the fly, by rendering the SVG server-side, or by building the SVG in javascript and setting it as the source by using the Data URI scheme.
</p>
<div class="rateit svg" data-rateit-starwidth="15" data-rateit-starheight="15">
</div>
<h4>
Inline code
</h4>
<pre class="brush: xml">
<div class="rateit svg" data-rateit-starwidth="15" data-rateit-starheight="15"></div>
</pre>
<h4>
Style sheet
</h4>
<p>In the CSS file I've chosen to embed the SVG image using the Data URI scheme.</p>
<pre class="brush: css">
div.svg div.rateit-range {
background: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4NCjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB3aWR0aD0iMTVweCIgaGVpZ2h0PSIxNXB4Ij4NCiAgPHRleHQgeD0iMCIgeT0iMTUiIGZpbGw9ImJsYWNrIiBmb250LXNpemU9IjE4Ij7inKY8L3RleHQ+DQo8L3N2Zz4=') /*star-normal.svg*/;
*background: url(star-normal.svg); /* For IE 6 and 7 */
}
div.svg div.rateit-hover {
background: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4NCjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB3aWR0aD0iMTUiIGhlaWdodD0iMTUiPg0KICA8dGV4dCB4PSIwIiB5PSIxNSIgZmlsbD0ieWVsbG93IiBmb250LXNpemU9IjE4Ij7inKY8L3RleHQ+DQo8L3N2Zz4=') /*star-hover.svg*/;
*background: url(star-hover.svg); /* For IE 6 and 7 */
}
div.svg div.rateit-selected {
background: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4NCjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB3aWR0aD0iMTUiIGhlaWdodD0iMTUiPg0KICA8dGV4dCB4PSIwIiB5PSIxNSIgZmlsbD0icmVkIiBmb250LXNpemU9IjE4Ij7inKY8L3RleHQ+DQo8L3N2Zz4=') /*star-selected.svg*/;
*background: url(star-selected.svg); /* For IE 6 and 7 */
}
div.svg div.rateit-preset {
background: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4NCjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIj4NCiAgPHRleHQgeD0iMCIgeT0iMTUiIGZpbGw9ImJsYWNrIiBmb250LXNpemU9IjE1Ij7inKY8L3RleHQ+DQo8L3N2Zz4=') /*star-preset.svg*/;
*background: url(star-preset.svg); /* For IE 6 and 7 */
}
</pre>
<h4>SVG file</h4>
<p>This SVG file shows a simple Black four-pointed star unicode glyph</p>
<pre class="brush: xml">
<?xml version="1.0" encoding="UTF-8" ?>
<svg xmlns="http://www.w3.org/2000/svg" width="15px" height="15px">
<text x="0" y="15" fill="black" font-size="18">✦</text>
</svg>
</pre>
</li>
<li id="ex_8">
<h3>
8) RTL support</h3>
<div style="direction: rtl">
Now we are in RTL mode. No changes needed to make this work.
<div class="rateit">
</div>
</div>
</li>
<li id="ex_9">
<h3>
9) Setting and Getting values</h3>
<p>
All properties can also be set on the fly. Here are a few examples:</p>
<div class="rateit" id="rateit9">
</div>
<div>
<button onclick="alert($('#rateit9').rateit('value'))">
Get value</button>
<button onclick="$('#rateit9').rateit('value', prompt('Input numerical value'))">
Set value</button>
</div>
<div>
<button onclick="alert($('#rateit9').rateit('max'))">
Get max value</button>
<button onclick="$('#rateit9').rateit('max', prompt('Input numerical value'))">
Set max value</button>
</div>
<div>
<button onclick="alert($('#rateit9').rateit('min'))">
Get min value</button>
<button onclick="$('#rateit9').rateit('min', prompt('Input numerical value'))">
Set min value</button>
</div>
<div>
<button onclick="alert($('#rateit9').rateit('step'))">
Get step size</button>
<button onclick="$('#rateit9').rateit('step', prompt('Input numerical value'))">
Set step size</button>
</div>
<div>
<button onclick="alert($('#rateit9').rateit('readonly'))">
Get readonly value</button>
<button onclick="$('#rateit9').rateit('readonly',!$('#rateit9').rateit('readonly'))">
Toggle readonly</button>
</div>
<div>
<button onclick="alert($('#rateit9').rateit('ispreset'))">
Get ispreset value</button>
<button onclick="$('#rateit9').rateit('ispreset',!$('#rateit9').rateit('ispreset'))">
Toggle ispreset</button>
</div>
<div>
<button onclick="$('#rateit9').rateit('reset')">
Reset
</button>
</div>
<pre class="brush: xml">
<div class="rateit" id="rateit9">
</div>
<div>
<button onclick="alert($('#rateit9').rateit('value'))">Get value</button>
<button onclick="$('#rateit9').rateit('value', prompt('Input numerical value'))">Set value</button>
</div>
<div>
<button onclick="alert($('#rateit9').rateit('max'))">Get max value</button>
<button onclick="$('#rateit9').rateit('max', prompt('Input numerical value'))">Set max value</button>
</div>
<div>
<button onclick="alert($('#rateit9').rateit('step'))">Get step size</button>
<button onclick="$('#rateit9').rateit('step', prompt('Input numerical value'))">Set step size</button>
</div>
<div>
<button onclick="alert($('#rateit9').rateit('readonly'))">Get readonly value</button>
<button onclick="$('#rateit9').rateit('readonly',!$('#rateit9').rateit('readonly'))">Toggle readonly</button>
</div>
<div>
<button onclick="alert($('#rateit9').rateit('ispreset'))">Get ispreset value</button>
<button onclick="$('#rateit9').rateit('ispreset',!$('#rateit9').rateit('ispreset'))">Toggle ispreset</button>
</div>
<div>
<button onclick="$('#rateit9').rateit('reset')">Reset</button>
</div>
</pre>
</li>
<li id="ex_10">
<h3>
10) Tooltip example</h3>
<p>
Using tooltips is easy. Just bind to the hover event, and do your thing. Shown here
is the basic tooltip, but of course you can use any tooltip you'd like.</p>
<h4>
Basic numbers</h4>
<div class="rateit" id="rateit10">
</div>
<script type="text/javascript">
$("#rateit10").bind('over', function (event, value) { $(this).attr('title', value); });
</script>
<pre class="brush: xml">
<div class="rateit" id="rateit10">
</div>
<script type="text/javascript">
$("#rateit10").bind('over', function (event,value) { $(this).attr('title', value); });
</script>
</pre>
<h4>
Custom text</h4>
<div class="rateit" id="rateit10b" data-rateit-step="1">
</div>
<script type="text/javascript">
var tooltipvalues = ['bad', 'poor', 'ok', 'good', 'super'];
$("#rateit10b").bind('over', function (event, value) { $(this).attr('title', tooltipvalues[value - 1]); });
</script>
<pre class="brush: xml">
<div class="rateit" id="rateit10b" data-rateit-step="1">
</div>
<script type="text/javascript">
var tooltipvalues = ['bad', 'poor', 'ok', 'good', 'super'];
$("#rateit10b").bind('over', function (event, value) { $(this).attr('title', tooltipvalues[value-1]); });
</script>
</pre>
</li>
<li id="ex_11">
<h3>
11) AJAX example</h3>
<p>
Most times RateIt will be used using some Ajax. There are different ways of implementing
it (with/without backing field, using data-* attributes etc.)</p>
<div id="products">
<div style="float: right; width: 350px; border: 1px solid #ccc; padding: 1em;">
<strong>Server response:</strong>
<ul id="response">
</ul>
</div>
<ul>
<li>
<h4>
Product X (id: 312)</h4>
RateIt:
<div data-productid="312" class="rateit">
</div>
</li>
<li>
<h4>
Product Y (id: 423)</h4>
RateIt:
<div data-productid="423" class="rateit">
</div>
</li>
<li>
<h4>
Product Z (id: 653)</h4>
RateIt:
<div data-productid="653" class="rateit">
</div>
</li>
</ul>
</div>
<script type="text/javascript">
//we bind only to the rateit controls within the products div
$('#products .rateit').bind('rated reset', function (e) {
var ri = $(this);
//if the use pressed reset, it will get value: 0 (to be compatible with the HTML range control), we could check if e.type == 'reset', and then set the value to null .
var value = ri.rateit('value');
var productID = ri.data('productid'); // if the product id was in some hidden field: ri.closest('li').find('input[name="productid"]').val()
//maybe we want to disable voting?
ri.rateit('readonly', true);
$.ajax({
url: 'rateit.aspx', //your server side script
data: { id: productID, value: value }, //our data
type: 'POST',
success: function (data) {
$('#response').append('<li>' + data + '</li>');
},
error: function (jxhr, msg, err) {
$('#response').append('<li style="color:red">' + msg + '</li>');
}
});
});
</script>
<h4>
Client</h4>
<pre class="brush: xml">
<div id="products">
<div style="float:right; width:350px; border:1px solid #ccc; padding:1em;">
<strong>Server response:</strong>
<ul id="response">
</ul>
</div>
<ul>
<li><h4>Product X (id: 312)</h4>
RateIt: <div data-productid="312" class="rateit"></div>
</li>
<li><h4>Product Y (id: 423)</h4>
RateIt: <div data-productid="423" class="rateit"></div></li>
<li><h4>Product Z (id: 653)</h4>
RateIt: <div data-productid="653" class="rateit"></div>
</li>
</ul>
</div>
<script type ="text/javascript">
//we bind only to the rateit controls within the products div
$('#products .rateit').bind('rated reset', function (e) {
var ri = $(this);
//if the use pressed reset, it will get value: 0 (to be compatible with the HTML range control), we could check if e.type == 'reset', and then set the value to null .
var value = ri.rateit('value');
var productID = ri.data('productid'); // if the product id was in some hidden field: ri.closest('li').find('input[name="productid"]').val()
//maybe we want to disable voting?
ri.rateit('readonly', true);
$.ajax({
url: 'rateit.aspx', //your server side script
data: { id: productID, value: value }, //our data
type: 'POST',
success: function (data) {
$('#response').append('<li>' + data + '</li>');
},
error: function (jxhr, msg, err) {
$('#response').append('<li style="color:red">' + msg + '</li>');
}
});
});
</script>
</pre>
<h4>
Server (ASPX) super simplified</h4>
<pre class="brush: c-sharp">
<%@ Page Language="C#" %>
<%
//Get value
float value = float.Parse(Request.Form["value"]);
int productID = int.Parse(Request.Form["id"]);
Response.Write(string.Format("You voted {0} on product: {1}.<br/>Time on server: {2}", value, productID, DateTime.Now.ToString()));
%>
</pre>
</li>
<li id="ex_12">
<h3>
12) Resizing
</h3>
<p>
Sometimes we would like to resize the rating controls (perhaps based on screen size). <br />
This is as easy as<br />
a) adding a class to the rateit control, which would change the background image.<br/>
b) modifying the starwidth and starheigth properties.
<br /><br />
The alternative styling is taken from example <a href="#ex_7a">7a) styling</a>.
</p>
<div class="rateit" id="rateit12">
</div>
<p>Pick a size: <select id="size_12"><option data-class="" data-size="16" selected>normal</option><option data-class="bigstars" data-size="32">big</option></select></p>
<script type="text/javascript">
$('#size_12').change(function () {
var option = $(this.options[this.selectedIndex]);
$('#rateit12').removeClass('bigstars')
.addClass(option.data('class'))
.rateit('starwidth', option.data('size'))
.rateit('starheight', option.data('size'));
});
</script>
<pre class="brush: xml">
<div class="rateit" id="rateit12"></div>
<p>Pick a size:
<select id="size_12">
<option data-class="" data-size="16" selected>normal</option>
<option data-class="bigstars" data-size="32">big</option>
</select>
</p>
<script type="text/javascript">
$('#size_12').change(function () {
var option = $(this.options[this.selectedIndex]);
$('#rateit12').removeClass('bigstars') //remove old class
.addClass(option.data('class')) //add new class
.rateit('starwidth', option.data('size')) //change width
.rateit('starheight', option.data('size')); //change height
});
</script>
</pre>
</li>
<li id="ex_13">
<h3>
13) Confirmation before rating or resetting
</h3>
<p>
Sometimes we would like to ask the user to confirm his/her action, or to show some dialog box before the rating is submitted.<br />
We can now bind to the "beforerated" and "beforereset" events. Both events occur before the actual rating/resetting. Both events might also be cancelled, by using the <code>e.preventDefault()</code> method.
</p>
<div class="rateit" id="rateit13">
</div>
<script type="text/javascript">
$('#rateit13').on('beforerated', function (e, value) {
if (!confirm('Are you sure you want to rate this item: ' + value + ' stars?')) {
e.preventDefault();
}
});
$('#rateit13').on('beforereset', function (e) {
if (!confirm('Are you sure you want to reset the rating?')) {
e.preventDefault();
}
});
</script>
<pre class="brush: xml">
<div class="rateit" id="rateit3"></div>
<script type="text/javascript">
$('#rateit13').on('beforerated', function (e, value) {
if (!confirm('Are you sure you want to rate this item: ' + value + ' stars?')) {
e.preventDefault();
}
});
$('#rateit13').on('beforereset', function (e) {
if (!confirm('Are you sure you want to reset the rating?')) {
e.preventDefault();
}
});
</script>
</pre>
</li>
</ul>
<script src="../src/jquery.rateit.js" type="text/javascript"></script>
<script>
//build toc
var toc = [];
$('#examples > li').each(function (i, e) {
toc.push('<li><a href="#')
toc.push(e.id)
toc.push('">')
toc.push($(e).find('h3:first').text());
toc.push('</a></li>');
});
$('#toc').html(toc.join(''));
</script>
<!-- syntax highlighter -->
<script src="sh/shCore.js" type="text/javascript"></script>
<script src="sh/shBrushJScript.js" type="text/javascript"></script>
<script src="sh/shBrushXml.js" type="text/javascript"></script>
<script src="sh/shBrushCss.js" type="text/javascript"></script>
<script src="sh/shBrushCSharp.js" type="text/javascript"></script>
<script type="text/javascript">
SyntaxHighlighter.all()
</script>
</body>
</html>