Better focus delay for modals

This commit is contained in:
Max Lynch
2014-01-30 13:50:34 -06:00
parent bc297ed49c
commit 41fc43675c
7 changed files with 38 additions and 18 deletions

1
dist/css/ionic.css vendored
View File

@@ -1,3 +1,4 @@
@charset "UTF-8";
/*!
* Copyright 2014 Drifty Co.
* http://drifty.com/

View File

@@ -1,4 +1,4 @@
/*!
@charset "UTF-8";/*!
* Copyright 2014 Drifty Co.
* http://drifty.com/
*

View File

File diff suppressed because one or more lines are too long

21
dist/js/ionic.js vendored
View File

@@ -4951,7 +4951,8 @@ ionic.views.Scroll = ionic.views.View.inherit({
initialize: function(opts) {
opts = ionic.extend({
focusFirstInput: false,
unfocusOnHide: true
unfocusOnHide: true,
focusFirstDelay: 600
}, opts);
ionic.extend(this, opts);
@@ -4959,11 +4960,16 @@ ionic.views.Scroll = ionic.views.View.inherit({
this.el = opts.el;
},
show: function() {
var self = this;
this.el.classList.add('active');
if(this.focusFirstInput) {
var input = this.el.querySelector('input, textarea');
input && input.focus && input.focus();
// Let any animations run first
window.setTimeout(function() {
var input = self.el.querySelector('input, textarea');
input && input.focus && input.focus();
}, this.focusFirstDelay);
}
},
hide: function() {
@@ -4972,9 +4978,12 @@ ionic.views.Scroll = ionic.views.View.inherit({
// Unfocus all elements
if(this.unfocusOnHide) {
var inputs = this.el.querySelectorAll('input, textarea');
for(var i = 0; i < inputs.length; i++) {
inputs[i].blur && inputs[i].blur();
}
// Let any animations run first
window.setTimeout(function() {
for(var i = 0; i < inputs.length; i++) {
inputs[i].blur && inputs[i].blur();
}
});
}
}
});

View File

File diff suppressed because one or more lines are too long

View File

@@ -81,7 +81,8 @@
$ionicModal.fromTemplateUrl('modal.html', function(modal) {
$scope.modal = modal;
}, {
animation: 'slide-in-up'
animation: 'slide-in-up',
focusFirstInput: true
});
})

View File

@@ -5,7 +5,8 @@
initialize: function(opts) {
opts = ionic.extend({
focusFirstInput: false,
unfocusOnHide: true
unfocusOnHide: true,
focusFirstDelay: 600
}, opts);
ionic.extend(this, opts);
@@ -13,11 +14,16 @@
this.el = opts.el;
},
show: function() {
var self = this;
this.el.classList.add('active');
if(this.focusFirstInput) {
var input = this.el.querySelector('input, textarea');
input && input.focus && input.focus();
// Let any animations run first
window.setTimeout(function() {
var input = self.el.querySelector('input, textarea');
input && input.focus && input.focus();
}, this.focusFirstDelay);
}
},
hide: function() {
@@ -26,9 +32,12 @@
// Unfocus all elements
if(this.unfocusOnHide) {
var inputs = this.el.querySelectorAll('input, textarea');
for(var i = 0; i < inputs.length; i++) {
inputs[i].blur && inputs[i].blur();
}
// Let any animations run first
window.setTimeout(function() {
for(var i = 0; i < inputs.length; i++) {
inputs[i].blur && inputs[i].blur();
}
});
}
}
});