1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/asai-LoadJS

Клонировать/Скачать
LoadJS-compiled.js 5 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
Dongasai Отправлено 11.10.2016 10:38 695d27f
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* Created by dongasai on 16-10-7.
*/
var LoadJS = function () {
function LoadJS($config) {
_classCallCheck(this, LoadJS);
this.queue5 = [];
this.already = {}; //已经加载过的
this.ready = {};
this.configing($config);
this.head = document.getElementsByTagName('head');
}
_createClass(LoadJS, [{
key: 'configing',
value: function configing($config) {
this.base = $config.base;
if (typeof $config.module === 'undefined') {
this.modules = {};
} else {
this.modules = $config.module;
}
}
}, {
key: 'all',
value: function all($list) {
var $name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 're';
for (var li in $list) {
this.one($list[li]);
}
var $name2 = $name;
this.queue.push($name);
}
/**
* 加载一个扩展 并且只加载一次
* @param $name
*/
}, {
key: 'one',
value: function one($name) {
var $this = this;
if (this.already[$name] === true) {
//这个资源已经加载了一次了
console.log('这个资源已经加载了一次了:', $name);
return;
}
var scriptobj = void 0;
if (typeof this.modules[$name] === 'undefined') {
//没有定义该扩展
scriptobj = this.analysis($name);
} else {
//扩展已经定义
scriptobj = this.modules[$name];
}
var srcpat = this.srcpat(scriptobj);
//动态加载
var scriptsq = document.createElement("SCRIPT");
scriptsq.typ = "text/javascript";
// scriptsq.defer = "defer";
scriptsq.src = srcpat; //设置路径
scriptsq.addEventListener('load', function () {
$this.onload(this);
});
scriptsq.className = '';
LoadJS.addClass(scriptsq, 'RequireJS'); //设置代表加载中的 class
this.head[0].appendChild(scriptsq);
this.already[$name] = true;
}
}, {
key: 'onload',
value: function onload(thisob) {
LoadJS.removeClass(thisob, 'RequireJS');
//减掉这个class
var x = document.getElementsByClassName('RequireJS');
if (x.length === 0) {
console.log('全部加载完成!!');
this.loadok();
}
}
}, {
key: 'loadok',
value: function loadok() {
console.log('loadok', this);
for (var li in this.queue) {
if (typeof this.ready[this.queue[li]] === 'undefined') {
//没有定义就继续走
console.log(this.queue[li] + '没有后续方法!');
} else {
this.ready[this.queue[li]].call();
}
}
}
}, {
key: 'analysis',
value: function analysis($name) {
var obj = {
'Require_base': false, //从base路径加载 默认为 true
'src': this.base + $name
};
return obj;
}
}, {
key: 'srcpat',
value: function srcpat(obj) {
if (obj.Require_base) {
//从base加载
return this.base + obj.src;
} else {
//不从 base加载
return obj.src;
}
}
}], [{
key: 'hasClass',
value: function hasClass(obj, cls) {
return obj.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
}
}, {
key: 'addClass',
value: function addClass(obj, cls) {
if (!LoadJS.hasClass(obj, cls)) obj.className += " " + cls;
}
}, {
key: 'removeClass',
value: function removeClass(obj, cls) {
if (LoadJS.hasClass(obj, cls)) {
var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
obj.className = obj.className.replace(reg, ' ');
}
}
}]);
return LoadJS;
}();
//# sourceMappingURL=LoadJS-compiled.js.map

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/asai-LoadJS.git
git@api.gitlife.ru:oschina-mirror/asai-LoadJS.git
oschina-mirror
asai-LoadJS
asai-LoadJS
master