You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

650 lines
21 KiB
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

(function (_w) {
var w = _w;
//main namespace
CH = {};
CH.Zodiac = {};
//cookie设置 调用:$.Cookie.Set('abc');
$.Cookie = {
//写cookies并加密
SetCookie: function (name, value, option) {
//用于存储赋值给document.cookie的cookie格式字符串
var str = name + "=" + escape($.Cookie.CodeCookie(value));
if (option) {
//如果设置了过期时间
if (option.expireDays) {
var date = new Date();
var ms = option.expireDays * 24 * 3600 * 1000;
date.setTime(date.getTime() + ms);
str += ";expires=" + date.toGMTString();
}
if (option.path) str += ";path=" + path;
if (option.domain) str += ";domain=" + domain;
if (option.secure) str += ";true";
}
document.cookie = str;
}
,
//读cookie并解密
GetCookie: function (name) {
var cookieArray = document.cookie.split(";");
var cookie = new Object();
for (var i = 0; i < cookieArray.length; i++) {
var arr = cookieArray[i].split("=");
if ($.trim(arr[0]) == $.trim(name)) return $.Cookie.DecodeCookie(unescape(arr[1]));
};
return "";
}
,
//加密cookie
CodeCookie: function (str) {
var strRtn = "";
for (var i = str.length - 1; i >= 0; i--) {
strRtn += str.charCodeAt(i);
if (i) strRtn += "a"; //用a作分隔符
}
return strRtn;
}
,
//解码cookie
DecodeCookie: function (str) {
var strArr;
var strRtn = "";
strArr = str.split("a");
for (var i = strArr.length - 1; i >= 0; i--)
strRtn += String.fromCharCode(eval(strArr[i]));
return strRtn;
}
,
// write cookies
Set: function (name, value, hours) {
var expire = "";
if (hours != null) {
expire = new Date((new Date()).getTime() + hours * 3600000);
expire = "; expires=" + expire.toGMTString();
}
document.cookie = name + "=" + escape(value) + expire + ";path=/";
},
// read cookies
Get: function (name) {
var cookieValue = "";
var search = name + "=";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search);
if (offset != -1) {
offset += search.length;
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
cookieValue = unescape(document.cookie.substring(offset, end));
}
}
return cookieValue;
}
,
// delete cookie
Del: function (name) {
var date = new Date();
date.setTime(date.getTime() - 10000);
document.cookie = name + "=''; expires=" + date.toGMTString();
}
},
//弹窗工具箱
$.Dialog = {
iframe: function (url, w, h) {
return '<iframe id="Dialog-iframe" frameborder="0" src="' + url + '" style="width: ' + w + 'px; height: ' + h + 'px;" scrolling=\"auto\"></iframe>';
},
//弹出框
ShowDialog: function (title, id, w, h) {
if ($("#dialog").length != "0")
$("div#dialog").remove();
var tmp = "<div id=\"dialog\" title=\"" + title + "\" class='StyleNone'><p>" + $(id).html() + "</p></div>";
$("body").append(tmp);
$('#dialog').dialog({
autoOpen: false,
modal: true,
height: h + 60,
width: w + 36,
close: function (event, ui) { $(this).dialog("destroy"); }
});
$('#dialog').dialog('open');
},
//弹窗框 IFrame
ShowIFrame: function (title, url, w, h) {
if ($("#dialog").length != "0")
$("div#dialog").remove();
var tmp = "<div id=\"dialog\" title=\"" + title + "\" class='StyleNone'><p>" + $.Dialog.iframe(url, w, h) + "</p></div>";
$("body").append(tmp);
$('#dialog').dialog({
autoOpen: false,
modal: true,
height: h + 60,
width: w + 36,
close: function (event, ui) { $(this).dialog("destroy"); }
});
$('#dialog').dialog('open');
},
iframe: function (url, w, h) {
return '<iframe id="Dialog-iframe" frameborder="0" src="' + url + '" style="width: ' + w + 'px; height: ' + h + 'px;" scrolling=\"auto\"></iframe>';
},
InsertMsgDiv: function (title, msg, id) {
if ($("#" + id).length == "0") {
var tmp = "<div id=\"" + id + "\" title=\"" + title + "\" style='font-size:12px;display:none;z-index:9999999;'><p>" + msg + "</p></div>";
$("body").append(tmp);
}
else
$("#" + id + " > p").attr("title", title).html(msg);
},
//显示文本消息
PrintMsg: function (title, msg, modal, time, topButton) {
var divID = "js_msg";
InsertMsgDiv(title, msg, divID, topButton);
$("#" + divID).dialog({ autoOpen: false, modal: modal });
if (typeof topButton == "boolean" && topButton)
$("a.ui-dialog-titlebar-close").remove();
$("#" + divID).dialog('open');
if (typeof time == 'number' && time > 0)
setTimeout("$('#" + divID + "').dialog('close')", time * 1000);
},
//显示文本消息,点击跳转
UpdateJump: function () {
divID = "js_msg";
InsertMsgDiv(title, msg, divID);
$("#" + divID).dialog(
{
autoOpen: false,
modal: modal,
buttons:
{
close: function () {
if (url == "")
window.parent.location.reload();
else if (url == "history(-1)")
window.history.back();
else
window.parent.location.href = url;
}
}
}
);
$("a.ui-dialog-titlebar-close").remove();
$("#" + divID).dialog('open');
},
//打开Windows弹窗
OpenWindow: function (u, w, h, t, n, top, left) {
if (u == "" || typeof (u) == "undefined")
u = that.attr("uri");
if (typeof t != 'undefined' && t == 'confirm') return false;
h = (h == "" || typeof h == 'undefined') ? 600 : h;
w = (w == "" || typeof w == 'undefined') ? 600 : w;
n = (n == "" || typeof n == "undefined") ? "newwindow" : n;
top = (top == "" || typeof top == "undefined") ? "90" : top;
left = (left == "" || typeof left == "undefined") ? "160" : left;
if ($.browser.msie) {
if ($.browser.version == "8.0")
window.open(u, n);
else
window.open(u, n, 'height=' + h + ',width=' + w + ',top=' + top + ',left=' + left + ',scrollbars=no,toolbar=no,menubar=no, Resizable=no,location=no,status=no');
}
else
window.open(u, n, 'height=' + h + ',width=' + w + ',top=' + top + ',left=' + left + ',scrollbars=no,toolbar=no,menubar=no, Resizable=no,location=no,status=no');
}
};
CH.Zodiac.Fun = {
//转换成字符串,防XSS攻击
ToStr: function (str) {
return str.replace("<", "&lt;").replace(">", "&gt;");
},
//搜索聚焦
SearchFocusContent: function () {
var hash = (!window.location.hash) ? "#content" : window.location.hash;
window.location.hash = hash;
},
CheckEmail:function(e)
{
var reg =/^([a-zA-Z0-9_-_\.])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
return reg.test(String(e));
},
CheckDate:function(d)
{
var reg = /[01|02|03|04|05|06|07|08|09|10|11|12]\/[0-9]{2}\/[0-9]{4}$/;
return reg.test(String(d));
},
//载入Jquery UI
LoadUI: function () {
if ($("link[href='/css/smoothness/jquery-ui.css']").length == 0) {
var uicss = $("<link>");
uicss.attr("type", "text/css").attr("rev", "Stylesheet").attr("rel", "Stylesheet").attr("href", "/css/smoothness/jquery-ui.css");
$("head").append(uicss);
}
if ($("script[src='/js/jquery-ui.js']").length == 0) {
var uijs = $("<script></sctipt>");
uijs.attr("type", "text/javascript").attr("src", "/js/jquery-ui.js");
$("head").append(uijs);
}
},
OnFocusMenu: function (active) {
if ($("#nav ul li").length > 0) {
$.each($("#nav li"), function () {
var that = $(this);
var data = that.attr("data");
if (data.length > 0) {
var json = new Function("return " + data)();
for (i = 0; i < json.active.length; i++) {
if (json.active[i] == active) {
that.addClass("active");
break;
}
}
}
});
}
},
DiffDate: function(date1,date2,Format)
{
var y1,M1,d1,y2,M2,d2;
var day = 24 * 60 * 60 *1000;
try{
var dateArr = date1.split("/");
var checkDate = new Date();
var dateArr2 = date2.split("/");
var checkDate2 = new Date();
switch(Format)
{
case "yyyy/MM/dd":
y1 = dateArr[0];M1 = dateArr[1] - 1;d1 = dateArr[2] - 1;
y2 = dateArr2[0];M2 = dateArr2[1] - 1;d2 = dateArr2[2] - 1;
break;
case "MM/dd/yyyy":
y1 = dateArr[2];M1 = dateArr[0] - 1;d1 = dateArr[1] - 1;
y2 = dateArr2[2];M2 = dateArr2[0] - 1;d2 = dateArr2[1] - 1;
break;
case "dd/MM/yyyy":
y1 = dateArr[2];M1 = dateArr[1] - 1;d1 = dateArr[0] - 1;
y2 = dateArr2[2];M2 = dateArr2[1] - 1;d2 = dateArr2[0] - 1;
break;
case "yyyy-MM-dd":
var dateArr = date1.split("-");
var checkDate = new Date();
var dateArr2 = date2.split("-");
var checkDate2 = new Date();
y1 = dateArr[0]; M1 = dateArr[1] - 1; d1 = dateArr[2] - 1;
y2 = dateArr2[0]; M2 = dateArr2[1] - 1; d2 = dateArr2[2] - 1;
}
checkDate.setFullYear(y1, M1, d1);
var checkTime = checkDate.getTime();
checkDate2.setFullYear(y2, M2, d2);
var checkTime2 = checkDate2.getTime();
var cha = (checkTime - checkTime2)/day;
return cha;
}
catch(e)
{
return false;
}
},
//判断是否有填充奇、偶行的表格
OddEvenRows: function(s)
{
if($("table.t").length > 0)
{
var trs = s == "" ? "table.t tr" : "table.t tr[class!='"+s+"']";
$.each($(trs),function(x,y){
if(x % 2 == 1)
{
$(this).addClass("odd");
}
else
{
$(this).addClass("even");
}
});
}
},
Mask: function(obj,left,top,width,height)
{
var o = obj.offset();
var _w = obj.width();
var _h = obj.height();
var _l = o.left;
var _t = o.top;
$("#Mask").width(_w + width).height(_h + height).css({top:_t + top,left:_l + left});
},
CheckBoxColor: function()
{
//复选框着色
$.each($("input[type='checkbox']"),function(){
if($(this).attr("checked"))
$(this).parent("label").addClass("checked");
});
$("input[type='checkbox']").click(function(){
if ($(this).is(":checked"))
$(this).parent("label").addClass("checked");
else
$(this).parent("label").removeClass("checked");
});
},
OnFocusMenu: function (active) {
if ($("#menu a").length > 0) {
$.each($("#menu a"), function () {
var that = $(this);
var data = that.attr("data");
if (typeof data != "undefined") {
var json = new Function("return " + data)();
for (i = 0; i < json.active.length; i++) {
if (json.active[i] == active) {
that.addClass("active");
break;
}
}
}
});
}
},
OnFocusMenu: function (active) {
if ($("#menu-main-center a").length > 0) {
$.each($("#menu-main-center a"), function () {
var that = $(this);
var data = that.attr("data");
if (typeof data != "undefined") {
var json = new Function("return " + data)();
for (i = 0; i < json.active.length; i++) {
if (json.active[i] == active) {
that.addClass("active");
for(var i=0; i<CH.Zodiac.SubMenu[that.index()].length; i++)
{
$("#menu-sub-center").append("| <a href='"+CH.Zodiac.SubMenu[that.index()][i].u+"' data=\"{'active':['"+CH.Zodiac.SubMenu[$(this).index()][i].ac+"']}\">"+CH.Zodiac.SubMenu[that.index()][i].t+"</a>");
}
break;
}
}
}
});
}
},
OnFocusSubMenu: function(active) {
if ($("#menu-sub-center a").length > 0) {
$.each($("#menu-sub-center a"), function () {
var that = $(this);
var data = that.attr("data");
if (data.length > 0) {
var json = new Function("return " + data)();
for (i = 0; i < json.active.length; i++) {
if (json.active[i] == active) {
that.addClass("active");
break;
}
}
}
});
}
},
//初始化操作
init: function () {
//按钮手型显示
$("input[type=submit],input[type=button]").css("cursor","pointer");
//块消隐操作
$(".js_ShowToggle").click(function () {
var that = $(this);
var DivID = that.attr("divid");
var SrcID = that.attr("srcid");
if (SrcID != "") {
var tmp = $("#" + SrcID).attr("src");
$("#" + SrcID).attr("src", $("#" + SrcID).attr("srctemp"))
$("#" + SrcID).attr("srctemp", tmp);
}
$("#" + DivID).slideToggle();
});
//日历控件
if ($(".datepickerall,.datepicker,.datepickerfromto").length > 0) {
CH.Zodiac.Fun.LoadUI();
$.datepicker.regional["zh-CN"]; //设置语言
$(".datepickerall").datepicker({
showAnim: "fadeIn",
duration: 0,
minDate: null, //null=不屏蔽过往日期,0=屏蔽
maxDate: "2y",
numberOfMonths: 2,
showButtonPanel: true
});
//日历控件
$(".datepicker").datepicker({
showAnim: "fadeIn",
duration: 0,
minDate: 0, //""null不屏蔽过往日期,0=屏蔽
maxDate: "2y",
numberOfMonths: 2,
showButtonPanel: true
});
//双日历
var dates = $(".datepickerfromto#from, .datepickerfromto#to").datepicker({
defaultDate: "+1w",
numberOfMonths: 2,
minDate: 0, //""null不屏蔽过往日期,0=屏蔽
onSelect: function (selectedDate) {
var option = this.id == "from" ? "minDate" : "maxDate",
instance = $(this).data("datepicker"),
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings);
dates.not(this).datepicker("option", option, date);
}
});
}
//全选复选框
$("input#js_selectcheckboxall").click(function () {
var that = $(this);
if (that.attr("checked"))
$("input.js_select").attr("checked", "checked");
else
$("input.js_select").attr("checked", "");
});
//全选复选框
$("a#js_selectcheckboxall").click(function () {
$("input#js_selectcheckboxall").attr("checked", "checked");
$("input.js_select").attr("checked", "checked");
});
$(".openwindow").click(function () {
var that = $(this);
var u = that.attr("uri");
var w = that.attr("w");
var h = that.attr("h");
var t = that.attr("t");
var n = that.attr("n");
var top = that.attr("top");
var left = that.attr("left");
$.Dialog.OpenWindow(u, w, h, t, n, top, left);
});
//选项卡切换
$(".ac-tab li, .ac-tab span").click(function () {
var that = $(this);
$("div.ac-tab li, div.ac-tab span").removeClass("active");
that.addClass("active");
$("div.ac-tab-body .ac-tab-item").hide();
$("div.ac-tab-body .ac-tab-item:eq(" + that.index() + ")").show();
}).mouseover(function(){
var that = $(this);
$("div.ac-tab li, div.ac-tab span").removeClass("active");
that.addClass("active");
$("div.ac-tab-body .ac-tab-item").hide();
$("div.ac-tab-body .ac-tab-item:eq(" + that.index() + ")").show();
});
//重置表单操作
$("input[type=button][name=reset]").click(function(){
$("input[type=text],textarea").val("");
$("select option").attr("selected","");
$.each($("select"),function(){
$(this).children("option").eq(0).attr("selected","selected");
})
});
///////////////////////////////////////////////////////////////
$("#js_ResultDiv").hide();
$("#js_ZodiacSearch").click(function(){
var searchname = $("#searchname").val();
var searchError = document.getElementById("showError");
if (searchname == null || searchname == "" || (!searchname.trim().length)) {
searchError.style.display = "block";
}else{
searchError.style.display = "none";
}
var year = $("#year").val();
var month = $("#month").val();
var day = $("#day").val();
/*发现api文件直接跳转的无法获取json改为直接跳转接口。2020-5-9 zp*/
var params = {
'ac':'ZodiacSearch',
'searchname':searchname,
'year':year,
'month':month,
'day':day
};
Post("/travelguide/chinese-zodiac/date/api.asp",params);
/*
$.post(
"/travelguide/chinese-zodiac/date/api.asp",
{
ac:"ZodiacSearch",
searchname:searchname,
year:year,
month:month,
day:day
},
function(d)
{
if (d.error == 200)
{
$("#js_ResultDiv").show();
$(".result_sx").text(d.SX);
$(".result_zodiaccode").attr("src","//www.chinahighlights.com/image/travelguide/culture/zodiac/"+d.SX+"-zodiac.jpg");
$(".result_zodiacmonth").attr("src","//www.chinahighlights.com/image/travelguide/culture/zodiac/"+d.SX+"-month.jpg");
$(".result_searchname").text(searchname);
$(".result_lucknumber").text(d.LuckyNumber);
$(".result_luckcolor").text(d.LuckyColor);
$(".result_luckflower").text(d.LuckyFlower);
$(".result_url").attr("href","/travelguide/chinese-zodiac/"+d.SX.toLowerCase()+".asp")
$(".result_TheYearFortune").html(d.TheYearFortune);
}
}
,"json"
);
*/
});
}
};
$(function () {
CH.Zodiac.Fun.init();
});
/*
*功能: 模拟form表单的提交
*参数: URL 跳转地址 PARAMTERS 参数
*/
function Post(URL, PARAMTERS) {
//创建form表单
var temp_form = document.createElement("form");
temp_form.action = URL;
//如需打开新窗口form的target属性要设置为'_blank'
temp_form.target = "_self";
temp_form.method = "post";
temp_form.style.display = "none";
//添加参数
for (var item in PARAMTERS) {
var opt = document.createElement("textarea");
opt.name = item;
opt.value = PARAMTERS[item];
temp_form.appendChild(opt);
}
document.body.appendChild(temp_form);
//提交数据
temp_form.submit();
}
})();