sync file

This commit is contained in:
iFish 2014-08-13 00:14:00 +08:00
parent a8d8f0d12a
commit 066d7795c2
28 changed files with 623 additions and 176 deletions

30
12306聊天室协议.txt Normal file
View File

@ -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-预置

View File

@ -220,7 +220,8 @@ var CFG_MANGER = (function () {
captchaServerUrl: "http://api.12306.liebao.cn/code.php", captchaServerUrl: "http://api.12306.liebao.cn/code.php",
appendPriceUnit: true, appendPriceUnit: true,
blockVcVerify: false, blockVcVerify: false,
blockQueueCount: false blockQueueCount: false,
chatServerApi: "http://test.fishlee.net/chathandler.ashx"
}; };
this.sysConfig = {}; this.sysConfig = {};
this.userConfig = { enableAutoCaptcha: false }; this.userConfig = { enableAutoCaptcha: false };
@ -1176,9 +1177,9 @@ window.cbl = function (u, h) {
else localStorage.removeItem(k); else localStorage.removeItem(k);
}); });
r({ action: "sendStorage", detail: m.detail }); 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" }) var notify = new Notification(m.title || "订票助手", { body: m.content || null, icon: "/icons/icon_128.png" })
setTimeout(function() { setTimeout(function () {
notify.close(); notify.close();
}, 5000); }, 5000);
} }
@ -1193,23 +1194,96 @@ window.cbl = function (u, h) {
(function () { (function () {
var ports = []; 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); var idx = _.indexOf(ports, port);
if (idx > -1) { if (idx > -1) {
ports.splice(idx, 1); ports.splice(idx, 1);
} }
}; };
chrome.runtime.onConnectExternal.addListener(function(port) { chrome.runtime.onConnectExternal.addListener(function (port) {
ports.push(port); ports.push(port);
port.onMessage.addListener(portOnMessage); port.onMessage.addListener(portOnMessage);
port.onDisconnect.addListener(portOnDisconnect); 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 //#endregion

101
Web12306/ChatServers.cs Normal file
View File

@ -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
{
/// <summary>
/// 您将需要在网站的 Web.config 文件中配置此处理程序
/// 并向 IIS 注册它,然后才能使用它。有关详细信息,
/// 请参见下面的链接: http://go.microsoft.com/?linkid=8101007
/// </summary>
#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<AspNetWebSocketContext> _allContexts = new HashSet<AspNetWebSocketContext>();
static readonly Dictionary<string, HashSet<AspNetWebSocketContext>> _allRooms = new Dictionary<string, HashSet<AspNetWebSocketContext>>();
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<AspNetWebSocketContext>();
_allRooms.Add(roomid, room);
}
}
}
lock (_allRooms)
{
}
while (true)
{
if (socket.State == WebSocketState.Open)
{
ArraySegment<byte> buffer = new ArraySegment<byte>(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<byte>(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);
}
}
}
}
}

View File

@ -20,6 +20,7 @@
<remove name="OPTIONSVerbHandler" /> <remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" /> <remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
<add name="ChatServersHandler" path="ChatHandler.ashx" verb="*" type="Web12306.ChatServers"/>
</handlers> </handlers>
</system.webServer> </system.webServer>
<runtime> <runtime>

View File

@ -130,6 +130,7 @@
<Compile Include="App_Start\FilterConfig.cs" /> <Compile Include="App_Start\FilterConfig.cs" />
<Compile Include="App_Start\RouteConfig.cs" /> <Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="App_Start\WebApiConfig.cs" /> <Compile Include="App_Start\WebApiConfig.cs" />
<Compile Include="ChatServers.cs" />
<Compile Include="Global.asax.cs"> <Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon> <DependentUpon>Global.asax</DependentUpon>
</Compile> </Compile>
@ -184,6 +185,7 @@
<Content Include="css\fa\fonts\fontawesome-webfont.ttf" /> <Content Include="css\fa\fonts\fontawesome-webfont.ttf" />
<Content Include="css\fa\fonts\fontawesome-webfont.woff" /> <Content Include="css\fa\fonts\fontawesome-webfont.woff" />
<Content Include="css\fa\fonts\FontAwesome.otf" /> <Content Include="css\fa\fonts\FontAwesome.otf" />
<Content Include="chatservers.json" />
<None Include="js\docs\chrome-api-vsdoc.js" /> <None Include="js\docs\chrome-api-vsdoc.js" />
<Content Include="js\data.js" /> <Content Include="js\data.js" />
<Content Include="js\modules\doT.js" /> <Content Include="js\modules\doT.js" />

20
Web12306/chatservers.json Normal file
View File

@ -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
}
]

