]> source.dussan.org Git - jquery.git/commitdiff
Updated formatting for the change/submit special event logic. Also switched the funct...
authorjeresig <jeresig@gmail.com>
Tue, 9 Feb 2010 04:28:15 +0000 (23:28 -0500)
committerjeresig <jeresig@gmail.com>
Tue, 9 Feb 2010 04:28:15 +0000 (23:28 -0500)
src/event.js

index 2fda802545f1e73f683a515ecc6814c9c285c149..6fe8a5b15b20a7d10d0937a3e66a55195f2b5287 100644 (file)
@@ -652,64 +652,66 @@ jQuery.each({
 // submit delegation
 if ( !jQuery.support.submitBubbles ) {
 
-jQuery.event.special.submit = {
-       setup: function( data, namespaces ) {
-               if ( this.nodeName.toLowerCase() !== "form" ) {
-                       jQuery.event.add(this, "click.specialSubmit", function( e ) {
-                               var elem = e.target, type = elem.type;
-
-                               if ( (type === "submit" || type === "image") && jQuery( elem ).closest("form").length ) {
-                                       return trigger( "submit", this, arguments );
-                               }
-                       });
+       jQuery.event.special.submit = {
+               setup: function( data, namespaces ) {
+                       if ( this.nodeName.toLowerCase() !== "form" ) {
+                               jQuery.event.add(this, "click.specialSubmit", function( e ) {
+                                       var elem = e.target, type = elem.type;
+
+                                       if ( (type === "submit" || type === "image") && jQuery( elem ).closest("form").length ) {
+                                               return trigger( "submit", this, arguments );
+                                       }
+                               });
         
-                       jQuery.event.add(this, "keypress.specialSubmit", function( e ) {
-                               var elem = e.target, type = elem.type;
+                               jQuery.event.add(this, "keypress.specialSubmit", function( e ) {
+                                       var elem = e.target, type = elem.type;
 
-                               if ( (type === "text" || type === "password") && jQuery( elem ).closest("form").length && e.keyCode === 13 ) {
-                                       return trigger( "submit", this, arguments );
-                               }
-                       });
+                                       if ( (type === "text" || type === "password") && jQuery( elem ).closest("form").length && e.keyCode === 13 ) {
+                                               return trigger( "submit", this, arguments );
+                                       }
+                               });
 
-               } else {
-                       return false;
-               }
-       },
+                       } else {
+                               return false;
+                       }
+               },
 
-       teardown: function( namespaces ) {
-               jQuery.event.remove( this, "click.specialSubmit" );
-               jQuery.event.remove( this, "keypress.specialSubmit" );
-       }
-};
+               teardown: function( namespaces ) {
+                       jQuery.event.remove( this, "click.specialSubmit" );
+                       jQuery.event.remove( this, "keypress.specialSubmit" );
+               }
+       };
 
 }
 
 // change delegation, happens here so we have bind.
 if ( !jQuery.support.changeBubbles ) {
 
-var formElems = /textarea|input|select/i;
+       var formElems = /textarea|input|select/i,
 
-function getVal( elem ) {
-       var type = elem.type, val = elem.value;
+       changeFilters,
 
-       if ( type === "radio" || type === "checkbox" ) {
-               val = elem.checked;
+       getVal = function( elem ) {
+               var type = elem.type, val = elem.value;
 
-       } else if ( type === "select-multiple" ) {
-               val = elem.selectedIndex > -1 ?
-                       jQuery.map( elem.options, function( elem ) {
-                               return elem.selected;
-                       }).join("-") :
-                       "";
+               if ( type === "radio" || type === "checkbox" ) {
+                       val = elem.checked;
 
-       } else if ( elem.nodeName.toLowerCase() === "select" ) {
-               val = elem.selectedIndex;
-       }
+               } else if ( type === "select-multiple" ) {
+                       val = elem.selectedIndex > -1 ?
+                               jQuery.map( elem.options, function( elem ) {
+                                       return elem.selected;
+                               }).join("-") :
+                               "";
 
-       return val;
-}
+               } else if ( elem.nodeName.toLowerCase() === "select" ) {
+                       val = elem.selectedIndex;
+               }
+
+               return val;
+       },
 
-function testChange( e ) {
+       testChange = function testChange( e ) {
                var elem = e.target, data, val;
 
                if ( !formElems.test( elem.nodeName ) || elem.readOnly ) {
@@ -732,60 +734,59 @@ function testChange( e ) {
                        e.type = "change";
                        return jQuery.event.trigger( e, arguments[1], elem );
                }
-}
+       };
 
-jQuery.event.special.change = {
-       filters: {
-               focusout: testChange, 
+       jQuery.event.special.change = {
+               filters: {
+                       focusout: testChange, 
 
-               click: function( e ) {
-                       var elem = e.target, type = elem.type;
+                       click: function( e ) {
+                               var elem = e.target, type = elem.type;
 
-                       if ( type === "radio" || type === "checkbox" || elem.nodeName.toLowerCase() === "select" ) {
-                               return testChange.call( this, e );
-                       }
-               },
+                               if ( type === "radio" || type === "checkbox" || elem.nodeName.toLowerCase() === "select" ) {
+                                       return testChange.call( this, e );
+                               }
+                       },
+
+                       // Change has to be called before submit
+                       // Keydown will be called before keypress, which is used in submit-event delegation
+                       keydown: function( e ) {
+                               var elem = e.target, type = elem.type;
 
-               // Change has to be called before submit
-               // Keydown will be called before keypress, which is used in submit-event delegation
-               keydown: function( e ) {
-                       var elem = e.target, type = elem.type;
+                               if ( (e.keyCode === 13 && elem.nodeName.toLowerCase() !== "textarea") ||
+                                       (e.keyCode === 32 && (type === "checkbox" || type === "radio")) ||
+                                       type === "select-multiple" ) {
+                                       return testChange.call( this, e );
+                               }
+                       },
 
-                       if ( (e.keyCode === 13 && elem.nodeName.toLowerCase() !== "textarea") ||
-                               (e.keyCode === 32 && (type === "checkbox" || type === "radio")) ||
-                               type === "select-multiple" ) {
-                               return testChange.call( this, e );
+                       // Beforeactivate happens also before the previous element is blurred
+                       // with this event you can't trigger a change event, but you can store
+                       // information/focus[in] is not needed anymore
+                       beforeactivate: function( e ) {
+                               var elem = e.target;
+                               jQuery.data( elem, "_change_data", getVal(elem) );
                        }
                },
 
-               // Beforeactivate happens also before the previous element is blurred
-               // with this event you can't trigger a change event, but you can store
-               // information/focus[in] is not needed anymore
-               beforeactivate: function( e ) {
-                       var elem = e.target;
-                       jQuery.data( elem, "_change_data", getVal(elem) );
-               }
-       },
+               setup: function( data, namespaces ) {
+                       for ( var type in changeFilters ) {
+                               jQuery.event.add( this, type + ".specialChange", changeFilters[type] );
+                       }
 
-       setup: function( data, namespaces ) {
-               for ( var type in changeFilters ) {
-                       jQuery.event.add( this, type + ".specialChange", changeFilters[type] );
-               }
+                       return formElems.test( this.nodeName );
+               },
 
-               return formElems.test( this.nodeName );
-       },
+               teardown: function( namespaces ) {
+                       for ( var type in changeFilters ) {
+                               jQuery.event.remove( this, type + ".specialChange", changeFilters[type] );
+                       }
 
-       teardown: function( namespaces ) {
-               for ( var type in changeFilters ) {
-                       jQuery.event.remove( this, type + ".specialChange", changeFilters[type] );
+                       return formElems.test( this.nodeName );
                }
+       };
 
-               return formElems.test( this.nodeName );
-       }
-};
-
-var changeFilters = jQuery.event.special.change.filters;
-
+       changeFilters = jQuery.event.special.change.filters;
 }
 
 function trigger( type, elem, args ) {