--- a/src/ztfy/myams/resources/js/myams.js Tue Nov 17 15:40:24 2015 +0100
+++ b/src/ztfy/myams/resources/js/myams.js Wed Nov 18 16:10:11 2015 +0100
@@ -1249,6 +1249,26 @@
},
/**
+ * Set focus to first container input
+ */
+ setFocus: function(container) {
+ var focused = $('[data-ams-focus-target]', container).first();
+ if (!focused.exists()) {
+ focused = $('input, select', container).first();
+ }
+ if (focused.exists()) {
+ if (focused.hasClass('select2')) {
+ setTimeout(function() {
+ focused.select2('focus')
+ focused.select2('open');
+ }, 100);
+ } else {
+ focused.focus();
+ }
+ }
+ },
+
+ /**
* Check for modified forms before exiting
*/
checkBeforeUnload: function() {
@@ -1678,6 +1698,7 @@
.delay(50)
.animate({opacity: '1.0'}, 300);
ams.initContent(target);
+ ams.form.setFocus(target);
}
var callback = request.getResponseHeader('X-AMS-Callback');
if (callback) {
@@ -2023,14 +2044,7 @@
}
}
- // Set focus to first input
- var focused = $('[data-ams-focus-target]', modal).first();
- if (!focused.exists()) {
- focused = $('input, select', modal).first();
- }
- if (focused.exists()) {
- focused.focus();
- }
+ ams.form.setFocus(modal);
},
/**
@@ -4161,14 +4175,7 @@
.delay(50)
.animate({opacity: '1.0'}, 300);
ams.initContent(container);
- // Set focus to first input
- var focused = $('[data-ams-focus-target]', container).first();
- if (!focused.exists()) {
- focused = $('input, select', container).first();
- }
- if (focused.exists()) {
- focused.focus();
- }
+ ams.form.setFocus(container);
}
if (options && options.afterLoadCallback) {
ams.executeFunctionByName(options.afterLoadCallback, this);
@@ -4557,14 +4564,7 @@
setTimeout(function() {
form.find('.select2').trigger('change');
}, 10);
- // Set focus to first input
- var focused = $('[data-ams-focus-target]', form).first();
- if (!focused.exists()) {
- focused = $('input, select', form).first();
- }
- if (focused.exists()) {
- focused.focus();
- }
+ ams.form.setFocus(form);
});
// Initialize custom reset handlers
@@ -4633,6 +4633,7 @@
if (ams.ajax_nav && $('nav').exists()) {
ams.skin.checkURL();
}
+ ams.form.setFocus(document);
// Add unload event listener to check for modified forms
$(window).on('beforeunload', ams.form.checkBeforeUnload);