Added $().data(), $().removeData(), and .bind("click!"). .data() and .removeData() handle namespaced data, .data() triggers a "set-KEY" event on all modified elements, and .bind("click!") only triggers a click (and no namespaced events).
This commit is contained in:
parent
25c76232c6
commit
77da94552e
3 changed files with 79 additions and 1 deletions
20
src/core.js
20
src/core.js
|
@ -477,6 +477,26 @@ jQuery.fn = jQuery.prototype = {
|
|||
andSelf: function() {
|
||||
return this.add( this.prevObject );
|
||||
},
|
||||
|
||||
data: function( key, value ){
|
||||
if ( value == null ) {
|
||||
if ( this.length ) {
|
||||
var data = jQuery.data( this[0], key );
|
||||
return data == null ?
|
||||
jQuery.data( this[0], key.split(".")[0] ) :
|
||||
data;
|
||||
}
|
||||
} else
|
||||
return this.trigger("set-" + key + "!", [value]).each(function(){
|
||||
jQuery.data( this, key, value );
|
||||
});
|
||||
},
|
||||
|
||||
removeData: function( key ){
|
||||
return this.each(function(){
|
||||
jQuery.removeData( this, key );
|
||||
});
|
||||
},
|
||||
|
||||
domManip: function( args, table, reverse, callback ) {
|
||||
var clone = this.length > 1, elems;
|
||||
|
|
|
@ -169,6 +169,11 @@ jQuery.event = {
|
|||
// Clone the incoming data, if any
|
||||
data = jQuery.makeArray(data || []);
|
||||
|
||||
if ( type.indexOf("!") >= 0 ) {
|
||||
type = type.slice(0, -1);
|
||||
var exclusive = true;
|
||||
}
|
||||
|
||||
// Handle a global trigger
|
||||
if ( !elem ) {
|
||||
// Only trigger if we've ever bound an event for it
|
||||
|
@ -191,6 +196,8 @@ jQuery.event = {
|
|||
|
||||
// Enforce the right trigger type
|
||||
data[0].type = type;
|
||||
if ( exclusive )
|
||||
data[0].exclusive = true;
|
||||
|
||||
// Trigger the event
|
||||
if ( jQuery.isFunction( jQuery.data(elem, "handle") ) )
|
||||
|
@ -250,7 +257,7 @@ jQuery.event = {
|
|||
args[0].data = handler.data;
|
||||
|
||||
// Filter the functions by class
|
||||
if ( !parts[1] || handler.type == parts[1] ) {
|
||||
if ( !parts[1] && !event.exclusive || handler.type == parts[1] ) {
|
||||
var ret = handler.apply( this, args );
|
||||
|
||||
if ( val !== false )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue