Skip to content

Commit

Permalink
Actually fix issue #4 (touch/click issue) by fixing it in the source …
Browse files Browse the repository at this point in the history
…files.
  • Loading branch information
kylepaulsen committed May 18, 2015
1 parent 5acbf5f commit e3f4c75
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
22 changes: 12 additions & 10 deletions nanomodal.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,18 @@ function El(tag, classNames) {
};

var addClickListener = function(handler) {

This comment has been minimized.

Copy link
@josdejong

josdejong May 19, 2015

Where is all this throttle stuff needed for?

Why not reduce addClickListener to:

var addClickListener = function (handler) {
  addListener("click", handler);
}
var flag = false;
var wrappedHandler = function(evt){
if (!flag){
flag = true;
setTimeout(function(){ flag = false; }, 100);
handler(evt);
var throttle = false;
var throttleHandler = function(e) {
if (!throttle) {
throttle = true;
setTimeout(function() {
throttle = false;
}, 100);
handler(e);
}
}
addListener("touchstart", wrappedHandler);
addListener("mousedown", wrappedHandler);
};
addListener("touchstart", throttleHandler);
addListener("mousedown", throttleHandler);
};

var show = function(arg) {
Expand Down Expand Up @@ -376,7 +378,7 @@ var ModalEvent = require("./ModalEvent");

var nanoModalAPI = (function() {



var El = require("./El");
var Modal = require("./Modal");
Expand Down
2 changes: 1 addition & 1 deletion nanomodal.min.js

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

17 changes: 12 additions & 5 deletions src/El.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,18 @@ function El(tag, classNames) {
};

var addClickListener = function(handler) {
if ("ontouchend" in document.documentElement) {
addListener("touchstart", handler);
} else {
addListener("click", handler);
}
var throttle = false;
var throttleHandler = function(e) {
if (!throttle) {
throttle = true;
setTimeout(function() {
throttle = false;
}, 100);
handler(e);
}
};
addListener("touchstart", throttleHandler);
addListener("mousedown", throttleHandler);
};

var show = function(arg) {
Expand Down

0 comments on commit e3f4c75

Please sign in to comment.