From 066d7795c202c5d679c50c7a15d1d98aeb7c2b23 Mon Sep 17 00:00:00 2001 From: iFish Date: Wed, 13 Aug 2014 00:14:00 +0800 Subject: [PATCH] sync file --- 12306聊天室协议.txt | 30 ++++++ RwTicketAssistantV2/app/background.js | 88 +++++++++++++++-- Web12306/ChatServers.cs | 101 ++++++++++++++++++++ Web12306/Web.config | 85 ++++++++-------- Web12306/Web12306.csproj | 2 + Web12306/chatservers.json | 20 ++++ Web12306/css/ui/chat/chat-float-tip.css | 12 ++- Web12306/css/ui/chat/chat-frame.css | 68 +++++++------ Web12306/css/ui/chat/chat-server-select.css | 5 + Web12306/css/ui/options-param.css | 19 +++- Web12306/index.html | 41 ++++---- Web12306/js/account/sessionMgr.js | 7 ++ Web12306/js/boot.js | 8 +- Web12306/js/ui/chat/chatframe.js | 62 +++++++++++- Web12306/js/ui/chat/roomsession.js | 53 +++++++++- Web12306/js/ui/chat/servernode.js | 73 +++++++++++++- Web12306/js/ui/index.js | 15 +-- Web12306/js/ui/ui-autorefresh.js | 6 +- Web12306/js/ui/ui-autosubmitform.js | 4 +- Web12306/js/ui/ui-login.js | 11 ++- Web12306/js/ui/ui-order-submit-process.js | 7 +- Web12306/js/ui/ui-passenger-selection.js | 3 - Web12306/js/ui/ui-submit-order.js | 4 +- Web12306/js/ui/ui-theme-manager.js | 3 +- Web12306/js/ui/ui-trainlist.js | 31 +++--- Web12306/js/ui/widget_cityselector.js | 9 +- Web12306/js/ui/widget_datedropdown.js | 11 ++- Web12306/js/ui/widget_sell_notification.js | 21 ++-- 28 files changed, 623 insertions(+), 176 deletions(-) create mode 100644 12306聊天室协议.txt create mode 100644 Web12306/ChatServers.cs create mode 100644 Web12306/chatservers.json diff --git a/12306聊天室协议.txt b/12306聊天室协议.txt new file mode 100644 index 0000000..73e2d67 --- /dev/null +++ b/12306聊天室协议.txt @@ -0,0 +1,30 @@ + +[ + { + "id": "1", + "name": "ȫ1", + "status": "full", + "onlinecount": 2000, + "category": 0, + "url": "ws://test.fishlee.net/chathandler.ashx/room1" + }, + { + "id": "2", + "name": "ȫ2", + "status": "ok", + "onlinecount": 1533, + "category": 0, + "url": "ws://test.fishlee.net/chathandler.ashx/room2" + } +] + +Ϣ +1.뷿 +{action:"join", roomid:"room1", user:"iccfish", nickName:"ľ"} + +2.Ϣ +{action:"send", target:"@iccfish [˽]", content:"Ϣ", color:"red"} + +3.Ϣ +{action:"receive", items: [ source:"ľ(@iccfish)", time:"14:28:39", content:"Ϣ", color:"red", specid:0 ]} +specid:λ1-ϵͳϢ2-˽ģ4-Ԥã8-Ԥã16-Ԥã32-Ԥ \ No newline at end of file diff --git a/RwTicketAssistantV2/app/background.js b/RwTicketAssistantV2/app/background.js index 882c8f6..823e759 100644 --- a/RwTicketAssistantV2/app/background.js +++ b/RwTicketAssistantV2/app/background.js @@ -220,7 +220,8 @@ var CFG_MANGER = (function () { captchaServerUrl: "http://api.12306.liebao.cn/code.php", appendPriceUnit: true, blockVcVerify: false, - blockQueueCount: false + blockQueueCount: false, + chatServerApi: "http://test.fishlee.net/chathandler.ashx" }; this.sysConfig = {}; this.userConfig = { enableAutoCaptcha: false }; @@ -1057,7 +1058,7 @@ window.cbl = function (u, h) { trackback(m.detail.type, m.detail.values); }); - + chrome.runtime.onMessageExternal.addListener(function (m, s, r) { if (!m || !m.action || m.action !== 'track') return; @@ -1176,9 +1177,9 @@ window.cbl = function (u, h) { else localStorage.removeItem(k); }); r({ action: "sendStorage", detail: m.detail }); - }else if (m.action === "notify") { + } else if (m.action === "notify") { var notify = new Notification(m.title || "订票助手", { body: m.content || null, icon: "/icons/icon_128.png" }) - setTimeout(function() { + setTimeout(function () { notify.close(); }, 5000); } @@ -1193,23 +1194,96 @@ window.cbl = function (u, h) { (function () { var ports = []; - var portOnMessage = function(msg, port) { + var portOnMessage = function (msg, port) { + if (!msg || !msg.action) + return; + switch (msg.action) { + case "getChatServerStatus": + serverMgr.loadServers(function (servers) { + port.postMessage({ action: "responseServer", detail: servers }); + }); + break; + case "getCurrentRoomInfo": + port.postMessage({ action: "responseCurrentRoomInfo", detail: serverConnection.currentRoom }); + default: + } }; - var portOnDisconnect = function(port) { + var portOnDisconnect = function (port) { var idx = _.indexOf(ports, port); if (idx > -1) { ports.splice(idx, 1); } }; - chrome.runtime.onConnectExternal.addListener(function(port) { + chrome.runtime.onConnectExternal.addListener(function (port) { ports.push(port); port.onMessage.addListener(portOnMessage); port.onDisconnect.addListener(portOnDisconnect); }); + var serverMgr = (function chatServerManager() { + var isServerLoaded = null; + var isInServerLoading = false; + var servers = null; + var callbackQueue = []; + var lastLoad = null; + + var execCallback = function () { + var callback; + while (callbackQueue.length) { + (callback = callbackQueue.pop()) && callback(servers); + }; + }; + + var loadServers = function (callback) { + if (!callback) + return; + + if (isServerLoaded && (!lastLoad || (new Date() - lastLoad) < 1000 * 60 * 10)) + callback(servers); + else { + callbackQueue.push(callback); + if (!isInServerLoading) { + isInServerLoading = true; + + $.post(CFG_MANGER.config.chatServerApi, null).done(function (data) { + servers = data; + isInServerLoading = false; + isServerLoaded = true; + execCallback(); + }).fail(function () { + servers = null; + isInServerLoading = false; + execCallback(); + }); + } + } + }; + + return { + loadServers: loadServers + }; + })(); + + var serverConnection = (function () { + var currentRoom = null; + var socket = null; + + var connect = function (room, username) { + + }; + + var ret = {}; + Object.defineProperty(ret, "currentRoom", { + get: function () { + return currentRoom; + } + }); + + return ret; + })(); })(); //#endregion diff --git a/Web12306/ChatServers.cs b/Web12306/ChatServers.cs new file mode 100644 index 0000000..7032c47 --- /dev/null +++ b/Web12306/ChatServers.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections.Generic; +using System.Net.WebSockets; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Web; +using System.Web.WebSockets; + +namespace Web12306 +{ + public class ChatServers : IHttpHandler + { + /// + /// 您将需要在网站的 Web.config 文件中配置此处理程序 + /// 并向 IIS 注册它,然后才能使用它。有关详细信息, + /// 请参见下面的链接: http://go.microsoft.com/?linkid=8101007 + /// + #region IHttpHandler Members + + public bool IsReusable + { + // 如果无法为其他请求重用托管处理程序,则返回 false。 + // 如果按请求保留某些状态信息,则通常这将为 false。 + get { return true; } + } + + public void ProcessRequest(HttpContext context) + { + + if (context.IsWebSocketRequest) + { + //if(context.WebSocketNegotiatedProtocol=="Fish12306") + context.AcceptWebSocketRequest(ProcessChat); + } + else + { + context.Response.ContentType = "application/json"; + context.Response.WriteFile(context.Server.MapPath("/chatservers.json")); + } + } + + #endregion + + static readonly HashSet _allContexts = new HashSet(); + static readonly Dictionary> _allRooms = new Dictionary>(); + + private async Task ProcessChat(AspNetWebSocketContext context) + { + WebSocket socket = context.WebSocket; + var roomid = context.Path.Substring(context.Path.LastIndexOf('/')); + + lock (_allContexts) + { + if (!_allContexts.Contains(context)) + { + _allContexts.Add(context); + + var room = _allRooms.ContainsKey(roomid) ? _allRooms[roomid] : null; + if (room == null) + { + room = new HashSet(); + _allRooms.Add(roomid, room); + } + } + } + lock (_allRooms) + { + + + } + + while (true) + { + if (socket.State == WebSocketState.Open) + { + ArraySegment buffer = new ArraySegment(new byte[2048]); + WebSocketReceiveResult result = await socket.ReceiveAsync(buffer, CancellationToken.None); + string userMsg = Encoding.UTF8.GetString(buffer.Array, 0, result.Count); + userMsg = "你发送了:" + userMsg + "于" + DateTime.Now.ToLongTimeString(); + buffer = new ArraySegment(Encoding.UTF8.GetBytes(userMsg)); + await socket.SendAsync(buffer, WebSocketMessageType.Text, true, CancellationToken.None); + } + else + { + break; + } + } + lock (_allContexts) + { + if (_allContexts.Contains(context)) + _allContexts.Remove(context); + if (_allRooms.ContainsKey(roomid)) + { + var roomlist = _allRooms[roomid]; + roomlist.Remove(context); + } + } + } + } +} diff --git a/Web12306/Web.config b/Web12306/Web.config index 3a006da..e5266dd 100644 --- a/Web12306/Web.config +++ b/Web12306/Web.config @@ -4,46 +4,47 @@ http://go.microsoft.com/fwlink/?LinkId=301880 --> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Web12306/Web12306.csproj b/Web12306/Web12306.csproj index 78b699f..9a299c0 100644 --- a/Web12306/Web12306.csproj +++ b/Web12306/Web12306.csproj @@ -130,6 +130,7 @@ + Global.asax @@ -184,6 +185,7 @@ + diff --git a/Web12306/chatservers.json b/Web12306/chatservers.json new file mode 100644 index 0000000..52b07e9 --- /dev/null +++ b/Web12306/chatservers.json @@ -0,0 +1,20 @@ +[ + { + "id": "room1", + "name": "全国大区1", + "status": "full", + "onlinecount": 2000, + "category": 0, + "url": "ws://test.fishlee.net/chathandler.ashx/room1", + "recommand": true + }, + { + "id": "room2", + "name": "全国大区2", + "status": "ok", + "onlinecount": 1533, + "category": 0, + "url": "ws://test.fishlee.net/chathandler.ashx/room2", + "recommand": false + } +] diff --git a/Web12306/css/ui/chat/chat-float-tip.css b/Web12306/css/ui/chat/chat-float-tip.css index 39d6c69..876d03c 100644 --- a/Web12306/css/ui/chat/chat-float-tip.css +++ b/Web12306/css/ui/chat/chat-float-tip.css @@ -3,10 +3,18 @@ z-index: 2; right: 0; bottom: 0; - background: linear-gradient(to bottom, #FF962C, #C26B14); + background: linear-gradient(to bottom, #d17f2d, #C26B14); color: #ffffff; border: 1px solid #d67e29; font-size: 14px; - font-weight: bold; padding: 10px; + cursor: pointer; } + + #chat_float_tip span { + font-weight: bold; + } + + #chat_float_tip:hover { + background: linear-gradient(to bottom, #e48b31, #d17519); + } diff --git a/Web12306/css/ui/chat/chat-frame.css b/Web12306/css/ui/chat/chat-frame.css index 667f8c7..926a2cd 100644 --- a/Web12306/css/ui/chat/chat-frame.css +++ b/Web12306/css/ui/chat/chat-frame.css @@ -1,6 +1,6 @@ -#chat-frame { +#chat_frame { position: fixed; - right: 0; + right: -360px; top: 0; z-index: 2; width: 360px; @@ -9,42 +9,48 @@ border-left: 1px solid #d67e29; box-shadow: 0 0 5px rgba(214, 126, 41, 0.50); box-sizing: border-box; - display: none; + transition: all linear 0.3s; } -#chat_server_select { - display: none; -} + #chat_frame.open { + right: 0; + display: block; + } #chat_float_tip { display: none; } - #chat-frame .chat-page { - position: absolute; - top: 75px; - left: 360px; - bottom: 10px; - width: 340px; - transition: all linear 0.2s; - } +#chat_frame .chat-page { + position: absolute; + top: 75px; + left: 360px; + bottom: 10px; + width: 340px; + transition: all linear 0.2s; +} - #chat-frame .chat-page-current { - left: 10px; - opacity: 1; - transition: all linear 0.2s; - } +#chat_frame .chat-page-current { + left: 10px; + opacity: 1; + transition: all linear 0.2s; +} - #chat-frame > header { - line-height: 52px; - font-size: 18px; - padding: 5px 10px 5px 10px; - position: absolute; - display: block; - width: 100%; - background: linear-gradient(to bottom, #FF8005, #EF7108); - font-weight: bold; - color: #ffffff; - top: 0; - } +#chat_frame > header { + line-height: 52px; + font-size: 18px; + padding: 5px 10px 5px 10px; + position: absolute; + display: block; + width: 100%; + background: linear-gradient(to bottom, #FF8005, #EF7108); + font-weight: bold; + color: #ffffff; + top: 0; +} +@media(max-width:1730px) { + .wrap.chat-on { + margin-right: 365px; + } +} diff --git a/Web12306/css/ui/chat/chat-server-select.css b/Web12306/css/ui/chat/chat-server-select.css index 6687e91..d215ff2 100644 --- a/Web12306/css/ui/chat/chat-server-select.css +++ b/Web12306/css/ui/chat/chat-server-select.css @@ -46,6 +46,11 @@ border-color: #d67e29; } + #chat_server_select > article em { + margin-left: 10px; + color: #b28484; + } + #chat_server_select > article span { color: gray; float: right; diff --git a/Web12306/css/ui/options-param.css b/Web12306/css/ui/options-param.css index 3a95f26..256812e 100644 --- a/Web12306/css/ui/options-param.css +++ b/Web12306/css/ui/options-param.css @@ -142,9 +142,9 @@ cursor: pointer; } - .options-param .options-train-selectorwarp table tr:nth-child(1) td { - border-top: none; - } + .options-param .options-train-selectorwarp table tr:nth-child(1) td { + border-top: none; + } .options-param .options-train-selectorwarp table tr:hover td { background-color: #fff0d9; @@ -165,6 +165,19 @@ color: #985d33; } +.passenger-selector .passenger-selector-editor { + float: left; + margin-top: 12px; + display: none; +} + +.passenger-selector .passenger-selector-editor a{ + color: #8b8b8b; +} +.passenger-selector .passenger-selector-editor a:hover{ + text-decoration: underline; +} + .options-param .param-array label { width: 170px; display: block; diff --git a/Web12306/index.html b/Web12306/index.html index 931125c..7c6eafc 100644 --- a/Web12306/index.html +++ b/Web12306/index.html @@ -283,6 +283,9 @@ {{~}}
    +
    + 添加 +
    @@ -800,9 +803,9 @@
    - 当前有 88888 位票友正在聊天,快来加入吧! + 当前有 位票友正在聊天,快来加入吧!
    -
    +
    聊天室 @@ -812,29 +815,19 @@ 亲,请选择房间
    -
    -

    推荐房间

    + +
    -
    +
    当前房间: diff --git a/Web12306/js/account/sessionMgr.js b/Web12306/js/account/sessionMgr.js index 87583a0..39364b0 100644 --- a/Web12306/js/account/sessionMgr.js +++ b/Web12306/js/account/sessionMgr.js @@ -138,6 +138,13 @@ loadPassengers(); } }; + this.ensureLogined = function(callback) { + if (!that.isLogined) { + that.fireEvent("requireLogin", callback); + } else { + callback(that.current); + } + }; this.defaultProfile = { autoRefreshDelay: 5, hideNotInListTrain: true, diff --git a/Web12306/js/boot.js b/Web12306/js/boot.js index 3b5b794..963a82e 100644 --- a/Web12306/js/boot.js +++ b/Web12306/js/boot.js @@ -159,7 +159,9 @@ }); } else entryPoint(); }; - if (typeof (chrome) !== 'undefined') { - nextTest(); - } else entryPoint(); + $(function() { + if (typeof (chrome) !== 'undefined') { + nextTest(); + } else entryPoint(); + }); })(window, document); diff --git a/Web12306/js/ui/chat/chatframe.js b/Web12306/js/ui/chat/chatframe.js index e33e4eb..1fc52d8 100644 --- a/Web12306/js/ui/chat/chatframe.js +++ b/Web12306/js/ui/chat/chatframe.js @@ -1,14 +1,68 @@ -define(function(require, exports, module) { - var port = require("../../platform/extensionPort.js"); +define(function (require, exports, module) { + var ep = require("../../platform/extensionPort.js"); + var port = ep.port; var data = require("../../data.js"); var sessMgr = require("../../account/sessionMgr.js"); var ev = require("../../platform/EventObject.js"); var chat = require("../../platform/chat.js"); + var uiLogin = require("./ui-login.js"); + //frames + var servernode = require("./servernode.js"); + servernode.on("roomSelectHide", function () { + hideChatFrameUI(); + showChatFloatTip(); + }); + servernode.on("chatServerLoaded", function (e, serverList) { + servers = serverList; + if (servers) + showChatFloatTip(); + }); + servernode.on("enterRoot", function (e, room) { + //进入房间 + sessMgr.ensureLogined(enterroom.bind(room)); + }); + + //服务器 + var servers; + + var showChatFloatTip = function () { + if ($("#chat_frame.open").length) + return; + + var totalcount = _.reduce(_.pluck(servers, "onlinecount"), function (i, m) { return i + m; }, 0); + $("#chat_float_tip").find("span").html(totalcount).end().show(); + }; + var showChatFrameUI = function () { + $("#chat_frame").height(); + $("#chat_frame").addClass("open"); + $("div.wrap").addClass("chat-on"); + $("#chat_float_tip").hide(); + }; + var hideChatFrameUI = function () { + $("div.wrap").removeClass("chat-on"); + $("#chat_frame").removeClass("open"); + }; + var showServerList = function () { + showChatFrameUI(); + servernode.showRoomSelect(); + }; + + //进入房间 + var roomSession = require("./roomsession.js"); + var enterroom = function () { + showChatFrameUI(); + roomSession.enterRoom(this); + }; + + + (function ui() { + $("#chat_float_tip").click(showServerList); + })(); + + servernode.loadServers(); return { - init: function() { - } }; }); diff --git a/Web12306/js/ui/chat/roomsession.js b/Web12306/js/ui/chat/roomsession.js index 0970a7c..d334ab3 100644 --- a/Web12306/js/ui/chat/roomsession.js +++ b/Web12306/js/ui/chat/roomsession.js @@ -1,3 +1,54 @@ -define(function(require, exports, module) { +define(function (require, exports, module) { + var EventObject = require("../../platform/EventObject.js"); + var ep = require("../../platform/extensionPort.js"); + var port = ep.port; + + var RoomSession = function () { + EventObject.apply(this); + var that = this; + var room; + + this.enterRoom = function (targetRoom) { + if (targetRoom == room) + return; + + that.exitRoom(); + room = targetRoom; + port.postMessage("enterChatRoom", room); + }; + this.exitRoom = function () { + port.postMessage("disconnectChatRoom"); + that.fireEvent("exitRoom"); + }; + + Object.defineProperty(this, "room", { + get: function () { + return room; + } + }); + port.on("chatRoomConnecting", function () { + that.fireEvent("chatRoomConnecting"); + }); + port.on("chatRoomConnected", function () { + that.fireEvent("chatRoomConnected"); + }); + port.on("chatRoomMessageReceived", function () { + that.fireEvent("chatRoomMessageReceived"); + }); + port.on("chatRoomDisconnected", function () { + that.fireEvent("chatRoomDisconnected"); + }); + + return this; + }; + RoomSession.prototype = Object.create(EventObject); + RoomSession.constructor = RoomSession; + + var session = new RoomSession(); + + return { + session: session, + enterRoom: session.enterRoom + } }); diff --git a/Web12306/js/ui/chat/servernode.js b/Web12306/js/ui/chat/servernode.js index 0970a7c..c62331a 100644 --- a/Web12306/js/ui/chat/servernode.js +++ b/Web12306/js/ui/chat/servernode.js @@ -1,3 +1,74 @@ -define(function(require, exports, module) { +define(function (require, exports, module) { + var EventObject = require("../../platform/EventObject.js"); + var servers = null; + var container = $("#chat_server_select"); + var template = container.find(">script").doT(); + var serverNodeContainer = container.find(">article"); + var ep = require("../../platform/extensionPort.js"); + var port = ep.port; + var renderServerNodeList = function () { + //推荐房间 + serverNodeContainer.empty(); + var roomRecommand = _.where(servers, { recommand: true }); + if (roomRecommand && roomRecommand.length) + serverNodeContainer.append(template({ category: "推荐房间", list: roomRecommand })); + var roomGlobal = _.where(servers, { category: 0 }); + if (roomGlobal && roomGlobal.length) + serverNodeContainer.append(template({ category: "全国房间", list: roomGlobal })); + var roomPrivate = _.where(servers, { category: 1 }); + if (roomPrivate && roomPrivate.length) + serverNodeContainer.append(template({ category: "地区/专线房间", list: roomPrivate })); + }; + + var ServerNodeSelect = function () { + EventObject.apply(this); + var that = this; + + this.showRoomSelect = function () { + $("#chat_frame>section").removeClass("chat-page-current"); + $("#chat_server_select").addClass("chat-page-current"); + + that.fireEvent("roomSelectShown"); + }; + + this.exitRoomSelect = function () { + $("#chat_frame").removeClass("open"); + + that.fireEvent("roomSelectHide"); + }; + + port.on("responseServer", function (e, serverList) { + servers = serverList; + if (!servers) { + //TODO 无法加载服务器列表 + } else { + that.fireEvent("chatServerLoaded", servers); + + //渲染列表 + renderServerNodeList(); + } + }); + this.loadServers = function () { + port.postMessage("getChatServerStatus"); + }; + + return this; + }; + ServerNodeSelect.prototype = Object.create(EventObject); + ServerNodeSelect.constructor = ServerNodeSelect; + + var instance = new ServerNodeSelect(); + (function ui() { + $("#chat_server_select > footer >button").click(instance.exitRoomSelect); + $(document).on("click", "#chat_server_select article li", function() { + var id = this.dataset.id; + var server = _.findWhere(servers, { id: id }); + if (!server) + return; + instance.fireEvent("enterRoot", server); + }); + })(); + + return instance; }); diff --git a/Web12306/js/ui/index.js b/Web12306/js/ui/index.js index 99c58b7..4350a9d 100644 --- a/Web12306/js/ui/index.js +++ b/Web12306/js/ui/index.js @@ -18,7 +18,7 @@ //初始化日期 require("./widget_datedropdown.js").init("input.ui-date"); //预售期提示 - require("./widget_sell_notification.js").init(); + require("./widget_sell_notification.js"); //地区选择 var citySelector = require("./widget_cityselector.js"); citySelector.init("input.ui-cityselector"); @@ -27,29 +27,23 @@ //登录 var ui_login = require("./ui-login.js"); - ui_login.init(); //结果列表 var ui_result = require("./ui-trainlist.js"); - ui_result.init(); //自动刷新呢 var autorefresh = require("./ui-autorefresh.js"); - autorefresh.init(); autorefresh.on("requestQueryTicket", function () { ui_result.load(); }); //提交订单 var uiOrderProcess = require("./ui-order-submit-process.js"); - uiOrderProcess.init(); //查询参数 - var uiAutoSubmitForm = require("./ui-autosubmitform.js"); - uiAutoSubmitForm.init(); + require("./ui-autosubmitform.js"); //模式管理 - var uiThemeManager = require("./ui-theme-manager.js"); - uiThemeManager.init(); + require("./ui-theme-manager.js"); //用户配置和选项的加载以及保存 require("../platform/profileBinder.js"); @@ -226,8 +220,7 @@ })(); //聊天系统 - var chatframe = require("./chat/chatframe.js"); - chatframe.init(); + require("./chat/chatframe.js"); //统计报告 port.track(param.trackTypes.OPEN_PAGE_INDEX); diff --git a/Web12306/js/ui/ui-autorefresh.js b/Web12306/js/ui/ui-autorefresh.js index 3bea7d1..6b7d9d0 100644 --- a/Web12306/js/ui/ui-autorefresh.js +++ b/Web12306/js/ui/ui-autorefresh.js @@ -7,6 +7,7 @@ var media = require("../platform/media.js"); var query = require("../otn/queryticket.js"); var trainSuggest = require("../otn/trainstationsuggest.js"); + var port = require("../platform/extensionPort.js"); sessMgr.on("sessionChanged", function () { session = sessMgr.current; @@ -132,7 +133,7 @@ var currentSelectedDate; var currentDateLoopIndex = -1; - this.init = function () { + var init = function () { query.events.on("processTrains", function (e, d) { processTrains(d); if (inAutoRefresh) @@ -168,7 +169,7 @@ trainSuggest.clearQueryResultCache(); //track - port.track(param.trackTypes.START_AUTOREFRESH); + port.track(expdata.trackTypes.START_AUTOREFRESH); } inAutoRefresh = true; @@ -260,6 +261,7 @@ that.start(); }); $("#btn_stop_refresh").click(this.stop); + init(); return this; }; diff --git a/Web12306/js/ui/ui-autosubmitform.js b/Web12306/js/ui/ui-autosubmitform.js index b73a666..ae8da1c 100644 --- a/Web12306/js/ui/ui-autosubmitform.js +++ b/Web12306/js/ui/ui-autosubmitform.js @@ -458,12 +458,12 @@ }); }; - exports.init = function () { + var init = function () { initPassengerEditor(); initTrainSelectEditor(); initDateLoop(); initSeatOrder(); initProfileOperation(); }; - + init(); }); diff --git a/Web12306/js/ui/ui-login.js b/Web12306/js/ui/ui-login.js index 3aef4c3..f1c3103 100644 --- a/Web12306/js/ui/ui-login.js +++ b/Web12306/js/ui/ui-login.js @@ -18,9 +18,6 @@ ev.apply(this, arguments); - this.init = function() { - - }; this.showLoginDialog = function () { var info = storage.obj("12306_lastUser"); if (info) { @@ -155,7 +152,8 @@ loadLoginAsyncSuggest(); }; - dlg.on("closeDialog", function() { + dlg.on("closeDialog", function () { + that.off("loginSuccess"); that.fireEvent("closeLogin"); }).on("openDialog", function() { that.fireEvent("showLogin"); @@ -179,6 +177,11 @@ sessionMgr.on("userNotChecked", function () { mp.alert("提示", "用户尚未通过审核!"); }); + sessionMgr.on("requireLogin", function(e, c) { + if (c) + that.once("loginSuccess", c); + that.showLoginDialog(); + }); //界面事件绑定 $("#acc_login").click(function () { diff --git a/Web12306/js/ui/ui-order-submit-process.js b/Web12306/js/ui/ui-order-submit-process.js index 596f9fa..d00e77c 100644 --- a/Web12306/js/ui/ui-order-submit-process.js +++ b/Web12306/js/ui/ui-order-submit-process.js @@ -12,10 +12,7 @@ //提交参数 var pTrain, pSeat, pStu, pPassengers, pProfile; - exports.init = function () { - ps.init(); - so.init(); - + var init = function () { ps.on("passengerSelected", function () { pPassengers = ps.selectedPassenger; exports.prepareOrder().done(function () { exports.showConfirmOrderUi(); }); @@ -85,4 +82,6 @@ exports.showFailedUi = function (msg) { }; + + init(); }); diff --git a/Web12306/js/ui/ui-passenger-selection.js b/Web12306/js/ui/ui-passenger-selection.js index 174ad94..4de99b1 100644 --- a/Web12306/js/ui/ui-passenger-selection.js +++ b/Web12306/js/ui/ui-passenger-selection.js @@ -21,9 +21,6 @@ EO.apply(this); - this.init = function () { - - }; this.show = function (passengers, train, seat, stu) { preloadPasList = passengers; curTrain = train; diff --git a/Web12306/js/ui/ui-submit-order.js b/Web12306/js/ui/ui-submit-order.js index a274448..53e3a08 100644 --- a/Web12306/js/ui/ui-submit-order.js +++ b/Web12306/js/ui/ui-submit-order.js @@ -8,6 +8,7 @@ var param = require("../data.js"); var media = require("../platform/media.js"); var share = require("./ui_sns_share.js"); + var port = require("../platform/extensionPort.js"); //提交参数 var pTrain, pStu, pPassengers, pProfile; var submitDef; @@ -23,7 +24,7 @@ var submitProgress = $("#ticket-submit-info .ticket-submit-status"); var resubmitBtn = $("#ticket-submit-info .ticket-submit-info-status-failed button.button-primary"); - this.init = function () { + var init = function () { $("#ticket-submit-info .ticket-submit-vc input:text").keyup(function () { if (this.value.length === 4) that.submitOrder(); @@ -131,6 +132,7 @@ submitDef = null; }); }; + init(); return this; }; diff --git a/Web12306/js/ui/ui-theme-manager.js b/Web12306/js/ui/ui-theme-manager.js index 27b34c5..3887e30 100644 --- a/Web12306/js/ui/ui-theme-manager.js +++ b/Web12306/js/ui/ui-theme-manager.js @@ -18,7 +18,7 @@ listContainer.html(tpl(_.values(sessMgr.current.savedProfile.list || []))); }; - this.init = function () { + var init = function () { $("#travel-theme-select").focus(function () { $(this).parent().parent().addClass("hover"); }).blur(function () { @@ -109,6 +109,7 @@ }; initList(); sessMgr.on("sessionChanged", initList); + init(); return this; }; diff --git a/Web12306/js/ui/ui-trainlist.js b/Web12306/js/ui/ui-trainlist.js index e900056..68fd106 100644 --- a/Web12306/js/ui/ui-trainlist.js +++ b/Web12306/js/ui/ui-trainlist.js @@ -64,7 +64,7 @@ }); }; - this.init = function () { + var init = function () { tsquery.init(); datebar.init(); @@ -96,22 +96,23 @@ sessMgr.save(); __.load(); }); + //监听订票请求 + $(document).on("click", "a.ticket-block", function () { + var id = this.dataset.traincode; + var seatcode = this.dataset.seatcode; + + var train = _.findWhere(queryResult.original, { id: id }); + if (!train) + return; + + __.dispatchEvent("requireSubmitOrder", { + train: train, + seat: seatcode + }); + }); }; - //监听订票请求 - $(document).on("click", "a.ticket-block", function () { - var id = this.dataset.traincode; - var seatcode = this.dataset.seatcode; - - var train = _.findWhere(queryResult.original, { id: id }); - if (!train) - return; - - __.dispatchEvent("requireSubmitOrder", { - train: train, - seat: seatcode - }); - }); + init(); return this; }; diff --git a/Web12306/js/ui/widget_cityselector.js b/Web12306/js/ui/widget_cityselector.js index 86fbe11..1171a96 100644 --- a/Web12306/js/ui/widget_cityselector.js +++ b/Web12306/js/ui/widget_cityselector.js @@ -327,14 +327,14 @@ return this; }; - exports.init = function (eleSelector, args) { + var init = function(args) { $("body").append($html); //初始化常用城市 - (function () { + (function() { var html = []; - _.each(popcity, function (c) { + _.each(popcity, function(c) { var city = cityMap[c]; html.push("
  • " + city.n + "
  • "); @@ -352,7 +352,10 @@ args = $.extend({ rows: 9 }, args); selector = new CitySelector(args); exports.cityui = selector; + }; + init(); + exports.init = function (eleSelector) { $(document).on("focus", eleSelector, function () { selector.showPopup($(this)); setTimeout((function () { this.select(); }).bind(this), 1); diff --git a/Web12306/js/ui/widget_datedropdown.js b/Web12306/js/ui/widget_datedropdown.js index 3b6e59e..1ca8d53 100644 --- a/Web12306/js/ui/widget_datedropdown.js +++ b/Web12306/js/ui/widget_datedropdown.js @@ -91,7 +91,7 @@ var dropdownInstance; - exports.init = function (selector, params) { + var init = function (params) { var date_classes = ["month-first", "month-second"]; var dom = ['
    ']; @@ -136,11 +136,18 @@ minDate: getCurDate() }, params); dropdownInstance = new DateDropDown(params); + }; + init(); + exports.instance = dropdownInstance; + + + exports.init = function (selector) { + /// 初始化指定元素上的事件 $(document).on("focus", selector, function () { dropdownInstance.showPopup($(this)); }).on("blur", selector, function () { dropdownInstance.hidePopup($(this)); }); - }; + } }); \ No newline at end of file diff --git a/Web12306/js/ui/widget_sell_notification.js b/Web12306/js/ui/widget_sell_notification.js index 7f49be1..e2bb613 100644 --- a/Web12306/js/ui/widget_sell_notification.js +++ b/Web12306/js/ui/widget_sell_notification.js @@ -43,18 +43,19 @@ container.show(); }; + var init = function() { + sessMgr.on("save", function() { + checkTime(); + }); + if (cp) + checkTime(); + container.find(">header>a").click(function() { + container.hide(); + }); + }; + init(); return { - init: function () { - sessMgr.on("save", function () { - checkTime(); - }); - if (cp) - checkTime(); - container.find(">header>a").click(function() { - container.hide(); - }); - }, check: checkTime }; });