Browse Source

注销新增回调方法

DW-PC\DW 5 years ago
parent
commit
6b9960785e

+ 4 - 2
公共资源/src/_login.html

@@ -83,9 +83,11 @@
             });
 
             $('#udb_logout').click(function () {
-                dwUDBProxy.logout('');  //为空,退出成功后则跳转到当前页面
+                dwUDBProxy.logout(plainFunction);  //为空,退出成功后则跳转到当前页面
             });
-
+            dwUDBProxy.addLogout(function(){
+                    init()
+                })
             dwUDBProxy.addBind(function () {
                 console.log('绑定成功')
             })

+ 61 - 44
公共资源/src/dwNavBar2017/navbar2017.js

@@ -10,6 +10,8 @@
 
 	if (window.Navbar) return;
 
+	var navbarTpl = __inline("./navbar.tmpl")
+
 	var scripts = document.getElementsByTagName('script');
 
 	var isKa = (/\?type=ka/).test(scripts[scripts.length - 1].src);
@@ -314,46 +316,56 @@
 
 			}
 
+			var logoutSucc = function(){
+				renderNavbar()
+				initEvent()
+			}
+
+			var initEvent = function(){
+				$gSearch.on("focus", "input[type='text']", function () {
+					$gSearch.find(".g-search-tips").show()
+				}).on("blur", "input[type='text']", function () {
+					setTimeout(function () {
+						$gSearch.find(".g-search-tips").hide()
+					}, 500)
+				})
+	
+				if (location.host.indexOf("video.duowan.com") > -1) {
+					$gSearch.attr("action", "http://video.duowan.com/")
+					$gSearch.find("input[type=text]").attr("name", "w")
+					$gSearch.find("input[type=hidden]").attr("name", "r").val("search/index")
+				}
+	
+	
+				Event.attach(navDom.login, "click", function (e) {
+					Event.preventDefault(e);
+					if (dwUDBProxy.add && !isBBs) {
+						dwUDBProxy.login(plainFunction)
+					} else {
+						dwUDBProxy.login()
+					}
+				}).attach(navDom.reglink, 'click', function (e) {
+					Event.preventDefault(e);
+	
+					dwUDBProxy.register(plainFunction)
+				})
+				Event.attach(navDom.logout, "click", function (e) {
+					Event.preventDefault(e);
+					dwUDBProxy.logout(plainFunction);  //为空,退出成功后则跳转到当前页面
+				});
+			}
+
 			/**兼容旧版 */
 			if (dwUDBProxy.add) {
 				dwUDBProxy.add(loginSucc)
+				dwUDBProxy.addLogout(logoutSucc)
 			} else {
 				if (dwUDBProxy.isLogin()) {
 					loginSucc()
 				}
 			}
 
