Light12306/Mobile12306New/js/public.js

137 lines
3.2 KiB
JavaScript
Raw Normal View History

2014-08-19 16:11:37 +08:00
var WIN = window;
var DOC = document;
var SKIPVC = true;
var hostApi = "12306.cn/otsweb";
var baseProxyUrl = "/12306/proxy.php";
// var baseProxyUrl = "/12306/";
var isMobile = true;
var isIos = typeof (window.__gChrome) != 'undefined' || (typeof (liebaoExtentions) != 'undefined' && liebaoExtentions.isWebviewLiebao && liebaoExtentions.isWebviewLiebao());
var isAndLiebao = typeof (liebaoExtentions) != 'undefined';
var isWebApp = false;
DOC.addEventListener("mobileSupportInitialized", function () {
isWebApp = true;
});
var Public = {
init:function(){
$('.query_box .query_bigcheck').live('click',function(){
$('.query_bigcheck',$(this).parent('.query_box')).removeClass('query_bigcheck_checked');
// $('.query_bigcheck input[type=radio]',$(this).parent('.query_box')).removeAttr('checked');
$('input[type=radio]',this).attr('checked','checked');
$(this).addClass('query_bigcheck_checked');
});
},
/*
* 弹出提示
*
* @param {string} 弹出提示文字
*
*/
toast: function(text,ms) {
if (!text) {
return false;
}
var dom = $('<div class="public_toast">'+text+'</div>');
var ms = ms || 1500;
$('body').append(dom);
setTimeout(function(){
dom.addClass('public_toast_show');
},10);
setTimeout(function(){
dom.removeClass('public_toast_show');
dom.on('webkitTransitionEnd',function(){
dom.remove();
});
},ms);
},
/*
* 弹出层
* @param {string} 弹出提示文字
* @param {object} 弹层按钮 {'sure':'确定','cancel':'取消'}
*
*/
popHtml: function(text, btns) {
var html = "",
dom = DOC['createElement']('div'),
btnsHtml = '';
if (typeof btns == 'object') {
for (var k in btns) {
btnsHtml += '<a href="javascript:;" data-val="' + k + '">' + btns[k] + '</a>';
}
}
if (btnsHtml == '') {
btnsHtml = '<div class="public_btns"><a href="javascript:;" data-type="sure">确定</a></div>';
} else {
btnsHtml = '<div class="public_btns">' + btnsHtml + '</div>'
}
dom['className'] = 'public_layer';
html += '<div class="public_pop"><p>' + text + '</p>' + btnsHtml + '</div>';
dom.innerHTML = html;
document.getElementsByTagName('body')[0].appendChild(dom);
setTimeout(function() {
$('.public_pop', dom).addClass('public_pop_show');
}, 0);
$(dom).on('touchmove', function(e) {
e.preventDefault();
return false;
});
return $(dom);
},
/*
* 模拟 alert 弹出层
* 依赖 Public.popHtml()
*
* @param {string} 弹出提示文字
* @param {function} 点击确定后的回调 可选
*
*/
alert: function(text, callback) {
var dom = Public.popHtml(text, {
'sure': '确定'
});
$('.public_btns a', dom).on('click', function() {
dom.remove();
if (typeof callback == 'function') {
callback();
}
});
},
/*
* 模拟 confirm 弹出层
* 依赖 Public.popHtml()
*
* @param {string} 弹出提示文字
* @param {function} 点击确定后的回调 可选
*
*/
confirm: function(text, callback) {
var dom = Public.popHtml(text, {
'cancel': '取消',
'sure': '确定'
});
$('.public_btns a', dom).on('click', function() {
var type = $(this).attr('data-val');
dom.remove();
if (typeof callback == 'function' && type == "sure") {
callback();
}
});
}
}