Skip to content

Commit dda642a

Browse files
author
netboy
committed
removed touch detection
1 parent 82e7ab3 commit dda642a

File tree

3 files changed

+39
-34
lines changed

3 files changed

+39
-34
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ HEAD
1919

2020
- read-only and reversed rating marked with `.br-readonly` and `.br-reverse` classes respectively
2121

22+
- bugfix: removed touch detection - improved cross-browser compatibility (fixes issue #11)
23+
2224
1.0.4
2325
-----
2426

jquery.barrating.js

+36-33
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
*
44
* http://github.com/netboy/jquery-bar-rating
55
*
6-
* Copyright (c) 2012-2013 Kazik Pietruszewski
6+
* Copyright (c) 2012-2014 Kazik Pietruszewski
77
*
88
* Dual licensed under the MIT and GPL licenses:
99
* http://www.opensource.org/licenses/mit-license.php
1010
* http://www.gnu.org/licenses/gpl.html
1111
*/
1212
(function ($) {
13-
var BarRating, root, hasTouch;
13+
var BarRating, root;
14+
1415
root = typeof window !== "undefined" && window !== null ? window : global;
15-
hasTouch = 'ontouchstart' in root;
1616

1717
root.BarRating = BarRating = (function () {
1818

@@ -23,8 +23,7 @@
2323
$all,
2424
userOptions = this.options,
2525
nextAllorPreviousAll,
26-
initialOption,
27-
clickEvent = hasTouch ? 'touchstart' : 'click';
26+
initialOption;
2827

2928
// run only once
3029
if (!$this.data('barrating')) {
@@ -121,9 +120,16 @@
121120

122121
$all = $widget.find('a');
123122

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+
125131
// do not react to click events if rating is read-only
126-
if (hasTouch || userOptions.readonly) {
132+
if (userOptions.readonly) {
127133
$all.on('click', function (event) {
128134
event.preventDefault();
129135
});
@@ -132,7 +138,7 @@
132138
// add interactions
133139
if (!userOptions.readonly) {
134140

135-
$all.on(clickEvent, function (event) {
141+
$all.on('click', function (event) {
136142
var $a = $(this),
137143
value,
138144
text;
@@ -174,31 +180,28 @@
174180
});
175181

176182
// 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+
});
202205

203206
}
204207

jquery.barrating.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)