Skip to content

Commit 1a78cd9

Browse files
author
Constantin
committed
Detect touchable device with user agent AND touch event check
1 parent 798e786 commit 1a78cd9

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"name": "swipebox",
3-
"version": "1.2.6",
3+
"version": "1.2.7",
44
"main": "src/jquery.swipebox.js"
55
}

src/js/jquery.swipebox.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! Swipebox v1.2.6 | Constantin Saguin csag.co | MIT License | github.com/brutaldesign/swipebox */
1+
/*! Swipebox v1.2.7 | Constantin Saguin csag.co | MIT License | github.com/brutaldesign/swipebox */
22

33
;( function ( window, document, $, undefined ) {
44

@@ -20,6 +20,7 @@
2020
selector = elem.selector,
2121
$selector = $( selector ),
2222
isMobile = navigator.userAgent.match( /(iPad)|(iPhone)|(iPod)|(Android)|(PlayBook)|(BB10)|(BlackBerry)|(Opera Mini)|(IEMobile)|(webOS)|(MeeGo)/i ),
23+
isTouch = isMobile !== null || document.createTouch !== undefined || ( 'ontouchstart' in window ) || ( 'onmsgesturechange' in window ) || navigator.msMaxTouchPoints,
2324
supportSVG = !! document.createElementNS && !! document.createElementNS( 'http://www.w3.org/2000/svg', "svg").createSVGRect,
2425
winWidth = window.innerWidth ? window.innerWidth : $( window ).width(),
2526
winHeight = window.innerHeight ? window.innerHeight : $( window ).height(),
@@ -50,6 +51,8 @@
5051

5152
$( document ).on( 'click', selector, function( event ) {
5253

54+
// console.log( isTouch );
55+
5356
if ( event.target.parentNode.className === 'slide current' ) {
5457

5558
return false;
@@ -181,7 +184,7 @@
181184
$this.setDim();
182185
$this.actions();
183186

184-
if ( isMobile ) {
187+
if ( isTouch ) {
185188
$this.gesture();
186189
} else {
187190
$this.keyboard();
@@ -401,7 +404,7 @@
401404
}
402405
} );
403406

404-
if ( ! isMobile ) {
407+
if ( ! isTouch ) {
405408

406409
$( '#swipebox-action' ).hover( function() {
407410
$this.showBars();
@@ -448,7 +451,7 @@
448451
actions : function () {
449452
var $this = this;
450453

451-
var action = isMobile ? 'touchend' : 'click';
454+
var action = isTouch ? 'touchend' : 'click';
452455

453456
if ( elements.length < 2 ) {
454457

@@ -511,7 +514,7 @@
511514
*/
512515
openSlide : function ( index ) {
513516
$( 'html' ).addClass( 'swipebox-html' );
514-
if ( isMobile ) {
517+
if ( isTouch ) {
515518
$( 'html' ).addClass( 'swipebox-touch' );
516519
}
517520
$( window ).trigger( 'resize' ); // fix scroll bar visibility on desktop

0 commit comments

Comments
 (0)