Badman click

This commit is contained in:
Max Lynch
2015-06-03 16:31:56 -05:00
parent 5590adb1e5
commit ba1c630e33
2 changed files with 66 additions and 15 deletions

View File

@ -76,6 +76,23 @@ class PlatformController {
run() { run() {
activePlatform && activePlatform.run(); activePlatform && activePlatform.run();
} }
/**
* Check if the platform matches the provided one.
*/
is(platform) {
if(!activePlatform) { return false; }
return activePlatform.name === platform;
}
/**
* Check if the loaded device matches the provided one.
*/
isDevice(device) {
if(!activePlatform) { return false; }
return activePlatform.getDevice() === device;
}
} }
export let Platform = new PlatformController((util.getQuerystring('ionicplatform')).toLowerCase(), window.navigator.userAgent); export let Platform = new PlatformController((util.getQuerystring('ionicplatform')).toLowerCase(), window.navigator.userAgent);
@ -90,8 +107,10 @@ Platform.register({
} }
return /android/i.test(userAgent); return /android/i.test(userAgent);
}, },
getDevice: function() {
return 'android';
},
run() { run() {
} }
}); });
@ -103,16 +122,27 @@ Platform.register({
} }
return /ipad|iphone|ipod/i.test(userAgent); return /ipad|iphone|ipod/i.test(userAgent);
}, },
getDevice: function() {
if(/ipad/i.test(userAgent)) {
return 'ipad';
}
if(/iphone/i.test(userAgent)) {
return 'iphone';
}
},
run() { run() {
//Tap.run(); //Tap.run();
} }
}); });
// Last case is a catch-all // Last case is a catch-all
// TODO(mlynch): don't default to iOS, default to core,
// also make sure to remove getPlatform and set to detect()
Platform.setDefault({ Platform.setDefault({
name: 'ios' name: 'ios'
}); });
Platform.set( Platform.getPlatform('ios') );//Platform.detect() ); Platform.set( Platform.getPlatform('ios') );//Platform.detect() );
// If the platform needs to do some initialization (like load a custom
// tap strategy), run it now
Platform.run(); Platform.run();

View File

