接 jquery 国际化使用:
showLanguage()函数
language.js
function showLanguage()
{
var language = null;
try
{
language = getLanguage();
}
catch(e)
{
console.info("Can not get language.");
}
return isNull(language) ? "zh" : language;
}
function showDatePickerLanguage()
{
var language = showLanguage();
return ((language === "zh") ? "zh-CN" : language);
}
function getDataTableLanguage()
{
var language = showLanguage();
if(language === 'zh' || language === 'zh-CN') {
return 'i18n/Chinese.json';
}
return 'i18n/English.json';
}
function showAngularLanguage(){
var language = showLanguage();
if (language === 'zh' || language === 'zh-CN') {
language = 'zh_CN';
} else if (language === 'en' || language === 'en-US'){
language = 'en_US';
}
return language;
}
function getPCIDataTableLanguage()
{
var language = showLanguage();
if(language === 'zh' || language === 'zh-CN') {
return 'i18n/pciDataTables_zh.json';
}
return 'i18n/pciDataTables_en.json';
}
function isNull(value)
{
var result = false;
if(value == null|| value.length == 0)
{
result = true
}
return result
}
getLanguage()函数
gettool.js
/**
* 初始化脚本文件装载工具
* zongying 2010.12
* modify:
*/
$Boot = {};
/**
* 创建命名空间
* @param {Object} name
* @param {Object} object
*/
$Boot.createNamespace = function(name, object) {
var splits = name.split(".");
var parent = window;
//document.window浏览器内置对象
var part = splits[0];
for (var i = 0, len = splits.length - 1; i < len; i++, part = splits[i]) {
if (!parent[part]) {
parent = parent[part] = {};
} else {
parent = parent[part];
}
}
// 存放对象
parent[part] = object;
// 返回 last part name (例如:classname)
return part;
}
$Boot.isDefined = function(o) {
return typeof (o) != "undefined"
}
/**
* 启动配置类
*/
$Boot.Config = function() {
//取的浏览器语言设置和自定义皮肤
/* try {
if($userFrameDir=="/common/"){
$userFrameDir = httpRequest("GET", "/rest/web/common/getCasServerUrl", "") + "/common/"
}
}
catch (e) {
}
*/
function isDefined(o) {
return typeof (o) != "undefined"
}
//用户应用当前目录
if (!isDefined(window.$userAppDir)) {
window.$userAppDir = './'
}
//组件库目录
if (!isDefined(window.$userFrameDir)) {
window.$userFrameDir = '/common/'
}
//用户i18文件目录
if (!isDefined(window.$userI18nDir)) {
window.$userI18nDir = './'
}
/**
* 定义一个全局国际化信息的入口,所有涉及到我们自定义的国际化文件的引用为 zteMsg.i18nMessages.xxx,文件路劲改为res/web-common/comp/i18n/frameworkMessages_xx.js
*/
window.zteMsg = new Object();
/**
* smartclient 目录 (全局变量)
*/
window.isomorphicDir = "/web/res/web-common/thirdparty/smartclient/isomorphic/";
//脚本文件
var isc_jsPath = isomorphicDir + "system/development/";
//smartclient的核心组件位置 之前的代码太耦合了 先暂时单列一个目录出来
var isc_core_js_Path = "/web/res/web-common/thirdparty/smartclient/isomorphic/system/development/";
//非smartclint核心组件位置 之前的代码太耦合了 先暂时单列一个目录出来
var other_common_js_Path = "/web/res/web-common/comp/system/development/";
//i18n
var isc_i18nPath = "/web/res/web-common/thirdparty/smartclient/isomorphic/locales/";
//js库文件
var isc_jsLibs = ['ISC_Core', 'ISC_Foundation', 'ISC_Containers', 'ISC_Grids', 'ISC_Forms', 'ISC_DataBinding'];
//自定义js库文件
var aos_jsLibs = ['../../jquery', 'json2', 'cometd/cometd', 'cometd/jquery/jquery.cometd','ict-cometd','aos-component'];
// 皮肤文件
window.$isc_skinName = "EnterpriseBlue";
window.isc_skinPath = "/web/res/web-common/thirdparty/smartclient/isomorphic/skins/" + $isc_skinName + "/";
//当前语言 默认为英语
var language = "en-US";
var defLanguage = "en-US";
/**
* 应用目录
*/
//当前应用目录(html入口文件所在目录)
var appDir = window.$userAppDir;
// 当前应用i18n目录
var app_i18nPath = window.$userI18nDir + "i18n/";
var common_i18nPath = "/web/res/web-common/comp/i18n/";
var common_i18nFiles = [];
var common_fileString = "aos-header";
/**
* 当前应用js目录
*/
var app_jsPath = appDir + "js/";
/**
* 各个模块js文件后缀前缀
*/
var suffixTags = ['-i18n', '-logic', '-ui'];
var isMoz = (navigator.userAgent.indexOf("Gecko") != -1) &&
// NOTE: Safari sends "(like Gecko)", but behaves differently from Moz in many ways
(navigator.userAgent.indexOf("Safari") == -1) && (navigator.userAgent.indexOf("AppleWebKit") == -1);
var isFirefox = (isMoz && navigator.userAgent.indexOf("Firefox/") != -1);
//从服务端取客户端接受语言类型
var getAcceptLangFromServer = true;
/**
* 构造SmartClientjs文件实际路径
*/
function getSmartClientJsLibPath(jsLibs) {
var jsLibsPath = new Array(jsLibs.length);
var num = jsLibs.length;
for (var i = 0; i < num; i++) {
jsLibsPath[i] = isc_jsPath + jsLibs[i] + ".js";
}
return jsLibsPath
}
/**
* 构造其他js文件实际路径
*/
function getOtherJsLibPath(jsLibs) {
var jsLibsPath = new Array(jsLibs.length);
var num = jsLibs.length;
for (var i = 0; i < num; i++) {
jsLibsPath[i] = other_common_js_Path + jsLibs[i] + ".js";
}
return jsLibsPath
}
/**
* 构造SmartClientjs核心组件的文件实际路径
*/
function getSmartCoreClientJsLibPath(jsLibs) {
var jsLibsPath = new Array(jsLibs.length);
var num = jsLibs.length;
for (var i = 0; i < num; i++) {
jsLibsPath[i] = isc_core_js_Path + jsLibs[i] + ".js";
}
return jsLibsPath
}
/**
* 构造应用js文件实际路径
* @param {Object} files
*/
function getAppJsPaths(files) {
var jsPaths = new Array(files.length * 2);
var num = jsPaths.length;
for (var i = 0; i < num; ) {
jsPaths[i++] = app_jsPath + files[0] + '-logic' + '.js';
jsPaths[i++] = app_jsPath + files[0] + '-ui' + '.js';
}
return jsPaths;
}
/**
* 构造应用i18文件详细路径名称
* @param {Object} files
*/
function getAppI18nFilePaths(files) {
var jsPaths = new Array(files.length);
var num = files.length;
for (var i = 0; i < num; i++) {
jsPaths[i] = app_i18nPath + name + "-i18n-" + language + ".js";
}
return jsPaths;
}
/**
* 读取1个i18文件
* @param {Object} name
*/
this.loadI18File=function(name, path) {
var i18File = path + name + "-i18n-" + language + ".js";
load(i18File);
}
function arrayContains(array, element) {
for ( i = 0; i < array.length; i++) {
if (array[i] == element)
return true;
}
return false;
}
/**
* 读取SmartClient国际化文件
* @param {Object} path
*/
function loadSmartClientI18File(path) {
var i18File = path + "frameworkMessages_" + language.replace("-", "_") + ".properties";
load(i18File);
}
/**
* 读取一批i18文件
* @param {Object} names
*/
function loadI18Files(names, path) {
for (var i = 0; i < names.length; i++) {
loadI18File(names[i], path);
}
}
/**
* 异步动态装载,异步执行js
* @param {Object} url
*/
function load0(url) {
var script = document.createElement("script")
script.type = "text/javascript";
script.src = url;
document.getElementsByTagName("head")[0].appendChild(script);
}
/**
* 异步动态装载,同步执行js
* @param {Object} url
* @param {Object} callback
*/
function load(url) {
document.write("<" + "SCRIPT SRC=" + url + "><" + "/SCRIPT>");
}
/**
* 异步动态装载,同步执行js
* @param {Object} url
* @param {Object} callback
*/
function loadAppJs(url) {
document.write("<" + "SCRIPT SRC=" + app_jsPath + url + "><" + "/SCRIPT>");
}
/**
* 同步动态装载js,同步执行js
* @param {Object} url
* @param {Object} callback
*/
function loadSync(url, callback) {
var script = document.createElement("script")
script.type = "text/javascript";
if ($Boot.isDefined(script.readyState)) {//IE
script.onreadystatechange = function() {
if (script.readyState == "loaded" || script.readyState == "complete") {
script.onreadystatechange = null;
callback();
}
};
} else {//Others
script.onload = function() {
callback();
};
}
script.src = url;
document.getElementsByTagName("head")[0].appendChild(script);
}
/**
* 同步装载js文件集合
* @param {Object} urls
*/
function loadScriptsSync(urls) {
var nexturls = urls.slice(1, urls.length);
Sync(urls[0], function() {
loadSync(nexturls);
});
}
/**
* 同步装载js文件集合
* @param {Object} urls
*/
function loadScripts(urls) {
for (var i = 0; i < urls.length; i++) {
load(urls[i]);
}
}
/**
* 装载SmartClient
*/
function loadSmartClientModules(aLibs) {
var jsLibs;
if (isDefined(aLibs)) {
jsLibs = getSmartClientJsLibPath(aLibs);
} else {
jsLibs = getSmartCoreClientJsLibPath(isc_jsLibs);
}
loadScripts(jsLibs);
loadSmartClientI18File(isc_i18nPath);
loadScripts(getOtherJsLibPath(aos_jsLibs));
//loadSmartClientI18File(isc_i18nPath);
loadSkin();
}
function getMyStyle() {
var selectStyle = httpRequest("GET", "/rest/web/portal/getConfig?key=web_portal_myselectStyle", "");
if (eval("(" + selectStyle + ")").result != undefined) {
return isomorphicDir + "skins/" + eval("(" + selectStyle + ")").result + "/";
} else {
return "";
}
}
/**
* 装载皮肤
*/
function loadSkin() {
load(isc_skinPath + "load_skin.js");
//特殊处理firefox的input组件高度不够字符遮挡问题
var userAgent = navigator.userAgent.toLowerCase();
var isFirefox = /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent ) ;
if(isFirefox){
var styleInput =
"<style>" +
"input.selectItemText," +
"input.selectItemTextError," +
"input.selectItemTextFocused," +
"input.selectItemTextDisabled," +
"input.textItem," +
"input.textItemFocused," +
"input.textItemDisabled," +
"input.textItemDisabledHint," +
"input.textItemError," +
"input.textItemHint{" +
"min-height: 20px;" +
"padding-bottom: 0px;" +
"padding-top: 0px;" +
"}" +
"</style>";
document.write(styleInput);
}
}
/**
* 创建XMLHttpRequest对象
*/
function createXMLHttpRequest() {
if (window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
} else if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else {
throw new Error("This Brower do not support XMLHTTP!!");
}
}
/**
* 同步发送xml http 请求(给外部调用)
* @param {Object} url
* @param {Object} data
* @param {Object} method
*/
this.httpRequestStatic = function(method, url, data) {
var xmlhttp;
xmlhttp = createXMLHttpRequest();
var sendData = null;
if (method == "get") {
url = url + "?" + data;
} else if (method == "post") {
sendData = data;
}
xmlhttp.open(method, url, false);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
xmlhttp.setRequestHeader("If-Modified-Since", "0");
xmlhttp.send(sendData);
if (xmlhttp.status == 200)
return xmlhttp.responseText;
}
/**
* 同步发送xml http 请求
* @param {Object} url
* @param {Object} data
* @param {Object} method
*/
function httpRequest(method, url, data) {
var xmlhttp;
xmlhttp = createXMLHttpRequest();
var sendData = null;
if (method == "get") {
url = url + "?" + data;
} else if (method == "post") {
sendData = data;
}
xmlhttp.open(method, url, false);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
xmlhttp.setRequestHeader("If-Modified-Since", "0");
xmlhttp.send(sendData);
if (xmlhttp.status == 200)
return xmlhttp.responseText;
}
function contains(string1, substring) {
if (string1 == null)
return false;
return string1.indexOf(substring) > -1
}
function startsWith(string1, substring) {
if (string1 == null)
return false;
return (string1.lastIndexOf(substring, 0) == 0);
}
function endsWith(string1, substring) {
if (string1 == null)
return false;
var startPos = string1.length - substring.length;
if (startPos < 0)
return false;
// substring longer than main string
return (string1.indexOf(substring, startPos) == startPos);
}
function trim(str, chars) {
if (str == null)
return null;
var removeChars = chars || " \t\n\r", l = str.length, start = 0, end = l - 1, i = 0;
// find first character not in the removal list
while (start < l && contains(removeChars, str.charAt(i++)))
start++;
// find last character not in the removal list
i = l - 1;
while (end >= 0 && end >= start && contains(removeChars, str.charAt(i--)))
end--;
return str.substring(start, end + 1);
}
function inArray(array, obj) {
for (var i = 0; i < array.length; i++) {
if (array[i] == obj) {
return true;
}
}
return false;
}
//var languageList = ['ar', 'ba', 'cr', 'cs', 'de', 'el', 'es', 'fi', 'fr', 'fr-FR', 'hu-HU', 'id', 'it', 'ja', 'nb-NO', 'nl', 'pl', 'pl-PL', 'pt', 'pt-BR', 'ro-RO', 'ru-RU', 'sk', 'sr', 'sr-Latn', 'sv-SE', 'en-US','uk-UA', 'zh-CN', 'zh-TW'];
var languageList = ['en-US', 'zh-CN'];
/**
* 取得浏览器语言信息
*/
function getAcceptLanguage() {
if (getAcceptLangFromServer || isFirefox) {
var method = "get";
var url = "/web/rest/web-common/common?action=acceptlanguage&";
var param = "_operationType=rpc&_operationName=comm.getAcceptLanguage";
try {
var ret = httpRequest(method, url, param);
} catch (e) {
return defLanguage;
}
ret = trim(ret);
if (ret == null || ret == "" || ret == "null") {//如果返回空
return defLanguage;
}
ret = (ret.split(",")[0]);
templ = ret.split("-");
if (templ.length == 1) {//如果没有'-'号
if (ret == "en") {
return "en-US";
//默认为美国英语
} else if (ret == "zh") {
return "zh-CN";
//默认为汉语中国
} else {
if (!inArray(languageList, ret)) {
return defLanguage;
} else {
return ret;
}
}
} else {//如果有'-'号
ret = templ[0].toLowerCase() + "-" + templ[1].toUpperCase();
if (!inArray(languageList, ret)) {
return defLanguage;
} else {
return ret;
}
}
} else {
return (window.navigator.userLanguage || window.navigator.language);
}
}
//取的浏览器语言设置和自定义皮肤
try {
language = getAcceptLanguage();
} catch (e) {
}
/**
* 取门户的url
*/
this.getCasServerLoginUrl = function() {
var method = "get";
var url = "/web/rest/web-common/common?action=getCasServerLoginUrl";
var param = "_operationType=rpc&_operationName=comm.getCasServerLoginUrl";
var ret = "";
try {
ret = httpRequest(method, url, param);
} catch (e) {
}
ret = trim(ret);
return ret;
}
/**
* 获取AOS场景
*/
this.getSceneMode = function() {
var method = "get";
var url = "/web/rest/web-common/common?action=scenemode&";
var param = "";
var ret = "0";
try {
ret = httpRequest(method, url, param);
} catch (e) {
}
ret = trim(ret);
return ret;
}
/**
* 装载框架文件文件
*/
this.loadFrameModules = function(alibs) {
//load自定义I18N JS
load("/web/res/web-common/comp/i18n/frameworkMessages_"+language+".js");
//加载smartclient相关js
loadSmartClientModules(alibs);
}
/**
* 装载Jquery datatable文件
*/
this.loadDataTableModules = function() {
load("/web/newict/framework/thirdparty/bootstrap/js/bootstrap.min.js");
load("/web/newict/framework/zte/scripts/core/ZteFrameWork.min.js");
load("/web/newict/framework/thirdparty/uniform/jquery.uniform.min.js");
load("/web/newict/framework/thirdparty/data-tables/jquery.dataTables.js");
load("/web/newict/framework/thirdparty/data-tables/DT_bootstrap.js");
load("/web/newict/framework/thirdparty/data-tables/DataTableSmartClientApp.js");
}
/**
* 装载Jquery SelectableTreeCanvas文件
*/
this.loadSelectableTreeModules = function() {
load("/web/newict/framework/thirdparty/jquery-1.10.2.min.js");
load("/web/newict/framework/thirdparty/jquery-migrate-1.2.1.min.js");
load("/web/newict/framework/thirdparty/jquery-ui/jquery-ui-1.10.3.custom.min.js");
load("/web/newict/framework/thirdparty/uniform/jquery.uniform.min.js");
load("/web/newict/framework/thirdparty/bootstrap/js/bootstrap.min.js");
load("/web/newict/framework/thirdparty/selectable-tree-flat/seletableTreeFlat.js");
}
/**
* 装载应用文件集合
* @param {Object} files
*/
this.loadAppModules = function(files) {
//装载i18文件
if (!arrayContains(files, common_fileString)) {
loadI18Files(common_i18nFiles, common_i18nPath);
}
loadI18Files(files, app_i18nPath);
//装载
var jsLibs = getAppJsPaths(files);
loadScripts(jsLibs);
}
/**
* 只装载应用的国际化文件
* @param {Object} files
*/
this.loadAppI18n = function(files) {
//装载i18文件
if (!arrayContains(files, common_fileString)) {
loadI18Files(common_i18nFiles, common_i18nPath);
}
loadI18Files(files, app_i18nPath);
//loadI18Files(common_i18nFiles, common_i18nPath);
}
/**
* 装载js
* @param {Object} urls 完整url
*/
this.loadScripts = loadScripts;
/**
* 装载应用自己的js
* @param {Object} file 文件名
*/
this.loadAppJs = loadAppJs;
/**
* 装载皮肤
*/
this.loadSkin = loadSkin;
/**
* 装载SmartClient国际化
*/
this.loadSmartClientI18n = function() {
loadSmartClientI18File(isc_i18nPath)
}
/**
* 构造应用js文件实际路径
* @param {Object} files
*/
function getAppJsPathsSub(files) {
var jsPaths = new Array(files.length * 2);
var num = jsPaths.length;
for (var i = 0; i < num; ) {
jsPaths[i++] = files[0] + '/' + app_jsPath + files[0] + '-logic' + '.js';
jsPaths[i++] = files[0] + '/' + app_jsPath + files[0] + '-ui' + '.js';
}
return jsPaths;
}
/**
* 构造应用js文件实际路径
* @param {Object} files
*/
function getAppJsPathsByName(files, name) {
var jsPaths = new Array(files.length * 2);
var num = jsPaths.length;
for (var i = 0; i < num; ) {
jsPaths[i++] = name + files[0] + '-logic' + '.js';
jsPaths[i++] = name + files[0] + '-ui' + '.js';
}
return jsPaths;
}
/**
* 装载应用文件集合
* @param {Object} files
*/
this.loadAppModulesByName = function(files, name) {
name = "../" + name + '/';
//装载i18文件
loadI18Files(files, name + "i18n/");
//装载
var jsLibs = getAppJsPathsByName(files, name + "js/");
loadScripts(jsLibs);
}
/**
* 装载应用子文件集合
* @param {Object} files
*/
this.loadSubAppModule = function(subdir, file) {
var app_i18nPath_sub = window.$userI18nDir + subdir + "/i18n/";
var app_jsPath_sub = appDir + subdir + "/js/";
//装载i18文件
loadI18File(file, app_i18nPath_sub);
var jsLibs = getAppJsPathsSub([file]);
loadScripts(jsLibs);
}
/**
* 装载应用子文件集合
*
* @param {Object} urls
* 每个url例如['sub1','sub2']
*/
this.loadSubAppModules = function(urls) {
for (var i = 0; i < urls.length; i++) {
var url = urls[i];
this.loadSubAppModule(url, url);
}
}
this.loadJs = load;
this.getLanguage = function() {
return language;
}
this.loadAos = function(){
var isLoadBySelf = true;
try
{
isLoadBySelf =typeof(parent.loadJsFromIndex) == "undefined" || !parent.loadJsFromIndex;
}catch(Exception)
{
}
if(isLoadBySelf){
aos.framework = new aos.framework();
aos.extension=new aos.extension();
}
}
this.getUrlParam=function(name){
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
var search =decodeURIComponent(location.search.substring(1)); //decodeURIComponent() 函数可对 encodeURIComponent() 函数编码的 URI 进行解码。
var r =search.match(reg); //匹配目标参数
if (r != null) return unescape(r[2]); //unescape() 函数可对通过 escape() 编码的字符串进行解码。
return null; //返回参数值
}
}
//创建命名空间
$Boot.createNamespace("com.zte.ums.aos.framework.BootConfig", $Boot.Config);
//创建基础配置对象实例
$Boot.bootConfig = new com.zte.ums.aos.framework.BootConfig();
/**
* 装载应用模块
* @param {Object} files
*/
function loadAppModules(files) {
return $Boot.bootConfig.loadAppModules(files)
}
/**
* 只装载应用国际化文件
* @param {Object} files
*/
function loadAppI18n(files) {
return $Boot.bootConfig.loadAppI18n(files)
}
/**
* 在不加在smartclient组件库情况下,提供发起ajax请求的方法
* @param method ajax请求的方法,有GET、POST、PUT、DELETE
* @param url ajax请求的url
* @param data ajax请求的参数
*/
function httpRequest(method, url, data) {
return $Boot.bootConfig.httpRequestStatic(method, url, data)
}
/**
* 装载框架皮肤
*/
function loadSkin() {
return $Boot.bootConfig.loadSkin();
}
/**
* 装载框架I18n
*/
function loadFrameI18n() {
return $Boot.bootConfig.loadSmartClientI18n();
}
/**
* 如果是ie浏览器,装载excanvas.original.js,使用vml模拟canvas
*/
function loadExcanvasIfIE() {
var isCanvas = !!document.createElement('canvas').getContext;
if (!isCanvas) {
var excanvasJS = $userFrameDir + "system/development/excanvas.original.js";
document.write("<" + "SCRIPT SRC=" + excanvasJS + "><" + "/SCRIPT>");
}
}
/**
* 装载框架模块
*/
function loadFrameModules(alibs) {
return $Boot.bootConfig.loadFrameModules(alibs);
}
/**
* 取门户的url
*/
function getCasServerLoginUrl() {
return $Boot.bootConfig.getCasServerLoginUrl();
}
/**
* 装载平级其他应用模块
* @param {Object} files
*/
function loadAppModulesByName(files, name) {
return $Boot.bootConfig.loadAppModulesByName(files, name)
}
/**
* 控制台输出
* @param {Object} msg
*/
function log(msg) {
if ($Boot.isDefined(window.console))
console.log(msg);
}
function getSmartClientRootPath(){
return "/web/res/web-common/thirdparty/smartclient/isomorphic/";
}
function getIctImgRootPath(){
return "/web/res/web-common/comp/skins/EnterpriseBlue/images/";
}
/**
* 初始化参数类
*/
$Boot.createNamespace("com.zte.ums.aos.framework.Config", {
logEnable : false,
loadScripts : $Boot.bootConfig.loadScripts
});
com.zte.ums.aos.framework.Config.logEnable = true;
/**
* 跨浏览器日志类
*/
$Boot.Logger = function() {
var _levels = ["TRACE", "DEBUG", "INFO", "WARN", "ERROR"];
var LevelMap = {};
//构造名值hash表
for (var i = 0; i < _levels.length; i++) {
LevelMap[_levels[i]] = i;
}
var _rootCatalog = "root";
var catalogLevel = {
'root' : LevelMap.DEBUG
}
function isInited() {
return $Boot.isDefined(window.console);
}
/**
* 调试窗口是否关闭
*/
function debugWinClosed() {
if (isInited() && window.console.popwin) {
return console.popwin.close === true
} else {
return false;
}
}
function init() {
if (isInited()) {
return;
}
window.console = {};
console.log = function(msg) {
console.content = console.popwin.document.getElementById("debug_console");
var str = console.content.innerText + "\n" + msg;
console.content.innerText = str;
};
console.show = function() {
console.popwin = window.open("about:blank", null, "height=400,width=600,status=yes,toolbar=no,menubar=no,location=no");
console.popwin.document.write('<div id="debug_console">debug info:</div>');
};
console.hide = function() {
console.popwin.close();
};
//创佳和显示调试窗口
console.show();
}
function log(level, msg, catalogName) {
//如果调试窗口已经被关闭,则打印调试信息。
if (!com.zte.ums.aos.framework.Config.logEnable || debugWinClosed()) {
return;
}
if ( typeof (level) != "number") {
return;
}
if (!$Boot.isDefined(msg)) {
msg = 'undefined message';
}
//没有设置,采取root级别
if (!$Boot.isDefined(catalogName)) {
catalogName = _rootCatalog;
}
var configLevel = catalogLevel[catalogName];
if ($Boot.isDefined(configLevel) && level < configLevel) {
return;
}
var log_pre_fix = new Date().toLocaleString() + " [" + _levels[level] + "] " + "[" + catalogName + "] ";
console.log(log_pre_fix + msg);
}
this.Level = LevelMap;
this.rootCatalog = _rootCatalog;
this.trace = function(msg, catalogName) {
log(this.Level.TRACE, msg, catalogName);
}
this.debug = function(msg, catalogName) {
log(this.Level.DEBUG, msg, catalogName);
}
this.info = function(msg, catalogName) {
log(this.Level.INFO, msg, catalogName);
}
this.warn = function(msg, catalogName) {
log(this.Level.WARN, msg, catalogName);
}
this.error = function(msg, catalogName) {
log(this.Level.ERROR, msg, catalogName);
}
this.setCatalogLevel = function(catalog, level) {
catalogLevel[catalog] = level;
}
//默认构造时执行初始化。
if (com.zte.ums.aos.framework.Config.logEnable) {
init();
}
};
function confirmLogout(logoutUrl, prompt, location) {
var answer = confirm(prompt);
if (answer == true) {
location.href = logoutUrl;
}
}
/**
* 判断当前屏幕是否在锁定状态
* @return true|false
*/
function isInMaskState() {
/*if (typeof(isc_EH_screenSpan) == 'undefined' || isc_EH_screenSpan == null) {
return false;
}
else {
return isc_EH_screenSpan.isVisible();
}*/
if (isc.EH.getTopHardMask() != null) {
return true;
}
}
//注册菜单框架-当前屏幕是否在锁定状态回调函数
if ( typeof isc != "undefined" && typeof aos != "undefined" && aos.framework && aos.framework.setMenuPopupFreeze) {
aos.framework.setMenuPopupFreeze(function() {
return isInMaskState();
});
}
//创建命名空间
$Boot.createNamespace("com.zte.ums.aos.framework.Logger", $Boot.Logger);
/**
* Component配置信息类
*/
$Boot.ComponentConf = function() {
this.isPureIPV4 = true;
this.multizonesupport = "no_multizone_dst";
function getIPConfig() {
var method = "get";
var url = "/web/rest/web-common/common?action=getIPConfig&";
var param = "";
try {
var ret = httpRequest(method, url, param);
} catch (e) {
return true;
}
if (ret == "false") {
return false;
}
return true;
}
function getTimeZoneConf() {
var ret = "no_multizone_dst";
var method = "get";
var url = "/web/rest/web-common/common?action=getTimeZoneConfig&";
var param = "";
try {
ret = httpRequest(method, url, param);
} catch (e) {
return "no_multizone_dst";
}
return ret;
}
function getTimeZoneKey() {
var ret = "UTC";
var method = "get";
var url = "/web/rest/web-common/common?action=getTimeZoneKey&";
var param = "";
try {
ret = httpRequest(method, url, param);
} catch (e) {
return "UTC";
}
return ret;
}
try {
this.isPureIPV4 = getIPConfig();
this.multizonesupport = getTimeZoneConf();
this.timeZoneKey = getTimeZoneKey();
} catch(e) {
}
};
/**
* 初始化Component配置信息类
*/
$Boot.createNamespace("com.zte.ums.aos.ComponentConf", $Boot.ComponentConf);
$Boot.CompConf = new com.zte.ums.aos.ComponentConf();
function getIsPureIPV4() {
return $Boot.CompConf.isPureIPV4;
}
function getTimeZoneConf() {
return $Boot.CompConf.multizonesupport;
}
function getTimeZoneKey() {
return $Boot.CompConf.timeZoneKey;
}
function getLanguage(){
return $Boot.bootConfig.getLanguage();
}
function loadAos(){
return $Boot.bootConfig.loadAos();
}
function getUrlParam(name){
return $Boot.bootConfig.getUrlParam(name);
}
function loadI18File(name, path){
return $Boot.bootConfig.loadI18File(name, path)
}
function loadDataTableModules() {
return $Boot.bootConfig.loadDataTableModules();
}
function loadSelectableTreeModules() {
return $Boot.bootConfig.loadSelectableTreeModules();
}
主框架通用功能///
$Boot.Framework={}
$Boot.Framework.CommonFunc = function() {
this.IEVersion = undefined;
this.isChromeFrameAvailable = true;
function getIEversion() {
var userAgent = window.navigator.userAgent.toLowerCase();
$.browser.msie10 = $.browser.msie && /msie 10\.0/i.test(userAgent);
if ($.browser.msie10) {
IEVersion = 10;
}
$.browser.msie9 = $.browser.msie && /msie 9\.0/i.test(userAgent);
if ($.browser.msie9) {
IEVersion = 9;
}
$.browser.msie8 = $.browser.msie && /msie 8\.0/i.test(userAgent);
if ($.browser.msie8) {
IEVersion = 8;
}
$.browser.msie7 = $.browser.msie && /msie 7\.0/i.test(userAgent);
if ($.browser.msie7) {
IEVersion = 7;
}
$.browser.msie6 = !$.browser.msie8 && !$.browser.msie7 && $.browser.msie && /msie 6\.0/i.test(userAgent);
if ($.browser.msie6) {
IEVersion = 6;
}
return IEVersion;
}
try {
this.IEVersion = getIEversion();
} catch(e) {
}
function isChromeFrameAvailable() {
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf("chromeframe") >= 0) {
return true;
}
if (typeof window['ActiveXObject'] != 'undefined') {
try {
var obj = new ActiveXObject('ChromeTab.ChromeFrame');
if (obj) {
obj.registerBhoIfNeeded();
return true;
}
} catch(e) {
}
}
return false;
}
try {
this.isChromeFrameAvailable = isChromeFrameAvailable();
} catch(e) {
}
};
$Boot.createNamespace("com.zte.ums.aos.common.framework.func",$Boot.Framework.CommonFunc );
$Boot.Framework.Index = new com.zte.ums.aos.common.framework.func();
function getIEversion() {
return $Boot.Framework.Index.IEVersion;
}
function isChromeFrameAvailable() {
return $Boot.Framework.Index.isChromeFrameAvailable;
}
/**
* 获取AOS场景,默认值为0。key为aos.scene.mode
*/
function getAosSceneMode() {
return $Boot.bootConfig.getSceneMode()
}
function root_modify_location(path) {
$("#nav_location_path").text(path);
//parent.document.getElementById("index_module_name").value = path;
var val=parent.document.getElementById("index_module_name");
if(val) {//如果找到了当前路径标签才显示,否则什么都不作
val.value = path;
}
}
function module_modify_location(path) {
if(path instanceof Array){
var temp = "";
var len = path.length;
for(var i=0;i<len;i++){
temp = temp + path[i];
if(i<len-1){
temp = temp + " > ";
}
}
path = temp;
}
try
{
var val = parent.document.getElementById("nav_location_path");
if(val){//如果找到了当前路径标签才显示,否则什么都不作
val.innerHTML=path;
}}
catch(Exception)
{
}
}
function get_index_module_name() {
//return parent.document.getElementById("index_module_name").value;
var val = parent.document.getElementById("index_module_name");
if(val) {//如果找到了当前路径标签才显示,否则什么都不作,返回空串
return val.value;
}else{
return "";
}
}
// 定义JQUERY AJAX 完成函数,判断返回状态,如果状态正常,但HEADER头里有session超时信息,则刷新重登录
// 如果状态为 401, 也刷新重登录
// 注意如果在$.ajax() 函数中定义了 complete,则覆盖了这里预定义complete内容,以$.ajax()函数中定义的为准,这里预定义的函数则失效,如果
// 要继续判断session超时,则需要在 $.ajax()函数中定义的complete函数中加入这里预定义内容。
if (jQuery) {
$.ajaxSetup({
complete:function(XMLHttpRequest,textStatus){
if (XMLHttpRequest.status == 401) {
window.location.replace("/");
}
// if (XMLHttpRequest.status == 200) {
// var sessionstatus=XMLHttpRequest.getResponseHeader("sessionstatus"); 通过XMLHttpRequest取得响应头,sessionstatus,
// if(sessionstatus=="timeout"){
// window.location.replace("/");
// }
// } else if (XMLHttpRequest.status == 401) {
// window.location.replace("/");
// }
}
});
}
//扩展String 方法
String.prototype.trim = function() {
return this.replace(/^\s+/, '').replace(/\s+$/, '')
};
//将汉字编码成unicode
//若没有汉字直接返回原内容
function unicode(text){
var preStr = '\\u';
var value = text.trim();
var cnReg = /[\u0391-\uFFE5]/gm;
if (cnReg.test(value)) {
var ret = value.replace(cnReg,
function(str) {
return preStr + str.charCodeAt(0).toString(16)
});
return ret
} else {
return text
}
}
//将unicode转码为汉字
function chinese(text) {
var ovalue = text.trim();
if (ovalue) {
var omt = ovalue,
uReg = /\\u(\w{4})/img;
if (uReg.test(ovalue)) {
var ret = ovalue.replace(uReg,
function(str, subs) {
return unescape('%u' + subs)
});
return ret
}
} else {
return text;
}
}
function getStringWidth(text,fontSize)
{
var span = document.getElementById("_ictframework_getwidth");
if (span == null) {
span = document.createElement("span");
span.id = "_ictframework_getwidth";
document.body.appendChild(span);
}
span.innerText = text;
span.style.whiteSpace = "nowrap";
$("#_ictframework_getwidth").attr('style','font-size:'+fontSize+'px;');
var width = span.offsetWidth;
$("#_ictframework_getwidth").attr('style','display:none');
return width;
}
function initConf(){
//把框架所有的ajax请求集中到一起,发一条请求,获取所有的配置信息。
ZteFrameWork_conf = {};
$.ajax({
url : "/web/rest/web-common/getMenuItemVisible",
type : "GET",
cache:false,
contentType : 'application/json; charset=utf-8',
success: function(data){
var tempConf = JSON.parse(data.value);
ZteFrameWork_conf = tempConf;
//userName = data;
//console.info('login user is :' + data);
}
});
}