|
3 | 3 | *
|
4 | 4 | * http://github.com/netboy/jquery-bar-rating
|
5 | 5 | *
|
6 |
| - * Copyright (c) 2012-2013 Kazik Pietruszewski |
| 6 | + * Copyright (c) 2012-2014 Kazik Pietruszewski |
7 | 7 | *
|
8 | 8 | * Dual licensed under the MIT and GPL licenses:
|
9 | 9 | * http://www.opensource.org/licenses/mit-license.php
|
10 | 10 | * http://www.gnu.org/licenses/gpl.html
|
11 | 11 | */
|
12 | 12 | (function ($) {
|
13 |
| - var BarRating, root, hasTouch; |
| 13 | + var BarRating, root; |
| 14 | + |
14 | 15 | root = typeof window !== "undefined" && window !== null ? window : global;
|
15 |
| - hasTouch = 'ontouchstart' in root; |
16 | 16 |
|
17 | 17 | root.BarRating = BarRating = (function () {
|
18 | 18 |
|
|
23 | 23 | $all,
|
24 | 24 | userOptions = this.options,
|
25 | 25 | nextAllorPreviousAll,
|
26 |
| - initialOption, |
27 |
| - clickEvent = hasTouch ? 'touchstart' : 'click'; |
| 26 | + initialOption; |
28 | 27 |
|
29 | 28 | // run only once
|
30 | 29 | if (!$this.data('barrating')) {
|
|
121 | 120 |
|
122 | 121 | $all = $widget.find('a');
|
123 | 122 |
|
124 |
| - // make sure click event doesn't cause trouble on touch devices |
| 123 | + // fast clicks |
| 124 | + $all.on('touchstart', function (event) { |
| 125 | + event.preventDefault(); |
| 126 | + event.stopPropagation(); |
| 127 | + |
| 128 | + $(this).click(); |
| 129 | + }); |
| 130 | + |
125 | 131 | // do not react to click events if rating is read-only
|
126 |
| - if (hasTouch || userOptions.readonly) { |
| 132 | + if (userOptions.readonly) { |
127 | 133 | $all.on('click', function (event) {
|
128 | 134 | event.preventDefault();
|
129 | 135 | });
|
|
132 | 138 | // add interactions
|
133 | 139 | if (!userOptions.readonly) {
|
134 | 140 |
|
135 |
| - $all.on(clickEvent, function (event) { |
| 141 | + $all.on('click', function (event) { |
136 | 142 | var $a = $(this),
|
137 | 143 | value,
|
138 | 144 | text;
|
|
174 | 180 | });
|
175 | 181 |
|
176 | 182 | // attach mouseenter/mouseleave event handlers
|
177 |
| - if (!hasTouch) { |
178 |
| - |
179 |
| - $all.on({ |
180 |
| - mouseenter:function () { |
181 |
| - var $a = $(this); |
182 |
| - |
183 |
| - $all.removeClass('br-active').removeClass('br-selected'); |
184 |
| - $a.addClass('br-active')[nextAllorPreviousAll]() |
185 |
| - .addClass('br-active'); |
186 |
| - |
187 |
| - $widget.trigger('ratingchange', |
188 |
| - [$a.attr('data-rating-value'), $a.attr('data-rating-text')] |
189 |
| - ); |
190 |
| - } |
191 |
| - }); |
192 |
| - |
193 |
| - $widget.on({ |
194 |
| - mouseleave:function () { |
195 |
| - $all.removeClass('br-active'); |
196 |
| - $widget |
197 |
| - .trigger('ratingchange') |
198 |
| - .trigger('updaterating'); |
199 |
| - } |
200 |
| - }); |
201 |
| - } |
| 183 | + $all.on({ |
| 184 | + mouseenter:function () { |
| 185 | + var $a = $(this); |
| 186 | + |
| 187 | + $all.removeClass('br-active').removeClass('br-selected'); |
| 188 | + $a.addClass('br-active')[nextAllorPreviousAll]() |
| 189 | + .addClass('br-active'); |
| 190 | + |
| 191 | + $widget.trigger('ratingchange', |
| 192 | + [$a.attr('data-rating-value'), $a.attr('data-rating-text')] |
| 193 | + ); |
| 194 | + } |
| 195 | + }); |
| 196 | + |
| 197 | + $widget.on({ |
| 198 | + mouseleave:function () { |
| 199 | + $all.removeClass('br-active'); |
| 200 | + $widget |
| 201 | + .trigger('ratingchange') |
| 202 | + .trigger('updaterating'); |
| 203 | + } |
| 204 | + }); |
202 | 205 |
|
203 | 206 | }
|
204 | 207 |
|
|
0 commit comments