/** * sseinfo-menu-fun * 导航菜单/面包屑/网站地图 ---动态生成 * @version 1.0.2 * @project sseinfo opensseinfo site * @author tonyxiao@sse.com.cn * @copyright: sse infonet ltd reserve all rights * @example sseinfomenuobj.init(); **/ if(typeof sseinfomenuobj==='undefined'){ if (typeof (col_id) === 'undefined') { var col_id = 10286; // var col_id = 8318; } var sseinfomenuobj = { menu_tab_text: '', //主菜单 menu_con_text: '', //hover状态下显示的二三级菜单 mobile_menu_text: '', //手机版菜单 menu_type: '1', //菜单类型,默认为主菜单 siteobj: {},//站点obj act_id: col_id, //左侧菜单激活的id specialnodeobj: {},//专栏obj getnodechild: function (node) { //获取栏目子菜单 function compare(v1, v2) { return v1.order - v2.order; } if (typeof (node) !== 'object') { //如果找不到对应的栏目 return []; } var lv = [], childarr = node.children.split(";"); for (var i = 0, len = childarr.length; i < len; i++) { var thenode = this.formatnode(childarr[i]); if (typeof (thenode) == 'object') { lv.push(thenode); } } return lv.sort(compare); }, getnodespechild: function (node) { //获取快捷栏目子菜单 function compare_sorder(v1, v2) { return v1.sorder - v2.sorder; } if (typeof (node) != 'object') { //如果找不到对应的栏目 return []; } var lv = [[], [], [], [],[]], childarr = node.children.split(";"), haschild = false; for (var i = 0, len = childarr.length; i < len; i++) { var thenode = this.formatnode(childarr[i]); if (typeof (thenode) == 'object') { var col = parseint(thenode.sorder / 10) - 1; if (col >= 0 && col < lv.length) { haschild = true; lv[col].push(thenode); } } } if (!haschild) { return []; } for (var j = 0, len2 = lv.length; j < len2; j++) { lv[j] = lv[j].sort(compare_sorder); } var newlv = []; for (var j = 0, len2 = lv.length; j < len2; j++) { if(lv[j].length>0){ newlv.push(lv[j]); } } return newlv; }, formatnode: function (key) { //格式化栏目节点 var obj = sse_menu_32[key]; if (typeof (obj) != 'object') { //如果找不到对应的栏目 return false; } var checkflag = arguments[1] ? 1 : 0; if (!checkflag && key != '0') { if (obj.display == '0') { //如果不是栏目 return false; } if (this.menu_type == "1" && obj.type.split(";").indexof("1") < 0) { //判断菜单类型-主菜单 return false; } else if (this.menu_type == "2" && obj.type.split(";").indexof("2") < 0) { //判断菜单类型-左侧菜单 return false; } else if (this.menu_type == "3" && obj.type.split(";").indexof("3") < 0 ) { return false; } } return { code: key, //栏目id pcode: obj.parentcode, //父栏目id label: key == '0' ? '首页' : obj.chnlname, //标题 href: key == '0' ? '/home/' : obj.url, //链接 sorder: obj.shortcutorder, //快捷栏目类型序号 order: obj.order, //显示顺序 target: obj.target == '1' ? '_blank' : '_self', //打开窗口方式 children: obj.children, //子菜单 nodestyle: 'menu_style_' + obj.style, //显示样式 0=新栏目 active: key == sseinfomenuobj.act_id ? "active" : '' //是否是当前页面 }; }, checkspecialcookie:function(node){//检查当前专栏是否是前一页专栏的子级 var specialnode = sseinfocomm.cookie.get('ssemenuspecial'); function comparespecial(key){ var currnode = sse_menu_32[key]; if(currnode.parentcode == '0'){ sseinfocomm.cookie.set('ssemenuspecial',node,1); return node; } if(currnode.parentcode == specialnode){ return specialnode; } return comparespecial(currnode.parentcode); } if(specialnode === '') { sseinfocomm.cookie.set('ssemenuspecial',node,1); return node; }else{ return comparespecial(node); } }, findspecialnode: function (key) { //查找最近的专栏 var currnode = sse_menu_32[key]; if (typeof (currnode) != 'object') { //如果找不到对应的栏目 return false; } if ((currnode.display == "0" || currnode.type.split(";").indexof('2') < 0) && sseinfomenuobj.act_id == key) { sseinfomenuobj.act_id = currnode.parentcode; return this.findspecialnode(sseinfomenuobj.act_id); } if ( currnode.isspecialchannel == "1" || currnode.parentcode == '0') { //如果当前栏目是专栏或者一级菜单,直接返回当前节点 key = this.checkspecialcookie(key); var thenode = this.formatnode(key), lv = this.getnodechild(thenode); if (lv.length === 0) { //如果此专栏没有子菜单,则显示父级及其兄弟 thenode = this.formatnode(currnode.parentcode); sseinfocomm.cookie.set('ssemenuspecial',currnode.parentcode,1); lv = this.getnodechild(thenode); } return { node: thenode, lv: lv }; } return this.findspecialnode(currnode.parentcode); //如果当前栏目不是专栏,往上继续查找 }, findbreadnode: function (channel_id) { //查找面包屑 var lv = []; function findparent(key) { var currnode = sse_menu_32[key]; if (typeof (currnode) != 'object' || key === '') { //如果找不到对应的栏目 return false; } if(key == '0' || currnode.chnlname == "首页" || currnode.type != "0"){ lv.push(sseinfomenuobj.formatnode(key, 1)); } if (currnode.chnlname == "首页" && currnode.parentcode == "0") { return false; } findparent(currnode.parentcode); } findparent(channel_id); return lv; }, findmainactive: function (channel_id) { //查找主菜单激活状态id var activeidx = ''; var ischannel = true; function findparentmenu(key) { var currnode = sse_menu_32[key]; if (typeof (currnode) != 'object' || key === '') { //如果找不到对应的栏目 activeidx = 0; ischannel = false; return false; } if (currnode.parentcode === "0") { activeidx = key; return false; } findparentmenu(currnode.parentcode); } findparentmenu(channel_id); return { key:activeidx, name:sse_menu_32[activeidx].chnlname, ischannel:ischannel }; } }; //pc版主菜单 sseinfomenuobj.initpcmainmenu = function () { this.menu_type = '1'; var menu_tab = '