View File

@ -3,10 +3,18 @@
z-index: 2; z-index: 2;
right: 0; right: 0;
bottom: 0; bottom: 0;
background: linear-gradient(to bottom, #FF962C, #C26B14); background: linear-gradient(to bottom, #d17f2d, #C26B14);
color: #ffffff; color: #ffffff;
border: 1px solid #d67e29; border: 1px solid #d67e29;
font-size: 14px; font-size: 14px;
font-weight: bold;
padding: 10px; padding: 10px;
cursor: pointer;
} }
#chat_float_tip span {
font-weight: bold;
}
#chat_float_tip:hover {
background: linear-gradient(to bottom, #e48b31, #d17519);
}

View File

@ -1,6 +1,6 @@
#chat-frame { #chat_frame {
position: fixed; position: fixed;
right: 0; right: -360px;
top: 0; top: 0;
z-index: 2; z-index: 2;
width: 360px; width: 360px;
@ -9,33 +9,34 @@
border-left: 1px solid #d67e29; border-left: 1px solid #d67e29;
box-shadow: 0 0 5px rgba(214, 126, 41, 0.50); box-shadow: 0 0 5px rgba(214, 126, 41, 0.50);
box-sizing: border-box; box-sizing: border-box;
display: none; transition: all linear 0.3s;
} }
#chat_server_select { #chat_frame.open {
display: none; right: 0;
} display: block;
}
#chat_float_tip { #chat_float_tip {
display: none; display: none;
} }
#chat-frame .chat-page { #chat_frame .chat-page {
position: absolute; position: absolute;
top: 75px; top: 75px;
left: 360px; left: 360px;
bottom: 10px; bottom: 10px;
width: 340px; width: 340px;
transition: all linear 0.2s; transition: all linear 0.2s;
} }
#chat-frame .chat-page-current { #chat_frame .chat-page-current {
left: 10px; left: 10px;
opacity: 1; opacity: 1;
transition: all linear 0.2s; transition: all linear 0.2s;
} }
#chat-frame > header { #chat_frame > header {
line-height: 52px; line-height: 52px;
font-size: 18px; font-size: 18px;
padding: 5px 10px 5px 10px; padding: 5px 10px 5px 10px;
@ -46,5 +47,10 @@
font-weight: bold; font-weight: bold;
color: #ffffff; color: #ffffff;
top: 0; top: 0;
} }
@media(max-width:1730px) {
.wrap.chat-on {
margin-right: 365px;
}
}

View File

@ -46,6 +46,11 @@
border-color: #d67e29; border-color: #d67e29;
} }
#chat_server_select > article em {
margin-left: 10px;
color: #b28484;
}
#chat_server_select > article span { #chat_server_select > article span {
color: gray; color: gray;
float: right; float: right;

View File

@ -165,6 +165,19 @@
color: #985d33; 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 { .options-param .param-array label {
width: 170px; width: 170px;
display: block; display: block;

View File

