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的更多相关文章
随机推荐
- web 汇率
http://www.cnblogs.com/beimeng/p/3789940.html 网站虽小,五脏俱全(干货) 前言 最近一个朋友让帮忙做一个汇率换算的网站,用业余时间,到最后总算是实现了 ...
- duilib Webkit内核dui化浏览器控件
參考http://blog.csdn.net/zhuhongshu/article/details/38540711 改进: 1.跟其它duilib控件一样,不包括窗体 2.将onURLChanged ...
- 用ssh和互信链接建立批量执行
main server: 192.168.100.101 sub sever1: 192.168.100.102 sub server2: 192.168.100.103 main server执行脚 ...
- hrbustoj 1104:Leyni, LOLI and Line(解析几何,斜截式的应用)
Leyni, LOLI and Line Time Limit: 1000 MS Memory Limit: 65536 K Total Submit: 181(54 users) Tota ...
- iOS -转载-根据字母排序
1.从小到大自然排序NSDictionary *dic = @{", ", ", ", ", ", ", ", &quo ...
- IOS开发学习笔记039-autolayout 代码实现
本文转载至 http://www.cnblogs.com/songliquan/p/4548206.html 1.代码实现比较复杂 代码实现Autolayout的步骤 利用NSLayoutConstr ...
- 在centos linux上安装jdk7
在这里下载jdk7rpm安装包,并上传到centos服务器上http://www.oracle.com/technetwork/java/javase/downloads/java-se-jdk-7- ...
- vector排序问题<unresolved overloaded function type>
要对vector中的自定义类型进行排序,首先需要提供一个函数bool comp(const Interval & a, const Interval & b) 来定义类型的排序准则 然 ...
- Python--Get and Post
#python3 get and post 简单封装 from urllib import request, parse import json def RequestMethod(methodR, ...
- CodeForces 732B Cormen — The Best Friend Of a Man
B. Cormen - The Best Friend Of a Man time limit per test 1 second memory limit per test 256 megabyte ...