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