@ -283,6 +283,9 @@
{{~}} {{~}}
</script> </script>
<ul class="cl"></ul> <ul class="cl"></ul>
<div class="passenger-selector-editor">
<a href="javascript:;"><i class="fa fa-plus"></i> 添加</a>
</div>
<div class="passenger-pager"> <div class="passenger-pager">
<button class="passenger-pager-prev" disabled="disabled">上一页</button> <button class="passenger-pager-prev" disabled="disabled">上一页</button>
<button class="passenger-pager-next">下一页</button> <button class="passenger-pager-next">下一页</button>
@ -800,9 +803,9 @@
</article> </article>
<article id="chat"> <article id="chat">
<section id="chat_float_tip"> <section id="chat_float_tip">
当前有 88888 位票友正在聊天,快来加入吧! 当前有 <span></span> 位票友正在聊天,快来加入吧!
</section> </section>
<section id="chat-frame"> <section id="chat_frame">
<header> <header>
<i class="fa fa-users"></i> <i class="fa fa-users"></i>
聊天室 聊天室
@ -812,29 +815,19 @@
<i class="fa fa-cube"></i> <i class="fa fa-cube"></i>
亲,请选择房间 亲,请选择房间
</header> </header>
<article> <script type="text/x-dot-template">
<h1>推荐房间</h1> <h1>{{!it.category}}</h1>
<ul> <ul>
<li>全国大区1<span>(5000人)</span></li> {{~it.list:s:i}}
<li>北京出发1<span>(200人)</span></li> <li data-id="{{!s.id}}" class="chat-server-status-{{!s.status}}">
<li>到武汉1<span>(200人)</span></li> {{!s.name}}
<li>广州-武汉专线<span>(200人)</span></li> {{=s.status=='full'?"<em>(已满)</em>":""}}
<span>({{!s.onlinecount}}人)</span>
</li>
{{~}}
</ul> </ul>
<h1>全国大区</h1> </script>
<ul> <article></article>
<li>全国大区1<span>(5000人)</span></li>
<li>全国大区2<span>(200人)</span></li>
<li>全国大区3<span>(200人)</span></li>
<li>全国大区4<span>(200人)</span></li>
</ul>
<h1>地区房间/专线</h1>
<ul>
<li>北京1<span>(200人)</span></li>
<li>拉萨<span>(200人)</span></li>
<li>武汉1<span>(200人)</span></li>
<li>广州-武汉专线<span>(200人)</span></li>
</ul>
</article>
<footer> <footer>
<button type="button" class="button button-default"> <button type="button" class="button button-default">
<i class="fa fa-arrow-left"></i> <i class="fa fa-arrow-left"></i>
@ -842,7 +835,7 @@
</button> </button>
</footer> </footer>
</section> </section>
<section id="chat_container" class="chat-page chat-page-current"> <section id="chat_container" class="chat-page">
<header> <header>
当前房间: 当前房间:
<span> <span>

View File

@ -138,6 +138,13 @@
loadPassengers(); loadPassengers();
} }
}; };
this.ensureLogined = function(callback) {
if (!that.isLogined) {
that.fireEvent("requireLogin", callback);
} else {
callback(that.current);
}
};
this.defaultProfile = { this.defaultProfile = {
autoRefreshDelay: 5, autoRefreshDelay: 5,
hideNotInListTrain: true, hideNotInListTrain: true,

View File

@ -159,7 +159,9 @@
}); });
} else entryPoint(); } else entryPoint();
}; };
$(function() {
if (typeof (chrome) !== 'undefined') { if (typeof (chrome) !== 'undefined') {
nextTest(); nextTest();
} else entryPoint(); } else entryPoint();
});
})(window, document); })(window, document);

View File

@ -1,14 +1,68 @@
define(function(require, exports, module) { define(function (require, exports, module) {
var port = require("../../platform/extensionPort.js"); var ep = require("../../platform/extensionPort.js");
var port = ep.port;
var data = require("../../data.js"); var data = require("../../data.js");
var sessMgr = require("../../account/sessionMgr.js"); var sessMgr = require("../../account/sessionMgr.js");
var ev = require("../../platform/EventObject.js"); var ev = require("../../platform/EventObject.js");
var chat = require("../../platform/chat.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 { return {
init: function() {
}
}; };
}); });

