<commit_before>/*
 * QuickUI
 * Version 0.8.8
 * Modular web control framework
 * http://quickui.org/
 *
 * Copyright (c) 2009-2012 <NAME>
 * Licensed under the MIT license.
 *
 */

( function( $ ) {
 
/*
 * QuickUI "control" jQuery extension to create and manipulate
 * controls via a regular jQuery instance.
 * 
 * Usage:
 * 
 * $( element ).control()
 *         Returns the control that was created on that element.
 *
 * $( element ).control( { content: "Hello" } );
 *      Sets the content property of the control at this element.
 * 
 * $( element ).control( MyControlClass );
 *         Creates a new instance of MyControlClass around the element(s).
 * 
 * $( element ).control( MyControlClass, { content: "Hello" } );
 *         Creates new control instance(s) and sets its (their) content property.
 * 
 */
$.fn.control = function( arg1, arg2 ) {
    if ( arg1 === undefined ) {
        // Return the controls bound to these element(s), cast to the correct class.
        var $cast = Control( this ).cast( jQuery );
        return ( $cast instanceof Control ) ? $cast : null;
    } else if ( $.isFunction( arg1 ) ) {
        // Create a new control around the element(s).
        var controlClass = arg1;
        var properties = arg2;
        for ( var i = 0, length = this.length; i < length; i++ ) {
            controlClass.createAt( this.eq(i), properties );
        }
        
        // Return the control array as an instance of the desired class.
        // TODO: Handle differing classes if controls transmuted themselves
        // differently during initialize. A cast() each time seems excessive.
        var classFn = Control( this )._controlClass();
        return classFn( this );
    } else {
        // Set properties on the control(s).
        return Control( this ).cast().properties( arg1 );
    }
};



/*
 * Selector for ":control": reduces the set of matched elements to the ones
 * which are controls.
 * 
 * With this, $foo.is(":control") returns true if at least one element in $foo
 * is a control, and $foo.filter(":control") returns just the controls in $foo.
 */
$.expr[":"].control = function( elem ) {
    var controlClass = Control( elem )._controlClass(); 
    return controlClass
        ? controlClass === Control || controlClass.prototype instanceof Control
        : false;
};



/*
 * Control subclass of jQuery.
 * This is used as the base class for all QuickUI controls.
 */
var Control = $.sub();
$.extend( Control, {
    
    /*
     * Given an array of functions, repeatedly invoke them as a chain.
     * 
     * This function allows the compact definition of getter/setter functions
     * for Control classes that are delegated to aspects of the control or
     * elements within its DOM.
     * 
     * For example:
     * 
     *     MyControl.prototype.foo = Control.chain( "$foo", "content" );
     * 
     * will create a function foo() on all MyControl instances that sets or gets
     * the content of the elements returned by the element function $foo(),
     * which in turn likely means any element with id "#foo" inside the control.
     * 
     * The parameters to chain are the names of functions that are invoked in
     * turn to produce the result. The last parameter may be an optional side
     * effect function that will be invoked whenever the chain function is
     * invoked as a setter.
     * 
     * The function names passed as parameters may also define an optional
     * string-valued parameter that will be passed in. So chain( "css/display" )
     * creates a curried setter/getter function equivalent to css("display", value ).
     */
    chain: function() {
        
        // Check for a side effect function as last parameter.
        var args = arguments;
        var sideEffectFn;
        if ( $.isFunction( args[args.length - 1] ) ) {
            // Convert arguments to a real array in order to grab last param.
            args = [].slice.call( arguments );
            sideEffectFn = args.pop();
        }
        
        // Identify function names and optional parameters.
        var functionNames = [];
        var functionParams = [];
        for ( var i = 0, length = args.length; i < length; i++ ) {
            // Check for optional parameter.
            var parts = arguments[i].split( "/" );
            functionNames[i] = parts.shift();
            functionParams[i] = parts;
        }
        
        // Generate a function that executes the chain.
        return function chain( value ) {
            
            var result = this;
            for ( var i = 0, length = functionNames.length; i < length; i++ ) {
                var fn = result[ functionNames[i] ];
                var params = functionParams[i];
                if ( value !== undefined && i === length - 1 ) {
                    // Invoke last function as setter.
                    params = params.concat( [ value ] );
                }
                if ( fn === undefined ) {
                    var message = "Control class \"" + this.className() + "\" tried to chain to an undefined getter/setter function \"" + functionNames[i] + "\".";
                    throw message;
                }
                result = fn.apply( result, params );
            }
            
            if ( value === undefined ) {
                // Chain invoked as getter.
                return result;
            } else {
                if ( sideEffectFn ) {
                    // Carry out side effect.
                    sideEffectFn.call( this, value );
                }
                return this;
            }
        };
    },
    
    /*
     * A class' "classHierarchy" member reflects the names of all classes
     * in its class hierarchy, from most specific to most general class.
     * This member is automatically built by Control.subclass().
     * 
     * Example: If a control class Foo has superclasses Bar and Control,
     * this member will be "Foo Bar Control".
     */
    classHierarchy: "Control",
    
    /*
     * Each control class knows its own name.
     * We'd prefer to use "name" for this, but something (the browser? jQuery?)
     * creates a "name" property on jQuery instances that's unchangeable.
     */
    className: "Control",
    
    /*
     * Create an instance of this control class around a default element.
     * The class prototype's tag member can define a specific element tag. 
     */
    create: function( properties ) {
        return this.createAt( "<" + this.prototype.tag + "/>", properties );
    },
    
    /*
     * Create instance(s) of this control class around the given target(s).
     */
    createAt: function( target, properties ) {

        // Instantiate the control class.
        var $controls = this( target );
        
        // Grab the existing contents of the target elements.
        var oldContents = $controls._significantContents();
        
        $controls
            // Save a reference to the controls' class.
            .data( Control._controlClassData, this )
            
            // Apply all class names in the class hierarchy as style names.
            // This lets the element pick up styles defined by those classes.
            .addClass( this.classHierarchy )
            
            // Render controls as DOM elements.
            .render()

            // Pass in the target's old contents (if any).
            .propertyVector( "content", oldContents )
            
            // Set any requested properties.
            .properties( properties )
        
            // Tell the controls they're ready.
            .initialize();
        
        // It's possible (but unlikely) that a control transmuted itself
        // during its initialize() call, so get the class back and return
        // controls as an instance of that class.<commit_msg>createAt() now takes advantage of _controlClass() helper function.<commit_after>/*
 * QuickUI
 * Version 0.8.8
 * Modular web control framework
 * http://quickui.org/
 *
 * Copyright (c) 2009-2012 <NAME>
 * Licensed under the MIT license.
 *
 */

( function( $ ) {
 
/*
 * QuickUI "control" jQuery extension to create and manipulate
 * controls via a regular jQuery instance.
 * 
 * Usage:
 * 
 * $( element ).control()
 *         Returns the control that was created on that element.
 *
 * $( element ).control( { content: "Hello" } );
 *      Sets the content property of the control at this element.
 * 
 * $( element ).control( MyControlClass );
 *         Creates a new instance of MyControlClass around the element(s).
 * 
 * $( element ).control( MyControlClass, { content: "Hello" } );
 *         Creates new control instance(s) and sets its (their) content property.
 * 
 */
$.fn.control = function( arg1, arg2 ) {
    if ( arg1 === undefined ) {
        // Return the controls bound to these element(s), cast to the correct class.
        var $cast = Control( this ).cast( jQuery );
        return ( $cast instanceof Control ) ? $cast : null;
    } else if ( $.isFunction( arg1 ) ) {
        // Create a new control around the element(s).
        var controlClass = arg1;
        var properties = arg2;
        for ( var i = 0, length = this.length; i < length; i++ ) {
            controlClass.createAt( this.eq(i), properties );
        }
        
        // Return the control array as an instance of the desired class.
        // TODO: Handle differing classes if controls transmuted themselves
        // differently during initialize. A cast() each time seems excessive.
        var classFn = Control( this )._controlClass();
        return classFn( this );
    } else {
        // Set properties on the control(s).
        return Control( this ).cast().properties( arg1 );
    }
};



/*
 * Selector for ":control": reduces the set of matched elements to the ones
 * which are controls.
 * 
 * With this, $foo.is(":control") returns true if at least one element in $foo
 * is a control, and $foo.filter(":control") returns just the controls in $foo.
 */
$.expr[":"].control = function( elem ) {
    var controlClass = Control( elem )._controlClass(); 
    return controlClass
        ? controlClass === Control || controlClass.prototype instanceof Control
        : false;
};



/*
 * Control subclass of jQuery.
 * This is used as the base class for all QuickUI controls.
 */
var Control = $.sub();
$.extend( Control, {
    
    /*
     * Given an array of functions, repeatedly invoke them as a chain.
     * 
     * This function allows the compact definition of getter/setter functions
     * for Control classes that are delegated to aspects of the control or
     * elements within its DOM.
     * 
     * For example:
     * 
     *     MyControl.prototype.foo = Control.chain( "$foo", "content" );
     * 
     * will create a function foo() on all MyControl instances that sets or gets
     * the content of the elements returned by the element function $foo(),
     * which in turn likely means any element with id "#foo" inside the control.
     * 
     * The parameters to chain are the names of functions that are invoked in
     * turn to produce the result. The last parameter may be an optional side
     * effect function that will be invoked whenever the chain function is
     * invoked as a setter.
     * 
     * The function names passed as parameters may also define an optional
     * string-valued parameter that will be passed in. So chain( "css/display" )
     * creates a curried setter/getter function equivalent to css("display", value ).
     */
    chain: function() {
        
        // Check for a side effect function as last parameter.
        var args = arguments;
        var sideEffectFn;
        if ( $.isFunction( args[args.length - 1] ) ) {
            // Convert arguments to a real array in order to grab last param.
            args = [].slice.call( arguments );
            sideEffectFn = args.pop();
        }
        
        // Identify function names and optional parameters.
        var functionNames = [];
        var functionParams = [];
        for ( var i = 0, length = args.length; i < length; i++ ) {
            // Check for optional parameter.
            var parts = arguments[i].split( "/" );
            functionNames[i] = parts.shift();
            functionParams[i] = parts;
        }
        
        // Generate a function that executes the chain.
        return function chain( value ) {
            
            var result = this;
            for ( var i = 0, length = functionNames.length; i < length; i++ ) {
                var fn = result[ functionNames[i] ];
                var params = functionParams[i];
                if ( value !== undefined && i === length - 1 ) {
                    // Invoke last function as setter.
                    params = params.concat( [ value ] );
                }
                if ( fn === undefined ) {
                    var message = "Control class \"" + this.className() + "\" tried to chain to an undefined getter/setter function \"" + functionNames[i] + "\".";
                    throw message;
                }
                result = fn.apply( result, params );
            }
            
            if ( value === undefined ) {
                // Chain invoked as getter.
                return result;
            } else {
                if ( sideEffectFn ) {
                    // Carry out side effect.
                    sideEffectFn.call( this, value );
                }
                return this;
            }
        };
    },
    
    /*
     * A class' "classHierarchy" member reflects the names of all classes
     * in its class hierarchy, from most specific to most general class.
     * This member is automatically built by Control.subclass().
     * 
     * Example: If a control class Foo has superclasses Bar and Control,
     * this member will be "Foo Bar Control".
     */
    classHierarchy: "Control",
    
    /*
     * Each control class knows its own name.
     * We'd prefer to use "name" for this, but something (the browser? jQuery?)
     * creates a "name" property on jQuery instances that's unchangeable.
     */
    className: "Control",
    
    /*
     * Create an instance of this control class around a default element.
     * The class prototype's tag member can define a specific element tag. 
     */
    create: function( properties ) {
        return this.createAt( "<" + this.prototype.tag + "/>", properties );
    },
    
    /*
     * Create instance(s) of this control class around the given target(s).
     */
    createAt: function( target, properties ) {

        // Instantiate the control class.
        var $controls = this( target );
        
        // Grab the existing contents of the target elements.
        var oldContents = $controls._significantContents();
        
        $controls
            // Save a reference to the controls' class.
            ._controlClass( this )
            
            // Apply all class names in the class hierarchy as style names.
            // This lets the element pick up styles defined by those classes.
            .addClass( this.classHierarchy )
            
            // Render controls as DOM elements.
            .render()

            // Pass in the target's old contents (if any).
            .propertyVector( "content", oldContents )
            
            // Set any requested properties.
            .properties( properties )
        
            // Tell the controls they're ready.
            .initialize();
        
        // It's possible (but unlikely) that a control transmuted itself
        // during its initialize() call, so get the class back and return
        // controls as an instance of that class.
{'fraction_non_alphanumeric': 0.09720897704876343, 'fraction_numerical': 0.0029245342997011887, 'mean_word_length': 1.8688674083530914, 'pattern_counts': {'":': 10, '<': 13, '<?xml version=': 0, '>': 7, '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': '1623659', 'n_tokens_mistral': 3990, 'n_tokens_neox': 3852, 'n_words': 1611}