| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496 |
- /**
- * 包含通用公共方法的脚本,c为common的缩写
- */
- if (!window.wd)
- window.wd = {};
- wd.c = {};
- /*
- * wd.c.oriClose = window.close;//原版的window.close方法
- *
- * wd.c.closeWindow = function() {//在IE7中,无提示关闭窗口的方法 top.oriOpener =
- * top.opener;//保存原来的window.opener top.opener = null; top.open('', '_self');
- * wd.c.oriClose(); }
- *
- * window.close=wd.c.closeWindow;//覆盖原版的window.close方法
- */
- /** 通过NAME或ID获得页面元素的通用方法 * */
- wd.c.g = function (nameOrId, // 要获得的DOM元素的name或ID
- windowObj) { // 获得的DOM元素所属的window对象(可选参数,不填则默认为window)
- if (!windowObj)
- windowObj = window;
- var rs = windowObj.document.getElementById(nameOrId);
- if (!rs) // 如果上面获取不到对象,则采用下面的方法取得对象实例
- rs = windowObj.document.getElementsByName(nameOrId)[0];
- if (!rs) // 如果上面获取不到对象,则采用下面的方法取得对象实例
- rs = windowObj.frames[nameOrId];
- return rs;
- }
- /** 打印调信息的方法 * */
- wd.c.debug = function (s) {
- // 如果显示debug的窗口不存在,则初始化一个
- if (!window.debugWindow || window.debugWindow.closed) {
- window.debugWindow = window.open();
- // 如果本窗口关闭则debug窗口也关闭
- window.onbeforeunload = function () {
- window.debugWindow.close();
- };
- }
- window.debugWindow.document.write(s);
- window.debugWindow.document.write('<br/>');
- }
- /**
- * 为DOM元素targetElem的evenName事件追加事件触发时回调函数activeFun
- * 通过此函数为DOM元素绑定监听事件的好处在于:可以把新添加的监听函数与DOM元素
- * 已绑定的旧的监听函数合并成为新的监听函数,而不会覆盖DOM元素旧的同名监听函数。
- */
- wd.c.addEventListener = function (targetElem, // 需绑定监听事件的DOM元素
- eventName, // 事件名称,如:onclick
- activeFun) { // 事件触发的回调函数
- // DOM元素原来的监听事件
- var oriListener = targetElem[eventName];
- if (oriListener) { // 如果原来已经存在同名的监听事件了
- targetElem[eventName] = function () {
- oriListener.call(targetElem); // 调用原来已经存在监听方法
- return activeFun.call(targetElem); // 调用新添加的监听方法
- }
- } else {
- targetElem[eventName] = function () {
- return activeFun.call(targetElem); // 调用新添加的监听方法
- }
- }
- }
- // 把json转化为字符串格式
- wd.c.O2String = function (O) {
- // return JSON.stringify(jsonobj);
- var S = [];
- var J = "";
- if (Object.prototype.toString.apply(O) === "[object Array]") {
- for (var i = 0; i < O.length; i++) {
- S.push(O2String(O[i]));
- }
- J = "[" + S.join(",") + "]";
- } else {
- if (Object.prototype.toString.apply(O) === "[object Date]") {
- J = "new Date(" + O.getTime() + ")";
- } else {
- if (Object.prototype.toString.apply(O) === "[object RegExp]" || Object.prototype.toString.apply(O) === "[object Function]") {
- J = O.toString();
- } else {
- if (Object.prototype.toString.apply(O) === "[object Object]") {
- for (var i in O) {
- O[i] = typeof (O[i]) == "string" ? "\"" + O[i] + "\"" : (typeof (O[i]) === "object" ? O2String(O[i]) : O[i]);
- S.push(i + ":" + O[i]);
- }
- J = "{" + S.join(",") + "}";
- }
- }
- }
- }
- return J;
- };
- // 获得传入的对象的e的坐标、宽高,保存到一个对象中并返回
- wd.c.getAbsPoint = function (e) {
- try {
- var x = e.offsetLeft;
- var y = e.offsetTop;
- var w = e.offsetWidth;
- var h = e.offsetHeight;
- /**
- * OffsetParent为从中计算偏移量的元素。 如果某个元素的父级或此元素层次结构中的其他元素使用相对或绝对定位, 则
- * OffsetParent 将成为当前元素嵌套到的第一个相对或绝对定位元素。如果当前元素以上的任何元素都不是绝对 或相对定位的,则
- * OffsetParent 将是文档的 BODY 标记。
- *
- * obj.offsetTop 指 obj 距离上方或上层控件的位置,整型,单位像素。 obj.offsetLeft 指 obj
- * 距离左方或上层控件的位置,整型,单位像素。
- *
- * offsetTop与offsetLeft均为相对偏移量,但是下面不断地拿offsetParent的偏移量来累加,
- * 直至拿到offsetParent为body之后,就没有offsetParent了,此时循环才终止。
- * 最终计算出来的x,y为e相对body的绝对坐标。
- */
- while (e = e.offsetParent) { // 只要对象的offsetParent存在,则继续累加XY,
- x += e.offsetLeft;
- y += e.offsetTop;
- }
- return {
- "x": x,
- "y": y,
- "w": w,
- "h": h
- };
- } catch (e) {
- if (this.debug)
- alert('方法getAbsPoint执行异常:' + e);
- }
- };
- // var jb51 =new function() {
- // dom = [];
- // dom.isReady = false;
- // dom.isFunction = function(obj) {
- // return Object.prototype.toString.call(obj) === "[object Function]";
- // }
- // dom.Ready = function(fn) {
- // dom.initReady();
- // //如果没有建成DOM树,则走第二步,存储起来一起杀
- // if (dom.isFunction(fn)) {
- // if (dom.isReady) {
- // fn();
- // //如果已经建成DOM,则来一个杀一个
- // } else {
- // dom.push(fn);
- // //存储加载事件
- // }
- // }
- // }
- // dom.fireReady = function() {
- // if (dom.isReady) return;
- // dom.isReady = true;
- // for (var i = 0, n = dom.length; i < n; i++) {
- // var fn = dom[i];
- // fn();
- // }
- // dom.length = 0;
- // //清空事件
- // }
- // dom.initReady = function() {
- // if (document.addEventListener) {
- // document.addEventListener("DOMContentLoaded", function() {
- // document.removeEventListener("DOMContentLoaded", arguments.callee, false);
- // //清除加载函数
- // dom.fireReady();
- // },
- // false);
- // } else {
- // if (document.getElementById) {
- // document.write("<script id=\"ie-domReady\"
- // defer='defer'src=\"//:\"><\/script>");
- // document.getElementById("ie-domReady").onreadystatechange = function() {
- // if (this.readyState === "complete") {
- // dom.fireReady();
- // this.onreadystatechange = null;
- // this.parentNode.removeChild(this)
- // }
- // };
- // }
- // }
- // }
- // }
- Date.prototype.Format = Date.prototype.format = function (fmt) {
- var o = {
- "M+": this.getMonth() + 1, // 月份
- "d+": this.getDate(), // 日
- "h+": this.getHours(), // 小时
- "m+": this.getMinutes(), // 分
- "s+": this.getSeconds(), // 秒
- "q+": Math.floor((this.getMonth() + 3) / 3), // 季度
- "S": this.getMilliseconds(), // 毫秒
- "E": "星期" + "日一二三四五六".charAt(new Date().getDay())
- };
- if (/(y+)/.test(fmt))
- fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "")
- .substr(4 - RegExp.$1.length));
- for (var k in o)
- if (new RegExp("(" + k + ")").test(fmt))
- fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
- return fmt;
- };
- /**
- * 获取ueditor对应路径的html
- * @param {Object} fpath
- * @param {Object} options
- */
- wd.c.getUeditorData = function (fpath, options) {
- var ret = {};
- var opt = {};
- for (var key in options) {
- if (typeof options[key] == 'string') {
- opt[key] = options[key];
- }
- }
- if (fpath) fpath = fpath.replace(/(^\s*)|(\s*$)/g, "")
- opt.path = fpath;
- /* 再去掉,去掉 ?wdApplication= -- 不支持多个应用,ssServ= 里可以写 ss.xxx。Lin
- if (!opt.wdApp)
- console.error("没获取到当前应用名 参数 wdApp");
- */
- opt.extra = (opt && opt.isextra) || opt.extra || undefined;
- if (!opt.extra) {
- delete opt["extra"];
- }
- for(var key in opt){
- if(opt[key]==null){
- delete opt[key];
- }
- }
- wd.c.wdAjax({
- type: "post",
- /* 再改,规范命名。Lin
- * 去掉 ?wdApplication=,不支持多个应用 -- 服务名可以写 ss.xxx
- * &wdService= 改为 ssServ
- url: "/service?wdApplication=wd&wdService=loadEditorBody",
- */ url: "/service?ssServ=loadEditorBody",
- dataType: "json",
- data: opt,
- async: false,
- success: function (data) {
- if (data.msg_0) console.error("**" + data.msg_0 + "**");
- ret=data;
- },
- });
- return ret;
- };
- /**
- *
- * @param {Object} options
- */
- wd.c.wdAjax = function (options) {
- // function ga_ajax(options) {
- var xhr = createXHR();
- options.url = options.url; // 清除缓存
- options.data = params(options.data); // 转义字符串
- if (options.type === "get") { // 判断使用的是否是get方式发送
- options.url += options.url.indexOf("?") == "-1" ? "?" + options.data : "&" + options.data;
- }
- // 异步
- if (options.async === true) {
- // 异步的时候需要触发onreadystatechange事件
- xhr.onreadystatechange = function () {
- // 执行完成
- if (xhr.readyState == 4) {
- callBack();
- }
- }
- }
- xhr.open(options.type, options.url, options.async); // false是同步 true是异步 // "demo.php?rand="+Math.random()+"&name=ga&ga",
- if (options.type === "post") {
- xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
- xhr.send(options.data);
- } else {
- xhr.send(null);
- }
- // xhr.abort(); // 取消异步请求
- // 同步
- if (options.async === false) {
- callBack();
- }
- // 返回数据
- function callBack() {
- // 判断是否返回正确
- if (xhr.status == 200) {
- if (options.dataType == "json") {
- options.success(JSON.parse(xhr.responseText));
- } else {
- options.success(xhr.responseText);
- }
- } else {
- if (options.error)
- options.error("获取数据失败,错误代号为:" + xhr.status + "错误信息为:" + xhr.statusText);
- }
- }
- // }
- function createXHR() {
- if (typeof XMLHttpRequest != "undefined") { // 非IE6浏览器
- return new XMLHttpRequest();
- } else if (typeof ActiveXObject != "undefined") { // IE6浏览器
- var version = [
- "MSXML2.XMLHttp.6.0",
- "MSXML2.XMLHttp.3.0",
- "MSXML2.XMLHttp",
- ];
- for (var i = 0; i < version.length; i++) {
- try {
- return new ActiveXObject(version[i]);
- } catch (e) {
- //跳过
- }
- }
- } else {
- throw new Error("您的系统或浏览器不支持XHR对象!");
- }
- }
- // 转义字符
- function params(data) {
- var arr = [];
- for (var i in data) {
- arr.push(encodeURIComponent(i) + "=" + encodeURIComponent(data[i]));
- }
- return arr.join("&");
- }
- }
- wd.c.date2min = function (dateStr) {
- console.log(dateStr);
- var d = new Date(dateStr);
- return (d.getTime() / 60 / 1000);
- };
- wd.c.min2date = function (minStr) {
- if (!isNaN(minStr)) {
- var d = new Date(parseInt(minStr) * 60 * 1000);
- return d.Format("yyyy-MM-dd hh:mm:ss");
- }
- };
- wd.c.loadScriptIns = function (src, id, callback) {
- if (document.getElementById("#jquery_js")) {
- wd.c.loadSctipt("/wd/js/jquery/jquery.js", 'jquwey_js', function () {
- wd.c.loadScriptIns(src, callback)
- });
- return;
- } else {
- if ($("[src$='" + (src.substring(src.lastIndexOf("/"), src.length)) + "']").length > 0) {
- //已存在,直接callback
- callback();
- } else {
- wd.c.loadSctipt(src, id, callback);
- }
- }
- };
- wd.c.loadSctipt = function (src, id, callback) {
- if (src) {
- var head = document.getElementsByTagName('head')[0];
- var script = document.createElement('script');
- if (!id || id == "") {
- id = src.substring(src.lastIndexOf("/"), src.length);
- }
- script.id = id;
- script.type = 'text/javascript';
- script.onload = script.onreadystatechange = function () {
- if (!this.readyState || this.readyState === "loaded" || this.readyState === "complete") {
- callback();
- // Handle memory leak in IE
- script.onload = script.onreadystatechange = null;
- }
- };
- script.src = src;
- head.appendChild(script);
- }
- };
- (function () {
- var ie = !!(window.attachEvent && !window.opera);
- var wk = /webkit\/(\d+)/i.test(navigator.userAgent) && (RegExp.$1 < 525);
- var fn = [];
- var run = function () {
- for (var i = 0; i < fn.length; i++)
- fn[i]();
- };
- var d = document;
- d.ready = function (f) {
- if (!ie && !wk && d.addEventListener)
- return d.addEventListener('DOMContentLoaded', f, false);
- if (fn.push(f) > 1)
- return;
- if (ie)
- (function () {
- try {
- d.documentElement.doScroll('left');
- run();
- } catch (err) {
- setTimeout(arguments.callee, 0);
- }
- })();
- else if (wk)
- var t = setInterval(function () {
- if (/^(loaded|complete)$/.test(d.readyState))
- clearInterval(t), run();
- }, 0);
- };
- })();
- // document.ready(function(){ window.top.clearToken();});
- if(!wd.common)
- wd.common={}
- wd.common.loadFile=function(path){
- var appName="";
- $.ajax({url:"/wd/page/LoginAppName.jsp",
- async:false,
- success:function(res){
- res=$.trim(res)
- appName=res;
- }
- })
- return "/"+appName+"/"+path;
- }
- wd.common.loadSkinFile=function(path){
- var result="";
- $.ajax({url:"/skin/skinDir.jsp", // :"/ss/page/skinDir.jsp", < :"/wd/page/skinPath.jsp",。Lin
- async:false,
- success:function(res){
- res=$.trim(res)
- result=res;
- }
- })
- return result+path;
- }
- wd.common.wdPostAjax=function(id,url,callback,extradata){
- var opt={};
- if(extradata!=undefined){
- opt=extradata;
- }
- if(id!=null){
- if($('#'+id)[0].tagName=="FROM"){
- var t = $('#'+id).serializeArray();
- $.each(t, function() {
- if(this.value!=undefined&&this.value!=null&&this.value!=''){
- opt[this.name] = this.value;
- }
- });
- }else{
- var t = $('#'+id).find("[name='*']");
- $.each(t, function() {
- if(this.value!=undefined&&this.value!=null&&this.value!=''){
- opt[this.name] = this.value;
- }
- });
- }
- }else{
- if($("from")){
- var t = $("from").serializeArray();
- $.each(t, function() {
- if(this.value!=undefined&&this.value!=null&&this.value!=''){
- opt[this.name] = this.value;
- }
- });
- }
- }
- alert(JSON.stringify(d));
- wd.c.wdAjax({
- type: "post",
- url: url,
- dataType: "json",
- data: opt,
- async: false,
- success: function (data) {
- eval(callback)(data);
- },
- });
- }
|