1 2/** 3 * @file 4 * 5 * Fivestar JavaScript behaviors integration. 6 */ 7 8/** 9 * Create a degradable star rating interface out of a simple form structure. 10 * 11 * Originally based on the Star Rating jQuery plugin by Wil Stuckey: 12 * http://sandbox.wilstuckey.com/jquery-ratings/ 13 */ 14(function($) { 15 Drupal.behaviors.fivestar = { 16 attach: function(context) { 17 $('.vote').on('change', function() { 18 if (!$(this).prop('disabled')) { 19 $(this).closest('form').find('.form-submit').trigger('click'); 20 } 21 }); 22 23 $(once('fivestar', 'div.fivestar-form-item', context)).each(function() { 24 var $cancel, $container, $options, $select, $this, index; 25 $this = $(this); 26 $container = $('<div class="fivestar-widget clearfix"></div>'); 27 $select = $('select', $this); 28 $cancel = $('option[value="0"]', $this); 29 if ($cancel.length) { 30 $('<div class="cancel"><a href="#0" title="' + $cancel.text() + '">' + $cancel.text() + '</a></div>').appendTo($container); 31 } 32 $options = $('option', $this).not('[value="-"], [value="0"]'); 33 index = -1; 34 $options.each(function(i, element) { 35 var classes; 36 classes = 'star-' + (i + 1); 37 classes += (i + 1) % 2 === 0 ? ' even' : ' odd'; 38 classes += i === 0 ? ' star-first' : ''; 39 classes += (i + 1) === $options.length ? ' star-last' : ''; 40 $('<div class="star"><a href="#' + element.value + '" title="' + element.text + '">' + element.text + '</a></div>
40').addClass(classes).appendTo($container); 41 if (element.value === $select.val()) { 42 index = i + 1; 43 } 44 }); 45 if (index !== -1) { 46 $container.find('.star').slice(0, index).addClass('on'); 47 } 48 $container.addClass('fivestar-widget-' + $options.length); 49 $container.find('a').bind('click', $this, Drupal.behaviors.fivestar.rate).bind('mouseover', $this, Drupal.behaviors.fivestar.hover); 50 $container.bind('mouseover mouseout', $this, Drupal.behaviors.fivestar.hover); 51 $select.after($container).css('display', 'none'); 52 }); 53 }, 54 rate: function(event) { 55 var $this, $this_star, $widget, value; 56 $this = $(this); 57 $widget = event.data; 58 value = parseInt(this.hash.replace('#', '')); 59 $('select', $widget).val(value).change(); 60 if (value === 0) { 61 $this_star = $this.parent().parent().find('.star'); 62 } else { 63 $this_star = $this.closest('.star'); 64 } 65 $this_star.prevAll('.star').addBack().addClass('on'); 66 $this_star.nextAll('.star').removeClass('on'); 67 if (value === 0) { 68 $this_star.removeClass('on'); 69 } 70 event.preventDefault(); 71 }, 72 hover: function(event) { 73 var $stars, $target, $this, $widget, index; 74 $this = $(this); 75 $widget = event.data; 76 $target = $(event.target); 77 $stars = $('.star', $this); 78 if (event.type === 'mouseover') { 79 index = $stars.index($target.parent()); 80 $stars.each(function(i, element) { 81 if (i <= index) { 82 $(element).addClass('hover'); 83 } else { 84 $(element).removeClass('hover'); 85 } 86 }); 87 } else { 88 $stars.removeClass('hover'); 89 } 90 } 91 }; 92})(jQuery, once);
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.