<commit_before><commit_msg>Adding a utility file for the JS that eventually the entire framework for openphoto will exist in.  First adding custom events that will be heavily used.  You do not have to set up custom events, just use .fire or .on to fire and subscribe to events easily.<commit_after>/**
* Utility methods for OpenPhoto - this will include the entire framework
* And ability to swap frameworks (YUI or jQuery) in and out.
*/
(function() {

    // just make sure that OP, the global namespace for OpenPhoto
    // is defined
    if ( typeof(OP) === "undefined") {
        OP = {};
    }
        
    /**
    * Class that contains all utility functions for OpenPhoto
    * @class Util
    */
    OP.Util = {
    
    
        /* -------------------------------------------------
        *               Custom Events
        * ------------------------------------------------- */
        
        _customEvents: {},
        
        
        /**
        * Subscribe to a custom event - the callback will be executed when the custom event is fired 
        * @param {string} eventName - the name of the custom event to subscribe to
        * @param {Function} callback - the callback function that will be executed when the event is fired
        * @param {Object} scope - the scope of the callback function (what this will refer to)
        * @return {void}
        * @method on
        */
        on: function(eventName, callback, scope) {
        
            var events = this._customEvents,
                cEvent = events[eventName],
                scope = scope || window,
				length;
        
            if (! cEvent ) {
                events[eventName] = [];
                cEvent = events[eventName];
            }
            
			//make sure the event doesn't exist already - if it does, return without
			//adding the event again
			length = cEvent.length;
			while(length--) {
				if (cEvent[length].fn === callback) {
					return;
				}
			}
				
			cEvent[ cEvent.length ] = {
				fn: callback,
				scope: scope
			};
        
        },
        
        /**
        * A little less terse name, but removes an event listener if it exists
        * @param {string} eventName - the name of the custom event to unsubscribe from
        * @param {Function} callback - the callback function that would have been executed on fire of the custom event
        * @return {void}
        * @method unsubscribe
        */
        unsubscribe: function(eventName, callback) {
        
            var events = this._customEvents,
                cEvent = events[eventName],
                length;
        
            if (!!cEvent) {
                length = cEvent.length;
                while (length--) {
                    if (cEvent[length].fn === callback) {
                        cEvent.splice(length, 1);
                        break;
                    }
                }
            }
            

        },
        
        /**
        * Fire a custom event - invoke all listeners passing whatever optional arguments
        * @param {string} eventName - name of the event to fire
        * @return {void}
        * @method fire
        */
        fire: function(eventName, arg){
        
            var callbacks = this._customEvents[eventName],
                arg = arg || {},
                i, j;
                
            if (!!callbacks) {
                for ( i=0, j=callbacks.length; i<j; i++ ) {
                    callbacks[i].fn.call(callbacks[i].scope, arg);
                }
            }
        
        }
    
    };


}());
{'fraction_non_alphanumeric': 0.11461238148354713, 'fraction_numerical': 0.0005577244841048522, 'mean_word_length': 1.3292207792207793, 'pattern_counts': {'":': 0, '<': 4, '<?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': '3852207', 'n_tokens_mistral': 931, 'n_tokens_neox': 865, 'n_words': 317}