jQuery Plugin Container

/*
@name: jQuery Plugin Template for Coding
*/
;(function($) {//[--jQuery Plugin Container

//declare the plugin's version ; use to check the plugin exists
$.__plugin_name__ = $.__plugin_name__ || {version:'0.1.0'};

//[--Plugin Define
var __plugin_name__ = function(node,opts) {

    var me=this,$me=$(this);
    var $mine=$(node); //get the plugin's Operation jQuery DOM Element

    //Public Methods
    $.extend(me, {
        show: function() {
            __show__();
        },
        hide: function() {
            __hide__();
        },
        options: function() {
            //return the preset options to users code
            //let users can be change options by later code
            return opts;
        }
    });

    //Private Variables ( Module Level )
    var m_var1, m_var2, m_var3;

    //init the plugin
    function __init__(){
        alert('jQuery Plugin init');
        if (opts.autoShow) __show__();
    }
    __init__();

    //Private Functions
    function __show__(){
        //function code
        $mine.text('Hello jQuery Plugin !');
        //call the event
        opts.onShow(me,opts);
    }

    function __hide__(){
        //function code
        $mine.text('');
        //call the event
        opts.onHide(me,opts);
    }


};//--]Plugin Define


//jQuery Plugin Implementation
$.fn.__plugin_name__ = function(conf) {

    //return existing instance // let users can use the Public Methods
    //Usage: var obj = $('#id').__plugin_name__({ <options> }).data("__plugin_name__");
    var el = this.eq(typeof conf == 'number' ? conf : 0).data("__plugin_name__");
    if (el) { return el; }

    //setup default options
    var opts = {
        autoShow:true,
        onShow:function(e,o){},
        onHide:function(e,o){},
        api:false
    };

    //if no users options then use the default options
    $.extend(opts, conf);

    // install the plugin for each items in jQuery
    this.each(function() {
        el = new __plugin_name__(this, opts);
        $(this).data("__plugin_name__", el);
    });

    //api=true let users can immediate use the Public Methods
    return opts.api ? el: this;

};


})(jQuery);//--]jQuery Plugin Container

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值