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