1/*! 2 * jQuery Raty - A Star Rating Plugin 3 * 4 * The MIT License 5 * 6 * @author : Washington Botelho 7 * @doc : http://wbotelhos.com/raty 8 * @version : 2.6.0 9 * 10 */ 11 12;(function(pjQuery_1_12_4) { 13 'use strict'; 14 15 var methods = { 16 init: function(options) { 17 return this.each(function() { 18 this.self = pjQuery_1_12_4(this); 19 20 methods.destroy.call(this.self); 21 22 this.opt = pjQuery_1_12_4.extend(true, {}, pjQuery_1_12_4.fn.raty.defaults, options); 23 24 methods._adjustCallback.call(this); 25 26 methods._adjustNumber.call(this); 27 28 if (this.opt.starType !== 'img') { 29 methods._adjustStarType.call(this); 30 } 31 32 methods._adjustPath.call(this); 33 methods._createStars.call(this); 34 35 if (this.opt.cancel) { 36 methods._createCancel.call(this); 37 } 38 39 if (this.opt.precision) { 40 methods._adjustPrecision.call(this); 41 } 42 43 methods._createScore.call(this); 44 methods._apply.call(this, this.opt.score); 45 methods._target.call(this, this.opt.score); 46 47 if (this.opt.readOnly) { 48 methods._lock.call(this); 49 } else { 50 this.style.cursor = 'pointer'; 51 52 methods._binds.call(this); 53 } 54 55 this.self.data('options', this.opt); 56 }); 57 }, 58 59 _adjustCallback: function() { 60 var options = ['number', 'readOnly', 'score', 'scoreName']; 61 62 for (var i = 0; i < options.length; i++) { 63 if (typeof this.opt[options[i]] === 'function') { 64 this.opt[options[i]] = this.opt[options[i]].call(this); 65 } 66 } 67 }, 68 69 _adjustNumber: function() { 70 this.opt.number = methods._between(this.opt.number, 1, this.opt.numberMax); 71 }, 72 73 _adjustPath: function() { 74 this.opt.path = this.opt.path || ''; 75 76 if (this.opt.path && this.opt.path.charAt(this.opt.path.length - 1) !== '/') { 77 this.opt.path += '/'; 78 } 79 }, 80 81 _adjustPrecision: function() { 82 this.opt.half = true; 83 this.opt.targetType = 'score'; 84 }, 85 86 _adjustStarType: function() { 87 this.opt.path = ''; 88 89 var replaces = ['cancelOff', 'cancelOn', 'starHalf', 'starOff', 'starOn']; 90 91 for (var i = 0; i < replaces.length; i++) { 92 this.opt[replaces[i]] = this.opt[replaces[i]].replace('.', '-'); 93 } 94 }, 95 96 _apply: function(score) { 97 methods._fill.call(this, score); 98 99 if (score) { 100 if (score > 0) { 101 this.score.val(methods._between(score, 0, this.opt.number)); 102 } 103 104 methods._roundStars.call(this, score); 105 } 106 }, 107 108 _between: function(value, min, max) { 109 return Math.min(Math.max(parseFloat(value), min), max); 110 }, 111 112 _binds: function() { 113 if (this.cancel) { 114 methods._bindOverCancel.call(this); 115 methods._bindClickCancel.call(this); 116 methods._bindOutCancel.call(this); 117 } 118 119 methods._bindOver.call(this); 120 methods._bindClick.call(this); 121 methods._bindOut.call(this); 122 }, 123 124 _bindClick: function() { 125 var that = this; 126 127 that.stars.on('click.raty', function(evt) { 128 var star = pjQuery_1_12_4(this); 129 130 that.score.val((that.opt.half || that.opt.precision) ? that.self.data('score') : (this.alt || star.data('alt'))); 131 132 if (that.opt.click) { 133 that.opt.click.call(that, +that.score.val(), evt); 134 } 135 }); 136 }, 137 138 _bindClickCancel: function() { 139 var that = this; 140 141 that.cancel.on('click.raty', function(evt) { 142 that.score.removeAttr('value'); 143 144 if (that.opt.click) { 145 that.opt.click.call(that, null, evt); 146 } 147 }); 148 }, 149 150 _bindOut: function() { 151 var that = this; 152 153 that.self.on('mouseleave.raty', function(evt) { 154 var score = +that.score.val() || undefined; 155 156 methods._apply.call(that, score); 157 methods._target.call(that, score, evt); 158 159 if (that.opt.mouseout) { 160 that.opt.mouseout.call(that, score, evt); 161 } 162 }); 163 }, 164 165 _bindOutCancel: function() { 166 var that = this; 167 168 that.cancel.on('mouseleave.raty', function(evt) { 169 var 170 cancel = pjQuery_1_12_4(this), 171 cancelOff = that.opt.path + that.opt.cancelOff; 172 173 if (that.opt.starType === 'img') { 174 cancel.attr('src', cancelOff); 175 } else { 176 var cancelOn = that.opt.path + that.opt.cancelOn; 177 178 cancel.removeClass(cancelOn).addClass(cancelOff); 179 } 180 181 if (that.opt.mouseout) { 182 var score = +that.score.val() || undefined; 183 184 that.opt.mouseout.call(that, score, evt); 185 } 186 }); 187 }, 188 189 _bindOver: function() { 190 var that = this, 191 action = that.opt.half ? 'mousemove.raty' : 'mouseover.raty'; 192 193 that.stars.on(action, function(evt) { 194 var score = methods._getScoreByPosition.call(that, evt, this); 195 196 methods._fill.call(that, score); 197 198 if (that.opt.half) {
199 methods._roundStars.call(that, score); 200 201 that.self.data('score', score); 202 } 203 204 methods._target.call(that, score, evt); 205 206 if (that.opt.mouseover) { 207 that.opt.mouseover.call(that, score, evt); 208 } 209 }); 210 }, 211 212 _bindOverCancel: function() { 213 var that = this; 214 215 that.cancel.on('mouseover.raty', function(evt) { 216 var 217 cancelOn = that.opt.path + that.opt.cancelOn, 218 star = pjQuery_1_12_4(this), 219 starOff = that.opt.path + that.opt.starOff; 220 221 if (that.opt.starType === 'img') { 222 star.attr('src', cancelOn); 223 that.stars.attr('src', starOff); 224 } else { 225 that.stars.attr('class', starOff); 226 227 var cancelOff = that.opt.path + that.opt.cancelOff; 228 229 star.removeClass(cancelOff).addClass(cancelOn); 230 } 231 232 methods._target.call(that, null, evt); 233 234 if (that.opt.mouseover) { 235 that.opt.mouseover.call(that, null); 236 } 237 }); 238 }, 239 240 _buildScoreField: function() { 241 return pjQuery_1_12_4('<input />', { name: this.opt.scoreName, type: 'hidden' }).appendTo(this); 242 }, 243 244 _createCancel: function() { 245 var icon = this.opt.path + this.opt.cancelOff, 246 cancel = pjQuery_1_12_4('<' + this.opt.starType + ' />', { title: this.opt.cancelHint, 'class': 'raty-cancel' }); 247 248 if (this.opt.starType === 'img') { 249 cancel.attr({ src: icon, alt: 'x' }); 250 } else { 251 // TODO: use pjQuery_1_12_4.data 252 cancel.attr('data-alt', 'x').addClass(icon); 253 } 254 255 if (this.opt.cancelPlace === 'left') { 256 this.self.prepend(' ').prepend(cancel); 257 } else { 258 this.self.append(' ').append(cancel); 259 } 260 261 this.cancel = cancel; 262 }, 263 264 _createScore: function() { 265 var score = pjQuery_1_12_4(this.opt.targetScore); 266 267 this.score = score.length ? score : methods._buildScoreField.call(this); 268 }, 269 270 _createStars: function() { 271 for (var i = 1; i <= this.opt.number; i++) { 272 var 273 attrs , 274 icon = (this.opt.score && this.opt.score >= i) ? 'starOn' : 'starOff', 275 title = methods._getHint.call(this, i); 276 277 // TODO: extract as icon: && alt: 278 icon = this.opt.path + this.opt[icon]; 279 280 if (this.opt.starType !== 'img') { 281 // TODO: use pjQuery_1_12_4.data. 282 attrs = { 'data-alt': i, 'class': icon }; 283 } else { 284 attrs = { src: icon, alt: i }; 285 } 286 287 attrs.title = title; 288 289 pjQuery_1_12_4('<' + this.opt.starType + ' />', attrs).appendTo(this); 290 291 if (this.opt.space) { 292 this.self.append(i < this.opt.number ? ' ' : ''); 293 } 294 } 295 296 this.stars = this.self.children(this.opt.starType); 297 }, 298 299 _error: function(message) { 300 pjQuery_1_12_4(this).text(message); 301 302 pjQuery_1_12_4.error(message); 303 }, 304 305 _fill: function(score) { 306 var hash = 0; 307 308 for (var i = 1; i <= this.stars.length; i++) { 309 var 310 icon, 311 star = this.stars.eq(i - 1), 312 turnOn = methods._turnOn.call(this, i, score); 313 314 if (this.opt.iconRange && this.opt.iconRange.length > hash) { 315 var irange = this.opt.iconRange[hash]; 316 317 icon = methods._getIconRange.call(this, irange, turnOn); 318 319 if (i <= irange.range) { 320 // TODO: extract. 321 if (this.opt.starType === 'img') { 322 star.attr('src', icon); 323 } else { 324 star.attr('class', icon); 325 } 326 } 327 328 if (i === irange.range) { 329 hash++; 330 } 331 } else { 332 icon = this.opt.path + this.opt[turnOn ? 'starOn' : 'starOff']; 333 334 // TODO: extract. 335 if (this.opt.starType === 'img') { 336 star.attr('src', icon); 337 } else { 338 star.attr('class', icon); 339 } 340 } 341 } 342 }, 343 344 _getIconRange: function(irange, turnOn) { 345 return this.opt.path + (turnOn ? irange.on || this.opt.starOn : irange.off || this.opt.starOff); 346 }, 347 348 _getScoreByPosition: function(evt, icon) { 349 var 350 star = pjQuery_1_12_4(icon), 351 score = parseInt(icon.alt || star.data('alt'), 10); 352 353 if (this.opt.half) { 354 var 355 size = methods._getSize.call(this), 356 percent = parseFloat((evt.pageX - star.offset().left) / size); 357 358 if (this.opt.precision) { 359 score = score - 1 + percent; 360 } else { 361 score = score - 1 + (percent > 0.5 ? 1 : 0.5); 362 } 363 } 364 365 366 return score; 367 }, 368 369 _getSize: function() { 370 var size; 371 372 if (this.opt.starType === 'img') { 373 size = this.stars[0].width; 374 } else { 375 size = parseFloat(this.stars.eq(0).css('font-size')); 376 } 377 378 if (!size) { 379 methods._error.call(this, 'Could not be possible get the icon size!'); 380 } 381 382 return size; 383 }, 384 385 _turnOn: function(i, score) { 386 return this.opt.single ? (i === score) : (i <= score); 387 }, 388 389 _getHint: function(score) { 390 var hint = this.opt.hints[score - 1]; 391 392 return hint === '' ? '' : hint || score; 393 }, 394 395 _lock: function() { 396 var score = parseInt(this.score.val(), 10), // TODO: 3.1 >> [['1'], ['2'], ['3', '.1', '.2']] 397 hint = score ? methods._getHint.call(this, score) : this.opt.noRatedMsg; 398 399 this.style.cursor = ''; 400 this.title = hint; 401 402 this.score.prop('readonly', true); 403 this.stars.prop('title', hint); 404 405 if (this.cancel) { 406 this.cancel.hide(); 407 } 408 409 this.self.data('readonly', true); 410 }, 411 412 _roundStars: function(score) { 413 var rest = (score % 1).toFixed(2); 414 415 if (rest > this.opt.round.down) { // Up: [x.76 .. x.99] 416 var icon = 'starOn'; 417 418 if (this.opt.halfShow && rest < this.opt.round.up) { // Half: [x.26 .. x.75] 419 icon = 'starHalf'; 420 } else if (rest < this.opt.round.full) { // Down: [x.00 .. x.5] 421 icon = 'starOff'; 422 } 423 424 var star = this.stars[Math.ceil(score) - 1]; 425 426 if (this.opt.starType === 'img') { 427 star.src = this.opt.path + this.opt[icon]; 428 } else { 429 star.style.className = this.opt[icon]; 430 } 431 } // Full down: [x.00 .. x.25] 432 }, 433 434 _target: function(score, evt) { 435 if (this.opt.target) { 436 var target = pjQuery_1_12_4(this.opt.target); 437 438 if (!target.length) { 439 methods._error.call(this, 'Target selector invalid or missing!'); 440 } 441 442 var mouseover = evt && evt.type === 'mouseover'; 443 444 if (score === undefined) { 445 score = this.opt.targetText; 446 } else if (score === null) { 447 score = mouseover ? this.opt.cancelHint : this.opt.targetText; 448 } else { 449 if (this.opt.targetType === 'hint') { 450 score = methods._getHint.call(this, Math.ceil(score)); 451 } else if (this.opt.precision) { 452 score = parseFloat(score).toFixed(1); 453 } 454 455 var mousemove = evt && evt.type === 'mousemove'; 456 457 if (!mouseover && !mousemove && !this.opt.targetKeep) { 458 score = this.opt.targetText; 459 } 460 } 461 462 if (score) { 463 score = this.opt.targetFormat.toString().replace('{score}', score); 464 } 465 466 if (target.is(':input')) { 467 target.val(score); 468 } else { 469 target.html(score); 470 } 471 } 472 }, 473 474 _unlock: function() { 475 this.style.cursor = 'pointer'; 476 this.removeAttribute('title'); 477 478 this.score.removeAttr('readonly'); 479 480 this.self.data('readonly', false); 481 482 for (var i = 0; i < this.opt.number; i++) { 483 this.stars[i].title = methods._getHint.call(this, i + 1); 484 } 485 486 if (this.cancel) { 487 this.cancel.css('display', ''); 488 } 489 }, 490 491 cancel: function(click) { 492 return this.each(function() { 493 var el = pjQuery_1_12_4(this); 494 495 if (el.data('readonly') !== true) { 496 methods[click ? 'click' : 'score'].call(el, null); 497 498 this.score.removeAttr('value'); 499 } 500 }); 501 }, 502 503 click: function(score) { 504 return this.each(function() { 505 if (pjQuery_1_12_4(this).data('readonly') !== true) { 506 methods._apply.call(this, score); 507 508 if (this.opt.click) { 509 this.opt.click.call(this, score, pjQuery_1_12_4.Event('click')); 510 } 511 512 methods._target.call(this, score); 513 } 514 }); 515 }, 516 517 destroy: function() { 518 return this.each(function() { 519 var self = pjQuery_1_12_4(this), 520 raw = self.data('raw'); 521 522 if (raw) { 523 self.off('.raty').empty().css({ cursor: raw.style.cursor }).removeData('readonly'); 524 } else { 525 self.data('raw', self.clone()[0]); 526 } 527 }); 528 }, 529 530 getScore: function() { 531 var score = [], 532 value ; 533 534 this.each(function() { 535 value = this.score.val(); 536 537 score.push(value ? +value : undefined); 538 }); 539 540 return (score.length > 1) ? score : score[0]; 541 }, 542 543 move: function(score) { 544 return this.each(function() { 545 var 546 integer = parseInt(score, 10), 547 opt = pjQuery_1_12_4(this).data('options'), 548 decimal = (+score).toFixed(1).split('.')[1]; 549 550 if (integer >= opt.number) { 551 integer = opt.number - 1; 552 decimal = 10; 553 } 554 555 var 556 size = methods._getSize.call(this), 557 point = size / 10, 558 star = pjQuery_1_12_4(this.stars[integer]), 559 percent = star.offset().left + point * parseInt(decimal, 10), 560 evt = pjQuery_1_12_4.Event('mousemove', { pageX: percent }); 561 562 star.trigger(evt); 563 }); 564 }, 565 566 readOnly: function(readonly) { 567 return this.each(function() { 568 var self = pjQuery_1_12_4(this); 569 570 if (self.data('readonly') !== readonly) { 571 if (readonly) { 572 self.off('.raty').children('img').off('.raty'); 573 574 methods._lock.call(this); 575 } else { 576 methods._binds.call(this); 577 methods._unlock.call(this); 578 } 579 580 self.data('readonly', readonly); 581 } 582 }); 583 }, 584 585 reload: function() { 586 return methods.set.call(this, {}); 587 }, 588 589 score: function() { 590 var self = pjQuery_1_12_4(this); 591 592 return arguments.length ? methods.setScore.apply(self, arguments) : methods.getScore.call(self); 593 }, 594 595 set: function(options) { 596 return this.each(function() { 597 var self = pjQuery_1_12_4(this), 598 actual = self.data('options'), 599 news = pjQuery_1_12_4.extend({}, actual, options); 600 601 self.raty(news); 602 }); 603 }, 604 605 setScore: function(score) { 606 return this.each(function() { 607 if (pjQuery_1_12_4(this).data('readonly') !== true) { 608 methods._apply.call(this, score); 609 methods._target.call(this, score); 610 } 611 }); 612 } 613 }; 614 615 pjQuery_1_12_4.fn.raty = function(method) { 616 if (methods[method]) { 617 return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); 618 } else if (typeof method === 'object' || !method) { 619 return methods.init.apply(this, arguments); 620 } else { 621 pjQuery_1_12_4.error('Method ' + method + ' does not exist!'); 622 } 623 }; 624 625 pjQuery_1_12_4.fn.raty.defaults = { 626 cancel : false, 627 cancelHint : 'Cancel this rating!', 628 cancelOff : 'cancel-off.png', 629 cancelOn : 'cancel-on.png', 630 cancelPlace : 'left', 631 click : undefined, 632 half : false, 633 halfShow : true, 634 hints : ['bad', 'poor', 'regular', 'good', 'gorgeous'], 635 iconRange : undefined, 636 mouseout : undefined, 637 mouseover : undefined, 638 noRatedMsg : 'Not rated yet!', 639 number : 5, 640 numberMax : 20, 641 path : undefined, 642 precision : false, 643 readOnly : false, 644 round : { down: 0.25, full: 0.6, up: 0.76 }, 645 score : undefined, 646 scoreName : 'score', 647 single : false, 648 space : true, 649 starHalf : 'star-half.png', 650 starOff : 'star-off.png', 651 starOn : 'star-on.png', 652 starType : 'img', 653 target : undefined, 654 targetFormat : '{score}', 655 targetKeep : false, 656 targetScore : undefined, 657 targetText : '', 658 targetType : 'hint' 659 }; 660 661})(pjQuery_1_12_4);
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.