js扩展jquery对象基元的开发与代码编写
(function (window, $, undefined) {
var _Core = function () {
var eventarr = [];
var _OnPageLoad = undefined;
///获取USER信息
var getUser = function () {
//var obj = {};
//obj.USERID = $.cookie(COOKIE_USER);
var cookieData = $.cookie(COOKIE_USER);
if (cookieData === undefined) {
$Core.TimeOut();
return {};
}
var cookieuser;
try {
cookieuser = $.parseJSON(cookieData);
} catch (e) {
$Core.TimeOut();
//window.location.href = TIMEOUT_PATH;
return {};
}
if (cookieuser == undefined || cookieuser.USERID == undefined) {
//每一登录信息跳转至登录页面
//alert("登录超时!");
$Core.TimeOut();
//window.location.href = TIMEOUT_PATH;
return {};
}
return cookieuser;
}
//登录 设置用户本地信息
this.Login = function (userinfo) {
$.cookie(COOKIE_USER, JSON.stringify(userinfo), { json: true });
};
this.LogOut = function () {
$.removeCookie(COOKIE_USER);
};
//对外访问
this.USER = function () {
return getUser();
};
//服务地址
this.SERVICEPATH = function () {
return SERVICE_PATH;
};
this.SERVICEROOT = function () {
return SERVICE_ROOT;
}
this.APPID = APP_ID;
//验证失败,
this.TimeOut = function () {
//alert("身份验证失败,请重新登录!");
$Core.LogOut();
window.top.location.href = TIMEOUT_PATH;
};
//验证服务是否可用
this.ValidPage = function (rid) {
var resid = rid || $Core.util.getResId();
if (resid) {
var isexists = window.top.RESLIST.contains({ resId: resid },
function (item1, item2) {
return item1.resId === item2.resId;
});
if (!isexists) {
location.href = "/403.html";
return;
}
}
//验证
//$.ajax({
// url: "WebForm1.aspx",
// data: { resid:rid },
// success: function (datas) {
// if (datas.state == -1) {
// //没有权限跳转
// }
// }
//});
};
/**
* 获取
* @param {any} resid 页面资源id
* @param {any} func 回调
*/
this.ValidAction = function (resid, func) {
var btns = $("[data-rescode]");
btns.hide();
var resbtns = $Core.util.getResActions();
if (resbtns.length > 0);
{
$.each(resbtns,
function (i, n) {
$.each(btns,
function (j, btn) {
var jbtn = $(btn);
var btnRes = jbtn.data("rescode");
if (btnRes != undefined &&
btnRes !== "" &&
btnRes.toLowerCase() === n.resCode.toLowerCase()) {
jbtn.show();
}
});
});
btns.filter(":hidden").remove();
}
};
this.ajax = jqueryAjax;
this.IsAjaxTimeOut = false;
var _loading = function () {
this.AjaxLoadingStart = function () {
$("#pageloadingright").fadeIn();
};
this.HideAjaxLoading = function () {
$("#pageloadingright").fadeOut(500);
};
this.HidePageLoading = function () {
$("#pageloading").fadeOut(500);
}
this.HideAll = function () {
this.HideAjaxLoading();
this.HidePageLoading();
}
};
this.Loading = new _loading();
/**
* 页面所有ajax加在完毕后执行
* @param {function()} func 回调函数
*/
this.OnPageLoad = function (func) {
if (func !== undefined)
_OnPageLoad = func;
};
var pageLoad = function () {
if (_OnPageLoad)
_OnPageLoad();
};
$(function () {
var _interval = setInterval(function () {
//if
if (!window.ajaxruning) {
clearInterval(_interval);
pageLoad();
}
}, 100);
$Core.ValidPage();
$Core.ValidAction();
});
};
window.$Core = new _Core();
var config = function () {
return {
//附件上传单文件大小限制
WebUpload_fileSingleSizeLimit: 50 * 1024 * 1024,
//ajax请求超时时间
ajaxTimeout: 30000
};
};
$Core.Config = new config();
/******************************************UI****************************** */
var _UI = function () {
var _message = function () {
var createAlert = function (type, msg, timeout) {
if (timeout === undefined)
timeout = 2000;
var div = $(
'<div class="cntenalert" >' +
'<div class="alert-icons"></div>' +
'<div class="alert-close">×</div>' +
'<div class="alert-msg"></div></div>');
var winWidth = ($(window).width() - 200) / 2;
div.css("left", winWidth);
div.addClass(type);
var close = div.find(".alert-close");
var divmsg = div.find(".alert-msg");
close.click(function () {
div.fadeOut(function () {
div.remove();
});
});
divmsg.text(msg);
div.fadeIn(function () {
});
$("body").append(div);
if (timeout > 0)
setTimeout(function () {
div.fadeOut(function () {
div.remove();
});
}, timeout);
}
/**
* 成功提示
* @param {any} msg
*/
this.success = function (msg) {
createAlert("alert", msg);
}
/**
* 错误的提示
* @param {any} msg
*/
this.error = function (msg) {
createAlert("alert-error", msg, 5000);
}
/**
* 提醒
* @param {any} msg
*/
this.warning = function (msg) {
createAlert("alert-warning", msg, 3000);
}
/**
* 清除所有提示信息
* */
this.clear = function () {
$(".cntenalert").fadeOut(function () {
$(".cntenalert").remove();
});
}
}
this.message = new _message();
/**
* 打开一个url 的Dialog 对话框
* @param {any} id 指定一个名字
* @param {any} url 页面地址
* @param {any} options Dialog 参数
*/
this.openDialog = function (id, url, options) {
var frameid = id + "_frame";
var win = $("#" + id);
if (url.indexOf("?") > -1)
url = url + "&_r=" + Math.random();
else
url = url + "?_r=" + Math.random();
var getframe = function (id, url) {
var f = $('<iframe id="{0}" src="{1}" width="100%" height="100%" scrolling="no" frameborder="0" ></iframe>'.format(id, url));
return f;
};
if (win.size() == 0) {
var $frame = getframe(frameid, url);
//$frame.height(options.height - 43);
var defaultOptions = {
maximizable: true,
resizable: true,
closed: false,
cache: false,
modal: true,
constrain: true,
width: "80%",
height: "90%"
};
if (options) {
$.extend(defaultOptions, options,
{
onClose: function () {
win.remove();
if ($.isFunction(options.onClose)) {
options.onClose.apply(this);
}
}
});
}
defaultOptions.content = $frame;
var dd = $("<div id='" + id + "' style='overflow:hidden' />");
return dd.dialog(defaultOptions);
} else {
$("#" + frameid).attr("src", url);
return win.dialog("open");
}
}
/**
* 重新设置datagrid 排序状态
* @param {any} dg jquery对象
*/
this.resetDataGridSort = function (dg, psotrName, psortOrder) {
var opt = dg.datagrid('options');
opt.sortName = psotrName || "";
opt.sortOder = psortOrder || "";
var panel = dg.datagrid("getPanel");
var sortcell = panel.find(".datagrid-sort");
$.each(sortcell, function (i, n) {
var targer = $(n);
targer.removeClass("datagrid-sort-asc datagrid-sort-desc");
});
}
};
$Core.UI = new _UI();
})(window, jQuery);
基元使用
$Core.OnPageLoad(function () {
$Core.Loading.HidePageLoading();
});
var url = "InstallApplyForm.html?s=" + Math.random();
$Core.UI.openDialog("redwind", url + "&installApplyId=" + value +"&type=red",
{
title: "查看详情",
width: '80%',
height: '90%',
onClose: function () {
}
});