JS Plugin Development

Source: Internet
Author: User

/** * Node configuration attribute mode configuration parameters: The professional approach is to configure each of the attributes of the HTML tag that needs to be initialized to the plug-in (the value of this property must be a standard JSON string), and the advantage of this is that when there are multiple tags that need to be initialized to the plug-in, You can configure the respective desired parameters * For example: <div data-setting= "{' param1 ': 1, ' param2 ': 2}" ></div> * Created by Tonyzeng on 2016/7/6. *///The preceding semicolon, used to avoid other plug-ins without a semicolon closure, causes a syntax error after compressing the code. ;(function ($) {    /** This is the equivalent of a constructor, and when new Arealistbox (Fitlerareabox), it passes the arguments. * However, we did not initialize the plugin in new way, we defined an Init method to initialize, in the Init method, That's what we're using. Constructor to initialize, init with each to loop initialization, the DIV node object (this) pointer passed as a parameter to the constructor parameter list*/    varArealistbox =function(divfitlerareabox) {//Save the Node object, (get custom configuration) The GetSetting method uses it to get the attributes inside the node, such as custom configuration Properties         This. Divareabox =Divfitlerareabox; //Default configuration         This. setting = {"param1": 1, "param2": 2}; //To Configure the merge default configuration with a custom configuration$.extend ( This. setting, This. GetSetting ()); //Event Delegate         This. Bodynode.delegate (". Filterarea", "click",function(e) {//pop-up area selection panelShowfilterareapanel (); //Block event bubbling (bubbling event)e.stoppropagation ();    });    }; Arealistbox.prototype= {        //get a custom configurationGetSetting:function () {            varsetting = This. Divareabox.attr ("data-setting"); //If this node attribute exists and is not empty, it will be transferred to a JSON object.            if(setting && Setting! =NULL) {                return$.parsejson (setting); } Else {                return {}; }}, Showfilterareamask:function() {}, Selectedarea:function() {}, Renderarea:function () {        }    }; //(when there are multiple places in the page that need to be initialized to plug-ins) in order to avoid using new to initialize the plugin's cumbersome, we use an Init method to specifically handle the initializationArealistbox.init =function(list) {//this this points to the Arealistbox plug-in object        var_this_ = This; //Initialize the incoming element as a plug-in with each loopList.each (function () {            //this this points to the element object inside each loop            New_this_ ( This);    });    }; //Global Registrationwindow["Arealistbox"] =Arealistbox;}) (jQuery); $ (function() {Arealistbox.init ($ (". Arealistbox "));});

JS Plugin Development

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.