@@ 4844-4961 (lines=118) @@ | ||
4841 | ||
4842 | global: {}, |
|
4843 | ||
4844 | add: function( elem, types, handler, data, selector ) { |
|
4845 | var tmp, events, t, handleObjIn, |
|
4846 | special, eventHandle, handleObj, |
|
4847 | handlers, type, namespaces, origType, |
|
4848 | elemData = jQuery._data( elem ); |
|
4849 | ||
4850 | // Don't attach events to noData or text/comment nodes (but allow plain objects) |
|
4851 | if ( !elemData ) { |
|
4852 | return; |
|
4853 | } |
|
4854 | ||
4855 | // Caller can pass in an object of custom data in lieu of the handler |
|
4856 | if ( handler.handler ) { |
|
4857 | handleObjIn = handler; |
|
4858 | handler = handleObjIn.handler; |
|
4859 | selector = handleObjIn.selector; |
|
4860 | } |
|
4861 | ||
4862 | // Make sure that the handler has a unique ID, used to find/remove it later |
|
4863 | if ( !handler.guid ) { |
|
4864 | handler.guid = jQuery.guid++; |
|
4865 | } |
|
4866 | ||
4867 | // Init the element's event structure and main handler, if this is the first |
|
4868 | if ( !( events = elemData.events ) ) { |
|
4869 | events = elemData.events = {}; |
|
4870 | } |
|
4871 | if ( !( eventHandle = elemData.handle ) ) { |
|
4872 | eventHandle = elemData.handle = function( e ) { |
|
4873 | ||
4874 | // Discard the second event of a jQuery.event.trigger() and |
|
4875 | // when an event is called after a page has unloaded |
|
4876 | return typeof jQuery !== "undefined" && |
|
4877 | ( !e || jQuery.event.triggered !== e.type ) ? |
|
4878 | jQuery.event.dispatch.apply( eventHandle.elem, arguments ) : |
|
4879 | undefined; |
|
4880 | }; |
|
4881 | ||
4882 | // Add elem as a property of the handle fn to prevent a memory leak |
|
4883 | // with IE non-native events |
|
4884 | eventHandle.elem = elem; |
|
4885 | } |
|
4886 | ||
4887 | // Handle multiple events separated by a space |
|
4888 | types = ( types || "" ).match( rnotwhite ) || [ "" ]; |
|
4889 | t = types.length; |
|
4890 | while ( t-- ) { |
|
4891 | tmp = rtypenamespace.exec( types[ t ] ) || []; |
|
4892 | type = origType = tmp[ 1 ]; |
|
4893 | namespaces = ( tmp[ 2 ] || "" ).split( "." ).sort(); |
|
4894 | ||
4895 | // There *must* be a type, no attaching namespace-only handlers |
|
4896 | if ( !type ) { |
|
4897 | continue; |
|
4898 | } |
|
4899 | ||
4900 | // If event changes its type, use the special event handlers for the changed type |
|
4901 | special = jQuery.event.special[ type ] || {}; |
|
4902 | ||
4903 | // If selector defined, determine special event api type, otherwise given type |
|
4904 | type = ( selector ? special.delegateType : special.bindType ) || type; |
|
4905 | ||
4906 | // Update special based on newly reset type |
|
4907 | special = jQuery.event.special[ type ] || {}; |
|
4908 | ||
4909 | // handleObj is passed to all event handlers |
|
4910 | handleObj = jQuery.extend( { |
|
4911 | type: type, |
|
4912 | origType: origType, |
|
4913 | data: data, |
|
4914 | handler: handler, |
|
4915 | guid: handler.guid, |
|
4916 | selector: selector, |
|
4917 | needsContext: selector && jQuery.expr.match.needsContext.test( selector ), |
|
4918 | namespace: namespaces.join( "." ) |
|
4919 | }, handleObjIn ); |
|
4920 | ||
4921 | // Init the event handler queue if we're the first |
|
4922 | if ( !( handlers = events[ type ] ) ) { |
|
4923 | handlers = events[ type ] = []; |
|
4924 | handlers.delegateCount = 0; |
|
4925 | ||
4926 | // Only use addEventListener/attachEvent if the special events handler returns false |
|
4927 | if ( !special.setup || |
|
4928 | special.setup.call( elem, data, namespaces, eventHandle ) === false ) { |
|
4929 | ||
4930 | // Bind the global event handler to the element |
|
4931 | if ( elem.addEventListener ) { |
|
4932 | elem.addEventListener( type, eventHandle, false ); |
|
4933 | ||
4934 | } else if ( elem.attachEvent ) { |
|
4935 | elem.attachEvent( "on" + type, eventHandle ); |
|
4936 | } |
|
4937 | } |
|
4938 | } |
|
4939 | ||
4940 | if ( special.add ) { |
|
4941 | special.add.call( elem, handleObj ); |
|
4942 | ||
4943 | if ( !handleObj.handler.guid ) { |
|
4944 | handleObj.handler.guid = handler.guid; |
|
4945 | } |
|
4946 | } |
|
4947 | ||
4948 | // Add to the element's handler list, delegates in front |
|
4949 | if ( selector ) { |
|
4950 | handlers.splice( handlers.delegateCount++, 0, handleObj ); |
|
4951 | } else { |
|
4952 | handlers.push( handleObj ); |
|
4953 | } |
|
4954 | ||
4955 | // Keep track of which events have ever been used, for event optimization |
|
4956 | jQuery.event.global[ type ] = true; |
|
4957 | } |
|
4958 | ||
4959 | // Nullify elem to prevent memory leaks in IE |
|
4960 | elem = null; |
|
4961 | }, |
|
4962 | ||
4963 | // Detach an event or set of events from an element |
|
4964 | remove: function( elem, types, handler, selector, mappedTypes ) { |
@@ 4510-4616 (lines=107) @@ | ||
4507 | ||
4508 | global: {}, |
|
4509 | ||
4510 | add: function( elem, types, handler, data, selector ) { |
|
4511 | ||
4512 | var handleObjIn, eventHandle, tmp, |
|
4513 | events, t, handleObj, |
|
4514 | special, handlers, type, namespaces, origType, |
|
4515 | elemData = dataPriv.get( elem ); |
|
4516 | ||
4517 | // Don't attach events to noData or text/comment nodes (but allow plain objects) |
|
4518 | if ( !elemData ) { |
|
4519 | return; |
|
4520 | } |
|
4521 | ||
4522 | // Caller can pass in an object of custom data in lieu of the handler |
|
4523 | if ( handler.handler ) { |
|
4524 | handleObjIn = handler; |
|
4525 | handler = handleObjIn.handler; |
|
4526 | selector = handleObjIn.selector; |
|
4527 | } |
|
4528 | ||
4529 | // Make sure that the handler has a unique ID, used to find/remove it later |
|
4530 | if ( !handler.guid ) { |
|
4531 | handler.guid = jQuery.guid++; |
|
4532 | } |
|
4533 | ||
4534 | // Init the element's event structure and main handler, if this is the first |
|
4535 | if ( !( events = elemData.events ) ) { |
|
4536 | events = elemData.events = {}; |
|
4537 | } |
|
4538 | if ( !( eventHandle = elemData.handle ) ) { |
|
4539 | eventHandle = elemData.handle = function( e ) { |
|
4540 | ||
4541 | // Discard the second event of a jQuery.event.trigger() and |
|
4542 | // when an event is called after a page has unloaded |
|
4543 | return typeof jQuery !== "undefined" && jQuery.event.triggered !== e.type ? |
|
4544 | jQuery.event.dispatch.apply( elem, arguments ) : undefined; |
|
4545 | }; |
|
4546 | } |
|
4547 | ||
4548 | // Handle multiple events separated by a space |
|
4549 | types = ( types || "" ).match( rnotwhite ) || [ "" ]; |
|
4550 | t = types.length; |
|
4551 | while ( t-- ) { |
|
4552 | tmp = rtypenamespace.exec( types[ t ] ) || []; |
|
4553 | type = origType = tmp[ 1 ]; |
|
4554 | namespaces = ( tmp[ 2 ] || "" ).split( "." ).sort(); |
|
4555 | ||
4556 | // There *must* be a type, no attaching namespace-only handlers |
|
4557 | if ( !type ) { |
|
4558 | continue; |
|
4559 | } |
|
4560 | ||
4561 | // If event changes its type, use the special event handlers for the changed type |
|
4562 | special = jQuery.event.special[ type ] || {}; |
|
4563 | ||
4564 | // If selector defined, determine special event api type, otherwise given type |
|
4565 | type = ( selector ? special.delegateType : special.bindType ) || type; |
|
4566 | ||
4567 | // Update special based on newly reset type |
|
4568 | special = jQuery.event.special[ type ] || {}; |
|
4569 | ||
4570 | // handleObj is passed to all event handlers |
|
4571 | handleObj = jQuery.extend( { |
|
4572 | type: type, |
|
4573 | origType: origType, |
|
4574 | data: data, |
|
4575 | handler: handler, |
|
4576 | guid: handler.guid, |
|
4577 | selector: selector, |
|
4578 | needsContext: selector && jQuery.expr.match.needsContext.test( selector ), |
|
4579 | namespace: namespaces.join( "." ) |
|
4580 | }, handleObjIn ); |
|
4581 | ||
4582 | // Init the event handler queue if we're the first |
|
4583 | if ( !( handlers = events[ type ] ) ) { |
|
4584 | handlers = events[ type ] = []; |
|
4585 | handlers.delegateCount = 0; |
|
4586 | ||
4587 | // Only use addEventListener if the special events handler returns false |
|
4588 | if ( !special.setup || |
|
4589 | special.setup.call( elem, data, namespaces, eventHandle ) === false ) { |
|
4590 | ||
4591 | if ( elem.addEventListener ) { |
|
4592 | elem.addEventListener( type, eventHandle ); |
|
4593 | } |
|
4594 | } |
|
4595 | } |
|
4596 | ||
4597 | if ( special.add ) { |
|
4598 | special.add.call( elem, handleObj ); |
|
4599 | ||
4600 | if ( !handleObj.handler.guid ) { |
|
4601 | handleObj.handler.guid = handler.guid; |
|
4602 | } |
|
4603 | } |
|
4604 | ||
4605 | // Add to the element's handler list, delegates in front |
|
4606 | if ( selector ) { |
|
4607 | handlers.splice( handlers.delegateCount++, 0, handleObj ); |
|
4608 | } else { |
|
4609 | handlers.push( handleObj ); |
|
4610 | } |
|
4611 | ||
4612 | // Keep track of which events have ever been used, for event optimization |
|
4613 | jQuery.event.global[ type ] = true; |
|
4614 | } |
|
4615 | ||
4616 | }, |
|
4617 | ||
4618 | // Detach an event or set of events from an element |
|
4619 | remove: function( elem, types, handler, selector, mappedTypes ) { |
@@ 4062-4165 (lines=104) @@ | ||
4059 | ||
4060 | global: {}, |
|
4061 | ||
4062 | add: function( elem, types, handler, data, selector ) { |
|
4063 | ||
4064 | var handleObjIn, eventHandle, tmp, |
|
4065 | events, t, handleObj, |
|
4066 | special, handlers, type, namespaces, origType, |
|
4067 | elemData = data_priv.get( elem ); |
|
4068 | ||
4069 | // Don't attach events to noData or text/comment nodes (but allow plain objects) |
|
4070 | if ( !elemData ) { |
|
4071 | return; |
|
4072 | } |
|
4073 | ||
4074 | // Caller can pass in an object of custom data in lieu of the handler |
|
4075 | if ( handler.handler ) { |
|
4076 | handleObjIn = handler; |
|
4077 | handler = handleObjIn.handler; |
|
4078 | selector = handleObjIn.selector; |
|
4079 | } |
|
4080 | ||
4081 | // Make sure that the handler has a unique ID, used to find/remove it later |
|
4082 | if ( !handler.guid ) { |
|
4083 | handler.guid = jQuery.guid++; |
|
4084 | } |
|
4085 | ||
4086 | // Init the element's event structure and main handler, if this is the first |
|
4087 | if ( !(events = elemData.events) ) { |
|
4088 | events = elemData.events = {}; |
|
4089 | } |
|
4090 | if ( !(eventHandle = elemData.handle) ) { |
|
4091 | eventHandle = elemData.handle = function( e ) { |
|
4092 | // Discard the second event of a jQuery.event.trigger() and |
|
4093 | // when an event is called after a page has unloaded |
|
4094 | return typeof jQuery !== strundefined && jQuery.event.triggered !== e.type ? |
|
4095 | jQuery.event.dispatch.apply( elem, arguments ) : undefined; |
|
4096 | }; |
|
4097 | } |
|
4098 | ||
4099 | // Handle multiple events separated by a space |
|
4100 | types = ( types || "" ).match( rnotwhite ) || [ "" ]; |
|
4101 | t = types.length; |
|
4102 | while ( t-- ) { |
|
4103 | tmp = rtypenamespace.exec( types[t] ) || []; |
|
4104 | type = origType = tmp[1]; |
|
4105 | namespaces = ( tmp[2] || "" ).split( "." ).sort(); |
|
4106 | ||
4107 | // There *must* be a type, no attaching namespace-only handlers |
|
4108 | if ( !type ) { |
|
4109 | continue; |
|
4110 | } |
|
4111 | ||
4112 | // If event changes its type, use the special event handlers for the changed type |
|
4113 | special = jQuery.event.special[ type ] || {}; |
|
4114 | ||
4115 | // If selector defined, determine special event api type, otherwise given type |
|
4116 | type = ( selector ? special.delegateType : special.bindType ) || type; |
|
4117 | ||
4118 | // Update special based on newly reset type |
|
4119 | special = jQuery.event.special[ type ] || {}; |
|
4120 | ||
4121 | // handleObj is passed to all event handlers |
|
4122 | handleObj = jQuery.extend({ |
|
4123 | type: type, |
|
4124 | origType: origType, |
|
4125 | data: data, |
|
4126 | handler: handler, |
|
4127 | guid: handler.guid, |
|
4128 | selector: selector, |
|
4129 | needsContext: selector && jQuery.expr.match.needsContext.test( selector ), |
|
4130 | namespace: namespaces.join(".") |
|
4131 | }, handleObjIn ); |
|
4132 | ||
4133 | // Init the event handler queue if we're the first |
|
4134 | if ( !(handlers = events[ type ]) ) { |
|
4135 | handlers = events[ type ] = []; |
|
4136 | handlers.delegateCount = 0; |
|
4137 | ||
4138 | // Only use addEventListener if the special events handler returns false |
|
4139 | if ( !special.setup || special.setup.call( elem, data, namespaces, eventHandle ) === false ) { |
|
4140 | if ( elem.addEventListener ) { |
|
4141 | elem.addEventListener( type, eventHandle, false ); |
|
4142 | } |
|
4143 | } |
|
4144 | } |
|
4145 | ||
4146 | if ( special.add ) { |
|
4147 | special.add.call( elem, handleObj ); |
|
4148 | ||
4149 | if ( !handleObj.handler.guid ) { |
|
4150 | handleObj.handler.guid = handler.guid; |
|
4151 | } |
|
4152 | } |
|
4153 | ||
4154 | // Add to the element's handler list, delegates in front |
|
4155 | if ( selector ) { |
|
4156 | handlers.splice( handlers.delegateCount++, 0, handleObj ); |
|
4157 | } else { |
|
4158 | handlers.push( handleObj ); |
|
4159 | } |
|
4160 | ||
4161 | // Keep track of which events have ever been used, for event optimization |
|
4162 | jQuery.event.global[ type ] = true; |
|
4163 | } |
|
4164 | ||
4165 | }, |
|
4166 | ||
4167 | // Detach an event or set of events from an element |
|
4168 | remove: function( elem, types, handler, selector, mappedTypes ) { |