(function() { Application = {}; var StartTime; var $navMenus; /* 初始化导航菜单 */ Application.initNavMenu = function(nav, sideNav) { $navMenus = $(nav).find('a'); var $childNavMenus = $(sideNav).find('ul.sideNavigation'); /* 给横向菜单注册onclick方法 */ $navMenus.each(function(i) { this._index=i; var myChildMenu = Zving.getDom('_Child' + this.id); if(myChildMenu){ myChildMenu._index=this._index; } this.onclick = function() { var self = this; $childNavMenus.hide(); var url = self.getAttribute('url'); var myChildMenu = Zving.getDom('_Child' + self.id); $navMenus.removeClass('current'); $(self).addClass('current'); var iframes=$('#_framesWrap iframe:not(#_mainFrame_'+self._index+')'); iframes.each(function(i){ try { this.style.width = Zving.getDom('_framesWrap').clientWidth + 'px'; this.style.height = Zving.getDom('_framesWrap').clientHeight + 'px'; } catch (e) { //在ie下iframe不可见时,设置宽高会出错???(待证实) } this.style.position = 'absolute'; }); var targetIframe=Zving.getDom('_mainFrame_'+self._index); if(!targetIframe){ targetIframe=Dom.createNodeByHtml(''); targetIframe.appendTo(Zving.getDom('_framesWrap')) } targetIframe.style.position='static'; targetIframe.style.width = "100%"; targetIframe.style.height = "100%"; if (!url) { $('#leftColumnWrap').show(); self._childMenu = myChildMenu; // 给菜单添加childMenu属性 myChildMenu.onShow(); } else { $('#leftColumnWrap').hide(); if (!/^#/.test(url)) { if(!targetIframe.src.endsWith(url)){ targetIframe.src = url; var menuid = self.getAttribute('menuid') var dc = new DataCollection(); dc.add("MenuID",menuid); Server.sendRequest("Application.changeMenuClickCount",dc,null,null,null,'json'); } window.location.hash = self.id.substring("_Menu_".length); } Zving.preventEvent(); } }; }); /* 给左侧菜单注册onclick方法 */ $childNavMenus.each(function(i) { var childNavMenu=this; var $links = $(childNavMenu).find('a'); childNavMenu.onShow = function() { $(childNavMenu).show(); if (childNavMenu._activeMenu) { childNavMenu._activeMenu.onclick(); } else { if ($links[0]) { $links[0].onclick(); } else { Zving.getDom('_MainArea').src = 'about:blank'; } } } $links.each(function(j) { this.setAttribute('target','_mainFrame_'+childNavMenu._index) this._index=j; this.setActiveMenu = function() { // 设置hash window.location.hash = childNavMenu.id.substring("_Child_Menu_".length) + '-' + (this._index + 1); $links.each(function() { $(this).removeClass('current'); }) $(this).addClass('current'); childNavMenu._activeMenu = this; }; this.onclick = function(e) { e = e||window.event; var self = this; self.setActiveMenu(); var url = self.getAttribute("href"), target = self.getAttribute("target"); var targetIframe=Zving.getDom(target); //console.log(targetIframe.src, url) if (!/^#/.test(url)) { if(!targetIframe.src.endsWith(url)){ targetIframe.src = url; var menuid = self.getAttribute('menuid') var dc = new DataCollection(); dc.add("MenuID",menuid); Server.sendRequest("Application.changeMenuClickCount",dc,null,null,null,'json'); } } Zving.preventEvent(e); } }) }) }; Application.clickNavMenu = function(navMenuTag, childLinkIndex, flag) { // flag仅在回退/前进时置为true if (navMenuTag) { var ele = Zving.getDom('_Menu_' + navMenuTag); if (ele) { ele.onclick(); } else { if ($navMenus[0]) { $navMenus[0].onclick(); } } } if (childLinkIndex) { var p = Zving.getDom('_Child_Menu_' + navMenuTag); if (!p) { return; } var $links = $(p).find('a'); if ($links[childLinkIndex - 1]) { $links.get(childLinkIndex - 1).onclick(); } } } if(window.location.href.indexOf('/Application.')>0){ window.attachEvent('onunload', function() { if (window.location.hash) { var initdata = location.hash.match(/(\w+)(-(\d+))?/); if (initdata && initdata.length) { var navMenuTag = initdata[1], childLinkIndex = initdata[3]; Cookie.set('lastNavStatus', navMenuTag + '-' + childLinkIndex); } } }) } Page.onReady(function() { var i; var nav = Zving.getDom('_Navigation'), sideNav = Zving.getDom('_sideNavigation'); if (nav && sideNav) { $navMenus = $(nav).find('a'); Application.initNavMenu(nav, sideNav); // 导航菜单初始化 var h = window.location.hash || Cookie.get('lastNavStatus'); if (h) { if (h.startsWith("#")) { h = h.substring(1); } var index = h.lastIndexOf("-"); if (index > 0) { Application.clickNavMenu(h.substring(0, index), h.substring(index + 1)); } else { Application.clickNavMenu(h); } } else { $navMenus[0].onclick(); if ($navMenus[0]._childMenu) { $navMenus[0]._childMenu.getElementsByTagName('A')[0].fireEvent('onclick'); } } } if (!Zving.restricted && window.frameElement && window.frameElement.id == "_MainArea") { parent.Application.setCurrentMenu(window.location.pathname); } Application.setAllPriv(); }); Application.setCurrentMenu = function(pathname) { if (Zving.getDom("_Navigation")) { $navMenus.each(function(i){ var navMenuItem = this; var url = navMenuItem.getAttribute('href'); if (url) { if (url.indexOf(pathname) > -1) { if (!$(navMenuItem).hasClass('current')) { navMenuItem.setActiveMenu(); return false; } } } if (navMenuItem._childMenu) { // 查找与当前页面地址匹配的菜单,然后高亮 var $links = $(navMenuItem._childMenu).find('a'); $links.each(function(i){ if (this.getAttribute('href').indexOf(pathname) > -1) { if (!$(this).hasClass('current')) { this.setActiveMenu(); return false; } } }); } }); } }; Application.setPrivParam = function(key,value){ var win = Zving.rootWin; if (!win.Priv) { try{//测试发现在firefox下从其他域的页面跳转到ZCMS也存在opener if (window.opener && window.opener.Zving) { win = window.opener.Zving.rootWin; } }catch(e){ win=Zving.rootWin; } } if (win.Priv) { if(!win.PrivParams){ win.PrivParams = {}; } var params = win.PrivParams; params[key] = value; } }; Application.setAllPriv = function() { var $buttons = $("a.z-btn"); $buttons.each(function() { var p = this.getAttribute("priv"); if (p) { var flag = Application.hasPriv(p); if (flag) { $(this).enable(); } else { $(this).disable(); } } }); }; Application.hasPriv = function(privID) { var win = Zving.rootWin; if (!win.Priv||!win.Priv.Init) { try{//测试发现在firefox下从其他域的页面跳转到ZCMS也存在opener if (window.opener && window.opener.Zving) { win = window.opener.Zving.rootWin; } }catch(e){ win=Zving.rootWin; } } if (win.Priv) { var arr = privID.split("||"); var flag = false; if(win.Priv.AdminUserName==win.Priv.UserName){ flag = true; }else{ for (var i = 0; i < arr.length; i++) { if(!arr[i]){ continue; } var item = arr[i]; if(win.PrivParams){ for(var k in win.PrivParams){ item = item.replace("${"+k+"}",win.PrivParams[k]);//替换变量 } } if (win.Priv[item] == "1") { flag = true; } } } return flag; } return false; }; Priv = {}; Priv.init = function(privString) { if(!privString){ return; } var win = Zving.rootWin; if (!win.Priv||!win.Priv.Init) { try{//测试发现在firefox下从其他域的页面跳转到ZCMS也存在opener if (window.opener && window.opener.Zving) { win = window.opener.Zving.rootWin; } }catch(e){ win=Zving.rootWin; } } var str = privString.javaDecode(); var arr = str.split("\n"); for (var i = 0; i < arr.length; i++) { var line = arr[i]; var k = line.substring(0, line.indexOf("=")); var v = line.substring(line.indexOf("=") + 1); win.Priv[k] = v; } win.Priv.Init = true; }; })();