Debian Codegraph @

ui/form-reset-mixin.js

raw symbols SCIP
1 /*!
2 * jQuery UI Form Reset Mixin 1.14.2
3 * https://jqueryui.com
4 *
5 * Copyright OpenJS Foundation and other contributors
6 * Released under the MIT license.
7 * https://jquery.org/license
8 */
9
10 //>>label: Form Reset Mixin
11 //>>group: Core
12 //>>description: Refresh input widgets when their form is reset
13 //>>docs: https://api.jqueryui.com/form-reset-mixin/
14
15 ( function( factory ) {
16 "use strict";
17
18 if ( typeof define === "function" && define.amd ) {
19
20 // AMD. Register as an anonymous module.
21 define( [
22 "jquery",
23 "./version"
24 ], factory );
25 } else {
26
27 // Browser globals
28 factory( jQuery );
29 }
30 } )( function( $ ) {
31 "use strict";
32
33 return $.ui.formResetMixin = {
34 _formResetHandler: function() {
35 var form = $( this );
36
37 // Wait for the form reset to actually happen before refreshing
38 setTimeout( function() {
39 var instances = form.data( "ui-form-reset-instances" );
40 $.each( instances, function() {
41 this.refresh();
42 } );
43 } );
44 },
45
46 _bindFormResetHandler: function() {
47 this.form = $( this.element.prop( "form" ) );
48 if ( !this.form.length ) {
49 return;
50 }
51
52 var instances = this.form.data( "ui-form-reset-instances" ) || [];
53 if ( !instances.length ) {
54
55 // We don't use _on() here because we use a single event handler per form
56 this.form.on( "reset.ui-form-reset", this._formResetHandler );
57 }
58 instances.push( this );
59 this.form.data( "ui-form-reset-instances", instances );
60 },
61
62 _unbindFormResetHandler: function() {
63 if ( !this.form.length ) {
64 return;
65 }
66
67 var instances = this.form.data( "ui-form-reset-instances" );
68 instances.splice( $.inArray( this, instances ), 1 );
69 if ( instances.length ) {
70 this.form.data( "ui-form-reset-instances", instances );
71 } else {
72 this.form
73 .removeData( "ui-form-reset-instances" )
74 .off( "reset.ui-form-reset" );
75 }
76 }
77 };
78
79 } );