You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
2.1 KiB
55 lines
2.1 KiB
7 years ago
|
_.extend(BI, {
|
||
8 years ago
|
$import: function () {
|
||
|
var _LOADED = {}; // alex:保存加载过的
|
||
7 years ago
|
function loadReady (src, must) {
|
||
8 years ago
|
var $scripts = $("head script, body script");
|
||
8 years ago
|
$.each($scripts, function (i, item) {
|
||
|
if (item.src.indexOf(src) != -1) {
|
||
|
_LOADED[src] = true;
|
||
|
}
|
||
|
});
|
||
|
var $links = $("head link");
|
||
|
$.each($links, function (i, item) {
|
||
|
if (item.href.indexOf(src) != -1 && must) {
|
||
|
_LOADED[src] = false;
|
||
|
$(item).remove();
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
// must=true 强行加载
|
||
|
return function (src, ext, must) {
|
||
|
loadReady(src, must);
|
||
|
// alex:如果已经加载过了的,直接return
|
||
|
if (_LOADED[src] === true) {
|
||
|
return;
|
||
|
}
|
||
7 years ago
|
if (ext === "css") {
|
||
|
var link = document.createElement("link");
|
||
|
link.rel = "stylesheet";
|
||
|
link.type = "text/css";
|
||
8 years ago
|
link.href = src;
|
||
7 years ago
|
var head = document.getElementsByTagName("head")[0];
|
||
8 years ago
|
head.appendChild(link);
|
||
|
_LOADED[src] = true;
|
||
|
} else {
|
||
|
// alex:这里用同步调用的方式,必须等待ajax完成
|
||
|
$.ajax({
|
||
|
url: src,
|
||
|
dataType: "script", // alex:指定dataType为script,jquery会帮忙做globalEval的事情
|
||
|
async: false,
|
||
|
cache: true,
|
||
|
complete: function (res, status) {
|
||
|
/*
|
||
|
* alex:发现jquery会很智能地判断一下返回的数据类型是不是script,然后做一个globalEval
|
||
|
* 所以当status为success时就不需要再把其中的内容加到script里面去了
|
||
|
*/
|
||
7 years ago
|
if (status == "success") {
|
||
8 years ago
|
_LOADED[src] = true;
|
||
|
}
|
||
|
}
|
||
7 years ago
|
});
|
||
8 years ago
|
}
|
||
7 years ago
|
};
|
||
8 years ago
|
}()
|
||
|
});
|