Merge branch 'MDL-35673-master' of git://git.luns.net.uk/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2012-10-02 09:55:20 +02:00
commit 2aeb0fbb60

View file

@ -11,6 +11,10 @@ YUI.add('moodle-core-formchangechecker',
} }
Y.extend(FORMCHANGECHECKER, Y.Base, { Y.extend(FORMCHANGECHECKER, Y.Base, {
// The delegated listeners we need to detach after the initial value has been stored once
initialvaluelisteners : [],
/** /**
* Initialize the module * Initialize the module
*/ */
@ -18,14 +22,15 @@ YUI.add('moodle-core-formchangechecker',
var formid = 'form#' + this.get('formid'); var formid = 'form#' + this.get('formid');
// Add change events to the form elements // Add change events to the form elements
Y.all(formid + ' input').once('change', M.core_formchangechecker.set_form_changed, this); var currentform = Y.one(formid);
Y.all(formid + ' textarea').once('change', M.core_formchangechecker.set_form_changed, this); currentform.delegate('change', M.core_formchangechecker.set_form_changed, 'input', this);
Y.all(formid + ' select').once('change', M.core_formchangechecker.set_form_changed, this); currentform.delegate('change', M.core_formchangechecker.set_form_changed, 'textarea', this);
currentform.delegate('change', M.core_formchangechecker.set_form_changed, 'select', this);
// Add a focus event to check for changes which are made without triggering a change event // Add a focus event to check for changes which are made without triggering a change event
Y.all(formid + ' input').on('focus', this.store_initial_value, this); this.initialvaluelisteners.push(currentform.delegate('focus', this.store_initial_value, 'input', this));
Y.all(formid + ' textarea').on('focus', this.store_initial_value, this); this.initialvaluelisteners.push(currentform.delegate('focus', this.store_initial_value, 'textarea', this));
Y.all(formid + ' select').on('focus', this.store_initial_value, this); this.initialvaluelisteners.push(currentform.delegate('focus', this.store_initial_value, 'select', this));
// We need any submit buttons on the form to set the submitted flag // We need any submit buttons on the form to set the submitted flag
Y.one(formid).on('submit', M.core_formchangechecker.set_form_submitted, this); Y.one(formid).on('submit', M.core_formchangechecker.set_form_submitted, this);
@ -52,9 +57,12 @@ YUI.add('moodle-core-formchangechecker',
// we no longer need to call this function // we no longer need to call this function
var formid = 'form#' + this.get('formid'); var formid = 'form#' + this.get('formid');
Y.all(formid + ' input').detach('focus', this.store_initial_value, this); // Detach all listen events to prevent duplicate initial value setting
Y.all(formid + ' textarea').detach('focus', this.store_initial_value, this); var thisevent;
Y.all(formid + ' select').detach('focus', this.store_initial_value, this); while (thisevent = this.initialvaluelisteners.shift()) {
thisevent.detach();
}
return; return;
} }
@ -176,6 +184,6 @@ YUI.add('moodle-core-formchangechecker',
}; };
}, },
'@VERSION@', { '@VERSION@', {
requires : ['base'] requires : ['base', 'event-focus']
} }
); );