mirror of
https://github.com/moodle/moodle.git
synced 2025-01-31 12:45:04 +01:00
MDL-37366 Fix JS Lint issues with moodle-core-formautosubmit
This commit is contained in:
parent
469749706a
commit
699a13e1a6
50
lib/yui/formautosubmit/formautosubmit.js
vendored
50
lib/yui/formautosubmit/formautosubmit.js
vendored
@ -1,35 +1,38 @@
|
||||
YUI.add('moodle-core-formautosubmit',
|
||||
function(Y) {
|
||||
var CSS,
|
||||
FORMAUTOSUBMITNAME = 'core-formautosubmit',
|
||||
FORMAUTOSUBMIT,
|
||||
INITIALIZED = false;
|
||||
|
||||
// The CSS selectors we use
|
||||
var CSS = {
|
||||
CSS = {
|
||||
AUTOSUBMIT : 'autosubmit'
|
||||
};
|
||||
|
||||
var FORMAUTOSUBMITNAME = 'core-formautosubmit';
|
||||
|
||||
var FORMAUTOSUBMIT = function() {
|
||||
FORMAUTOSUBMIT = function() {
|
||||
FORMAUTOSUBMIT.superclass.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
// We only want to initialize the module fully once
|
||||
var INITIALIZED = false;
|
||||
};
|
||||
|
||||
Y.extend(FORMAUTOSUBMIT, Y.Base, {
|
||||
|
||||
/**
|
||||
* Initialize the module
|
||||
*/
|
||||
initializer : function(config) {
|
||||
initializer : function() {
|
||||
// Set up local variables
|
||||
var applyto,
|
||||
thisselect;
|
||||
// We only apply the delegation once
|
||||
if (!INITIALIZED) {
|
||||
INITIALIZED = true;
|
||||
var applyto = Y.one('body');
|
||||
applyto = Y.one('body');
|
||||
|
||||
// We don't listen for change events by default as using the keyboard triggers these too.
|
||||
applyto.delegate('key', this.process_changes, 'press:13', 'select.' + CSS.AUTOSUBMIT, this);
|
||||
applyto.delegate('click', this.process_changes, 'select.' + CSS.AUTOSUBMIT, this);
|
||||
|
||||
if (Y.UA.os == 'macintosh' && Y.UA.webkit) {
|
||||
if (Y.UA.os === 'macintosh' && Y.UA.webkit) {
|
||||
// Macintosh webkit browsers like change events, but non-macintosh webkit browsers don't.
|
||||
applyto.delegate('change', this.process_changes, 'select.' + CSS.AUTOSUBMIT, this);
|
||||
}
|
||||
@ -41,7 +44,7 @@ YUI.add('moodle-core-formautosubmit',
|
||||
|
||||
// Assign this select items 'nothing' value and lastindex (current value)
|
||||
if (this.get('selectid')) {
|
||||
var thisselect = Y.one('select#' + this.get('selectid'));
|
||||
thisselect = Y.one('select#' + this.get('selectid'));
|
||||
if (thisselect) {
|
||||
if (this.get('nothing')) {
|
||||
thisselect.setData('nothing', this.get('nothing'));
|
||||
@ -57,23 +60,29 @@ YUI.add('moodle-core-formautosubmit',
|
||||
* Check whether the select element was changed
|
||||
*/
|
||||
check_changed : function(e) {
|
||||
var select = e.target.ancestor('select.' + CSS.AUTOSUBMIT, true);
|
||||
var select,
|
||||
nothing,
|
||||
startindex,
|
||||
currentindex,
|
||||
previousindex;
|
||||
select = e.target.ancestor('select.' + CSS.AUTOSUBMIT, true);
|
||||
if (!select) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var nothing = select.getData('nothing');
|
||||
var startindex = select.getData('startindex');
|
||||
var currentindex = select.get('selectedIndex');
|
||||
nothing = select.getData('nothing');
|
||||
startindex = select.getData('startindex');
|
||||
currentindex = select.get('selectedIndex');
|
||||
|
||||
var previousindex = select.getAttribute('data-previousindex');
|
||||
previousindex = select.getAttribute('data-previousindex');
|
||||
select.setAttribute('data-previousindex', currentindex);
|
||||
if (!previousindex) {
|
||||
previousindex = startindex;
|
||||
}
|
||||
|
||||
// Check whether the field has changed, and is not the 'nothing' value
|
||||
if ((nothing===false || select.get('value') != nothing) && startindex != select.get('selectedIndex') && currentindex != previousindex) {
|
||||
if ((nothing===false || select.get('value') !== nothing)
|
||||
&& startindex !== select.get('selectedIndex') && currentindex !== previousindex) {
|
||||
return select;
|
||||
}
|
||||
return false;
|
||||
@ -83,9 +92,10 @@ YUI.add('moodle-core-formautosubmit',
|
||||
* Process any changes
|
||||
*/
|
||||
process_changes : function(e) {
|
||||
var select = this.check_changed(e);
|
||||
var select = this.check_changed(e),
|
||||
form;
|
||||
if (select) {
|
||||
var form = select.ancestor('form', true);
|
||||
form = select.ancestor('form', true);
|
||||
form.submit();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user