Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
71
assets/webapps/email.gaiamobile.org/js/form_navigation.js
Normal file
71
assets/webapps/email.gaiamobile.org/js/form_navigation.js
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
define(['require'], function (require) {
|
||||
function FormNavigation(options) {
|
||||
function extend(destination, source) {
|
||||
for (var property in source) {
|
||||
destination[property] = source[property];
|
||||
}
|
||||
return destination;
|
||||
}
|
||||
if (!options.formElem) {
|
||||
throw new Error('The form element should be defined.');
|
||||
}
|
||||
var self = this;
|
||||
this.options = extend({
|
||||
formElem: null,
|
||||
checkFormValidity: function checkFormValidity() {
|
||||
return self.options.formElem.checkValidity();
|
||||
},
|
||||
onLast: function () {
|
||||
}
|
||||
}, options);
|
||||
this.options.formElem.addEventListener('keypress', this.onKeyPress.bind(this));
|
||||
this.options.formElem.addEventListener('click', this.onClick.bind(this));
|
||||
}
|
||||
FormNavigation.prototype = {
|
||||
onKeyPress: function formNav_onKeyPress(event) {
|
||||
if (event.keyCode === 13) {
|
||||
var nextInput = this.focusNextInput(event);
|
||||
if (!nextInput && this.options.checkFormValidity()) {
|
||||
this.options.onLast(event);
|
||||
}
|
||||
}
|
||||
},
|
||||
onClick: function formNav_onClick(event) {
|
||||
if (event.target.type === 'reset') {
|
||||
var formValidity = this.options.checkFormValidity();
|
||||
var buttonElems = this.options.formElem.getElementsByTagName('button');
|
||||
for (var i = 0; i < buttonElems.length; i++) {
|
||||
var button = buttonElems[i];
|
||||
if (button.type !== 'reset') {
|
||||
button.disabled = !formValidity;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
focusNextInput: function formNav_focusNextInput(event) {
|
||||
var currentInput = event.target;
|
||||
var inputElems = this.options.formElem.getElementsByTagName('input');
|
||||
var currentInputFound = false;
|
||||
for (var i = 0; i < inputElems.length; i++) {
|
||||
var input = inputElems[i];
|
||||
if (currentInput === input) {
|
||||
currentInputFound = true;
|
||||
continue;
|
||||
} else if (!currentInputFound) {
|
||||
continue;
|
||||
}
|
||||
if (input.type === 'hidden' || input.type === 'button') {
|
||||
continue;
|
||||
}
|
||||
input.focus();
|
||||
if (document.activeElement !== input) {
|
||||
continue;
|
||||
}
|
||||
return input;
|
||||
}
|
||||
currentInput.blur();
|
||||
return null;
|
||||
}
|
||||
};
|
||||
return FormNavigation;
|
||||
});
|
||||
Loading…
Reference in a new issue