/**
* 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的更多相关文章

随机推荐

  1. java内存溢出怎么解决

    java.lang.OutOfMemoryError这个错误我相信大部分开发人员都有遇到过,产生该错误的原因大都出于以下原因:JVM内存过小.程序不严密,产生了过多的垃圾. 导致OutOfMemory ...

  2. 【UVa】Wavio Sequence(dp)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  3. hdu 5065 数学题

    #include<iostream> #include<cmath> #include<cstdio> using namespace std; int A,B,y ...

  4. cpio -H newc参数详解

    -H format 其中个format可以是: ‘bin’ The obsolete binary format. (2147483647 bytes) ‘odc’ The old (POSIX.1) ...

  5. HttpModule的简单示例

    1.HttpModule可用在asp.net 管线事件触发的过程中.. 可处理一些通用的操作,如给特定请求加 gzip压缩. 2.示例代码: using System; using System.We ...

  6. UIWindow小记

    If you choose to create a window in Interface Builder, be sure to select the Full Screen at Launch o ...

  7. [转]ASP.NET MVC 5 - 视图

    在本节中,你要去修改HelloWorldController类,使用视图模板文件,在干净利索地封装的过程中:客户端浏览器生成HTML. 您将创建一个视图模板文件,其中使用了ASP.NET MVC 3所 ...

  8. WebApi 异常处理解决方案

    1.继承ExceptionFilterAttribute类,重写OnException方法 public class WebApiExceptionFilterAttribute : Exceptio ...

  9. insmod 内核模块参数传递

    对于如何向模块传递参数,Linux kernel 提供了一个简单的框架.其允许驱动程序声明参数,并且用户在系统启动或模块装载时为参数指定相应值,在驱动程序里,参数的用法如同全局变量. 通过宏modul ...

  10. C语言while语句

    在C语言中,共有三大常用的程序结构: 顺序结构:代码从前往后执行,没有任何“拐弯抹角”: 选择结构:也叫分支结构,重点要掌握 if else.switch 以及条件运算符: 循环结构:重复执行同一段代 ...