Skip to content

Commit

Permalink
tap polyfill removeClickPrevent and label fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Bradley committed Feb 18, 2014
1 parent c168b48 commit ec8862a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
11 changes: 8 additions & 3 deletions js/ext/angular/test/clickTests.html
Expand Up @@ -68,8 +68,13 @@

<label class="label1">
<input type="radio" name="radio" id="radio1" class="radio1">
</label>
<input type="radio" name="radio" id="radio2" class="radio2">
</label> &nbsp;
<input type="radio" name="radio" id="radio2" class="radio2"> &nbsp;

<label class="label2">
<input type="checkbox" name="checkbox1" id="checkbox1" class="checkbox1">
</label> &nbsp;
<input type="checkbox" name="checkbox2" id="checkbox2" class="checkbox2">

</div>

Expand Down Expand Up @@ -241,7 +246,7 @@
// console.debug('mousemove', 'clientX: ' + event.clientX, 'clientY: ' + event.clientY);
// });
document.addEventListener('click', function(event){
console.debug('click', 'clientX: ' + event.clientX, 'clientY: ' + event.clientY);
console.debug('click', 'clientX: ' + event.clientX, 'clientY: ' + event.clientY, event.target.tagName);
});
document.getElementById('clear').addEventListener('click', function(){
setTimeout(clearMsgs, 200);
Expand Down
25 changes: 12 additions & 13 deletions js/utils/poly.js
Expand Up @@ -18,8 +18,11 @@
})();

// polyfill use to simulate native "tap"
ionic.tapElement = function(ele, e) {
ionic.tapElement = function(target, e) {
// simulate a normal click by running the element's click method then focus on it

var ele = target.control || target;

if(ele.disabled) return;

console.debug('tapElement', ele.tagName, ele.className);
Expand All @@ -46,6 +49,11 @@
if( !isRecentTap(e) ) {
recordCoordinates(e);
}

if(target.control) {
console.debug('tapElement, target.control, stop');
return stopEvent(e);
}
};

function tapPolyfill(orgEvent) {
Expand All @@ -66,16 +74,11 @@
if( ele.tagName === "INPUT" ||
ele.tagName === "A" ||
ele.tagName === "BUTTON" ||
ele.tagName === "LABEL" ||
ele.tagName === "TEXTAREA" ||
ele.tagName === "SELECT" ) {

return ionic.tapElement(ele, e);

} else if( ele.tagName === "LABEL" ) {
// check if the tapped label has an input associated to it
if(ele.control) {
return ionic.tapElement(ele.control, e);
}
}
ele = ele.parentElement;
}
Expand Down Expand Up @@ -158,13 +161,9 @@

function removeClickPrevent(e) {
setTimeout(function(){
if(e.target && e.target.control && e.target.control.labelLastTap) {
e.target.control.labelLastTap = null;
}
var c = isRecentTap(e);
if(c) delete tapCoordinates[c.id];
var tap = isRecentTap(e);
if(tap) delete tapCoordinates[tap.id];
}, REMOVE_PREVENT_DELAY);
return stopEvent(e);
}

function stopEvent(e){
Expand Down

0 comments on commit ec8862a

Please sign in to comment.