1/*! 2 * jQuery Raty - A Star Rating Plugin 3 * ------------------------------------------------------------------ 4 * 5 * jQuery Raty is a plugin that generates a customizable star rating. 6 * 7 * Licensed under The MIT License 8 * 9 * @version 2.5.2 10 * @since 2010.06.11 11 * @author Washington Botelho 12 * @documentation wbotelhos.com/raty 13 * 14 * ------------------------------------------------------------------ 15 * 16 * <div id="star"></div> 17 * 18 * $('#star').raty(); 19 * Changed imges to <i>. 20 */ 21 22;(function($) { 23 var methods = { 24 init: function(settings) { 25 return this.each(function() { 26 methods.destroy.call(this); 27 this.opt = $.extend(true, {}, $.fn.raty.defaults, settings); 28 var that = $(this), 29 inits = ['number', 'readOnly', 'score', 'scoreName']; 30 methods._callback.call(this, inits); 31 if (this.opt.precision) { 32 methods._adjustPrecision.call(this); 33 } 34 this.opt.number = methods._between(this.opt.number, 0, this.opt.numberMax) 35 this.opt.path = this.opt.path || ''; 36 if (this.opt.path && this.opt.path.slice(this.opt.path.length - 1, this.opt.path.length) !== '/') { 37 this.opt.path += '/'; 38 } 39 this.stars = methods._createStars.call(this); 40 this.score = methods._createScore.call(this); 41 methods._apply.call(this, this.opt.score); 42 var space = this.opt.space ? 4 : 0, 43 width = this.opt.width || (this.opt.number * this.opt.size + this.opt.number * space); 44 if (this.opt.cancel) { 45 this.cancel = methods._createCancel.call(this); 46 width += (this.opt.size + space); 47 } 48 if (this.opt.readOnly) { 49 methods._lock.call(this); 50 } else { 51 that.css('cursor', 'pointer'); 52 methods._binds.call(this); 53 } 54 if (this.opt.width !== false) { 55 that.css('width', width); 56 $(".bwg_rate_spun").css('width', width); 57 } 58 methods._target.call(this, this.opt.score); 59 that.data({ 'settings': this.opt, 'raty': true }); 60 }); 61 }, _adjustPrecision: function() { 62 this.opt.targetType = 'score'; 63 this.opt.half = true; 64 }, _apply: function(score) { 65 if (score && score > 0) { 66 score = methods._between(score, 0, this.opt.number); 67 this.score.val(score); 68 } 69 methods._fill.call(this, score); 70 if (score) { 71 methods._roundStars.call(this, score); 72 } 73 $("#bwg_star *").removeClass("bwg_rate_hover"); 74 }, _between: function(value, min, max) { 75 return Math.min(Math.max(parseFloat(value), min), max); 76 }, _binds: function() { 77 if (this.cancel) { 78 methods._bindCancel.call(this); 79 } 80 methods._bindClick.call(this); 81 methods._bindOut.call(this); 82 methods._bindOver.call(this); 83 }, _bindCancel: function() { 84 methods._bindClickCancel.call(this); 85 methods._bindOutCancel.call(this); 86 methods._bindOverCancel.call(this); 87 }, _bindClick: function() { 88 var self = this, 89 that = $(self); 90 self.stars.on('click.raty', function(evt) { 91 self.score.val((self.opt.half || self.opt.precision) ? that.data('score') : $(this).attr("alt")); 92 if (self.opt.click) { 93 self.opt.click.call(self, parseFloat(self.score.val()), evt); 94 } 95 }); 96 }, _bindClickCancel: function() { 97 var self = this; 98 self.cancel.on('click.raty', function(evt) { 99 self.score.removeAttr('value'); 100 if (self.opt.click) { 101 self.opt.click.call(self, null, evt); 102 } 103 }); 104 }, _bindOut: function() { 105 var self = this; 106 $(this).on('mouseleave.raty', function(evt) { 107 var score = parseFloat(self.score.val()) || undefined; 108 methods._apply.call(self, score); 109 methods._target.call(self, score, evt); 110 if (self.opt.mouseout) { 111 self.opt.mouseout.call(self, score, evt); 112 } 113 }); 114 }, _bindOutCancel: function() { 115 var self = this; 116 self.cancel.on('mouseleave.raty', function(evt) { 117 $(this).attr('class', self.opt.cancelOff); 118 if (self.opt.mouseout) { 119 self.opt.mouseout.call(self, self.score.val() || null, evt); 120 } 121 }); 122 }, _bindOverCancel: function() { 123 var self = this; 124 self.cancel.on('mouseover.raty', function(evt) { 125 $(this).attr('class', self.opt.cancelOn); 126 self.stars.attr('class', self.opt.starOff); 127 methods._target.call(self, null, evt); 128 if (self.opt.mouseover) { 129 self.opt.mouseover.call(self, null); 130 } 131 }); 132 }, _bindOver: function() { 133 var self = this, 134 that = $(self), 135 action = self.opt.half ? 'mousemove.raty' : 'mouseover.raty'; 136 self.stars.on(action, function(evt) { 137 var score = parseInt($(this).attr("alt"), 10); 138 if (self.opt.half) { 139 var position = parseFloat((evt.pageX - $(this).offset().left) / self.opt.size), 140 plus = (position > .5) ? 1 : .5; 141 score = score - 1 + plus; 142 methods._fill.call(self, score); 143 if (self.opt.precision) { 144 score = score - plus + position; 145 }
146 methods._roundStars.call(self, score); 147 that.data('score', score); 148 } else { 149 methods._fill.call(self, score); 150 } 151 methods._target.call(self, score, evt); 152 if (self.opt.mouseover) { 153 self.opt.mouseover.call(self, score, evt); 154 } 155 }); 156 }, _callback: function(options) { 157 for (i in options) { 158 if (typeof this.opt[options[i]] === 'function') { 159 this.opt[options[i]] = this.opt[options[i]].call(this); 160 } 161 } 162 }, _createCancel: function() { 163 var that = $(this), 164 icon = this.opt.cancelOff, 165 cancel = $('<i />', { 'class': 'raty-cancel ' + icon, 'alt': 'x', 'title': this.opt.cancelHint }); 166 if (this.opt.cancelPlace == 'left') { 167 that.prepend(' ').prepend(cancel); 168 } else { 169 that.append(' ').append(cancel); 170 } 171 return cancel; 172 }, _createScore: function() { 173 return $('<input />', { type: 'hidden', name: this.opt.scoreName }).appendTo(this); 174 }, _createStars: function() { 175 var that = $(this); 176 for (var i = 1; i <= this.opt.number; i++) { 177 var title = methods._getHint.call(this, i), 178 icon = (this.opt.score && this.opt.score >= i) ? 'starOn' : 'starOff'; 179 icon = this.opt[icon]; 180 $('<i />', { 'class' : icon, 'alt': i, 'title': title }).appendTo(this); 181 if (this.opt.space) { 182 that.append((i < this.opt.number) ? ' ' : ''); 183 } 184 } 185 186 return that.children('i'); 187 }, _error: function(message) { 188 $(this).html(message); 189 $.error(message); 190 }, _fill: function(score) { 191 var self = this, 192 hash = 0; 193 for (var i = 1; i <= self.stars.length; i++) { 194 var star = self.stars.eq(i - 1), 195 select = self.opt.single ? (i == score) : (i <= score); 196 if (self.opt.iconRange && self.opt.iconRange.length > hash) { 197 var irange = self.opt.iconRange[hash], 198 on = irange.on || "starOn", 199 off = irange.off || "starOff", 200 icon = select ? on : off; 201 if (i <= irange.range) { 202 star.attr('class', this.opt[icon]); 203 if (icon == on) { 204 star.addClass("bwg_rate_hover"); 205 } 206 } 207 if (i == irange.range) { 208 hash++; 209 } 210 } else { 211 var icon = select ? 'starOn' : 'starOff'; 212 star.attr('class', this.opt[icon]); 213 if (icon == "starOn") { 214 star.addClass("bwg_rate_hover"); 215 } 216 } 217 } 218 }, _getHint: function(score) { 219 var hint = this.opt.hints[score - 1]; 220 return (hint === '') ? '' : (hint || score); 221 }, _lock: function() { 222 var score = parseInt(this.score.val(), 10), // TODO: 3.1 >> [['1'], ['2'], ['3', '.1', '.2']] 223 hint = score ? methods._getHint.call(this, score) : this.opt.noRatedMsg; 224 $(this).data('readonly', true).css('cursor', '').attr('title', this.opt.alreadyRatedMsg); 225 this.score.attr('readonly', 'readonly'); 226 this.stars.attr('title', this.opt.alreadyRatedMsg); 227 if (this.cancel) { 228 this.cancel.hide(); 229 } 230 }, _roundStars: function(score) { 231 var rest = (score - Math.floor(score)).toFixed(2); 232 233 if (rest > this.opt.round.down) { 234 var icon = 'starOn'; // Up: [x.76 .. x.99] 235 if (this.opt.halfShow && rest < this.opt.round.up) { // Half: [x.26 .. x.75] 236 icon = 'starHalf'; 237 } else if (rest < this.opt.round.full) { // Down: [x.00 .. x.5] 238 icon = 'starOff'; 239 } 240 this.stars.eq(Math.ceil(score) - 1).attr('class', this.opt[icon]); 241 } // Full down: [x.00 .. x.25] 242 }, _target: function(score, evt) { 243 if (this.opt.target) { 244 var target = $(this.opt.target); 245 if (target.length === 0) { 246 methods._error.call(this, 'Target selector invalid or missing!'); 247 } 248 if (this.opt.targetFormat.indexOf('{score}') < 0) { 249 methods._error.call(this, 'Template "{score}" missing!'); 250 } 251 var mouseover = evt && evt.type == 'mouseover'; 252 if (score === undefined) { 253 score = this.opt.targetText; 254 } else if (score === null) { 255 score = mouseover ? this.opt.cancelHint : this.opt.targetText; 256 } else { 257 if (this.opt.targetType == 'hint') { 258 score = methods._getHint.call(this, Math.ceil(score)); 259 } else if (this.opt.precision) { 260 score = parseFloat(score).toFixed(1); 261 } 262 if (!mouseover && !this.opt.targetKeep) { 263 score = this.opt.targetText; 264 } 265 } 266 if (score) { 267 score = this.opt.targetFormat.toString().replace('{score}', score); 268 } 269 if (target.is(':input')) { 270 target.val(score); 271 } else { 272 target.html(score); 273 } 274 } 275 }, _unlock: function() { 276 $(this).data('readonly', false).css('cursor', 'pointer').removeAttr('title'); 277 this.score.removeAttr('readonly', 'readonly'); 278 for (var i = 0; i < this.opt.number; i++) { 279 this.stars.eq(i).attr('title', methods._getHint.call(this, i + 1)); 280 } 281 if (this.cancel) { 282 this.cancel.css('display', ''); 283 } 284 }, cancel: function(click) { 285 return this.each(function() { 286 if ($(this).data('readonly') !== true) { 287 methods[click ? 'click' : 'score'].call(this, null); 288 this.score.removeAttr('value'); 289 } 290 }); 291 }, click: function(score) { 292 return $(this).each(function() { 293 if ($(this).data('readonly') !== true) { 294 methods._apply.call(this, score); 295 if (!this.opt.click) { 296 methods._error.call(this, 'You must add the "click: function(score, evt) { }" callback.'); 297 } 298 this.opt.click.call(this, score, { type: 'click' }); 299 methods._target.call(this, score); 300 } 301 }); 302 }, destroy: function() { 303 return $(this).each(function() { 304 var that = $(this), 305 raw = that.data('raw'); 306 if (raw) { 307 that.off('.raty').empty().css({ cursor: raw.style.cursor, width: raw.style.width }).removeData('readonly'); 308 } else { 309 that.data('raw', that.clone()[0]); 310 } 311 }); 312 }, getScore: function() { 313 var score = [], 314 value ; 315 $(this).each(function() { 316 value = this.score.val(); 317 score.push(value ? parseFloat(value) : undefined); 318 }); 319 return (score.length > 1) ? score : score[0]; 320 }, readOnly: function(readonly) { 321 return this.each(function() { 322 var that = $(this); 323 if (that.data('readonly') !== readonly) { 324 if (readonly) { 325 that.off('.raty').children('i').off('.raty'); 326 methods._lock.call(this); 327 } else { 328 methods._binds.call(this); 329 methods._unlock.call(this); 330 } 331 that.data('readonly', readonly); 332 } 333 }); 334 }, reload: function() { 335 return methods.set.call(this, {}); 336 }, score: function() { 337 return arguments.length ? methods.setScore.apply(this, arguments) : methods.getScore.call(this); 338 }, set: function(settings) { 339 return this.each(function() { 340 var that = $(this), 341 actual = that.data('settings'), 342 news = $.extend({}, actual, settings); 343 that.raty(news); 344 }); 345 }, setScore: function(score) { 346 return $(this).each(function() { 347 if ($(this).data('readonly') !== true) { 348 methods._apply.call(this, score); 349 methods._target.call(this, score); 350 } 351 }); 352 } 353 }; 354 $.fn.raty = function(method) { 355 if (methods[method]) { 356 return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); 357 } else if (typeof method === 'object' || !method) { 358 return methods.init.apply(this, arguments); 359 } else { 360 $.error('Method ' + method + ' does not exist!'); 361 } 362 }; 363 $.fn.raty.defaults = { 364 cancel : false, 365 cancelHint : 'Cancel this rating!', 366 cancelOff : 'fa-minus-square-o', 367 cancelOn : 'fa-minus-square-o', 368 cancelPlace : 'left', 369 click : undefined, 370 half : false, 371 halfShow : true, 372 hints : ['bad', 'poor', 'regular', 'good', 'gorgeous'], 373 iconRange : undefined, 374 mouseout : undefined, 375 mouseover : undefined, 376 noRatedMsg : 'Not rated yet!', 377 alreadyRatedMsg : 'Not rated yet!', 378 number : 5, 379 numberMax : 20, 380 path : '', 381 precision : false, 382 readOnly : false, 383 round : { down: .25, full: .6, up: .76 }, 384 score : undefined, 385 scoreName : 'score', 386 single : false, 387 size : 16, 388 space : true, 389 starHalf : 'fa fa-star-half', 390 starOff : 'fa fa-star-o', 391 starOn : 'fa fa-star', 392 target : undefined, 393 targetFormat : '{score}', 394 targetKeep : false, 395 targetText : '', 396 targetType : 'hint', 397 width : undefined 398 }; 399})(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.