@ -181,7 +181,7 @@ export let Tap = {
}, },
isKeyboardElement: function(ele) { isKeyboardElement: function(ele) {
if ( !ionic.Platform.isIOS() || ionic.Platform.isIPad() ) { if ( !Platform.is('ios') || Platform.isDevice('ipad') ) {
return Tap.isTextInput(ele) && !Tap.isDateInput(ele); return Tap.isTextInput(ele) && !Tap.isDateInput(ele);
} else { } else {
return Tap.isTextInput(ele) || ( !!ele && ele.tagName == "SELECT"); return Tap.isTextInput(ele) || ( !!ele && ele.tagName == "SELECT");
@ -203,7 +203,7 @@ export let Tap = {
if (Tap.hasCheckedClone) return; if (Tap.hasCheckedClone) return;
Tap.hasCheckedClone = true; Tap.hasCheckedClone = true;
ionic.requestAnimationFrame(function() { dom.raf(function() {
var focusInput = container.querySelector(':focus'); var focusInput = container.querySelector(':focus');
if (Tap.isTextInput(focusInput)) { if (Tap.isTextInput(focusInput)) {
var clonedInput = focusInput.cloneNode(true); var clonedInput = focusInput.cloneNode(true);
@ -228,7 +228,7 @@ export let Tap = {
removeClonedInputs: function(container) { removeClonedInputs: function(container) {
Tap.hasCheckedClone = false; Tap.hasCheckedClone = false;
ionic.requestAnimationFrame(function() { dom.raf(function() {
var clonedInputs = container.querySelectorAll('.cloned-text-input'); var clonedInputs = container.querySelectorAll('.cloned-text-input');
var previousInputFocus = container.querySelectorAll('.previous-input-focus'); var previousInputFocus = container.querySelectorAll('.previous-input-focus');
var x; var x;
@ -240,7 +240,11 @@ export let Tap = {
for (x = 0; x < previousInputFocus.length; x++) { for (x = 0; x < previousInputFocus.length; x++) {
previousInputFocus[x].classList.remove('previous-input-focus'); previousInputFocus[x].classList.remove('previous-input-focus');
previousInputFocus[x].style.top = ''; previousInputFocus[x].style.top = '';
if ( ionic.keyboard.isOpen && !ionic.keyboard.isClosing ) previousInputFocus[x].focus();
// TODO(tlancina): Get this back to life
// if ( ionic.keyboard.isOpen && !ionic.keyboard.isClosing ) {
// previousInputFocus[x].focus();
// }
} }
}); });
}, },
@ -341,8 +345,10 @@ function tapClickGateKeeper(e) {
} }
// do not allow through any click events that were not created by Tap // do not allow through any click events that were not created by Tap
if ((ionic.scroll.isScrolling && Tap.containsOrIsTextInput(e.target)) ||
(!e.isIonicTap && !Tap.requiresNativeClick(e.target))) { // TODO(mlynch): re-enable this check
//if ((ionic.scroll.isScrolling && Tap.containsOrIsTextInput(e.target)) || (!e.isIonicTap && !Tap.requiresNativeClick(e.target))) {
if (!e.isIonicTap && !Tap.requiresNativeClick(e.target)) {
//console.log('clickPrevent', e.target.tagName); //console.log('clickPrevent', e.target.tagName);
e.stopPropagation(); e.stopPropagation();
@ -378,7 +384,9 @@ function tapMouseDown(e) {
tapPointerStart = Tap.pointerCoord(e); tapPointerStart = Tap.pointerCoord(e);
tapEventListener('mousemove'); tapEventListener('mousemove');
ionic.activator.start(e);
// TODO(mlynch): re-enable
// ionic.activator.start(e);
} }
function tapMouseUp(e) { function tapMouseUp(e) {
@ -395,14 +403,16 @@ function tapMouseUp(e) {
tapClick(e); tapClick(e);
} }
tapEventListener('mousemove', false); tapEventListener('mousemove', false);
ionic.activator.end(); // TODO(mlynch): re-enable
// ionic.activator.end();
tapPointerMoved = false; tapPointerMoved = false;
} }
function tapMouseMove(e) { function tapMouseMove(e) {
if (tapHasPointerMoved(e)) { if (tapHasPointerMoved(e)) {
tapEventListener('mousemove', false); tapEventListener('mousemove', false);
ionic.activator.end(); // TODO(mlynch): re-enable
// ionic.activator.end();
tapPointerMoved = true; tapPointerMoved = true;
return false; return false;
} }
@ -420,9 +430,10 @@ function tapTouchStart(e) {
tapPointerStart = Tap.pointerCoord(e); tapPointerStart = Tap.pointerCoord(e);
tapEventListener(tapTouchMoveListener); tapEventListener(tapTouchMoveListener);
ionic.activator.start(e); // TODO(mlynch): re-enable
//ionic.activator.start(e);
if (ionic.Platform.isIOS() && Tap.isLabelWithTextInput(e.target)) { if (Platform.is('ios') && Tap.isLabelWithTextInput(e.target)) {
// if the tapped element is a label, which has a child input // if the tapped element is a label, which has a child input
// then preventDefault so iOS doesn't ugly auto scroll to the input // then preventDefault so iOS doesn't ugly auto scroll to the input
// but do not prevent default on Android or else you cannot move the text caret // but do not prevent default on Android or else you cannot move the text caret
@ -457,14 +468,17 @@ function tapTouchMove(e) {
if (tapHasPointerMoved(e)) { if (tapHasPointerMoved(e)) {
tapPointerMoved = true; tapPointerMoved = true;
tapEventListener(tapTouchMoveListener, false); tapEventListener(tapTouchMoveListener, false);
ionic.activator.end();
// TODO(mlynch): re-enable
// ionic.activator.end();
return false; return false;
} }
} }
function tapTouchCancel() { function tapTouchCancel() {
tapEventListener(tapTouchMoveListener, false); tapEventListener(tapTouchMoveListener, false);
ionic.activator.end(); // TODO(mlynch): re-enable
// ionic.activator.end();
tapPointerMoved = false; tapPointerMoved = false;
} }
@ -480,10 +494,17 @@ function tapIgnoreEvent(e) {
if (e.isTapHandled) return true; if (e.isTapHandled) return true;
e.isTapHandled = true; e.isTapHandled = true;
// TODO(mlynch): re-enable
/*
if (ionic.scroll.isScrolling && Tap.containsOrIsTextInput(e.target)) { if (ionic.scroll.isScrolling && Tap.containsOrIsTextInput(e.target)) {
e.preventDefault(); e.preventDefault();
return true; return true;
} }
*/
if (Tap.containsOrIsTextInput(e.target)) {
e.preventDefault();
return true;
}
} }
function tapHandleFocus(ele) { function tapHandleFocus(ele) {