<commit_before>/**
 * RAPTOR EVENTS - 'cause raptors do stuff
 * 
 * Supports custom events.
 * 
 * Example:
 *   
 *   - Subscriber - 
 *   raptor.events.add(module, 'paperlessAccepted', function(data) {
 *     // do stuff with the data object
 *   });
 *   
 *   - Publisher -
 *   // fires on all paperlessAccepted bound targets
 *   raptor.events.fire('paperlessAccepted');
 *   
 *   OR
 *   
 *   // fires on all paperlessAccepted bound targets with additional data
 *   raptor.events.fire({
 *     type : 'paperlessAccepted',
 *     foo : 'some data'
 *   });
 *   
 *   OR
 *   
 *   // fires only on target
 *   raptor.events.fire({
 *     type : 'paperlessAccepted',
 *     target : module,
 *     // for multiple targets
 *     // targets : [module, div]
 *   });
 * 
 */

raptor.events = (function() {
	
	var _events = {};
	
	return {
		
		/**
		 * Binds an event/callback to a specific target.
		 * 
		 * Supports custom events which can be fired
		 * using the below fire() method
		 * 
		 * @param {HTMLElement|Object|Array|Function} target
		 * @param {String} type
		 * @param {Function} cb
		 */
		'add' : function(target, type, cb) {
			var type = 'on' + type;
			
			// if no events of this type exist, instantiate event type, and add event instance
			if (typeof _events[type] === 'undefined') _events[type] = [{'target' : target, 'callbacks' : [cb]}];
			else {
				
				var exists = false;
				
				// cycle through targets attached to this event
				for (var targetData in _events[type]) {
					var data = _events[type][targetData]; 
					
					// if target is already bound to this event, add callback to queue
					if (data.target == target) {
						data.callbacks.push(cb);	
						exists = true;
					}
				}
				
				// if event type exists, but target is not already bound, bind it
				if (!exists) _events[type].push({'target' : target, 'callbacks' : [cb]});
			}
			
			target[type] = this.fire;
		},
		
		/**
		 * Fires event(s)
		 * 
		 * Event param gets passed to all subscriber callbacks
		 * 
		 * @param {Object} event
		 */
		'fire' : function(event) {

			// event will either be served by the browser, or manually. window.event for IE.
			event = event || window.event;
			var type = (raptor.util.type('String', event)) ? 'on' + event : 'on' + event.type;
			
			// gather target(s) into an array
			var targets = [];
			if (event.targets || event.target) {
				targets = (event.targets) ? event.targets : [event.target];	
			}<commit_msg>minor edits. Needs some rigorous testing!<commit_after>/**
 * RAPTOR EVENTS - 'cause raptors do stuff
 * 
 * Supports custom events.
 * 
 * Example:
 *   
 *   - Subscriber - 
 *   raptor.events.add(module, 'paperlessAccepted', function(data) {
 *     // do stuff with the data object
 *   });
 *   
 *   - Publisher -
 *   // fires on all paperlessAccepted bound targets
 *   raptor.events.fire('paperlessAccepted');
 *   
 *   OR
 *   
 *   // fires on all paperlessAccepted bound targets with additional data
 *   raptor.events.fire({
 *     type : 'paperlessAccepted',
 *     foo : 'some data'
 *   });
 *   
 *   OR
 *   
 *   // fires only on target
 *   raptor.events.fire({
 *     type : 'paperlessAccepted',
 *     target : module,
 *     // for multiple targets
 *     // targets : [module, div]
 *   });
 * 
 */

raptor.events = (function() {
	
	var _events = {};
	
	return {
		
		/**
		 * Binds an event/callback to a specific target.
		 * 
		 * @param {HTMLElement|Object|Array|Function} target
		 * @param {String} type
		 * @param {Function} cb
		 */
		'add' : function(target, type, cb) {
			var type = 'on' + type;
			
			// if no events of this type exist, instantiate event type, and add event instance
			if (typeof _events[type] === 'undefined') _events[type] = [{'target' : target, 'callbacks' : [cb]}];
			else {
				
				// cycle through targets attached to this event
				for (var targetData in _events[type]) {
					var data = _events[type][targetData]; 
					
					// if target is already bound to this event, add callback to queue
					if (data.target == target) {
						data.callbacks.push(cb);	
						var exists = true;
					}
				}
				
				// if event type exists, but target is not already bound, bind it
				if (!exists) _events[type].push({'target' : target, 'callbacks' : [cb]});
			}
			
			target[type] = this.fire;
		},
		
		/**
		 * Fires event(s)
		 * 
		 * Event param gets passed to all subscriber callbacks
		 * 
		 * @param {Object} event
		 */
		'fire' : function(event) {

			// event will either be served by the browser, or manually. window.event for IE.
			event = event || window.event;
			var type = (raptor.util.type('String', event)) ? 'on' + event : 'on' + event.type;
			
			// gather target(s) into an array
			var targets = [];
			if (event.targets || event.target) {
				targets = (event.targets) ? event.targets : [event.target];	
			}
{'fraction_non_alphanumeric': 0.13846153846153847, 'fraction_numerical': 0.0, 'mean_word_length': 2.367403314917127, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1030729', 'n_tokens_mistral': 1831, 'n_tokens_neox': 1530, 'n_words': 461}