loading.js 912 Bytes
/**
 * 加载组件
 *
 * @author: Aiden Xu <aiden.xu@yoho.cn>
 * @date: 2016/07/18
 */

'use strict';

const Overlay = require('./overlay');
const template = require('components/loading.hbs');

if (!Overlay) {
    throw new Error('Required dependency "Overlay" not found!');
}

class Loading {
    constructor(opts) {
        this.defaults = {};
        this.settings = Object.assign({}, this.defaults, opts);

        this.elem = $(template());

        this.elem.appendTo('body');
    }

    /**
     * 显示
     */
    show() {
        this.overlay = $.overlay({
            animation: 'fade',
            clickToClose: false
        });
        this.overlay.show();
    }

    /**
     * 关闭
     */
    hide() {
        this.overlay.hide();
        this.elem.remove();
    }
}

((function($) {
    $.loading = opts => {
        return new Loading(opts);
    };
})(jQuery));

module.exports = Loading;