fix(toggle): Changed tap listener to use "release", closes #882 #881

This commit is contained in:
Adam Bradley
2014-03-24 16:21:44 -05:00
parent f1ed4b0084
commit b1a7c1990a
3 changed files with 17 additions and 11 deletions

View File

@@ -31,14 +31,14 @@ angular.module('ionic.ui.touch', [])
});
});
element[0].addEventListener('touchend', onTap, false);
ionic.on("release", onTap, element[0]);
// Hack for iOS Safari's benefit. It goes searching for onclick handlers and is liable to click
// something else nearby.
element.onclick = function(event) { };
scope.$on('$destroy', function () {
element[0].removeEventListener('touchend', onTap);
ionic.off("release", onTap, element[0]);
});
};
}])

View File

@@ -5,6 +5,16 @@
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<link rel="stylesheet" href="../../../../dist/css/ionic.css">
<script src="../../../../dist/js/ionic.bundle.js"></script>
<style>
#click-notify {
position: absolute;
display: none;
top: 150px;
left: 48%;
z-index: 9999;
background: red;
}
</style>
</head>
<body ng-controller="TestCtrl">
<div id="click-notify">CLICK!</div>

View File

@@ -184,11 +184,6 @@
}, REMOVE_PREVENT_DELAY);
}
function touchEnd(e) {
tapPolyfill(e);
removeClickPrevent(e);
}
function stopEvent(e){
e.stopPropagation();
e.preventDefault();
@@ -223,13 +218,14 @@
REMOVE_PREVENT_DELAY = 800;
}
// global action event listener for HTML elements that were tapped or held by the user
document.addEventListener('touchend', touchEnd, false);
// set global click handler and check if the event should stop or not
document.addEventListener('click', preventGhostClick, true);
// listener used to remove ghostclick prevention
// global release event listener polyfill for HTML elements that were tapped or held
ionic.on("release", tapPolyfill, document);
// listeners used to remove ghostclick prevention
document.addEventListener('touchend', removeClickPrevent, false);
document.addEventListener('mouseup', removeClickPrevent, false);
// in the case the user touched the screen, then scrolled, it shouldn't fire the click