FIxed #109 - modal auto focus and unfocus on close

This commit is contained in:
Max Lynch
2013-11-10 18:43:09 -06:00
parent 94824c9a66
commit 787101708d
5 changed files with 43 additions and 0 deletions

View File

@ -3,13 +3,30 @@
ionic.views.Modal = ionic.views.View.inherit({
initialize: function(opts) {
opts = ionic.extend({
focusFirstInput: true
}, opts);
ionic.extend(this, opts);
this.el = opts.el;
},
show: function() {
this.el.classList.add('active');
if(this.focusFirstInput) {
var input = this.el.querySelector('input, textarea');
input && input.focus && input.focus();
}
},
hide: function() {
this.el.classList.remove('active');
// Unfocus all elements
var inputs = this.el.querySelectorAll('input, textarea');
for(var i = 0; i < inputs.length; i++) {
inputs[i].blur && inputs[i].blur();
}
}
});