src/event/js/event.js
function(attribute, pattern, callback, interaction, maxDepth) {
	var classPattern = new RegExp(pattern),

		interaction = interaction || 'click',

		maxSearch,

		dispatcher,

		body = localnwt.one('body');

	// Currently only search one level for a mouse listener for performance reasons
	if (interaction == 'click') {
		maxSearch = 100;
	} else {
		maxSearch = maxDepth || 1;
	}

	dispatcher = 
	function(e) {
		var originalTarget = e.target,
			target = originalTarget,

			// Did we find it?
			found = true,

			// Keep track of how many times we bubble up
			depthSearched = 0;

		while(target._node && target._node.parentNode) {

			if (target._node == localnwt.one('body')._node || depthSearched >= maxSearch) { break; }

			if (target.hasAttribute(attribute)) {

				var matches = target.getAttribute(attribute).match(pattern);

				if (matches) {
					callback(originalTarget, target, matches);
	
					// If we found a callback, we usually want to stop the event
					// Except for input elements (still want checkboxes to check and stuff)
					if( target.get('nodeName').toUpperCase() !== "INPUT") {
						e.stop();
					}

					break;
				}
			}

			depthSearched++;
			target = target.parent();
		};

		return;
	};


	var enableListener = function() {
		body.on(interaction, dispatcher);
	};
	enableListener();

	if (interaction !== 'click') {

		// Disable mouseover listeners on scroll
		var timer = false;

		localnwt.one(document).on('scroll', function() {

			body.off(interaction, dispatcher);

			if (timer) {
				clearTimeout(timer);
				timer = false;
			}
			timer = setTimeout(enableListener, 75);
		});
	}
}
function(attribute, pattern, callback, interaction, maxDepth) {
	var classPattern = new RegExp(pattern),

		interaction = interaction || 'click',

		maxSearch,

		dispatcher,

		body = localnwt.one('body');

	// Currently only search one level for a mouse listener for performance reasons
	if (interaction == 'click') {
		maxSearch = 100;
	} else {
		maxSearch = maxDepth || 1;
	}

	dispatcher = 
	function(e) {
		var originalTarget = e.target,
			target = originalTarget,

			// Did we find it?
			found = true,

			// Keep track of how many times we bubble up
			depthSearched = 0;

		while(target._node && target._node.parentNode) {

			if (target._node == localnwt.one('body')._node || depthSearched >= maxSearch) { break; }

			if (target.hasAttribute(attribute)) {

				var matches = target.getAttribute(attribute).match(pattern);

				if (matches) {
					callback(originalTarget, target, matches);
	
					// If we found a callback, we usually want to stop the event
					// Except for input elements (still want checkboxes to check and stuff)
					if( target.get('nodeName').toUpperCase() !== "INPUT") {
						e.stop();
					}

					break;
				}
			}

			depthSearched++;
			target = target.parent();
		};

		return;
	};


	var enableListener = function() {
		body.on(interaction, dispatcher);
	};
	enableListener();

	if (interaction !== 'click') {

		// Disable mouseover listeners on scroll
		var timer = false;

		localnwt.one(document).on('scroll', function() {

			body.off(interaction, dispatcher);

			if (timer) {
				clearTimeout(timer);
				timer = false;
			}
			timer = setTimeout(enableListener, 75);
		});
	}
}
function ( attribute , pattern , callback , interaction , maxDepth ) { var classPattern = new RegExp ( pattern ) , interaction = interaction || 'click' , maxSearch , dispatcher , body = localnwt . one ( 'body' ) ; // Currently only search one level for a mouse listener for performance reasons if ( interaction == 'click' ) { maxSearch = 100 ; } else { maxSearch = maxDepth || 1 ; } dispatcher = function ( e ) { var originalTarget = e . target , target = originalTarget , // Did we find it? found = true , // Keep track of how many times we bubble up depthSearched = 0 ; while ( target . _node && target . _node . parentNode ) { if ( target . _node == localnwt . one ( 'body' ) . _node || depthSearched >= maxSearch ) { break ; } if ( target . hasAttribute ( attribute ) ) { var matches = target . getAttribute ( attribute ) . match ( pattern ) ; if ( matches ) { callback ( originalTarget , target , matches ) ; // If we found a callback, we usually want to stop the event // Except for input elements (still want checkboxes to check and stuff) if ( target . get ( 'nodeName' ) . toUpperCase ( ) !== "INPUT" ) { e . stop ( ) ; } break ; } } depthSearched ++ ; target = target . parent ( ) ; } ; return ; } ; var enableListener = function ( ) { body . on ( interaction , dispatcher ) ; } ; enableListener ( ) ; if ( interaction !== 'click' ) { // Disable mouseover listeners on scroll var timer = false ; localnwt . one ( document ) . on ( 'scroll' , function ( ) { body . off ( interaction , dispatcher ) ; if ( timer ) { clearTimeout ( timer ) ; timer = false ; } timer = setTimeout ( enableListener , 75 ) ; } ) ; } }
Adds a live listener to the page
This allows us to update page components,
and still have javascript function properly
@param string Attribute to check on
@param regex Pattern to match against the string
@param function callback if matched
@param string Type of listener to use, one of: click | mousemove | mouseout
@param integer Max depth to search. Defaults to 1 for a mouseover action
Adds a live listener to the page This allows us to update page components and still have javascript function properly