Skip to content

dmitryfar/jquery-fire

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

jquery-fire

JQuery event messaging like in AlloyUI.

jQuery.fire() or $.fire()

jQuery.on() or $.on()

Fire

Fire simple event

$.fire("simpleEvent");

Fire data event

$.fire("testEvent", "textstring");
$.fire("testEvent", {a: ["n=1", "m=1"]});
$.fire("testEvent", ["n=1", "m=1", 234]);

Fire multiple data event

$.fire("multpleDataEvent", "n1", "n2", "n3");

Fire once event

jQuery.fireOnce("fireOnceEvent", {"n": "1"});

Catch

Catch simple event

jQuery.on("simpleEvent", function(event) {
	console.log("simple event", event._type);
});

Catch data event

jQuery.on("testEvent", function(event, data) {
	console.log("%o: %o, data: %o", this._type, event, data);
	if (typeof data == 'function') {
		data.call(this, "WORLD", "!!!");
		data.apply(this, ["my ", "friend."]);
	} else {
		// something else
	}
});

var abcFnc = function(text1, text2){
	var event = this;
	console.log("-- Hello, " + text1 + text2 + " --");
};

$.fire("testEvent", abcFnc);

Catch multiple data event

jQuery.on("multpleDataEvent", function(event, data1, data2, data3, data4) {
	console.log("%o: %o, data1: %o, data2: %o, data3: %o, data4: %o", this._type, event, data1, data2, data3, data4);
});

or

jQuery.on("multpleDataEvent", function(event) {
	console.log("%o: %o, details: %o", event._type, event, event.details);
});

Catch once

With many fires it wil be catched just once

jQuery.on("fireOnceEvent", function(event, data) {
	console.log("%o, event.n: %o, data.n: %o", this._type, event.n, data.n);
});

jQuery.fireOnce("fireOnceEvent", {"n": "1"});
jQuery.fireOnce("fireOnceEvent", {"n": "2"});
jQuery.fireOnce("fireOnceEvent", {"n": "3"});

About

JQuery event messaging like in AlloyUI.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published