mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
android click firing twice fix
This commit is contained in:
1
dist/js/ionic-angular.js
vendored
1
dist/js/ionic-angular.js
vendored
@@ -1100,7 +1100,6 @@ angular.module('ionic.ui.header', ['ngAnimate'])
|
||||
});
|
||||
|
||||
$scope.$watch('rightButtons', function(val) {
|
||||
console.log('Right buttons changed');
|
||||
// Resize the title since the buttons have changed
|
||||
hb.align();
|
||||
});
|
||||
|
||||
40
dist/js/ionic.js
vendored
40
dist/js/ionic.js
vendored
@@ -259,13 +259,37 @@ window.ionic = {
|
||||
ionic.EventController = {
|
||||
VIRTUALIZED_EVENTS: ['tap', 'swipe', 'swiperight', 'swipeleft', 'drag', 'hold', 'release'],
|
||||
|
||||
isAndroidBrowser: (navigator.userAgent.indexOf('Android') > 0 && navigator.userAgent.indexOf('Chrome') < 0),
|
||||
|
||||
// Trigger a new event
|
||||
trigger: function(eventType, data) {
|
||||
var event = new CustomEvent(eventType, { detail: data });
|
||||
|
||||
// Make sure to trigger the event on the given target, or dispatch it from
|
||||
// the window if we don't have an event target
|
||||
data && data.target && data.target.dispatchEvent(event) || window.dispatchEvent(event);
|
||||
if(data && data.target) {
|
||||
|
||||
// fire the event
|
||||
data.target.dispatchEvent(event) || window.dispatchEvent(event);
|
||||
|
||||
// fix for "click" firing twice on our Android friends
|
||||
if(ionic.EventController.isAndroidBrowser && eventType === 'click') {
|
||||
// Due to a bug, old Android browser fires both touchstart/touchend
|
||||
// and mousedown/mouseup. Because both are fired it results in
|
||||
// the "click" running twice on an element. Since this was a
|
||||
// triggered "click", which probably came from our "tap", then
|
||||
// set this element to be disabled for X milliseconds. While this
|
||||
// element is disabled, a second "click" by the browser would not
|
||||
// execute, hence the "click" only fires once from the initial "tap".
|
||||
var orgVal = data.target.disabled;
|
||||
data.target.disabled = true;
|
||||
|
||||
// After X milliseconds set the disabled value back to what it was
|
||||
setTimeout(function(){
|
||||
data.target.disabled = orgVal;
|
||||
}, 200);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Bind an event
|
||||
@@ -1910,19 +1934,13 @@ window.ionic = {
|
||||
// polyfill use to simulate native "tap"
|
||||
function inputTapPolyfill(ele, e) {
|
||||
if(ele.type === "radio") {
|
||||
ele.checked = !ele.checked;
|
||||
ionic.trigger('click', {
|
||||
target: ele
|
||||
});
|
||||
if(!ele.checked) ele.checked = true;
|
||||
ionic.trigger('click', { target: ele });
|
||||
} else if(ele.type === "checkbox") {
|
||||
ele.checked = !ele.checked;
|
||||
ionic.trigger('click', {
|
||||
target: ele
|
||||
});
|
||||
ionic.trigger('click', { target: ele });
|
||||
} else if(ele.type === "submit" || ele.type === "button") {
|
||||
ionic.trigger('click', {
|
||||
target: ele
|
||||
});
|
||||
ionic.trigger('click', { target: ele });
|
||||
} else {
|
||||
ele.focus();
|
||||
}
|
||||
|
||||
@@ -38,13 +38,37 @@
|
||||
ionic.EventController = {
|
||||
VIRTUALIZED_EVENTS: ['tap', 'swipe', 'swiperight', 'swipeleft', 'drag', 'hold', 'release'],
|
||||
|
||||
isAndroidBrowser: (navigator.userAgent.indexOf('Android') > 0 && navigator.userAgent.indexOf('Chrome') < 0),
|
||||
|
||||
// Trigger a new event
|
||||
trigger: function(eventType, data) {
|
||||
var event = new CustomEvent(eventType, { detail: data });
|
||||
|
||||
// Make sure to trigger the event on the given target, or dispatch it from
|
||||
// the window if we don't have an event target
|
||||
data && data.target && data.target.dispatchEvent(event) || window.dispatchEvent(event);
|
||||
if(data && data.target) {
|
||||
|
||||
// fire the event
|
||||
data.target.dispatchEvent(event) || window.dispatchEvent(event);
|
||||
|
||||
// fix for "click" firing twice on our Android friends
|
||||
if(ionic.EventController.isAndroidBrowser && eventType === 'click') {
|
||||
// Due to a bug, old Android browser fires both touchstart/touchend
|
||||
// and mousedown/mouseup. Because both are fired it results in
|
||||
// the "click" running twice on an element. Since this was a
|
||||
// triggered "click", which probably came from our "tap", then
|
||||
// set this element to be disabled for X milliseconds. While this
|
||||
// element is disabled, a second "click" by the browser would not
|
||||
// execute, hence the "click" only fires once from the initial "tap".
|
||||
var orgVal = data.target.disabled;
|
||||
data.target.disabled = true;
|
||||
|
||||
// After X milliseconds set the disabled value back to what it was
|
||||
setTimeout(function(){
|
||||
data.target.disabled = orgVal;
|
||||
}, 200);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Bind an event
|
||||
|
||||
Reference in New Issue
Block a user