View File

@ -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
}
}); });

View File

@ -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;
}); });

View File

@ -18,7 +18,7 @@
//初始化日期 //初始化日期
require("./widget_datedropdown.js").init("input.ui-date"); 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"); var citySelector = require("./widget_cityselector.js");
citySelector.init("input.ui-cityselector"); citySelector.init("input.ui-cityselector");
@ -27,29 +27,23 @@
//登录 //登录
var ui_login = require("./ui-login.js"); var ui_login = require("./ui-login.js");
ui_login.init();
//结果列表 //结果列表
var ui_result = require("./ui-trainlist.js"); var ui_result = require("./ui-trainlist.js");
ui_result.init();
//自动刷新呢 //自动刷新呢
var autorefresh = require("./ui-autorefresh.js"); var autorefresh = require("./ui-autorefresh.js");
autorefresh.init();
autorefresh.on("requestQueryTicket", function () { autorefresh.on("requestQueryTicket", function () {
ui_result.load(); ui_result.load();
}); });
//提交订单 //提交订单
var uiOrderProcess = require("./ui-order-submit-process.js"); var uiOrderProcess = require("./ui-order-submit-process.js");
uiOrderProcess.init();
//查询参数 //查询参数
var uiAutoSubmitForm = require("./ui-autosubmitform.js"); require("./ui-autosubmitform.js");
uiAutoSubmitForm.init();
//模式管理 //模式管理
var uiThemeManager = require("./ui-theme-manager.js"); require("./ui-theme-manager.js");
uiThemeManager.init();
//用户配置和选项的加载以及保存 //用户配置和选项的加载以及保存
require("../platform/profileBinder.js"); require("../platform/profileBinder.js");
@ -226,8 +220,7 @@
})(); })();
//聊天系统 //聊天系统
var chatframe = require("./chat/chatframe.js"); require("./chat/chatframe.js");
chatframe.init();
//统计报告 //统计报告
port.track(param.trackTypes.OPEN_PAGE_INDEX); port.track(param.trackTypes.OPEN_PAGE_INDEX);

View File

@ -7,6 +7,7 @@
var media = require("../platform/media.js"); var media = require("../platform/media.js");
var query = require("../otn/queryticket.js"); var query = require("../otn/queryticket.js");
var trainSuggest = require("../otn/trainstationsuggest.js"); var trainSuggest = require("../otn/trainstationsuggest.js");
var port = require("../platform/extensionPort.js");
sessMgr.on("sessionChanged", function () { sessMgr.on("sessionChanged", function () {
session = sessMgr.current; session = sessMgr.current;
@ -132,7 +133,7 @@
var currentSelectedDate; var currentSelectedDate;
var currentDateLoopIndex = -1; var currentDateLoopIndex = -1;
this.init = function () { var init = function () {
query.events.on("processTrains", function (e, d) { query.events.on("processTrains", function (e, d) {
processTrains(d); processTrains(d);
if (inAutoRefresh) if (inAutoRefresh)
@ -168,7 +169,7 @@
trainSuggest.clearQueryResultCache(); trainSuggest.clearQueryResultCache();
//track //track
port.track(param.trackTypes.START_AUTOREFRESH); port.track(expdata.trackTypes.START_AUTOREFRESH);
} }
inAutoRefresh = true; inAutoRefresh = true;
@ -260,6 +261,7 @@
that.start(); that.start();
}); });
$("#btn_stop_refresh").click(this.stop); $("#btn_stop_refresh").click(this.stop);
init();
return this; return this;
}; };

View File

@ -458,12 +458,12 @@
}); });
}; };
exports.init = function () { var init = function () {
initPassengerEditor(); initPassengerEditor();
initTrainSelectEditor(); initTrainSelectEditor();
initDateLoop(); initDateLoop();
initSeatOrder(); initSeatOrder();
initProfileOperation(); initProfileOperation();
}; };
init();
}); });

