/* Version:1.0 */ /* 参数说明 url: 跳转解析地址,如“http://*.com/Transfer” width: 头部宽度 objid: 头部容器Id,如果空默认插入在body前。 如果是点击消息会自动加上:opname=msg,回调地址变为:http://*.com/Transfer?opname=msg 如果是点击退出会自动加上:opname=loginout,回调地址变为:http://*.com/Transfer?opname=loginout */ (function(){ var main = function(Passport){ Passport.Header = { identities : [ ] } Passport(['/content/header.css'], function($){ var getUrl = function(id, opName, url) { url = url || 'http://forum.im2x.com' || Passport.baseUrl; if(url.indexOf('://')<0){ url = Passport.baseUrl + url; } if(opName){ url += (url.indexOf('?')>0 ? '&' : '?') + 'opname=' + opName; } if(typeof id == "string"){ if(id.indexOf('://')<0){ id = Passport.baseUrl + id; } return id + (id.indexOf('?')>0 ? '&' : '?') + 'gotourl='+ escape(url); } return Passport.userInfo.id ? Passport.baseUrl + '/User/'+ (Passport.userInfo.entId==id ? 'MyEnt/GoApp' : 'UInfo/SwitchEnt') +'?entid='+id+'&gotourl='+ escape(url) : url; } if(Passport.isLogin && !Passport.userInfo.id){ //window.location.href = getUrl('/Login/LoginOut', 'loginout'); return; } $(function(){ var loginname,username,msgcount=0,msgs,softs; var showsites=3,headw='930',objid='header', className='', hideids=false; softs = []; var html = '\
\
\
'; if(softs && softs.length>0){ var moremsg = 0; for(var i in softs){ if(softs.length>showsites+1 && i>=showsites){ moremsg += softs[i].msg; }else{ html += ''+ softs[i].name + (Passport.isLogin && softs[i].msg ? '' : '') +''; } } if(softs && softs.length>showsites+1){ html += ''; html += '
'; for(var i=showsites+1; i'+ softs[i].name + (Passport.isLogin && softs[i].msg ? '' : '') +'\ '; } html += '
'; } } html += '
\
\
    '; if(!Passport.userInfo.id || !Passport.isLogin){ html += '
  • 登录 | 注册
  • '; } else { html += '
  • \ 欢迎您,'+ loginname +''+ (!hideids ? '当前身份:' : '')+ '\ '+ (!hideids ? '' : '') + '\
  • \
  • [退出]
  • '; } html += '
'; if(Passport.isLogin && Passport.Header.identities.length>0 && !hideids){ html += '
'; for(var i in Passport.Header.identities){ var user = Passport.Header.identities[i]; html += '\ '+ user.name +' - '+ user.entName +'\ '+ (msgs[i]>0 ? '' : '')+'\ '; } html += '
切换身份加入企业身份选择列表
'+ msgs[i] +'
'; } html += '
\
\
'; $(!objid ? "body" : "#"+objid).prepend(html); var hideusers = function (target, items) { items.data("tohide", true); setTimeout(function () { if (items.data("tohide")) { target.removeClass("pt-actived"); items.removeData("tohide").unbind().hide(); } }, 100); } var showusers = function (target, items) { var offset = target.addClass("pt-actived").offset(); items.removeData("tohide").css({ left: offset.left + target.get(0).offsetWidth - items.width() - 3, top: offset.top + target.height() + 1 }).show(); } $("#passport_top label[data-items]").each(function(){ var elemItems =$("#passport_top").find($(this).attr("data-items")); var self = $(this).bind({ "mouseenter": function () { elemItems.bind({ "mouseenter": function(){ showusers(self, elemItems); }, "mouseleave": function(){ hideusers(self, elemItems); } }); showusers(self, elemItems); }, "mouseleave": function(){ hideusers(self, elemItems); } }); }); }) if(Passport.userInfo.id && Passport.userInfo.entId){ var winInactive = false; var fromElement = false; var hasNotify = false; if(!window.FileReader){//IE9以下 $(document.body).bind({ "focus": function(e){ fromElement = true; } }) } $(window).bind({ "focus": function(e){ if(winInactive && !fromElement && !hasNotify && (e.target == window || e.target == document)){ hasNotify = true; Passport.postBack({ url: Passport.baseUrl + "/api/login", type: "GET", dataType: "jsonp", data: $.param({ "getuserid": '' }), success: function(data){ var notify = function(msg, cmd, url){ Passport.require('/Plugins/Dialog', function(){ setTimeout(function(){ Passport.Dialog.show(msg, [cmd], function(){ hasNotify = false; window.location.href = url; }, { buttonAlign: "center", modal: false, beforeHide: function(){ hasNotify = false; } }); },100); }); } if(data){ if(data.EntId != Passport.userInfo.entId || data.EntUserId != Passport.userInfo.id){ notify('当前登录用户身份已变更。', "点击刷新", getUrl(data.EntId)); }else{ hasNotify = false; } }else{ notify('当前登录用户已退出。', "重新登录", getUrl('/Login')); } }, error: function(){ hasNotify = false; return false; } }); winInactive = false; } fromElement = false; }, "blur": function(){ winInactive = true; } }); } }); } if (window.Passport) { main(window.Passport); }else if(typeof define === 'function'){ define(function (require, exports) { var Passport = require("Passport"); return main(Passport); }); } })();