A good old fashioned events with new skool handling. Shortcuts exist for:
Registers a callback function to a DOM event on the element collection.
x$( 'button' ).on( type, fn );
or
x$( 'button' ).click( fn );
String
is the event to subscribe (e.g. load, click, touchstart, etc).Function
is a callback function to execute when the event is fired.x$( 'button' ).on( 'click', function(e) {
alert('hey that tickles!');
});
or
x$(window).load(function(e) {
x$('.save').touchstart( function(evt) { alert('tee hee!'); }).css(background:'grey');
});
Unregisters a specific callback, or if no specific callback is passed in, unregisters all event callbacks of a specific type.
Unregister the given function, for the given type, on all button elements:
x$( 'button' ).un( type, fn );
Unregisters all callbacks of the given type, on all button elements:
x$( 'button' ).un( type );
String
is the event to unsubscribe (e.g. load, click, touchstart, etc).Function
is the callback function to unsubscribe (optional).// First, create a click event that display an alert message
x$('button').on('click', function() {
alert('hi!');
});
// Now unsubscribe all functions that response to click on all button elements
x$('button').un('click');
or
var greeting = function() { alert('yo!'); };
x$('button').on('click', greeting);
x$('button').on('click', function() {
alert('hi!');
});
// When any button is clicked, the 'hi!' message will fire, but not the 'yo!' message.
x$('button').un('click', greeting);
Triggers a specific event on the xui collection.
x$( selector ).fire( type, data );
String
is the event to fire (e.g. load, click, touchstart, etc).Object
is a JSON object to use as the event's data
property.x$('button#reset').fire('click', { died:true });
x$('.target').fire('touchstart');
Event handler for when the DOM is ready. Thank you domready!
x$.ready(handler);
Function
event handler to be attached to the "dom is ready" event.x$.ready(function() { alert('mah doms are ready'); });
xui.ready(function() { console.log('ready, set, go!'); });