View File

@ -18,9 +18,6 @@
ev.apply(this, arguments); ev.apply(this, arguments);
this.init = function() {
};
this.showLoginDialog = function () { this.showLoginDialog = function () {
var info = storage.obj("12306_lastUser"); var info = storage.obj("12306_lastUser");
if (info) { if (info) {
@ -155,7 +152,8 @@
loadLoginAsyncSuggest(); loadLoginAsyncSuggest();
}; };
dlg.on("closeDialog", function() { dlg.on("closeDialog", function () {
that.off("loginSuccess");
that.fireEvent("closeLogin"); that.fireEvent("closeLogin");
}).on("openDialog", function() { }).on("openDialog", function() {
that.fireEvent("showLogin"); that.fireEvent("showLogin");
@ -179,6 +177,11 @@
sessionMgr.on("userNotChecked", function () { sessionMgr.on("userNotChecked", function () {
mp.alert("提示", "用户尚未通过审核!"); mp.alert("提示", "用户尚未通过审核!");
}); });
sessionMgr.on("requireLogin", function(e, c) {
if (c)
that.once("loginSuccess", c);
that.showLoginDialog();
});
//界面事件绑定 //界面事件绑定
$("#acc_login").click(function () { $("#acc_login").click(function () {

View File

@ -12,10 +12,7 @@
//提交参数 //提交参数
var pTrain, pSeat, pStu, pPassengers, pProfile; var pTrain, pSeat, pStu, pPassengers, pProfile;
exports.init = function () { var init = function () {
ps.init();
so.init();
ps.on("passengerSelected", function () { ps.on("passengerSelected", function () {
pPassengers = ps.selectedPassenger; pPassengers = ps.selectedPassenger;
exports.prepareOrder().done(function () { exports.showConfirmOrderUi(); }); exports.prepareOrder().done(function () { exports.showConfirmOrderUi(); });
@ -85,4 +82,6 @@
exports.showFailedUi = function (msg) { exports.showFailedUi = function (msg) {
}; };
init();
}); });

View File

@ -21,9 +21,6 @@
EO.apply(this); EO.apply(this);
this.init = function () {
};
this.show = function (passengers, train, seat, stu) { this.show = function (passengers, train, seat, stu) {
preloadPasList = passengers; preloadPasList = passengers;
curTrain = train; curTrain = train;

View File

@ -8,6 +8,7 @@
var param = require("../data.js"); var param = require("../data.js");
var media = require("../platform/media.js"); var media = require("../platform/media.js");
var share = require("./ui_sns_share.js"); var share = require("./ui_sns_share.js");
var port = require("../platform/extensionPort.js");
//提交参数 //提交参数
var pTrain, pStu, pPassengers, pProfile; var pTrain, pStu, pPassengers, pProfile;
var submitDef; var submitDef;
@ -23,7 +24,7 @@
var submitProgress = $("#ticket-submit-info .ticket-submit-status"); var submitProgress = $("#ticket-submit-info .ticket-submit-status");
var resubmitBtn = $("#ticket-submit-info .ticket-submit-info-status-failed button.button-primary"); 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 () { $("#ticket-submit-info .ticket-submit-vc input:text").keyup(function () {
if (this.value.length === 4) if (this.value.length === 4)
that.submitOrder(); that.submitOrder();
@ -131,6 +132,7 @@
submitDef = null; submitDef = null;
}); });
}; };
init();
return this; return this;
}; };

View File

@ -18,7 +18,7 @@
listContainer.html(tpl(_.values(sessMgr.current.savedProfile.list || []))); listContainer.html(tpl(_.values(sessMgr.current.savedProfile.list || [])));
}; };
this.init = function () { var init = function () {
$("#travel-theme-select").focus(function () { $("#travel-theme-select").focus(function () {
$(this).parent().parent().addClass("hover"); $(this).parent().parent().addClass("hover");
}).blur(function () { }).blur(function () {
@ -109,6 +109,7 @@
}; };
initList(); initList();
sessMgr.on("sessionChanged", initList); sessMgr.on("sessionChanged", initList);
init();
return this; return this;
}; };

View File

@ -64,7 +64,7 @@
}); });
}; };
this.init = function () { var init = function () {
tsquery.init(); tsquery.init();
datebar.init(); datebar.init();
@ -96,8 +96,6 @@
sessMgr.save(); sessMgr.save();
__.load(); __.load();
}); });
};
//监听订票请求 //监听订票请求
$(document).on("click", "a.ticket-block", function () { $(document).on("click", "a.ticket-block", function () {
var id = this.dataset.traincode; var id = this.dataset.traincode;
@ -112,6 +110,9 @@
seat: seatcode seat: seatcode
}); });
}); });
};
init();
return this; return this;
}; };

