From 699a13e1a625976e12947e96724c28abd796564d Mon Sep 17 00:00:00 2001 From: Andrew Robert Nicols Date: Fri, 4 Jan 2013 15:39:13 +0000 Subject: [PATCH] MDL-37366 Fix JS Lint issues with moodle-core-formautosubmit --- lib/yui/formautosubmit/formautosubmit.js | 50 ++++++++++++++---------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/lib/yui/formautosubmit/formautosubmit.js b/lib/yui/formautosubmit/formautosubmit.js index 39525dbf9d1..3c349f4a99d 100644 --- a/lib/yui/formautosubmit/formautosubmit.js +++ b/lib/yui/formautosubmit/formautosubmit.js @@ -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(); } }