Fixed #138 - radio and checkbox tap/click

This commit is contained in:
Max Lynch
2013-11-14 20:19:54 -06:00
parent cc0e4ea306
commit df1d9c4d75
11 changed files with 326 additions and 131 deletions

92
dist/js/ionic.js vendored
View File

@ -1769,7 +1769,7 @@ window.ionic = {
ionic.Platform.detect();
})(window.ionic);
;
(function(ionic) {
(function(window, document, ionic) {
'use strict';
// From the man himself, Mr. Paul Irish.
@ -1799,7 +1799,71 @@ window.ionic = {
}
})();
})(window.ionic);
// polyfill use to simulate native "tap"
function inputTapPolyfill(ele, e) {
if(ele.type === "radio" || ele.type === "checkbox") {
console.log('RADIOPOLY');
ele.checked = !ele.checked;
} else if(ele.type === "submit" || ele.type === "button") {
ele.click();
} else {
ele.focus();
}
e.stopPropagation();
e.preventDefault();
return false;
}
function tapPolyfill(e) {
// if the source event wasn't from a touch event then don't use this polyfill
if(!e.gesture || e.gesture.pointerType !== "touch" || !e.gesture.srcEvent) return;
if(e.defaultPrevented) {
e.stopPropagation();
e.preventDefault();
return false;
}
e = e.gesture.srcEvent; // evaluate the actual source event, not the created event by gestures.js
var ele = e.target;
while(ele) {
if( ele.tagName === "INPUT" || ele.tagName === "TEXTAREA" || ele.tagName === "SELECT" ) {
return inputTapPolyfill(ele, e);
} else if( ele.tagName === "LABEL" ) {
if(ele.control) {
return inputTapPolyfill(ele.control, e);
}
}
/* Let ng-click handle this
else if( ele.tagName === "A" || ele.tagName === "BUTTON" ) {
ele.click();
e.stopPropagation();
e.preventDefault();
return false;
}
*/
ele = ele.parentElement;
}
// they didn't tap one of the above elements
// if the currently active element is an input, and they tapped outside
// of the current input, then unset its focus (blur) so the keyboard goes away
var activeElement = document.activeElement;
if(activeElement && (activeElement.tagName === "INPUT" || activeElement.tagName === "TEXTAREA" || activeElement.tagName === "SELECT")) {
activeElement.blur();
e.stopPropagation();
e.preventDefault();
return false;
}
}
// global tap event listener polyfill for HTML elements that were "tapped" by the user
ionic.on("tap", tapPolyfill, window);
})(this, document, ionic);
;
(function(ionic) {
@ -2779,30 +2843,6 @@ window.ionic = {
}
});
})(ionic);
;
(function(ionic) {
'use strict';
ionic.views.Checkbox = ionic.views.View.inherit({
initialize: function(opts) {
this.el = opts.el;
this.checkbox = opts.checkbox;
this.handle = opts.handle;
},
tap: function(e) {
this.val( !this.checkbox.checked );
},
val: function(value) {
if(value === true || value === false) {
this.checkbox.checked = value;
}
return this.checkbox.checked;
}
});
})(ionic);
;
(function(ionic) {