2014-06-12 21:36:05 +08:00
|
|
|
|
define(function (require, exports, module) {
|
2014-08-30 01:32:27 +08:00
|
|
|
|
var md = require("./widget_modalDialog.js");
|
2015-11-23 19:52:48 +08:00
|
|
|
|
var events = require("../events.js");
|
|
|
|
|
|
2014-06-12 21:36:05 +08:00
|
|
|
|
var htmlTemplate = '<section class="message-popup"><div class="message-popup-inner"><b class=""></b> <span></span></div></section>';
|
|
|
|
|
var iconMap = {
|
|
|
|
|
warn: "warning",
|
|
|
|
|
ok: "check",
|
|
|
|
|
error: "times-circle",
|
|
|
|
|
loading: "spinner"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var MessagePopup = function (type, content, options) {
|
|
|
|
|
var that = this;
|
|
|
|
|
var html = $(htmlTemplate);
|
|
|
|
|
var shown = false;
|
|
|
|
|
options = $.extend({ closeAfter: null }, options);
|
|
|
|
|
$("body").append(html);
|
|
|
|
|
|
|
|
|
|
var centerElement = function (ele) {
|
|
|
|
|
ele = ele || html;
|
|
|
|
|
|
|
|
|
|
var width = ele.width();
|
|
|
|
|
var height = ele.height();
|
|
|
|
|
|
|
|
|
|
ele.css({
|
|
|
|
|
"margin-left": "-" + (width / 2) + "px",
|
|
|
|
|
"margin-top": "-" + (height / 2 - 40) + "px"
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
this.show = function () {
|
2014-07-04 20:57:57 +08:00
|
|
|
|
html.css("opacity", "0");
|
|
|
|
|
html.show();
|
2014-06-12 21:36:05 +08:00
|
|
|
|
html.animate({ "margin-top": "-=20px", opacity: "1" }, "fast", "linear", function () {
|
|
|
|
|
shown = true;
|
|
|
|
|
if (options.closeAfter) {
|
|
|
|
|
that.delayClose();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
this.close = function () {
|
2014-07-04 20:57:57 +08:00
|
|
|
|
html.animate({ "margin-top": "-=20px", opacity: "0" }, "fast", "linear", function () {
|
|
|
|
|
html.hide();
|
2014-06-12 21:36:05 +08:00
|
|
|
|
html.remove();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
this.delayClose = function (timeout) {
|
2014-06-27 22:25:42 +08:00
|
|
|
|
timeout = timeout || options.closeAfter || 1500;
|
2014-06-12 21:36:05 +08:00
|
|
|
|
if (that.shown)
|
2014-06-27 22:25:42 +08:00
|
|
|
|
setTimeout(that.close, timeout);
|
2014-06-12 21:36:05 +08:00
|
|
|
|
else {
|
2014-06-27 22:25:42 +08:00
|
|
|
|
options.closeAfter = timeout;
|
2014-06-12 21:36:05 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
that.setState = function (type, content) {
|
|
|
|
|
that.type = type;
|
|
|
|
|
that.content = content;
|
|
|
|
|
};
|
|
|
|
|
Object.defineProperties(this, {
|
|
|
|
|
"content": {
|
|
|
|
|
get: function () {
|
|
|
|
|
return html.find("span").html();
|
|
|
|
|
},
|
|
|
|
|
set: function (value) {
|
|
|
|
|
html.find("span").html(value);
|
|
|
|
|
centerElement();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"type": {
|
|
|
|
|
get: function () {
|
|
|
|
|
return html.attr("data-type");
|
|
|
|
|
},
|
|
|
|
|
set: function (value) {
|
|
|
|
|
html.attr("data-type", value);
|
|
|
|
|
html.removeClass().addClass("message-popup message-popup-" + value);
|
|
|
|
|
html.find("b").removeClass().addClass("fa fa-" + iconMap[value] + (value === "loading" ? " fa-spin" : ""));
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"shown": {
|
|
|
|
|
get: function () {
|
|
|
|
|
return shown;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
this.content = content;
|
|
|
|
|
this.type = type;
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
exports.MessagePopup = MessagePopup;
|
|
|
|
|
|
|
|
|
|
exports.showMessagePopup = function (icon, content, options) {
|
2014-08-18 23:12:35 +08:00
|
|
|
|
options = $.extend({ closeAfter: 2000 }, options);
|
2014-06-12 21:36:05 +08:00
|
|
|
|
|
|
|
|
|
var popup = new MessagePopup(icon, content, options);
|
|
|
|
|
popup.show();
|
|
|
|
|
return popup;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
exports.confirm = function (title, content, yes, no) {
|
2014-08-30 01:32:27 +08:00
|
|
|
|
$.showModalDialog(content, {
|
|
|
|
|
buttons: [
|
|
|
|
|
{ text: "确定", callback: yes, type: "primary" },
|
|
|
|
|
{ text: "取消", callback: no }
|
|
|
|
|
],
|
|
|
|
|
closeOnAction: true
|
|
|
|
|
});
|
2014-06-12 21:36:05 +08:00
|
|
|
|
};
|
2014-08-30 01:32:27 +08:00
|
|
|
|
|
2014-06-12 21:36:05 +08:00
|
|
|
|
exports.alert = function (title, content, callback) {
|
2014-08-30 01:32:27 +08:00
|
|
|
|
content = content || title;
|
|
|
|
|
$.showModalDialog(content, {
|
|
|
|
|
buttons: [
|
|
|
|
|
{ text: "确定", callback: callback, type: "primary" }
|
|
|
|
|
],
|
|
|
|
|
closeOnAction: true
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
exports.showFatalError = function () {
|
|
|
|
|
$.showModalDialog("12306又不肯配合或者干脆罢工了...现在抢票功能暂时无法使用,请暂时使用12306官网购票,订票助手依然会帮你的....", {
|
|
|
|
|
image: "/images/cat.png",
|
|
|
|
|
buttons: [
|
|
|
|
|
{
|
|
|
|
|
text: "打开12306官网",
|
|
|
|
|
type: "primary",
|
|
|
|
|
callback: function () {
|
|
|
|
|
window.open("https://kyfw.12306.cn/otn/leftTicket/init");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
text: "刷新重试",
|
|
|
|
|
callback: function () {
|
|
|
|
|
self.location.reload();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-09-01 20:24:57 +08:00
|
|
|
|
],
|
|
|
|
|
closeOnAction: false
|
2014-08-30 01:32:27 +08:00
|
|
|
|
});
|
|
|
|
|
};
|
2015-07-31 19:54:22 +08:00
|
|
|
|
//exports.showSecurityAlert = function () {
|
|
|
|
|
// $.showModalDialog("<div style='font-size: 14px;line-height:22px; width:430px;'><span style='color:red;font-size:120%;'>12306账号密码发生大规模泄露,请尽快修改密码。</span>\
|
|
|
|
|
// <br /><span style='color:green;'>猎豹不会上传保存您的密码,请放心使用。</span><br />\
|
|
|
|
|
// <span style=''>如使用过其它第三方抢票(含离线抢票),建议修改密码。</span>\
|
|
|
|
|
// <span style=''>此事警方已介入,<a href='https://kyfw.12306.cn/otn/gonggao/t20141225_2448.html' style='text-decoration:underline;' target='_blank'>点此查看详情</a>。</span></div>",
|
|
|
|
|
// {
|
|
|
|
|
// image: "/images/cat1.png",
|
|
|
|
|
// buttons: [
|
|
|
|
|
// {
|
|
|
|
|
// text: "立刻修改密码",
|
|
|
|
|
// type: "primary",
|
|
|
|
|
// callback: function () {
|
|
|
|
|
// window.open("https://kyfw.12306.cn/otn/userSecurity/init");
|
|
|
|
|
// localStorage["tip_showSecurityAlert"] = "1";
|
|
|
|
|
// return true;
|
|
|
|
|
// }
|
|
|
|
|
// }, {
|
|
|
|
|
// text: "我知道了",
|
|
|
|
|
// callback: function () {
|
|
|
|
|
// localStorage["tip_showSecurityAlert"] = "1";
|
|
|
|
|
// return true;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// ],
|
|
|
|
|
// closeOnAction: false
|
|
|
|
|
// });
|
|
|
|
|
//};
|
|
|
|
|
//if (localStorage["tip_showSecurityAlert"] != "1")
|
|
|
|
|
// exports.showSecurityAlert();
|
2015-03-13 19:25:08 +08:00
|
|
|
|
|
2014-09-01 20:24:57 +08:00
|
|
|
|
exports.showNonExtensionInstall = function () {
|
2015-11-23 19:52:48 +08:00
|
|
|
|
var isLb = navigator.userAgent.indexOf("LBBROWSER") !== -1;
|
2014-09-09 11:00:45 +08:00
|
|
|
|
var btns = [
|
|
|
|
|
{
|
2014-09-09 11:17:58 +08:00
|
|
|
|
text: "刷新",
|
|
|
|
|
type: "default",
|
2014-09-10 21:49:46 +08:00
|
|
|
|
callback: function () {
|
2014-09-09 11:17:58 +08:00
|
|
|
|
self.location.reload();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
];
|
2014-09-09 14:55:30 +08:00
|
|
|
|
if (!isLb) {
|
2014-09-09 11:17:58 +08:00
|
|
|
|
btns.unshift({
|
2014-09-09 11:00:45 +08:00
|
|
|
|
text: "安装猎豹浏览器",
|
|
|
|
|
type: "primary",
|
2014-09-11 22:19:33 +08:00
|
|
|
|
callback: function (opt, btn) {
|
2014-09-09 11:00:45 +08:00
|
|
|
|
window.open("http://dl.liebao.cn/coop/KSBrowser_12306.exe");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-09-09 11:17:58 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
2014-09-10 21:49:46 +08:00
|
|
|
|
btns.unshift({
|
|
|
|
|
text: "安装扩展",
|
|
|
|
|
type: "primary",
|
2014-09-11 22:19:33 +08:00
|
|
|
|
callback: function (opt, btn) {
|
|
|
|
|
btn.html("正在安装...");
|
|
|
|
|
btn.removeClass("button-primary").addClass("button-default");
|
2014-09-10 21:49:46 +08:00
|
|
|
|
window.open("http://12306.fishlee.net/crx");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-09-09 11:00:45 +08:00
|
|
|
|
|
2014-09-09 15:56:01 +08:00
|
|
|
|
$.showModalDialog("您需要安装" + (isLb ? "" : "<u>猎豹浏览器</u>并") + "启用<u>最新版12306订票助手扩展</u>才可以使用极速版订票。请安装后刷新此页面。如果已安装,请检查是否不小心禁用了 :-(", {
|
2014-09-09 11:00:45 +08:00
|
|
|
|
image: "/images/cat.png",
|
|
|
|
|
buttons: btns,
|
2014-09-01 20:24:57 +08:00
|
|
|
|
closeOnAction: false
|
2014-08-30 01:32:27 +08:00
|
|
|
|
});
|
2014-06-12 21:36:05 +08:00
|
|
|
|
};
|
2015-11-23 19:52:48 +08:00
|
|
|
|
events.msgFrom12306.addEventListener(function(ev, msg) {
|
|
|
|
|
exports.alert("12306通知", msg);
|
|
|
|
|
});
|
2014-06-12 21:36:05 +08:00
|
|
|
|
|
|
|
|
|
//捕捉一些通用的事件
|
|
|
|
|
document.addEventListener("requestSupportError", function () {
|
2014-08-30 01:32:27 +08:00
|
|
|
|
exports.showNonExtensionInstall();
|
2014-06-12 21:36:05 +08:00
|
|
|
|
});
|
2014-08-27 23:05:50 +08:00
|
|
|
|
document.addEventListener("verifyCodeLoadFailed", function () {
|
2014-06-13 19:52:22 +08:00
|
|
|
|
exports.showMessagePopup("error", "验证码加载失败,请点击验证码图片刷新哦。");
|
|
|
|
|
});
|
2014-08-27 23:05:50 +08:00
|
|
|
|
document.addEventListener("platformError", function () {
|
2014-08-30 01:32:27 +08:00
|
|
|
|
exports.showFatalError();
|
2014-08-27 23:05:50 +08:00
|
|
|
|
});
|
2014-06-12 21:36:05 +08:00
|
|
|
|
});
|