2015-10-26 16:52:42 +00:00
|
|
|
/*!
|
|
|
|
* jQuery UI Form Reset Mixin @VERSION
|
|
|
|
* http://jqueryui.com
|
|
|
|
*
|
2022-07-19 07:36:55 +00:00
|
|
|
* Copyright OpenJS Foundation and other contributors
|
2015-10-26 16:52:42 +00:00
|
|
|
* Released under the MIT license.
|
|
|
|
* http://jquery.org/license
|
|
|
|
*/
|
|
|
|
|
|
|
|
//>>label: Form Reset Mixin
|
|
|
|
//>>group: Core
|
|
|
|
//>>description: Refresh input widgets when their form is reset
|
|
|
|
//>>docs: http://api.jqueryui.com/form-reset-mixin/
|
|
|
|
|
2015-04-23 19:11:41 +00:00
|
|
|
( function( factory ) {
|
2021-06-06 22:58:12 +00:00
|
|
|
"use strict";
|
|
|
|
|
2015-04-23 19:11:41 +00:00
|
|
|
if ( typeof define === "function" && define.amd ) {
|
|
|
|
|
|
|
|
// AMD. Register as an anonymous module.
|
|
|
|
define( [
|
|
|
|
"jquery",
|
2015-07-16 13:14:58 +00:00
|
|
|
"./form",
|
2015-07-15 22:26:12 +00:00
|
|
|
"./version"
|
2015-04-23 19:11:41 +00:00
|
|
|
], factory );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Browser globals
|
|
|
|
factory( jQuery );
|
|
|
|
}
|
2021-06-06 22:58:12 +00:00
|
|
|
} )( function( $ ) {
|
|
|
|
"use strict";
|
2015-04-23 19:11:41 +00:00
|
|
|
|
|
|
|
return $.ui.formResetMixin = {
|
|
|
|
_formResetHandler: function() {
|
|
|
|
var form = $( this );
|
|
|
|
|
|
|
|
// Wait for the form reset to actually happen before refreshing
|
|
|
|
setTimeout( function() {
|
|
|
|
var instances = form.data( "ui-form-reset-instances" );
|
|
|
|
$.each( instances, function() {
|
|
|
|
this.refresh();
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
_bindFormResetHandler: function() {
|
2016-10-11 13:59:32 +00:00
|
|
|
this.form = this.element._form();
|
2015-04-23 19:11:41 +00:00
|
|
|
if ( !this.form.length ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var instances = this.form.data( "ui-form-reset-instances" ) || [];
|
|
|
|
if ( !instances.length ) {
|
|
|
|
|
|
|
|
// We don't use _on() here because we use a single event handler per form
|
|
|
|
this.form.on( "reset.ui-form-reset", this._formResetHandler );
|
|
|
|
}
|
|
|
|
instances.push( this );
|
|
|
|
this.form.data( "ui-form-reset-instances", instances );
|
|
|
|
},
|
|
|
|
|
|
|
|
_unbindFormResetHandler: function() {
|
|
|
|
if ( !this.form.length ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var instances = this.form.data( "ui-form-reset-instances" );
|
|
|
|
instances.splice( $.inArray( this, instances ), 1 );
|
|
|
|
if ( instances.length ) {
|
|
|
|
this.form.data( "ui-form-reset-instances", instances );
|
|
|
|
} else {
|
|
|
|
this.form
|
|
|
|
.removeData( "ui-form-reset-instances" )
|
|
|
|
.off( "reset.ui-form-reset" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-06 22:58:12 +00:00
|
|
|
} );
|