diff --git a/dist/js/ionic-angular.js b/dist/js/ionic-angular.js index 50684c5fb9..9b095cc322 100644 --- a/dist/js/ionic-angular.js +++ b/dist/js/ionic-angular.js @@ -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(); }); diff --git a/dist/js/ionic.js b/dist/js/ionic.js index 140493e965..73c49c4240 100644 --- a/dist/js/ionic.js +++ b/dist/js/ionic.js @@ -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(); } diff --git a/js/utils/events.js b/js/utils/events.js index 5b5ae5afa2..04561974c2 100644 --- a/js/utils/events.js +++ b/js/utils/events.js @@ -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