-			$gSearch.on("focus", "input[type='text']", function () {
-				$gSearch.find(".g-search-tips").show()
-			}).on("blur", "input[type='text']", function () {
-				setTimeout(function () {
-					$gSearch.find(".g-search-tips").hide()
-				}, 500)
-			})
-
-			if (location.host.indexOf("video.duowan.com") > -1) {
-				$gSearch.attr("action", "http://video.duowan.com/")
-				$gSearch.find("input[type=text]").attr("name", "w")
-				$gSearch.find("input[type=hidden]").attr("name", "r").val("search/index")
-			}
-
-
-			Event.attach(navDom.login, "click", function (e) {
-				Event.preventDefault(e);
-				if (dwUDBProxy.add && !isBBs) {
-					dwUDBProxy.login(plainFunction)
-				} else {
-					dwUDBProxy.login()
-				}
-			}).attach(navDom.reglink, 'click', function (e) {
-				Event.preventDefault(e);
-
-				dwUDBProxy.register(plainFunction)
-			})
-			Event.attach(navDom.logout, "click", function (e) {
-				Event.preventDefault(e);
-				dwUDBProxy.logout('');  //为空,退出成功后则跳转到当前页面
-			});
+			initEvent()
 		})
 
 		if (window.dwUDBProxy) {
@@ -369,25 +381,30 @@
 	var CSS_TEXT = __inline("./style.css");
 	var dynamicStyle = Util.createStyleSheet(CSS_TEXT);
 	var navDom = {};
-	var rootEl = navDom.el = document.createElement("div");
-
-	rootEl.id = "dw-topbar";
-	rootEl.innerHTML = __inline("./navbar.tmpl")({
-		isKa: isKa
-	})
+	var rootEl = null;
+	renderNavbar();
+	function renderNavbar(){
+		if(rootEl){
+			navDom = {}
+			document.body.removeChild(rootEl)
+		}
+		rootEl = navDom.el = document.createElement("div");
+		rootEl.id = "dw-topbar";
+		rootEl.innerHTML = navbarTpl({
+			isKa: isKa
+		})
 
-	Util.hashElements(rootEl, navDom);
+		Util.hashElements(rootEl, navDom);
 
-	document.body.insertBefore(rootEl, document.body.firstChild);
+		document.body.insertBefore(rootEl, document.body.firstChild);
 
-	if (document.domain.toLowerCase().indexOf("sc2.com") > -1) {
-		navDom.loginform.action = "https://udb.sc2.com.cn/login.jsp"
+		if (document.domain.toLowerCase().indexOf("sc2.com") > -1) {
+			navDom.loginform.action = "https://udb.sc2.com.cn/login.jsp"
+		}
 	}
 
 	var defineNavbar = function () {
-
-		var Navbar = window.Navbar = {
-			dom: navDom,
+		window.Navbar = {
 			bbsCallbacks: jQuery.Callbacks('memory'),
 			unreadCallbacks: jQuery.Callbacks('memory'),
 			systemCallbacks: jQuery.Callbacks('memory'),

+ 31 - 6
公共资源/src/js/dwudbproxy.js

@@ -16,7 +16,7 @@
         },
         open(url,target){
             if(dwClientIncompatible.isClient()){
-                DW_ClIENT_SDK.openThirdLogin(url)
+                window.external.OpenThirdLogin(url)
             } else {    
               return window.open(url,target)
             }
@@ -28,7 +28,7 @@
         },
         close(context){
             if(dwClientIncompatible.isClient()){
-                DW_ClIENT_SDK.closeThirdLogin()
+                window.external.CloseThirdLogin()
             } else {
                 context && context.close()
             }
@@ -60,6 +60,8 @@
         loginSuccCallbacks: $.Callbacks('memory'),//登录成功后的回调队列
         bindCallbacks: $.Callbacks('memory'),
         bindSuccCallbacks: $.Callbacks('memory'),//绑定成功后的回调队列
+        logoutCallbacks: $.Callbacks('memory'),
+        logoutSuccCallbacks: $.Callbacks('memory'),//注销成功后的回调队列
         intervalHandle: 0,
 
         getCookie: Cookie.get,
@@ -202,12 +204,14 @@
                     fn = function () {
                         that.bindCallbacks.fire()
                         that.bindSuccCallbacks.fire()
+                        that.bindCallbacks = $.Callbacks('memory')
                     }
                 } else {
 
                     fn = function () {
-                        that.loginCallbacks.fire();
-                        that.loginSuccCallbacks.fire(Util.getUserInfo());
+                        that.loginCallbacks.fire()
+                        that.loginSuccCallbacks.fire(Util.getUserInfo())
+                        that.loginCallbacks = $.Callbacks('memory')
                     }
                 }
 
@@ -455,7 +459,17 @@
 
         logout: function (successURL) {
             var that = this;
-            successURL = Util.decorateURL(successURL);
+
+            Util.logoutCallbacks.empty()
+
+            if ('function' == typeof successURL) {
+                Util.logoutCallbacks.add(successURL)
+            } else {
+                Util.logoutCallbacks.add(function(){
+                    window.location.href = successURL;
+                })
+            }
+            
             $.getJSON(that.getDelCookieURL + '&jsonpcallback=?', function (data) {
                 if ("1" != data.success) {
                     alert(data.errMsg);
@@ -465,7 +479,13 @@
                     UDBSdk.deleteCrossmainCookieWithCallBack(
                         data.delCookieURL,
                         function () {
-                            window.location.href = successURL;
+                            if(dwClientIncompatible.isClient()){
+                                window.external.Logout()
+                            } else {
+                                Util.logoutCallbacks.fire()
+                                Util.logoutSuccCallbacks.fire()
+                                Util.logoutCallbacks = $.Callbacks('memory')
+                            }
                         });
                 });
             });
@@ -913,6 +933,7 @@
             if (this.loginPopupObj) this.loginPopupObj.hide()
             if (this.loginMaskObj) this.loginMaskObj.hide()
             if (this.setNickName) this.setNickName.hide()
+            if (this.yyLoginTip) this.yyLoginTip.hide()
         }
     };
 
@@ -996,6 +1017,10 @@
             Util.bindSuccCallbacks.add(callback)
         },
 
+        addLogout:function(callback){
+            Util.logoutSuccCallbacks.add(callback)
+        },
+
         /**绑定相关的操作 */
         bind: function (type, callback) {
             return __ThirdLogin.bind(type, callback);