Js外掛程式開發

來源:互聯網
上載者:User

標籤:

/** * 節點配置屬性方式配置參數:專業的做法是配置到,每一個需要初始化為外掛程式的那個html標籤的屬性上面(這個屬性的value必須是標準的json字串), * 這樣做的好處是,當存在多個需要初始化為外掛程式的標籤時,可以配置各自想要的參數 * 例如:<div data-setting="{‘param1‘:1,‘param2‘:2}"></div> * Created by TonyZeng on 2016/7/6. *///前面的這個分號,用於避免其他外掛程式沒有分號閉合導致在壓縮代碼後導致文法的錯誤。;(function ($) {    /**這裡相當於一個建構函式,當new AreaListBox(fitlerAreaBox)時,就會傳遞參數過來     * 不過,我們沒有採用new的方式來初始化外掛程式,我們定義了一個init方法來初始化,在init方法中,我們用的其實也就是這個     * 建構函式來初始化,init裡面用each來迴圈初始化,將div節點對象(this)指標作為參數傳入建構函式的參數列表     */    var AreaListBox = function (divFitlerAreaBox) {        //儲存節點對象,(擷取自訂配置)getSetting方法會用它來擷取節點裡面的屬性,比如自訂配置屬性        this.divAreaBox = divFitlerAreaBox;        //預設配置        this.setting = {"param1": 1, "param2": 2};        //用自訂配置merge預設配置        $.extend(this.setting,this.getSetting());        //事件委託        this.bodyNode.delegate(".filterArea", "click", function (e) {            //彈出area選擇panel            showFilterAreaPanel();            //阻止事件冒泡出現(冒泡事件)            e.stopPropagation();        });    };    AreaListBox.prototype = {        //擷取自訂配置        getSetting: function () {            var setting = this.divAreaBox.attr("data-setting");            //如果這個節點屬性存在,並且不為空白的話就轉成json對象傳出去            if (setting && setting != null) {                return $.parseJSON(setting);            } else {                return {};            }        },        showFilterAreaMask: function () {        },        selectedArea: function () {        },        renderArea: function () {        }    };    //(當頁面有多個地方需要初始化成外掛程式時)為了避免用new的方式來初始化外掛程式的繁瑣,我們用一個init方法來專門處理初始化    AreaListBox.init = function (list) {        //這個this指向AreaListBox外掛程式對象        var _this_ = this;        //用each迴圈初始化傳入的元素為外掛程式        list.each(function () {            //這個this指向each迴圈裡面的元素對象            new _this_(this);        });    };    //全域註冊    Window["AreaListBox"] = AreaListBox;})(jQuery);$(function () {    AreaListBox.init($(".AreaListBox"));});

 

Js外掛程式開發

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.