Last active
August 29, 2015 14:20
-
-
Save arschmitz/b3e95ebf05067811734c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| ( function( factory ) { | |
| if ( typeof define === "function" && define.amd ) { | |
| // AMD. Register as an anonymous module. | |
| define( [ | |
| "jquery" | |
| ], factory ); | |
| } else { | |
| // Browser globals | |
| factory( jQuery ); | |
| } | |
| }( function( $ ) { | |
| function resetHandler() { | |
| var form = $( this ); | |
| // Wait for the form reset to actually happen before refreshing | |
| setTimeout( function() { | |
| var instances = form.data( "widget-instances" ); | |
| $.each( instances, function( instance ) { | |
| this.refresh(); | |
| } ); | |
| } ); | |
| }; | |
| return $.ui.formResetMixin = { | |
| _bindFormResetHandler: function() { | |
| this.form = this.element.form(); | |
| if ( !this.form.length ) { | |
| return; | |
| } | |
| var instances = this.form.data( "widget-instances" ) || []; | |
| if ( !instances.length ) { | |
| // We don't use _on() here because we use a single event handler per form | |
| this.form.on( "reset.widgetInstances", resetHandler ); | |
| } | |
| instances.push( this ); | |
| this.form.data( "widget-instances", instances ); | |
| }, | |
| _unbindFormResetHandler: function() { | |
| if ( this.form.length ) { | |
| var instances = this.form.data( "widget-instances" ); | |
| instances.splice( $.inArray( this, instances ), 1 ); | |
| if ( instances.length ) { | |
| this.form.data( "widget-instances", instances ); | |
| } else { | |
| this.form | |
| .removeData( dataKey ) | |
| .off( "reset.widgetInstances" ); | |
| } | |
| } | |
| } | |
| }; | |
| } ) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment