popupLogin.js
3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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);
};
var html = '<div class="login-pop"> <a href="https://passport.nong12.com/uc/popup/login.aspx?referUrl=' + location.href + '" id="s-login-pop"></a></div>';
$("body").append(html);
$("#s-login-pop").fancybox({
width:'380px',
height:'310px',
type: "iframe",
fitToView: false,
iframe: {
preload: false,
scrolling: 'no'
},
scrolling: 'visible'
});
return self;
},
tbClose: function () {
0 != $('.n-popup').length && jQuery(".n-popup").remove();
},
login: function () {
var self = this;
self.tbClose();
$("#s-login-pop").click();
},
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 = "";
},
checkLogin : function(fn){
var flag = false;
jQuery.ajax({
type : "POST",
url : "http://www.nong12.com/common/checkLogin.html",
dataType : "json",
async : false,
xhrFields: {
withCredentials: true
},
success : function(data) {
if(fn && typeof(fn) == 'function'){
fn(data);
}
if(data.code == "000"){
flag = true;
}
}
});
return flag;
}
};