Login   Register  
Icontem

File: examples_and_documents/js/sampleModuleWithListener.js

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Tomas Corral  >  Hydra.js  >  examples_and_documents/js/sampleModuleWithListener.js  >  Download  
File: examples_and_documents/js/sampleModuleWithListener.js
Role: Example script
Content type: text/plain
Description: Example module with listener
Class: Hydra.js
Modular event action handler
Author: By
Last change:
Date: 2011-07-21 13:19
Size: 757 bytes
 

Contents

Class file image Download
Hydra.module.register("sampleModuleWithListener", function (action) {
	return {
		sModule: 'BaseSample',
		init: function (oData) {
			alert("Single Module started");
			
			this.createLinkAndAddEvent();
			
			action.listen(['linkClicked'], this.handleAction, this);
		},
		createLinkAndAddEvent: function()
		{
			var oLink = document.createElement("a");
			oLink.href = '#';
			oLink.innerHTML = 'Notify';
			$(oLink).click(function () {
				action.notify({
					type: 'linkClicked',
					data: null
				});
			});
			document.body.appendChild(oLink);
		},
		handleAction: function (oNotifier) {
			if(oNotifier.type !== 'linkClicked')
			{
				return;
			}
			alert('Link clicked');
		},
		destroy: function () {}
	};
});