Skip to content

Commit

Permalink
Implementing fastclick and fixing laptop touchscreen problems. This f…
Browse files Browse the repository at this point in the history
…ixes #179 and fixes #266 and fixes #246 and fixes #245 and fixes #211 and fixes #178 and fixes #118 and fixes #98  and fixes #214 and fixes #117 and fixes #130 and fixes #144 and fixes #146 and fixes #165 and fixes #189 and fixes #193 and fixes #203 and fixes #213 and fixes #218 and fixes #240 and fixes #249
  • Loading branch information
artberri committed Jan 9, 2016
1 parent 2f511ab commit dfa93b6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 45 deletions.
39 changes: 17 additions & 22 deletions dist/jquery.sidr.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,11 @@
if (typeof settings.source === 'function') {
var newContent = settings.source(name);
privateMethods.loadContent($sideMenu, newContent);
} else if(typeof settings.source === 'string' && privateMethods.isUrl(settings.source)) {
} else if (typeof settings.source === 'string' && privateMethods.isUrl(settings.source)) {
$.get(settings.source, function(data) {
privateMethods.loadContent($sideMenu, data);
});
} else if(typeof settings.source === 'string') {
} else if (typeof settings.source === 'string') {
var htmlContent = '',
selectors = settings.source.split(',');

Expand All @@ -262,7 +262,7 @@
});

// Renaming ids and classes
if(settings.renaming) {
if (settings.renaming) {
var $htmlContent = $('<div />').html(htmlContent);
$htmlContent.find('*').each(function(index, element) {
var $element = $(element);
Expand All @@ -271,38 +271,33 @@
htmlContent = $htmlContent.html();
}
privateMethods.loadContent($sideMenu, htmlContent);
} else if(settings.source !== null) {
} else if (settings.source !== null) {
$.error('Invalid Sidr Source');
}

return this.each(function(){
var $this = $(this),
data = $this.data('sidr');
data = $this.data('sidr'),
flag = false;

// If the plugin hasn't been initialized yet
if ( ! data ) {
sidrMoving = false;
sidrOpened = false;

$this.data('sidr', name);
if('ontouchstart' in document.documentElement) {
$this.bind('touchstart', function(e) {
this.touched = e.timeStamp;
});
$this.bind('touchend', function(e) {
var delta = Math.abs(e.timeStamp - this.touched);
if(delta < 200) {
e.preventDefault();
methods.toggle(name);
}
});
}
else {
$this.click(function(e) {
e.preventDefault();

$this.bind('touchstart click', function(event) {
event.preventDefault();

if (!flag) {
flag = true;
methods.toggle(name);
});
}
setTimeout(function () {
flag = false;
}, 100);
}
});
}
});
};
Expand Down
2 changes: 1 addition & 1 deletion dist/jquery.sidr.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 17 additions & 22 deletions src/jquery.sidr.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,11 @@
if (typeof settings.source === 'function') {
var newContent = settings.source(name);
privateMethods.loadContent($sideMenu, newContent);
} else if(typeof settings.source === 'string' && privateMethods.isUrl(settings.source)) {
} else if (typeof settings.source === 'string' && privateMethods.isUrl(settings.source)) {
$.get(settings.source, function(data) {
privateMethods.loadContent($sideMenu, data);
});
} else if(typeof settings.source === 'string') {
} else if (typeof settings.source === 'string') {
var htmlContent = '',
selectors = settings.source.split(',');

Expand All @@ -262,7 +262,7 @@
});

// Renaming ids and classes
if(settings.renaming) {
if (settings.renaming) {
var $htmlContent = $('<div />').html(htmlContent);
$htmlContent.find('*').each(function(index, element) {
var $element = $(element);
Expand All @@ -271,38 +271,33 @@
htmlContent = $htmlContent.html();
}
privateMethods.loadContent($sideMenu, htmlContent);
} else if(settings.source !== null) {
} else if (settings.source !== null) {
$.error('Invalid Sidr Source');
}

return this.each(function(){
var $this = $(this),
data = $this.data('sidr');
data = $this.data('sidr'),
flag = false;

// If the plugin hasn't been initialized yet
if ( ! data ) {
sidrMoving = false;
sidrOpened = false;

$this.data('sidr', name);
if('ontouchstart' in document.documentElement) {
$this.bind('touchstart', function(e) {
this.touched = e.timeStamp;
});
$this.bind('touchend', function(e) {
var delta = Math.abs(e.timeStamp - this.touched);
if(delta < 200) {
e.preventDefault();
methods.toggle(name);
}
});
}
else {
$this.click(function(e) {
e.preventDefault();

$this.bind('touchstart click', function(event) {
event.preventDefault();

if (!flag) {
flag = true;
methods.toggle(name);
});
}
setTimeout(function () {
flag = false;
}, 100);
}
});
}
});
};
Expand Down

0 comments on commit dfa93b6

Please sign in to comment.