all files / dui/src/widget/ Panel.js

39.13% Statements 9/23
18.75% Branches 3/16
50% Functions 2/4
39.13% Lines 9/23
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56                                                                                             
/**
 * Panel
 *
 * @file Panel
 * @author Brian Li (lbxxlht@163.com)
 */
var define = typeof define === 'function' && define.amd ? define : function (factory) {
    typeof module === 'object' ? (module.exports = factory(require)) : '';
};
 
define(function (require) {
 
    var Controller = require('../core/controller');
    var util = require('../core/util');
 
    // public /////////////////////////////////////////////////////////////////
 
    /**
     * Panel构造函数
     *
     * @param {Object} param 初始化参数
     * @return {Panel} Panel实例
     */
    function Panel(param) {
 
        if (!(this instanceof Panel)) {
            return new Panel(param);
        }
 
        param = param || {};
 
        // 原始模板
        param.tpl = '';
        util.appendHandler(param, 'click', mouseHandler);
 
        // 调用父类初始化
        Controller.call(this, param);
    }
 
    util.inherit(Panel, Controller);
 
    return Panel;
 
    function mouseHandler(e) {
        var dom = e.target;
        var dataset = util.getDataset(dom);
        if (dataset.uiCmd !== 'panel-toggle-button') {
            return;
        }
        var icons = typeof dataset.uiIcons === 'string' ? dataset.uiIcons.split(';') : ['', ''];
        var container = $(this.container);
        container.find('.panel-content').toggleClass('hidden');
        dom.className = container.find('.panel-content').hasClass('hidden') ? icons[1] : icons[0];
    }
});