Skip to content

Commit ec8862a

Browse files
author
Adam Bradley
committed
tap polyfill removeClickPrevent and label fixes
1 parent c168b48 commit ec8862a

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

js/ext/angular/test/clickTests.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,13 @@
6868

6969
<label class="label1">
7070
<input type="radio" name="radio" id="radio1" class="radio1">
71-
</label>
72-
<input type="radio" name="radio" id="radio2" class="radio2">
71+
</label> &nbsp;
72+
<input type="radio" name="radio" id="radio2" class="radio2"> &nbsp;
73+
74+
<label class="label2">
75+
<input type="checkbox" name="checkbox1" id="checkbox1" class="checkbox1">
76+
</label> &nbsp;
77+
<input type="checkbox" name="checkbox2" id="checkbox2" class="checkbox2">
7378

7479
</div>
7580

@@ -241,7 +246,7 @@
241246
// console.debug('mousemove', 'clientX: ' + event.clientX, 'clientY: ' + event.clientY);
242247
// });
243248
document.addEventListener('click', function(event){
244-
console.debug('click', 'clientX: ' + event.clientX, 'clientY: ' + event.clientY);
249+
console.debug('click', 'clientX: ' + event.clientX, 'clientY: ' + event.clientY, event.target.tagName);
245250
});
246251
document.getElementById('clear').addEventListener('click', function(){
247252
setTimeout(clearMsgs, 200);

js/utils/poly.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
})();
1919

2020
// polyfill use to simulate native "tap"
21-
ionic.tapElement = function(ele, e) {
21+
ionic.tapElement = function(target, e) {
2222
// simulate a normal click by running the element's click method then focus on it
23+
24+
var ele = target.control || target;
25+
2326
if(ele.disabled) return;
2427

2528
console.debug('tapElement', ele.tagName, ele.className);
@@ -46,6 +49,11 @@
4649
if( !isRecentTap(e) ) {
4750
recordCoordinates(e);
4851
}
52+
53+
if(target.control) {
54+
console.debug('tapElement, target.control, stop');
55+
return stopEvent(e);
56+
}
4957
};
5058

5159
function tapPolyfill(orgEvent) {
@@ -66,16 +74,11 @@
6674
if( ele.tagName === "INPUT" ||
6775
ele.tagName === "A" ||
6876
ele.tagName === "BUTTON" ||
77+
ele.tagName === "LABEL" ||
6978
ele.tagName === "TEXTAREA" ||
7079
ele.tagName === "SELECT" ) {
7180

7281
return ionic.tapElement(ele, e);
73-
74-
} else if( ele.tagName === "LABEL" ) {
75-
// check if the tapped label has an input associated to it
76-
if(ele.control) {
77-
return ionic.tapElement(ele.control, e);
78-
}
7982
}
8083
ele = ele.parentElement;
8184
}
@@ -158,13 +161,9 @@
158161

159162
function removeClickPrevent(e) {
160163
setTimeout(function(){
161-
if(e.target && e.target.control && e.target.control.labelLastTap) {
162-
e.target.control.labelLastTap = null;
163-
}
164-
var c = isRecentTap(e);
165-
if(c) delete tapCoordinates[c.id];
164+
var tap = isRecentTap(e);
165+
if(tap) delete tapCoordinates[tap.id];
166166
}, REMOVE_PREVENT_DELAY);
167-
return stopEvent(e);
168167
}
169168

170169
function stopEvent(e){

0 commit comments

Comments
 (0)