mirrored from git://git.moodle.org/moodle.git
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-31315 Ask before moving away from a modified form
- Loading branch information
Andrew Robert Nicols
committed
Feb 9, 2012
1 parent
216f6d8
commit 00e8d08
Showing
6 changed files
with
149 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
YUI.add('moodle-core-formslib', | ||
function(Y) { | ||
// The CSS selectors we use | ||
var CSS = { | ||
}; | ||
|
||
var FORMSLIBNAME = 'core-formslib'; | ||
|
||
var FORMSLIB = function() { | ||
FORMSLIB.superclass.constructor.apply(this, arguments); | ||
} | ||
|
||
Y.extend(FORMSLIB, Y.Base, { | ||
/** | ||
* Initialize the module | ||
*/ | ||
initializer : function(config) { | ||
var formid = 'form#' + this.get('formid'); | ||
|
||
// Add change events to the form elements | ||
Y.all(formid + ' input').on('change', M.util.set_form_changed, this); | ||
Y.all(formid + ' textarea').on('change', M.util.set_form_changed, this); | ||
Y.all(formid + ' select').on('change', M.util.set_form_changed, this); | ||
|
||
// We need any submit buttons on the form to set the submitted flag | ||
Y.one(formid).on('submit', M.util.set_form_submitted, this); | ||
|
||
// YUI doesn't support onbeforeunload properly so we must use the DOM to set the onbeforeunload. As | ||
// a result, the has_changed must stay in the DOM too | ||
window.onbeforeunload = M.util.report_form_dirty_state; | ||
}, | ||
|
||
/** | ||
* Unset the form dirty state and also set the form submitted flag to true | ||
*/ | ||
unset_changed : function(e) { | ||
M.util.set_form_changed(); | ||
} | ||
}, | ||
{ | ||
NAME : FORMSLIBNAME, | ||
ATTRS : { | ||
formid : { | ||
'value' : '' | ||
} | ||
} | ||
} | ||
); | ||
|
||
M.core = M.core || {}; | ||
M.core.init_formslib = function(config) { | ||
return new FORMSLIB(config); | ||
} | ||
|
||
}, | ||
'@VERSION@', { | ||
requires : ['base'] | ||
} | ||
); |