Skip to content

Commit

Permalink
MDL-37426 Fix JSHint issues for moodle-core-formchangechecker
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Robert Nicols committed Jan 15, 2013
1 parent 9da506c commit d7d68b0
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions lib/yui/formchangechecker/formchangechecker.js
@@ -1,14 +1,10 @@
YUI.add('moodle-core-formchangechecker',
function(Y) {
// The CSS selectors we use
var CSS = {
};

var FORMCHANGECHECKERNAME = 'core-formchangechecker';
var FORMCHANGECHECKERNAME = 'core-formchangechecker',

var FORMCHANGECHECKER = function() {
FORMCHANGECHECKER.superclass.constructor.apply(this, arguments);
}
FORMCHANGECHECKER = function() {
FORMCHANGECHECKER.superclass.constructor.apply(this, arguments);
};

Y.extend(FORMCHANGECHECKER, Y.Base, {

Expand All @@ -18,11 +14,11 @@ YUI.add('moodle-core-formchangechecker',
/**
* Initialize the module
*/
initializer : function(config) {
var formid = 'form#' + this.get('formid');
initializer : function() {
var formid = 'form#' + this.get('formid'),
currentform = Y.one(formid);

// Add change events to the form elements
var currentform = Y.one(formid);
currentform.delegate('change', M.core_formchangechecker.set_form_changed, 'input', this);
currentform.delegate('change', M.core_formchangechecker.set_form_changed, 'textarea', this);
currentform.delegate('change', M.core_formchangechecker.set_form_changed, 'select', this);
Expand All @@ -48,18 +44,15 @@ YUI.add('moodle-core-formchangechecker',
* get_form_dirty_state function later.
*/
store_initial_value : function(e) {
var thisevent;
if (e.target.hasClass('ignoredirty')) {
// Don't warn on elements with the ignoredirty class
return;
}
if (M.core_formchangechecker.get_form_dirty_state()) {
// Clear the store_initial_value listeners as the form is already dirty so
// we no longer need to call this function
var formid = 'form#' + this.get('formid');

// Detach all listen events to prevent duplicate initial value setting
var thisevent;
while (thisevent = this.initialvaluelisteners.shift()) {
while (this.initialvaluelisteners.length) {
thisevent = this.initialvaluelisteners.shift();
thisevent.detach();
}

Expand All @@ -71,7 +64,7 @@ YUI.add('moodle-core-formchangechecker',
M.core_formchangechecker.stateinformation.focused_element = {
element : e.target,
initial_value : e.target.get('value')
}
};
}
},
{
Expand All @@ -92,7 +85,7 @@ YUI.add('moodle-core-formchangechecker',
var formchangechecker = new FORMCHANGECHECKER(config);
M.core_formchangechecker.instances.push(formchangechecker);
return formchangechecker;
}
};

// Store state information
M.core_formchangechecker.stateinformation = [];
Expand All @@ -110,14 +103,14 @@ YUI.add('moodle-core-formchangechecker',
// Once the form has been marked as dirty, we no longer need to keep track of form elements
// which haven't yet blurred
delete M.core_formchangechecker.stateinformation.focused_element;
}
};

/**
* Set the form submitted state to true
*/
M.core_formchangechecker.set_form_submitted = function() {
M.core_formchangechecker.stateinformation.formsubmitted = 1;
}
};

/**
* Attempt to determine whether the form has been modified in any way and
Expand All @@ -126,7 +119,8 @@ YUI.add('moodle-core-formchangechecker',
* @return Integer 1 is the form is dirty; 0 if not
*/
M.core_formchangechecker.get_form_dirty_state = function() {
var state = M.core_formchangechecker.stateinformation;
var state = M.core_formchangechecker.stateinformation,
editor;

// If the form was submitted, then return a non-dirty state
if (state.formsubmitted) {
Expand All @@ -141,16 +135,16 @@ YUI.add('moodle-core-formchangechecker',
// If a field has been focused and changed, but still has focus then the browser won't fire the
// onChange event. We check for this eventuality here
if (state.focused_element) {
if (state.focused_element.element.get('value') != state.focused_element.initial_value) {
if (state.focused_element.element.get('value') !== state.focused_element.initial_value) {
return 1;
}
}

// Handle TinyMCE editor instances
// We can't add a listener in the initializer as the editors may not have been created by that point
// so we do so here instead
if (typeof tinyMCE != 'undefined') {
for (var editor in tinyMCE.editors) {
if (typeof tinyMCE !== 'undefined') {
for (editor in tinyMCE.editors) {
if (tinyMCE.editors[editor].isDirty()) {
return 1;
}
Expand Down

0 comments on commit d7d68b0

Please sign in to comment.