//请尊重开发者劳动成果，勿将本程序发布到网上或倒卖，感谢您的支持！程序唯一联系QQ:6777107 如有违规内容发布，请自行删除！
layui.define(['layer', 'nprogress', 'utils'], function(exports) {
    var $ = layui.jquery,
        layer = layui.layer,
        _modName = 'spa',
        utils = layui.utils;

    var Spa = function() {
        this.config = {
            elem: '#container',
            openWait: true
        };
        this.v = '1.0.0';
    };
    Spa.fn = Spa.prototype;
    Spa.fn.set = function(options) {
        var that = this;
        $.extend(true, that.config, options);
        return that;
    };
    Spa.fn.render = function(url, callback) {
        var that = this,
            _config = that.config,
            _elem = $(_config.elem),
            loadIndex = undefined;
        NProgress.start();
        if (_config.openWait)
            loadIndex = utils.load();
        var html = utils.getBodyContent(utils.loadHtml(url + '?v=' + new Date().getTime(), function() {
            setTimeout(function() {
                NProgress.done();
                _config.openWait && loadIndex && layer.close(loadIndex);
            }, 500);
            typeof callback === 'function' && callback();
        }));
        _elem.html(html);
    };


    var t = new Spa();

    exports('spa', t);
});