src/state_machine/cjs_events.js
function(event_type) {
			var rest_args = arguments.length > 1 ? rest(arguments) : root,
				// no parent, no filter by default
				event = new CJSEvent(false, false, function(transition) {
					var targets = [],
						timeout_id = false,
						event_type_val = [],
						listener = bind(this._fire, this),
						fsm = transition.getFSM(),
						from = transition.getFrom(),
						state_selector = new StateSelector(from),
						from_state_selector = new TransitionSelector(true, state_selector, new AnyStateSelector()),
						on_listener = function() {
							each(event_type_val, function(event_type) {
								// If the event is 'timeout'
								if(event_type === timeout_event_type) {
									// clear the previous timeout
									if(timeout_id) {
										cTO(timeout_id);
										timeout_id = false;
									}

									// and set a new one
									var delay = cjs.get(rest_args[0]);
									if(!isNumber(delay) || delay < 0) {
										delay = 0;
									}

									timeout_id = sTO(listener, delay);
								} else {
									each(targets, function(target) {
										// otherwise, add the event listener to every one of my targets
										aEL(target, event_type, listener);
									});
								}
							});
						},
						off_listener = function() {
							each(event_type_val, function(event_type) {
								each(targets, function(target) {
									if(event_type === timeout_event_type) {
										// If the event is 'timeout'
										if(timeout_id) {
											cTO(timeout_id);
											timeout_id = false;
										}
									} else {
										rEL(target, event_type, listener);
									}
								});
							});
						},
						live_fn = cjs.liven(function() {
							off_listener();

							event_type_val = split_and_trim(cjs.get(event_type));
							// only use DOM elements (or the window) as my target
							targets = flatten(map(filter(get_dom_array(rest_args), isElementOrWindow), getDOMChildren , true));

							// when entering the state, add the event listeners, then remove them when leaving the state
							fsm	.on(state_selector, on_listener)
								.on(from_state_selector, off_listener);

							if(fsm.is(from)) {
								// if the FSM is already in the transition's starting state
								on_listener();
							}
						});
					return live_fn;
				});
			return event;
		}
function(event_type) {
			var rest_args = arguments.length > 1 ? rest(arguments) : root,
				// no parent, no filter by default
				event = new CJSEvent(false, false, function(transition) {
					var targets = [],
						timeout_id = false,
						event_type_val = [],
						listener = bind(this._fire, this),
						fsm = transition.getFSM(),
						from = transition.getFrom(),
						state_selector = new StateSelector(from),
						from_state_selector = new TransitionSelector(true, state_selector, new AnyStateSelector()),
						on_listener = function() {
							each(event_type_val, function(event_type) {
								// If the event is 'timeout'
								if(event_type === timeout_event_type) {
									// clear the previous timeout
									if(timeout_id) {
										cTO(timeout_id);
										timeout_id = false;
									}

									// and set a new one
									var delay = cjs.get(rest_args[0]);
									if(!isNumber(delay) || delay < 0) {
										delay = 0;
									}

									timeout_id = sTO(listener, delay);
								} else {
									each(targets, function(target) {
										// otherwise, add the event listener to every one of my targets
										aEL(target, event_type, listener);
									});
								}
							});
						},
						off_listener = function() {
							each(event_type_val, function(event_type) {
								each(targets, function(target) {
									if(event_type === timeout_event_type) {
										// If the event is 'timeout'
										if(timeout_id) {
											cTO(timeout_id);
											timeout_id = false;
										}
									} else {
										rEL(target, event_type, listener);
									}
								});
							});
						},
						live_fn = cjs.liven(function() {
							off_listener();

							event_type_val = split_and_trim(cjs.get(event_type));
							// only use DOM elements (or the window) as my target
							targets = flatten(map(filter(get_dom_array(rest_args), isElementOrWindow), getDOMChildren , true));

							// when entering the state, add the event listeners, then remove them when leaving the state
							fsm	.on(state_selector, on_listener)
								.on(from_state_selector, off_listener);

							if(fsm.is(from)) {
								// if the FSM is already in the transition's starting state
								on_listener();
							}
						});
					return live_fn;
				});
			return event;
		}
function ( event_type ) { var rest_args = arguments . length > 1 ? rest ( arguments ) : root , // no parent, no filter by default event = new CJSEvent ( false , false , function ( transition ) { var targets = [ ] , timeout_id = false , event_type_val = [ ] , listener = bind ( this . _fire , this ) , fsm = transition . getFSM ( ) , from = transition . getFrom ( ) , state_selector = new StateSelector ( from ) , from_state_selector = new TransitionSelector ( true , state_selector , new AnyStateSelector ( ) ) , on_listener = function ( ) { each ( event_type_val , function ( event_type ) { // If the event is 'timeout' if ( event_type === timeout_event_type ) { // clear the previous timeout if ( timeout_id ) { cTO ( timeout_id ) ; timeout_id = false ; } // and set a new one var delay = cjs . get ( rest_args [ 0 ] ) ; if ( ! isNumber ( delay ) || delay < 0 ) { delay = 0 ; } timeout_id = sTO ( listener , delay ) ; } else { each ( targets , function ( target ) { // otherwise, add the event listener to every one of my targets aEL ( target , event_type , listener ) ; } ) ; } } ) ; } , off_listener = function ( ) { each ( event_type_val , function ( event_type ) { each ( targets , function ( target ) { if ( event_type === timeout_event_type ) { // If the event is 'timeout' if ( timeout_id ) { cTO ( timeout_id ) ; timeout_id = false ; } } else { rEL ( target , event_type , listener ) ; } } ) ; } ) ; } , live_fn = cjs . liven ( function ( ) { off_listener ( ) ; event_type_val = split_and_trim ( cjs . get ( event_type ) ) ; // only use DOM elements (or the window) as my target targets = flatten ( map ( filter ( get_dom_array ( rest_args ) , isElementOrWindow ) , getDOMChildren , true ) ) ; // when entering the state, add the event listeners, then remove them when leaving the state fsm . on ( state_selector , on_listener ) . on ( from_state_selector , off_listener ) ; if ( fsm . is ( from ) ) { // if the FSM is already in the transition's starting state on_listener ( ) ; } } ) ; return live_fn ; } ) ; return event ; }
Create a new event for use in a finite state machine transition

@constructs CJSEvent
@method cjs.on
@param {string} event_type - the type of event to listen for (e.g. mousedown, timeout)
@param {element|number} ...targets=window - Any number of target objects to listen to
@return {CJSEvent} - An event that can be attached to
@example When the window resizes

cjs.on("resize")

@example When the user clicks `elem1` or `elem2`

cjs.on("click", elem1, elem2)

@example After 3 seconds

cjs.on("timeout", 3000)
Create a new event for use in a finite state machine transition