PageSourceSearch

https://www.syl.ru/misc/js/library/jRating.jquery.js?142022019

js syl.ru collected 2026-10-02 04:52:49 UTC 6,841 bytes, 217 lines download raw bytes

1/************************************************************************
2*************************************************************************
3@Name :       	jRating - jQuery Plugin
4@Revison :    	2.1
5@Date : 		26/01/2011
6@Author:     	 Surrel Mickael (www.myjqueryplugins.com - www.msconcept.fr) 
7@License :		 Open Source - MIT License : http://www.opensource.org/licenses/mit-license.php
8 
9**************************************************************************
10*************************************************************************/
11(function($) {
12	$.fn.jRating = function(op) {
13		var defaults = {
14			/** String vars **/
15			bigStarsPath : '/misc/icons/stars.png', // path of the icon stars.png
16			smallStarsPath : '/misc/icons/small.png', // path of the icon small.png
17			phpPath : '../save_rating', // path of the php file jRating.php
18			type : 'big', // can be set to 'small' or 'big'
19			
20			/** Boolean vars **/
21			step:false, // if true,  mouseover binded star by star,
22			isDisabled:false,
23			showRateInfo: true,
24			
25			/** Integer vars **/
26			length:5, // number of star to display
27			decimalLength : 0, // number of decimals.. Max 3, but you can complete the function 'getNote'
28			rateMax : 5, // maximal rate - integer from 0 to 9999 (or more)
29			rateInfosX : -45, // relative position in X axis of the info box when mouseover
30			rateInfosY : 5, // relative position in Y axis of the info box when mouseover
31			
32			/** Functions **/
33			onSuccess : null,
34			onError : null
35		}; 
36		
37		if(this.length>0)
38		return this.each(function() {
39			var opts = $.extend(defaults, op),    
40			newWidth = 0,
41			starWidth = 0,
42			starHeight = 0,
43			bgPath = '';
44
45			if($(this).hasClass('jDisabled') || opts.isDisabled)
46				var jDisabled = true;
47			else
48				var jDisabled = false;
49
50			getStarWidth();
51			$(this).height(starHeight);
52
53			var average = parseFloat($(this).attr('data').split('_')[0]),
54			idBox = parseInt($(this).attr('data').split('_')[1]), // get the id of the box
55			widthRatingContainer = starWidth*opts.length, // Width of the Container
56			widthColor = average/opts.rateMax*widthRatingContainer, // Width of the color Container
57			
58			quotient = 
59			$('<div>', 
60			{
61				'class' : 'jRatingColor',
62				css:{
63					width:widthColor
64				}
65			}).appendTo($(this)),
66			
67			average = 
68			$('<div>', 
69			{
70				'class' : 'jRatingAverage',
71				css:{
72					width:0,
73					top:- starHeight
74				}
75			}).appendTo($(this)),
76
77			 jstar =
78			$('<div>', 
79			{
80				'class' : 'jStar',
81				css:{
82					width:widthRatingContainer,
83					height:starHeight,
84					top:- (starHeight*2),
85					background: 'url('+bgPath+') repeat-x'
86				}
87			}).appendTo($(this));
88
89			$(this).css({width: widthRatingContainer,overflow:'hidden',zIndex:1,position:'relative'});
90
91			if(!jDisabled)
92			$(this).bind({
93				mouseenter : function(e){
94					var realOffsetLeft = findRealLeft(this);
95					var relativeX = e.pageX - realOffsetLeft;
96					if (opts.showRateInfo)
97					var tooltip = 
98					$('<p>',{
99						'class' : 'jRatingInfos',
100						html : getNote(relativeX)+' <span class="maxRate">/ '+opts.rateMax+'</span>',
101						css : {
102							top: (e.pageY + opts.rateInfosY),
103							left: (e.pageX + opts.rateInfosX)
104						}
105					}).appendTo('body').show();
106				},
107				mouseover : function(e){
108					$(this).css('cursor','pointer');	
109				},
110				mouseout : function(){
111					$(this).css('cursor','default');
112					average.width(0);
113				},
114				mousemove : function(e){
115					var realOffsetLeft = findRealLeft(this);
116					var relativeX = e.pageX - realOffsetLeft;
117					if(opts.step) newWidth = Math.floor(relativeX/starWidth)*starWidth + starWidth;
118					else newWidth = relativeX;
119					average.width(newWidth);					
120					if (opts.showRateInfo)
121					$("p.jRatingInfos")
122					.css({
123						left: (e.pageX + opts.rateInfosX)
124					})
125					.html(getNote(newWidth) +' <span class="maxRate">/ '+opts.rateMax+'</span>');
126				},
127				mouseleave : function(){
128					$("p.jRatingInfos").remove();
129				},
130				click : function(e){
131					$(this).unbind().css('cursor','default').addClass('jDisabled');
132					if (opts.showRateInfo) $("p.jRatingInfos").fadeOut('fast',function(){$(this).remove();});
133					e.preventDefault();
134					var rate = getNote(newWidth);
135					average.width(newWidth);
136					
137					/** ONLY FOR THE DEMO, YOU CAN REMOVE THIS CODE **/
138						$('.datasSent p').html('<strong>ID ���������� : </strong>'+idBox+'<br /><strong>������ : </strong>'+rate+'<br /><strong>�������� :</strong> ����������');
139						$('.serverResponse p').html('<strong>��������...</strong>');
140					/** END ONLY FOR THE DEMO **/
141						
142					$.post(opts.phpPath,{
143							idBox : idBox,
144							rate : rate,
145							action : 'rating'
146						},
147						function(data) {
148							if(!data.error)
149							{
150								/** ONLY FOR THE DEMO, YOU CAN REMOVE THIS CODE **/
151									$('.serverResponse p').html(data.server);
152								/** END ONLY FOR THE DEMO **/
153								
154								
155								/** Here you can display an alert box, 
156									or use the jNotify Plugin :) http://www.myqjqueryplugins.com/jNotify
157									exemple :	*/
158								if(opts.onSuccess) opts.onSuccess();
159							}
160							else
161							{
162								
163								/** ONLY FOR THE DEMO, YOU CAN REMOVE THIS CODE **/
164									$('.serverResponse p').html(data.server);
165								/** END ONLY FOR THE DEMO **/
166								
167								/** Here you can display an alert box, 
168									or use the jNotify Plugin :) http://www.myqjqueryplugins.com/jNotify
169									exemple :	*/
170								if(opts.onError) opts.onError();
171							}
172						},
173						'json'
174					);
175				}
176			});
177
178			function getNote(relativeX) {
179				var noteBrut = parseFloat((relativeX*100/widthRatingContainer)*opts.rateMax/100);
180				switch(opts.decimalLength) {
181					case 1 :
182						var note = Math.round(noteBrut*10)/10;
183						break;
184					case 2 :
185						var note = Math.round(noteBrut*100)/100;
186						break;
187					case 3 :
188						var note = Math.round(noteBrut*1000)/1000;
189						break;
190					default :
191						var note = Math.round(noteBrut*1)/1;
192				}
193				return note;
194			};
195
196			function getStarWidth(){
197				switch(opts.type) {
198					case 'small' :
199						starWidth = 12; // width of the picture small.png
200						starHeight = 10; // height of the picture small.png
201						bgPath = opts.smallStarsPath;
202					break;
203					default :
204						starWidth = 23; // width of the picture stars.png
205						starHeight = 20; // height of the picture stars.png
206						bgPath = opts.bigStarsPath;
207				}
208			};
209			
210			function findRealLeft(obj) {
211			  if( !obj ) return 0;
212			  return obj.offsetLeft + findRealLeft( obj.offsetParent );
213			};
214		});
215
216	}
217})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.