if (!window.wd) var wd = {}; (function () { String.prototype.trim = function () { return this.replace(/(^\s*)|(\s*$)/g, ""); } String.prototype.ltrim = function () { return this.replace(/(^\s*)/g, ""); } String.prototype.rtrim = function () { return this.replace(/(\s*$)/g, ""); } if (!("addEventListener" in Element.prototype)) { console.log("兼容IE8 addEventListener") Element.prototype.addEventListener = function (type, listener, useCapture) { this.attachEvent("on" + type, listener); }; } if (!("addEventListener" in document.constructor)) { console.log("兼容IE8 addEventListener") document.constructor.addEventListener = function (type, listener, useCapture) { this.attachEvent("on" + type, listener); }; } if (!("addEventListener" in document)) { console.log("兼容IE8 addEventListener") document.addEventListener = function (type, listener, useCapture) { this.attachEvent("on" + type, listener); }; } if (!("addEventListener" in window.constructor)) { console.log("兼容IE8 addEventListener") window.constructor.addEventListener = function (type, listener, useCapture) { this.attachEvent("on" + type, listener); }; } if (!("addEventListener" in window)) { console.log("兼容IE8 addEventListener") window.addEventListener = function (type, listener, useCapture) { this.attachEvent("on" + type, listener); }; } if (!("removeEventListener" in Element.prototype)) { console.log("兼容IE8 removeEventListener") Element.prototype.removeEventListener = function (type, listener, useCapture) { this.detachEvent("on" + type, listener); }; } if (!("removeEventListener" in document.constructor)) { console.log("兼容IE8 removeEventListener") document.constructor.removeEventListener = function (type, listener, useCapture) { this.detachEvent("on" + type, listener); }; } if (!("removeEventListener" in document)) { console.log("兼容IE8 removeEventListener") document.removeEventListener = function (type, listener, useCapture) { this.detachEvent("on" + type, listener); }; } if (!("removeEventListener" in window.constructor)) { console.log("兼容IE8 removeEventListener") window.constructor.removeEventListener = function (type, listener, useCapture) { this.detachEvent("on" + type, listener); }; } if (!("removeEventListener" in window)) { console.log("兼容IE8 removeEventListener") window.removeEventListener = function (type, listener, useCapture) { this.detachEvent("on" + type, listener); }; } })(); // if ("addEventListener" in _el) // window.constructor.prototype.addEventListener = document.constructor.prototype.addEventListener = Element.prototype.addEventListener = function (type, listener, useCapture) { // this.attachEvent("on" + type, listener); // }; // window.constructor.prototype.removeEventListener = document.constructor.prototype.removeEventListener = Element.prototype.removeEventListener = function (type, listener, useCapture) { // this.detachEvent("on" + type, listener); // }; (function () { var currParent = window; var i = 1; while (currParent != top) { try { currParent.parent[new Date().getMilliseconds()] = 1; //如果这行不报“没权限错误”,才执行下一行。 currParent = currParent.parent; } catch (e) { break; } } /** * 得到同域的顶层窗口,不直接用top,是因为有把WD的页面嵌入到OA的作子页面的情形 * 如果顶层窗口直接用top,当顶层窗口是另一网站时,就会报错。 */ wd.topWindow = currParent; })(); //---- if (!wd.base) { wd.base = {}; } wd.base.win2FitHeight = function (target, url) { wd.base.refreshApplyIframeHeight(null, url); var win2 = wd.base.applyIframeElement; var height = parseInt(win2.getAttribute("height")); win2.src = wd.base.setRowCountPerPage(url, height,parseInt(win2.offsetWidth)); } wd.base.applyIframe = function (bj, url, height, minHeight, maxHeight) { var high = height var availbleHeight = wd.topWindow.wd.base.refreshApplyIframeHeight(); if (availbleHeight && availbleHeight > 0) { high = availbleHeight; } if (minHeight || maxHeight) { var id = bj.getAttribute("id"); var divid = id.replace(/[^0-9]/, "m"); var div = document.querySelector("#" + divid); if (div) { div.style.height = high + "px"; } if (document.querySelector("table")) { document.querySelector("table").setAttribute("width", div.style.width); } bj.setAttribute("width", "100%"); bj.setAttribute("height", "100%"); } bj.src = wd.base.setRowCountPerPage(url, high); } //储存应用窗口使用的iframe if (!wd.base.applyIframeElement) wd.base.applyIframeElement = null; /** * 刷新应用窗口可用高度 * @param {Object} iframeElement */ wd.base.refreshApplyIframeHeight = function (iframeElement, url) { if (iframeElement) { wd.base.applyIframeElement = iframeElement; } //自动修复,未改发布程序时的问题 if (!wd.base.applyIframeElement) { var win = wd.topWindow.document.getElementsByName("win2")[0]; wd.base.applyIframeElement = win; } var pageHeight = wd.topWindow.innerHeight || wd.topWindow.document.documentElement.clientHeight || wd.topWindow.document.body.clientHeight var ifm = wd.base.applyIframeElement; if (!url) url = ifm.getAttribute("src"); //强制平铺iframe try { var p = /pageWidth=([0-9]+)/.exec(url); var miniWidth=1025; if (p) { // // var pageWidth = parseInt(p[1]); // // var pwidth = parseInt(ifm.parentNode.style.width); // var marginLeft = ""; // if (pwidth < pageWidth) { // marginLeft = (pwidth - pageWidth) * 0.5 + "px"; // ifm.width = pageWidth + "px"; // } else { // ifm.width = "100%"; // } // // ifm.style.marginLeft = marginLeft; } else { // // var ibound = ifm.parentNode.getBoundingClientRect(); // // ifm.width = window.innerWidth + "px"; // ifm.style.marginLeft = -ibound.left + "px"; //顶部,底部留白 pageHeight -= (28); } var ibound = ifm.parentNode.getBoundingClientRect(); var marginLeft = -ibound.left + "px"; var usewidth=Math.max($(wd.topWindow).outerWidth(true),1025); if(!url||wd.display.isPersonalHomePageUrl(url)){ //个人首页 ifm.width =(usewidth)+ "px"; }else{ //管理2 // wd.topWindow.win2width var width=usewidth; ifm.width =width+ "px"; var outerWidth=usewidth; marginLeft=((outerWidth-width)*0.5-ibound.left) +"px"; } ifm.style.width=(usewidth)+ "px"; ifm.style.marginLeft = marginLeft; wd.base.setHomeWidth(usewidth); } catch (e) { console.error(e); } function getTop(e) { var offset = e.offsetTop; if (e.offsetParent != null) offset += getTop(e.offsetParent); return offset; } var result = (pageHeight - getTop(wd.base.applyIframeElement)); wd.base.applyIframeElement.height = result; if (!wd.topWindow.resizeFrameFunc) { wd.topWindow.resizeFrameFunc = wd.base.refreshApplyIframeHeight; wd.topWindow.addEventListener("resize", function () { wd.topWindow.resizeFrameFunc(wd.base.applyIframeElement); }); } return result; } /** * 加载iframe * 计算窗口高度 * 初始化内门户显示窗口 * * * * @param {Object} iframeName :"win2" */ wd.base.initApplyIframe = function (iframeName) { //原页面js使用代码: // function getTop(e) { //var offset = e.offsetTop; //if (e.offsetParent != null) offset += getTop(e.offsetParent); //return offset; //} //(function() { //var pageHeight = wd.topWindow.innerHeight; //if (typeof pageHeight != 'number') { //if (document.compatMode == 'CSS1Compat') { //pageHeight = wd.topWindow.document.documentElement.clientHeight; //} else { //pageHeight = wd.topWindow.document.body.clientHeight; //} //} //var win = wd.topWindow.document.getElementsByName('win2')[0]; //win.height = (pageHeight - getTop(win)) + 'px'; //var num = ''; //win.src = '/main/sheji/yeMianSheJi.do?ymid=44019441&high=' + (pageHeight - getTop(win));})() // // var win = wd.topWindow.document.getElementsByName(iframeName)[0]; //记住iframe,点击应用菜单时,重新计算高度时计算可用高度用到 wd.topWindow.wd.base.applyIframeElement = win; var oriSrc = win.getAttribute("oriSrc"); var availbleHeight = wd.base.refreshApplyIframeHeight(win); // win.height=availbleHeight; win.src = oriSrc + "&high=" + availbleHeight; } wd.base.setRowCountPerPage = function (url, availHeight, availWidth, numOnly) { var defaultWidth = availWidth || 755; var allype = { longCardList: 0, list: 0, iconList: 120, cardList: 245 } var result = url + ""; var urlparam = {} var s = url.replace(/.+\?/, "").split("&"); for (var i = 0; i < s.length; i++) { var aa = s[i].split("="); if (aa.length == 2) urlparam[aa[0]] = aa[1]; } var defaultType = urlparam["rowType"] || "list"; var eachWidth = allype[defaultType] || 0; var val; if (urlparam["rowHigh"]) { // 1、查询是否有&rowCountPerPage字符串 // 1-1、如果有,则删除该属性 // 1-2、如果没有,跳过 // 2、添加&rowCountPerPage属性 var rowHighValue = parseInt(urlparam["rowHigh"]); var removeHighValue = urlparam["removeHigh"] ? parseInt(urlparam["removeHigh"]) : 0; var multiple = 1; if (eachWidth != 0) { multiple = parseInt(defaultWidth / eachWidth); } val =(parseFloat(availHeight) - parseFloat(removeHighValue)) / parseFloat(rowHighValue); /* * 运行时行数为整数,如果最终高度超出availHeight就减一行 */ var valInt=parseInt(val); val=val> valInt?(valInt-1):val; val=parseInt(multiple *val); // result = result.replace(/&rowHigh=[0-9]+/, "").replace(/&removeHigh=[0-9]+/, "").replace(/&rowCountPerPage=[0-9]+/, ""); result = result.replace(/&(rowHigh|rowCountPerPage|removeHigh)=[0-9]+/g, ""); result += "&rowCountPerPage=" +val; }else{ } //只需要返回数字情况 if (numOnly) return val; return result; } /** *设置首页菜单宽度 */ wd.base.setHomeWidth=function(){ var usewidth=Math.max($(wd.topWindow).outerWidth(true),1025); var maxwidth=usewidth; //管理2用 wd.topWindow.win2width=maxwidth; //iconList wd.topWindow.$("#iconGroup >div").css({width:maxwidth}); //menu wd.topWindow.$("#menuGroup").css({width:maxwidth}); if(typeof wd.topWindow.initMenuTotally=="function"){ wd.topWindow.initMenuTotally(); } }