popupLogin.js 2.53 KB
var PassportPopupLogin = {
    settings: {
        callbackFn : null
    },
    init : function(){
    	var self = this;
    	var intInterval = null;
    	var oldHashVal = "";
    	if(window.postMessage && ((typeof document.documentMode==='undefined') || document.documentMode > 8)){
    		window.onmessage = function(e){
    			self.switchCenter(e.data);
    		};
    	}else if( ('onhashchange' in window) && ((typeof document.documentMode==='undefined') || document.documentMode==8)) {
    	    // 浏览器支持onhashchange事件
    	    window.onhashchange = function(){
    	    	self.switchCenter(location.hash.substring(1)); // 对应新的hash执行的操作函数
    	    }; 
    	} else {
    	    // 不支持则用定时器检测的办法
    		intInterval = setInterval(function() {
    	        var ischanged = isHashChanged();  // 检测hash值或其中某一段是否更改的函数
    	        if(ischanged) {
    	        	intInterval = clearInterval(intInterval);
    	        	self.switchCenter(location.hash.substring(1));  // 对应新的hash执行的操作函数
    	        }
    	    }, 300);
    	}
    	var isHashChanged = function (){
    		return (location.hash != "#" && oldHashVal != location.hash);
    	};
    	return self;
    },
    tbClose: function () {
        0 != $('.n-popup').length && jQuery(".n-popup").remove();
    },
    login: function () {
    	var self = this;
    	self.tbClose();
        return  Popup.start({
			title   : '登录地利',
			url : "https://passport.nong12.com/uc/popup/login.aspx?referUrl=" + location.href,
			width:530,
			height:400,
			hideheaderBar:false,
			hidefooterBar:false
		});
    },
    regist: function () {
        var self = this;
        self.tbClose(),
        window.location = "https://passport.nong12.com/regedit/regedit.aspx";
    },
    lostPassword: function () {
    	var self = this;
    	self.tbClose(),
    	window.location = "https://passport.nong12.com/forgot/forgot.aspx";
    },
    switchCenter : function (val) {
    	var self = this;
    	self._clear();
    	switch(val){
    	case 'login_success':
    		self.callFunc();
    		break;
    	case 'passport_register':
    		self.regist();
    		break;
    	case 'passpor_lostPwd':
    		self.lostPassword();
    		break;
    	default :
    		break;
    	}
    },
    callFunc: function () {
        var self = this;
        self.tbClose();
        if(self.settings.callbackFn && $.isFunction(self.settings.callbackFn)){
        	self.settings.callbackFn();
        }
    },
    _clear : function(){
    	location.hash = "";
    }
};