QWiPS Javascript Library, v2

Using events

QWiPS Javascript Library mostly relies on jQuery's events implementation internally. It also provides two convenience functions:

When events are invoked by QWiPS Javascript Library, the internal method qwips.trigger() is used, which works exactly like jQuery(window).trigger(), but also triggers native browser events, appending Native to the eventType (example: "qwipAddedNative").

While we recommend using qwips.bind() and qwips.unbind(), you can bind to events in a number of ways:

//Bind using qwips.bind
qwips.bind(qwips.EV_QWIP_ADDED, function(ev, params) {
	console.log(params.qwip, params.pqbc);
});
//Bind to namespaced event using qwips.bind
qwips.bind(qwips.EV_QWIP_ADDED + '.MyListener', function(ev, params) {
	console.log(params.qwip, params.pqbc);
});
//Bind to multiple events using qwips.bind
qwips.bind({
	'qwipAdded' : function(ev, params) {
		console.log(params.qwip, params.pqbc);
	},
	'qwipShared' : function(ev, params) {
		console.log(params.token, params.count);
	}
});
//Bind using jQuery
jQuery(window).bind(qwips.EV_QWIP_ADDED, function(ev, params) {
	console.log(params.qwip, params.pqbc);
});

//Bind using native browser functions, mind that 'Native' is added to eventType
//Note: IE 6-8 are not supported
window.addEventListener(qwips.EV_QWIP_ADDED + 'Native', function(ev) {
	//Get passed params via ev.params
	console.log(ev.params.qwip, ev.params.pqbc);
});

Depending on the method you use to bind to events, you can unbind from them in a similar way by using qwips.unbind(), jQuery(window).unbind() or window.removeEventListener().


Events reference


Listed below are the constants defined in the qwips object. Use them to specify eventType when you call qwips.bind():

//Bind using qwips.bind
qwips.bind(qwips.EV_QWIP_ADDED, function(ev, params) {
	console.log(params.qwip, params.pqbc);
});