View File

@ -327,14 +327,14 @@
return this; return this;
}; };
exports.init = function (eleSelector, args) { var init = function(args) {
$("body").append($html); $("body").append($html);
//初始化常用城市 //初始化常用城市
(function () { (function() {
var html = []; var html = [];
_.each(popcity, function (c) { _.each(popcity, function(c) {
var city = cityMap[c]; var city = cityMap[c];
html.push("<li data-code='" + city.c + "' data-py='" + city.p + "' data-name='" + city.n + "' data-fl='" + city.h + "'>" + city.n + "</li>"); html.push("<li data-code='" + city.c + "' data-py='" + city.p + "' data-name='" + city.n + "' data-fl='" + city.h + "'>" + city.n + "</li>");
@ -352,7 +352,10 @@
args = $.extend({ rows: 9 }, args); args = $.extend({ rows: 9 }, args);
selector = new CitySelector(args); selector = new CitySelector(args);
exports.cityui = selector; exports.cityui = selector;
};
init();
exports.init = function (eleSelector) {
$(document).on("focus", eleSelector, function () { $(document).on("focus", eleSelector, function () {
selector.showPopup($(this)); selector.showPopup($(this));
setTimeout((function () { this.select(); }).bind(this), 1); setTimeout((function () { this.select(); }).bind(this), 1);

View File

@ -91,7 +91,7 @@
var dropdownInstance; var dropdownInstance;
exports.init = function (selector, params) { var init = function (params) {
var date_classes = ["month-first", "month-second"]; var date_classes = ["month-first", "month-second"];
var dom = ['<div id="dateSelector">']; var dom = ['<div id="dateSelector">'];
@ -136,11 +136,18 @@
minDate: getCurDate() minDate: getCurDate()
}, params); }, params);
dropdownInstance = new DateDropDown(params); dropdownInstance = new DateDropDown(params);
};
init();
exports.instance = dropdownInstance;
exports.init = function (selector) {
/// <summary>初始化指定元素上的事件</summary>
$(document).on("focus", selector, function () { $(document).on("focus", selector, function () {
dropdownInstance.showPopup($(this)); dropdownInstance.showPopup($(this));
}).on("blur", selector, function () { }).on("blur", selector, function () {
dropdownInstance.hidePopup($(this)); dropdownInstance.hidePopup($(this));
}); });
}; }
}); });

View File

@ -43,10 +43,8 @@
container.show(); container.show();
}; };
var init = function() {
return { sessMgr.on("save", function() {
init: function () {
sessMgr.on("save", function () {
checkTime(); checkTime();
}); });
if (cp) if (cp)
@ -54,7 +52,10 @@
container.find(">header>a").click(function() { container.find(">header>a").click(function() {
container.hide(); container.hide();
}); });
}, };
init();
return {
check: checkTime check: checkTime
}; };
}); });