common/core.js
/*
	* Create a jQuery plugin from a widget class.
	* @param {String} name The name of the plugin. The created jQuery plugin will be named shield[name]
	* @param {Object} widget The widget constructor.
	*/
Create a jQuery plugin from a widget class.
@param {String} name The name of the plugin. The created jQuery plugin will be named shield[name]
@param {Object} widget The widget constructor.
Create a jQuery plugin from a widget class . @param { String } name The name of the plugin . The created jQuery plugin will be named shield [ name ] @param { Object } widget The widget constructor .
function plugin(name, WidgetClass) {
        shield.ui[name] = WidgetClass;
        $.fn[SHIELD + name] = function (options) {
            var ret = this,
                args;
            if (typeof options === STRING) {
                args = [].slice.call(arguments, 1);
                this.each(function () {
                    var instance = $(this).data(SHIELD_WIDGET),
                        method,
                        result;
                    if (!instance) {
                        throw new Error(format("shield: cannot call method '{0}' on uninitialized {1}.", options, name));
                    }
                    method = instance[options];
                    if (typeof method !== FUNCTION) {
                        throw new Error(format("shield: cannot find method '{0}' of {1}", options, name));
                    }
                    result = method.apply(instance, args);
                    if (result !== undefined) {
                        ret = result;
                        return false;
                    }
                });
                return ret;
            }
            else {
                return this.each(function () {
                    var instance = new WidgetClass(this, options);
                    $(this).data(SHIELD_WIDGET, instance);
                    $(this).data(SHIELD_WIDGET + "-" + name, instance);
                });
            }
        }
    }
function plugin ( name , WidgetClass ) { shield . ui [ name ] = WidgetClass ; $ . fn [ SHIELD + name ] = function ( options ) { var ret = this , args ; if ( typeof options === STRING ) { args = [ ] . slice . call ( arguments , 1 ) ; this . each ( function ( ) { var instance = $ ( this ) . data ( SHIELD_WIDGET ) , method , result ; if ( ! instance ) { throw new Error ( format ( "shield: cannot call method '{0}' on uninitialized {1}." , options , name ) ) ; } method = instance [ options ] ; if ( typeof method !== FUNCTION ) { throw new Error ( format ( "shield: cannot find method '{0}' of {1}" , options , name ) ) ; } result = method . apply ( instance , args ) ; if ( result !== undefined ) { ret = result ; return false ; } } ) ; return ret ; } else { return this . each ( function ( ) { var instance = new WidgetClass ( this , options ) ; $ ( this ) . data ( SHIELD_WIDGET , instance ) ; $ ( this ) . data ( SHIELD_WIDGET + "-" + name , instance ) ; } ) ; } } }
Create a jQuery plugin from a widget class.
Create a jQuery plugin from a widget class .
// extend jQuery.fn with the plugin name, e.g. $("#div1").shieldChart({...}); // the first param to the plugin constructor is a string -  // treat this as a function name that must be executed for the instance, // passing the rest of the arguments as params to that function // call the method with the provided arguments // if there's any result, break from the $.each() iteration and return the result from the plugin() function // in the rest of the cases, construct the plugin as normal // construct an instance of the widget // store a reference to the instance in the element's .data, // overwriting all previous ones