FileLoadTools
/**
* Created by dev013 on 9/9/14.
*/
var FileLoadTools = (function () {
var my = {};
var htmlFile = [];// array for storing name of files loaded
var jsFile = [];
var cssFile = []; /**
* @param {Object} file filename
* @param {Object} fileArray
* function for judging if the file is loaded or not
*/
function isLoaded(file, fileArray) {
for (var i = 0; i < fileArray.length; i++) {
if (fileArray[i] == file) {
return true;
}
}
return false;
} function getLastArray(array) {
return array[array.length - 1];
} /**
* @param {Object} baseurl
* @param {Object} names
* function to load js files by names
*/
my.loadJsFile = function (names) {
var name = getLastArray(names);
if (!isLoaded(name, jsFile)) {
var url = g_applicationContext + g_jsPath + names.join("/") + ".js";
$("head").append("<script src='" + url + "'></script>");
jsFile.push(name);
}
}; /**
* load js files by jQuery ,support callback after js file loaded.
* @method loadJsFileByJQ
* @param {Array} names
* @param {Function} onload
*/
my.loadJsFileByJQ = function (names, onload) {
var name = getLastArray(names);
if (!isLoaded(name, jsFile)) {
var url = g_applicationContext + g_jsPath + names.join("/") + ".js";
jsFile.push(name);
$.getScript(url, function (data, textStatus, jqxhr) {
if (typeof onload == 'function') {
onload.apply();
}
});
} }; my.loadMock = function (name, onload) {
if (!isLoaded(name, jsFile)) {
var url = g_applicationContext + g_mockPath + name + ".js";
jsFile.push(name);
$("head").append("<script src='" + url + "'></script>");
}
} my.loadCssFile = function (names) {
var name = names[0];
if (!isLoaded(name, cssFile)) {
var url = g_applicationContext + g_cssPath + name + ".css";
$("head").append("<link type='text/css' rel='stylesheet' href='" + url + "'>");
cssFile.push(name);
}
}; my.loadRqrFiles = function (names, jqObj) {
var name = getLastArray(names);
if (!isLoaded(name, htmlFile)) {
var url = g_applicationContext + g_htmlPath + names.join("/") + ".html";
var func = function (data) {
//after the html file loaded,load the js and css files
jqObj.append(data);
htmlFile.push(name);
my.loadJsFile(names);
my.loadCssFile(names);
if (names.length == 1) {
populateThePageWithLanguageSetting(names.join("-") + "Page");
} else {
populateThePageWithLanguageSetting(names.join("-"));
}
}; var errorFunc = function (xhr) {
alert(xhr.statusText);
}; $.ajax({
async: false,
url: url,
type: "GET",
success: func,
error: errorFunc
});
}
};
return my;
}()); /*
*function for load file needed when menu item clicked
**/
$.fn.loadPageToContent = function (names) {
FileLoadTools.loadRqrFiles(names, $(this));
};
FileLoadTools的更多相关文章
随机推荐
- Tensorflow 梯度下降实例
# coding: utf-8 # #### 假设我们要最小化函数 $y=x^2$, 选择初始点 $x_0=5$ # #### 1. 学习率为1的时候,x在5和-5之间震荡. # In[1]: imp ...
- 【NLP+Deep learning】好文
http://blog.jobbole.com/77709/ 原文出处: http://colah.github.io/posts/2014-07-NLP-RNNs-Representations/
- Maven编译失败,提示No compiler is provided in this enviroment. Perhaps you are running on a JRE rathen a JDK ?
用maven对项目进行构建时,提示No compiler is provided in this enviroment. Perhaps you are running on a JRE rathen ...
- MemSQL start[c]up Round 1.b
二分查找题, 不知道用double的人,用LL果断错了... B. Stadium and Games time limit per test 1 second memory limit per te ...
- 【BZOJ4297】[PA2015]Rozstaw szyn 树形DP
[BZOJ4297][PA2015]Rozstaw szyn Description 给定一棵有n个点,m个叶子节点的树,其中m个叶子节点分别为1到m号点,每个叶子节点有一个权值r[i].你需要给剩下 ...
- 文艺青年、普通青年、2b青年到底是什么意思?
文艺青年.普通青年.2b青年到底是什么意思? 文艺青年就是脑子里跟别人想的不一样,思维跟人家相反或者另类的人. 普通青年呢就是像你一样,普普通通的. 2B青年就是黑铅笔青年,做事比较搞怪,古怪到让你哭 ...
- Maven的安装配置及初次创建项目与java单元测试工具JUnit
Maven 安装 1.把maven安装包解压到某个位置 2.配置M2_HOME环境变量指向这个位置 3.在path环境变量中添加;%M2_HOME%\bin 配置镜像 国内的阿里云镜 ...
- Spring在Web应用中使用的原理
那Spring如何在web应用中使用 ①加入Spring web应用的特定jar包spring-web-4.0.0.RELEASE.jar.spring-webmvc-4.0.0.RELEASE.ja ...
- 巨蟒python全栈开发flask10 项目开始2
1.websocket异常处理 出现上图报错的原因是什么? 原因是:websocket断开了,所以报错 19行接收的msg是None值,所以报错. 打开一个文件,点击发送音乐,出现上面的内容: 客户端 ...
- Game 游戏开发
Scut:https://git.oschina.net/scutgame/Scut unity3d:http://unity3d.com/get-unity cocos2d-x:http://www ...