/** * 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