https://brennertv.ru/wp-content/themes/neptune-by-osetin/assets/js/lib/jquery.barrating.js?ver=3.0.1
1/** 2 * jQuery Bar Rating Plugin v1.1.2 3 * 4 * http://github.com/antennaio/jquery-bar-rating 5 * 6 * Copyright (c) 2012-2015 Kazik Pietruszewski 7 * 8 * Dual licensed under the MIT and GPL licenses: 9 * http://www.opensource.org/licenses/mit-license.php 10 * http://www.gnu.org/licenses/gpl.html 11 */ 12(function (factory) { 13 if (typeof define === 'function' && define.amd) { 14 // AMD 15 define(['jquery'], factory); 16 } else if (typeof module === 'object' && module.exports) { 17 // Node/CommonJS 18 module.exports = factory(require('jquery')); 19 } else { 20 // browser globals 21 factory(jQuery); 22 } 23}(function ($) { 24 25 var BarRating = (function() { 26 27 function BarRating() { 28 var self = this; 29 30 // wrap element in a wrapper div 31 var wrapElement = function() { 32 var classes = [self.options.wrapperClass]; 33 34 if (self.options.theme !== '') { 35 classes.push('br-theme-' + self.options.theme); 36 } 37 38 self.$elem.wrap($('<div />', { 39 'class': classes.join(' ') 40 })); 41 }; 42 43 // unwrap element 44 var unwrapElement = function() { 45 self.$elem.unwrap(); 46 }; 47 48 // return initial option 49 var findInitialOption = function() { 50 var option; 51 52 if (self.options.initialRating) { 53 option = $('option[value="' + self.options.initialRating + '"]', self.$elem); 54 } else { 55 option = $('option:selected', self.$elem); 56 } 57 58 return option; 59 }; 60 61 // save data on element 62 var saveDataOnElement = function() { 63 var $opt = findInitialOption(); 64 65 self.$elem.data('barrating', { 66 67 userOptions: self.options, 68 69 // initial rating based on the OPTION value 70 currentRatingValue: $opt.val(), 71 currentRatingText: ($opt.data('html')) ? $opt.data('html') : $opt.text(), 72 73 // rating will be restored by calling clear method 74 originalRatingValue: $opt.val(), 75 originalRatingText: ($opt.data('html')) ? $opt.data('html') : $opt.text() 76 77 }); 78 79 // first OPTION empty - allow deselecting of ratings 80 self.$elem.data('barrating').deselectable = 81 (!self.$elem.find('option:first').val()) ? true : false; 82 }; 83 84 // remove data on element 85 var removeDataOnElement = function() { 86 self.$elem.removeData('barrating'); 87 }; 88 89 // build widget and return jQuery element 90 var buildWidget = function() { 91 var $w = $('<div />', { 'class': 'br-widget' }); 92 93 // create A elements that will replace OPTIONs 94 self.$elem.find('option').each(function() { 95 var val, text, html, $a, $span; 96 97 val = $(this).val(); 98 99 // create ratings - but only if val is defined 100 if (val) { 101 text = $(this).text(); 102 html = $(this).data('html'); 103 if (html) { text = html; } 104 105 $a = $('<a />', { 'href': '#', 'data-rating-value': val, 'data-rating-text': text }); 106 $span = $('<span />', { 'html': (self.options.showValues) ? text : '' }); 107 108 $w.append($a.append($span)); 109 } 110 111 }); 112 113 // append .br-current-rating div to the widget 114 if (self.options.showSelectedRating) { 115 $w.append($('<div />', { 'text': '', 'class': 'br-current-rating' })); 116 } 117 118 // additional classes for the widget 119 if (self.options.reverse) { 120 $w.addClass('br-reverse'); 121 } 122 123 if (self.options.readonly) { 124 $w.addClass('br-readonly'); 125 } 126 127 return $w; 128 }; 129 130 // return a jQuery function name depending on the 'reverse' setting 131 var nextAllorPreviousAll = function() { 132 if (self.options.reverse) { 133 return 'nextAll'; 134 } else { 135 return 'prevAll'; 136 } 137 }; 138 139 // set the value of the select field 140 var setSelectFieldValue = function(value) { 141 // change selected OPTION in the select field (hidden) 142 self.$elem.find('option[value="' + value + '"]').prop('selected', true); 143 self.$elem.change(); 144 }; 145 146 // display the currently selected rating 147 var showSelectedRating = function(text) { 148 // text undefined? 149 text = text ? text : self.$elem.data('barrating').currentRatingText; 150 151 // update .br-current-rating div 152 if (self.options.showSelectedRating) { 153 self.$elem.parent().find('.br-current-rating').text(text); 154 } 155 }; 156 157 // apply style by setting classes on elements 158 var applyStyle = function($w) { 159 // remove classes 160 $w.find('a').removeClass('br-selected br-current'); 161 162 // add classes 163 $w.find('a[data-rating-value="' + self.$elem.data('barrating').currentRatingValue + '"]') 164 .addClass('br-selected br-current')[nextAllorPreviousAll()]() 165 .addClass('br-selected'); 166 }; 167 168 // handle click events 169 var attachClickHandler = function($all) { 170 $all.on('click', function(event) { 171 var $a = $(this), 172 value, 173 text; 174 175 event.preventDefault(); 176 177 $all.removeClass('br-active br-selected'); 178 $a.addClass('br-selected')[nextAllorPreviousAll()]() 179 .addClass('br-selected'); 180 181 value = $a.attr('data-rating-value'); 182 text = $a.attr('data-rating-text'); 183 184 // is current and deselectable? 185 if ($a.hasClass('br-current') && self.$elem.data('barrating').deselectable) { 186 $a.removeClass('br-selected br-current')[nextAllorPreviousAll()]() 187 .removeClass('br-selected br-current'); 188 value = ''; text = ''; 189 } else { 190 $all.removeClass('br-current'); 191 $a.addClass('br-current'); 192 } 193 194 // remember selected rating 195 self.$elem.data('barrating').currentRatingValue = value; 196 self.$elem.data('barrating').currentRatingText = text; 197 198 setSelectFieldValue(value); 199 showSelectedRating(text); 200 201 // onSelect callback 202 self.options.onSelect.call( 203 this, 204 self.$elem.data('barrating').currentRatingValue, 205 self.$elem.data('barrating').currentRatingText 206 ); 207 208 return false;
209 }); 210 }; 211 212 // handle mouseenter events 213 var attachMouseEnterHandler = function($all) { 214 $all.on({ 215 mouseenter: function() { 216 var $a = $(this); 217 218 $all.removeClass('br-active br-selected'); 219 $a.addClass('br-active')[nextAllorPreviousAll()]() 220 .addClass('br-active'); 221 222 showSelectedRating($a.attr('data-rating-text')); 223 } 224 }); 225 }; 226 227 // handle mouseleave events 228 var attachMouseLeaveHandler = function($all, $widget) { 229 $widget.on({ 230 mouseleave: function() { 231 $all.removeClass('br-active'); 232 showSelectedRating(); 233 applyStyle($widget); 234 } 235 }); 236 }; 237 238 // somewhat primitive way to remove 300ms click delay on touch devices 239 // for a more advanced solution consider setting `fastClicks` option to false 240 // and using a library such as fastclick (https://github.com/ftlabs/fastclick) 241 var fastClicks = function($all) { 242 $all.on('touchstart', function(event) { 243 event.preventDefault(); 244 event.stopPropagation(); 245 246 $(this).click(); 247 }); 248 }; 249 250 // disable clicks 251 var disableClicks = function($all) { 252 $all.on('click', function(event) { 253 event.preventDefault(); 254 }); 255 }; 256 257 this.show = function() { 258 var $widget, $all; 259 260 // run only once 261 if (self.$elem.data('barrating')) return; 262 263 // wrap element 264 wrapElement(); 265 266 // save data 267 saveDataOnElement(); 268 269 // build & append widget to the DOM 270 $widget = buildWidget(); 271 $widget.insertAfter(self.$elem); 272 applyStyle($widget); 273 274 showSelectedRating(); 275 276 $all = $widget.find('a'); 277 278 if (self.options.fastClicks) { 279 fastClicks($all); 280 } 281 282 if (self.options.readonly) { 283 284 // do not react to click events if rating is read-only 285 disableClicks($all); 286 287 } else { 288 289 // attach click event handler 290 attachClickHandler($all); 291 292 if (self.options.hoverState) { 293 // attach mouseenter event handler 294 attachMouseEnterHandler($all); 295 296 // attach mouseleave event handler 297 attachMouseLeaveHandler($all, $widget); 298 } 299 300 } 301 302 // hide the select field 303 self.$elem.hide(); 304 }; 305 306 this.set = function(value) { 307 if (!this.$elem.find('option[value="' + value + '"]').val()) return; 308 309 // set data 310 this.$elem.data('barrating').currentRatingValue = value; 311 this.$elem.data('barrating').currentRatingText = this.$elem.find('option[value="' + value + '"]').text(); 312 313 setSelectFieldValue(this.$elem.data('barrating').currentRatingValue); 314 showSelectedRating(this.$elem.data('barrating').currentRatingText); 315 316 applyStyle(this.$widget); 317 318 // onSelect callback 319 this.$elem.data('barrating').userOptions.onSelect.call( 320 this, 321 this.$elem.data('barrating').currentRatingValue, 322 this.$elem.data('barrating').currentRatingText 323 ); 324 }; 325 326 this.clear = function() { 327 // restore original data 328 this.$elem.data('barrating').currentRatingValue = this.$elem.data('barrating').originalRatingValue; 329 this.$elem.data('barrating').currentRatingText = this.$elem.data('barrating').originalRatingText; 330 331 setSelectFieldValue(this.$elem.data('barrating').currentRatingValue); 332 showSelectedRating(this.$elem.data('barrating').currentRatingText); 333 334 applyStyle(this.$widget); 335 336 // onClear callback 337 this.$elem.data('barrating').userOptions.onClear.call( 338 this, 339 this.$elem.data('barrating').currentRatingValue, 340 this.$elem.data('barrating').currentRatingText 341 ); 342 }; 343 344 this.destroy = function() { 345 var value = this.$elem.data('barrating').currentRatingValue; 346 var text = this.$elem.data('barrating').currentRatingText; 347 var options = this.$elem.data('barrating').userOptions; 348 349 this.$widget.off().remove(); 350 351 // remove data 352 removeDataOnElement(); 353 354 // unwrap the element 355 unwrapElement(); 356 357 // show the element 358 this.$elem.show(); 359 360 // onDestroy callback 361 options.onDestroy.call( 362 this, 363 value, 364 text 365 ); 366 }; 367 } 368 369 BarRating.prototype.init = function (options, elem) { 370 this.$elem = $(elem); 371 this.options = $.extend({}, $.fn.barrating.defaults, options); 372 373 return this.options; 374 }; 375 376 return BarRating; 377 })(); 378 379 $.fn.barrating = function (method, options) { 380 return this.each(function () { 381 var plugin = new BarRating(); 382 383 // plugin works with select fields 384 if (!$(this).is('select')) { 385 $.error('Sorry, this plugin only works with select fields.'); 386 } 387 388 // method supplied
389 if (plugin.hasOwnProperty(method)) { 390 plugin.init(options, this); 391 if (method === 'show') { 392 return plugin.show(options); 393 } else { 394 // plugin exists? 395 if (plugin.$elem.data('barrating')) { 396 plugin.$widget = $(this).next('.br-widget'); 397 return plugin[method](options); 398 } 399 } 400 401 // no method supplied or only options supplied 402 } else if (typeof method === 'object' || !method) { 403 options = method; 404 plugin.init(options, this); 405 return plugin.show(); 406 407 } else { 408 $.error('Method ' + method + ' does not exist on jQuery.barrating'); 409 } 410 }); 411 }; 412 413 $.fn.barrating.defaults = { 414 theme:'', 415 initialRating:null, // initial rating 416 showValues:false, // display rating values on the bars? 417 showSelectedRating:true, // append a div with a rating to the widget? 418 reverse:false, // reverse the rating? 419 readonly:false, // make the rating ready-only? 420 fastClicks:true, // remove 300ms click delay on touch devices? 421 hoverState:true, // change state on hover? 422 wrapperClass:'br-wrapper', // class applied to wrapper div 423 onSelect:function (value, text) { 424 }, // callback fired when a rating is selected 425 onClear:function (value, text) { 426 }, // callback fired when a rating is cleared 427 onDestroy:function (value, text) { 428 } // callback fired when a widget is destroyed 429 }; 430 431 $.fn.barrating.BarRating = BarRating; 432 433}));
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.