//json.js /* Copyright (c) 2005 JSON.org Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The Software shall be used for Good, not Evil. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* The global object JSON contains two methods. JSON.stringify(value) takes a JavaScript value and produces a JSON text. The value must not be cyclical. JSON.parse(text) takes a JSON text and produces a JavaScript value. It will return false if there is an error. */ var JSON = function () { var m = { '\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"' : '\\"', '\\': '\\\\' }, s = { 'boolean': function (x) { return String(x); }, number: function (x) { return isFinite(x) ? String(x) : 'null'; }, string: function (x) { if (/["\\\x00-\x1f]/.test(x)) { x = x.replace(/([\x00-\x1f\\"])/g, function(a, b) { var c = m[b]; if (c) { return c; } c = b.charCodeAt(); return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16); }); } return '"' + x + '"'; }, object: function (x) { if (x) { var a = [], b, f, i, l, v; if (x instanceof Array) { a[0] = '['; l = x.length; for (i = 0; i < l; i += 1) { v = x[i]; f = s[typeof v]; if (f) { v = f(v); if (typeof v == 'string') { if (b) { a[a.length] = ','; } a[a.length] = v; b = true; } } } a[a.length] = ']'; } else if (x instanceof Object) { a[0] = '{'; for (i in x) { v = x[i]; f = s[typeof v]; if (f) { v = f(v); if (typeof v == 'string') { if (b) { a[a.length] = ','; } a.push(s.string(i), ':', v); b = true; } } } a[a.length] = '}'; } else { return; } return a.join(''); } return 'null'; } }; return { copyright: '(c)2005 JSON.org', license: 'http://www.crockford.com/JSON/license.html', /* Stringify a JavaScript value, producing a JSON text. */ stringify: function (v) { var f = s[typeof v]; if (f) { v = f(v); if (typeof v == 'string') { return v; } } return null; }, /* Parse a JSON text, producing a JavaScript value. It returns false if there is a syntax error. */ parse: function (text) { try { return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test( text.replace(/"(\\.|[^"\\])*"/g, ''))) && eval('(' + text + ')'); } catch (e) { return false; } } }; }(); // --calendarObj.js //日期资料 var lunarInfo=new Array( 0x4bd8,0x4ae0,0xa570,0x54d5,0xd260,0xd950,0x5554,0x56af,0x9ad0,0x55d2, 0x4ae0,0xa5b6,0xa4d0,0xd250,0xd295,0xb54f,0xd6a0,0xada2,0x95b0,0x4977, 0x497f,0xa4b0,0xb4b5,0x6a50,0x6d40,0xab54,0x2b6f,0x9570,0x52f2,0x4970, 0x6566,0xd4a0,0xea50,0x6a95,0x5adf,0x2b60,0x86e3,0x92ef,0xc8d7,0xc95f, 0xd4a0,0xd8a6,0xb55f,0x56a0,0xa5b4,0x25df,0x92d0,0xd2b2,0xa950,0xb557, 0x6ca0,0xb550,0x5355,0x4daf,0xa5b0,0x4573,0x52bf,0xa9a8,0xe950,0x6aa0, 0xaea6,0xab50,0x4b60,0xaae4,0xa570,0x5260,0xf263,0xd950,0x5b57,0x56a0, 0x96d0,0x4dd5,0x4ad0,0xa4d0,0xd4d4,0xd250,0xd558,0xb540,0xb6a0,0x95a6, 0x95bf,0x49b0,0xa974,0xa4b0,0xb27a,0x6a50,0x6d40,0xaf46,0xab60,0x9570, 0x4af5,0x4970,0x64b0,0x74a3,0xea50,0x6b58,0x5ac0,0xab60,0x96d5,0x92e0, 0xc960,0xd954,0xd4a0,0xda50,0x7552,0x56a0,0xabb7,0x25d0,0x92d0,0xcab5, 0xa950,0xb4a0,0xbaa4,0xad50,0x55d9,0x4ba0,0xa5b0,0x5176,0x52bf,0xa930, 0x7954,0x6aa0,0xad50,0x5b52,0x4b60,0xa6e6,0xa4e0,0xd260,0xea65,0xd530, 0x5aa0,0x76a3,0x96d0,0x4afb,0x4ad0,0xa4d0,0xd0b6,0xd25f,0xd520,0xdd45, 0xb5a0,0x56d0,0x55b2,0x49b0,0xa577,0xa4b0,0xaa50,0xb255,0x6d2f,0xada0, 0x4b63,0x937f,0x49f8,0x4970,0x64b0,0x68a6,0xea5f,0x6b20,0xa6c4,0xaaef, 0x92e0,0xd2e3,0xc960,0xd557,0xd4a0,0xda50,0x5d55,0x56a0,0xa6d0,0x55d4, 0x52d0,0xa9b8,0xa950,0xb4a0,0xb6a6,0xad50,0x55a0,0xaba4,0xa5b0,0x52b0, 0xb273,0x6930,0x7337,0x6aa0,0xad50,0x4b55,0x4b6f,0xa570,0x54e4,0xd260, 0xe968,0xd520,0xdaa0,0x6aa6,0x56df,0x4ae0,0xa9d4,0xa4d0,0xd150,0xf252, 0xd520); var solarMonth=new Array(31,28,31,30,31,30,31,31,30,31,30,31); var Gan=new Array("甲","乙","丙","丁","戊","己","庚","辛","壬","癸"); var Zhi=new Array("子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"); var Animals=new Array("鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"); var solarTerm = new Array("小寒","大寒","立春","雨水","惊蛰","春分","清明","谷雨","立夏","小满","芒种","夏至","小暑","大暑","立秋","处暑","白露","秋分","寒露","霜降","立冬","小雪","大雪","冬至"); var sTermInfo = new Array(0,21208,42467,63836,85337,107014,128867,150921,173149,195551,218072,240693,263343,285989,308563,331033,353350,375494,397447,419210,440795,462224,483532,504758); var nStr1 = new Array('日','一','二','三','四','五','六','七','八','九','十'); var nStr2 = new Array('初','十','廿','卅','□'); var monthName = new Array("JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"); var cmonthName = new Array('正','二','三','四','五','六','七','八','九','十','十一','腊'); //公历节日 *表示放假日 var sFtv = new Array( "0101*元旦", "0210 气象节", "0214 情人节", "0303 爱耳日", "0308 妇女节", "0312 植树节", "0314 国际警察节", "0315 国际消费者权益日", "0323 世界气象日", "0401 愚人节", "0422 地球日", "0501 劳动节", "0512 护士节", "0515 国际家庭日", "0519 中国旅游日", "0504 青年节", "0531 无烟日", "0601 儿童节", "0605 世界环境日", "0626 国际反毒品日", //"0606 爱眼日", "0701 建党日", "0707 七七事变", "0711 中国航海日", "0801 建军节", "0805 里约热内卢奥运会", "0815 日本投降日", "0903 抗战胜利日", "0910 教师节", "0920 爱牙日", "0930 烈士纪念日", "0910 教师节", "0918 九·一八事变纪念日", "1001*国庆节", "1009 重阳节", "1031 万圣节", "1016 世界粮食日", "1108 记者节", "1111 光棍节", "1117 国际大学生节", "1201 艾滋病日", "1210 世界人权日", "1213 南京大屠杀纪念日", "1220 澳门回归纪念日", "1224 平安夜", "1225 圣诞节"); //某月的第几个星期几。 5,6,7,8 表示到数第 1,2,3,4 个星期几 var wFtv = new Array( //一月的最后一个星期日(月倒数第一个星期日) "0508 母亲节", "0619 父亲节", "1124 感恩节"); //农历节日 var lFtv = new Array( "0101*春节", "0115 元宵节", "0202 龙抬头", "0505 端午节", "0707 七夕", "0715 中元节", "0815 中秋节", "0909 重阳节", "1208 腊八节", "1223 北方小年", "1224 南方小年", "0100*除夕"); /***************************************************************************** 日期计算 *****************************************************************************/ //====================================== 返回农历 y年的总天数 function lYearDays(y) { var i, sum = 348; for(i=0x8000; i>0x8; i>>=1) sum += (lunarInfo[y-1900] & i)? 1: 0; return(sum+leapDays(y)); } //====================================== 返回农历 y年闰月的天数 function leapDays(y) { if(leapMonth(y)) return( (lunarInfo[y-1899]&0xf)==0xf? 30: 29); else return(0); } //====================================== 返回农历 y年闰哪个月 1-12 , 没闰返回 0 function leapMonth(y) { var lm = lunarInfo[y-1900] & 0xf; return(lm==0xf?0:lm); } //====================================== 返回农历 y年m月的总天数 function monthDays(y,m) { return( (lunarInfo[y-1900] & (0x10000>>m))? 30: 29 ); } //====================================== 算出农历, 传入日期控件, 返回农历日期控件 // 该控件属性有 .year .month .day .isLeap function Lunar(objDate) { var i, leap=0, temp=0; var offset = (Date.UTC(objDate.getFullYear(),objDate.getMonth(),objDate.getDate()) - Date.UTC(1900,0,31))/86400000; for(i=1900; i<2100 && offset>0; i++) { temp=lYearDays(i); offset-=temp; } if(offset<0) { offset+=temp; i--; } this.year = i; leap = leapMonth(i); //闰哪个月 this.isLeap = false; for(i=1; i<13 && offset>0; i++) { //闰月 if(leap>0 && i==(leap+1) && this.isLeap==false) { --i; this.isLeap = true; temp = leapDays(this.year); } else { temp = monthDays(this.year, i); } //解除闰月 if(this.isLeap==true && i==(leap+1)) this.isLeap = false; offset -= temp; } if(offset==0 && leap>0 && i==leap+1) if(this.isLeap) { this.isLeap = false; } else { this.isLeap = true; --i; } if(offset<0){ offset += temp; --i; } this.month = i; this.day = offset + 1; } function getSolarDate(lyear, lmonth, lday, isLeap) { var offset = 0; // increment year for(var i = 1900; i < lyear; i++) { offset += lYearDays(i); } // increment month // add days in all months up to the current month for (var i = 1; i < lmonth; i++) { // add extra days for leap month if (i == leapMonth(lyear)) { offset += leapDays(lyear); } offset += monthDays(lyear, i); } // if current month is leap month, add days in normal month if (isLeap) { offset += monthDays(lyear, i); } // increment offset += parseInt(lday) - 1; var baseDate = new Date(1900,0,31); var solarDate = new Date(baseDate.valueOf() + offset * 86400000); return solarDate; } //==============================返回公历 y年某m+1月的天数 function solarDays(y,m) { if(m==1) return(((y%4 == 0) && (y%100 != 0) || (y%400 == 0))? 29: 28); else return(solarMonth[m]); } //============================== 传入 offset 返回干支, 0=甲子 function cyclical(num) { return(Gan[num%10]+Zhi[num%12]); } //============================== 阴历属性 function calElement(sYear,sMonth,sDay,week,lYear,lMonth,lDay,isLeap,cYear,cMonth,cDay,cMnum,cDnum) { this.isToday = false; //瓣句 this.sYear = sYear; //公元年4位数字 this.sMonth = sMonth; //公元月数字 this.sDay = sDay; //公元日数字 this.week = week; //星期, 1个中文 //农历 this.lYear = lYear; //公元年4位数字 this.lMonth = lMonth; //农历月数字 this.lDay = lDay; //农历日数字 this.isLeap = isLeap; //是否为农历闰月? //八字 this.cYear = cYear; //年柱, 2个中文 this.cMonth = cMonth; //月柱, 2个中文 this.cDay = cDay; //日柱, 2个中文 this.color = ''; this.lunarFestival = ''; //农历节日 this.solarFestival = ''; //公历节日 this.solarTerms = ''; //节气 this.cMnumber=cMnum; this.cDnumber=cDnum; } //===== 某年的第n个节气为几日(从0小寒起算) function sTerm(y,n) { if(!!jieqiJson["y"+y]) return jieqiJson["y"+y][n]; var offDate = new Date( ( 31556925974.7*(y-1900) + sTermInfo[n]*60000 ) + Date.UTC(1900,0,6,2,5) ); return(offDate.getDate()); } //============================== 返回阴历控件 (y年,m+1月) /* 功能说明: 返回整个月的日期资料控件 使用方式: OBJ = new calendar(年,零起算月); OBJ.length 返回当月最大日 OBJ.firstWeek 返回当月一日星期 由 OBJ[日期].属性名称 即可取得各项值 OBJ[日期].isToday 返回是否为今日 true 或 false 其他 OBJ[日期] 属性参见 calElement() 中的注解 */ function calendar(y,m) { var sDObj, lDObj, lY, lM, lD=1, lL, lX=0, tmp1, tmp2, tmp3; var cY, cM, cD; //年柱,月柱,日柱 var lDPOS = new Array(3); var n = 0; var firstLM = 0; sDObj = new Date(y,m,1,0,0,0,0); //当月一日日期 this.length = solarDays(y,m); //公历当月天数 this.firstWeek = sDObj.getDay(); //公历当月1日星期几 ////////年柱 1900年立春后为庚子年(60进制36) if(m<2) cY=cyclical(y-1900+36-1); //当m为1时,应计算前一年的阴历 else cY=cyclical(y-1900+36); var term2=sTerm(y,2); //立春日期 ////////月柱 1900年1月小寒以前为 丙子月(60进制12) var firstNode = sTerm(y,m*2); //返回当月「节」为几日开始 var cMnum=(y-1900)*12+m+12; cM = cyclical(cMnum); //当月一日与 1900/1/1 相差天数 //1900/1/1与 1970/1/1 相差25567日, 1900/1/1 日柱为甲戌日(60进制10) var dayCyclical = Date.UTC(y,m,1,0,0,0,0)/86400000+25567+10; for(var i=0;ilX) { sDObj = new Date(y,m,i+1); //当月一日日期 lDObj = new Lunar(sDObj); //农历 lY = lDObj.year; //农历年 lM = lDObj.month; //农历月 lD = lDObj.day; //农历日 lL = lDObj.isLeap; //农历是否闰月 lX = lL? leapDays(lY): monthDays(lY,lM); //农历当月最后一天 if(n==0) firstLM = lM; lDPOS[n++] = i-lD+1; } //依节气调整二月分的年柱, 以立春为界 if(m==1 && (i+1)==term2) cY=cyclical(y-1900+36); //依节气月柱, 以「节」为界 if((i+1)==firstNode) cM = cyclical((y-1900)*12+m+13); //日柱 var cDnum=dayCyclical+i; if((i+1)>=firstNode){ cMnum=(y-1900)*12+m+13; } cD = cyclical(cDnum); //sYear,sMonth,sDay,week, //lYear,lMonth,lDay,isLeap, //cYear,cMonth,cDay this[i] = new calElement(y, m+1, i+1, nStr1[(i+this.firstWeek)%7], lY, lM, lD++, lL, cY ,cM, cD,cMnum,cDnum); } //节气 tmp1=sTerm(y,m*2 )-1; tmp2=sTerm(y,m*2+1)-1; this[tmp1].solarTerms = solarTerm[m*2]; this[tmp2].solarTerms = solarTerm[m*2+1]; //if(m==3) this[tmp1].color = 'red'; //清明颜色 //公历节日 for(var i= 0; i < sFtv.length ; i++){ if(sFtv[i].match(/^(\d{2})(\d{2})([\s\*])(.+)$/)) if(Number(RegExp.$1)==(m+1)) { this[Number(RegExp.$2)-1].solarFestival += RegExp.$4 + ' '; if(RegExp.$3=='*') this[Number(RegExp.$2)-1].color = 'red'; } } //月周节日 for(var i=0;i < wFtv.length;i++) if(wFtv[i].match(/^(\d{2})(\d)(\d)([\s\*])(.+)$/)) if(Number(RegExp.$1)==(m+1)) { tmp1=Number(RegExp.$2); tmp2=Number(RegExp.$3); if(tmp1<5) this[((this.firstWeek>tmp2)?7:0) + 7*(tmp1-1) + tmp2 - this.firstWeek].solarFestival += RegExp.$5 + ' '; else { tmp1 -= 5; tmp3 = (this.firstWeek+this.length-1)%7; //当月最后一天星期? this[this.length - tmp3 - 7*tmp1 + tmp2 - (tmp2>tmp3?7:0) - 1 ].solarFestival += RegExp.$5 + ' '; } } //农历节日 for(var i=0;i < lFtv.length;i++) if(lFtv[i].match(/^(\d{2})(.{2})([\s\*])(.+)$/)) { tmp1=Number(RegExp.$1)-firstLM; if(tmp1==-11) tmp1=1; if(tmp1 >=0 && tmp1= 0 && tmp2/g, ">").replace(/"/g, """).replace(/'/g, "´").replace(/&/g, "&"); return this; }; function getMonthKey(year, month) { // 传入的month为0-11的数值 -> (1->01,2->02...11->11) return year.toString() + (month + 1).toString().leftpad(2); // 返回yyyyMM格式的字符串 } function getDateKey(date) { return date.getFullYear().toString() +"-"+(date.getMonth() + 1).toString().leftpad(2)+"-"+date.getDate().toString().leftpad(2); // 返回yyyy-MM-dd格式的字符串 } function is_leap_year(cur_year){ //判断年份是否为闰年,是则返回1,否则返回0 if(cur_year % 400 == 0 || (cur_year % 100 !=0 && cur_year % 4 == 0)) return 1; return 0; } function getDaysByMonth(date){ var days = [[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]]; return days[is_leap_year(date.getFullYear())][date.getMonth()]; } function dateDiff(now, date){ var diff = dateDiffDays(now, date); if(diff == 0) return "今天"; else if(diff < 0) return (0-diff) + "天前"; else return diff + "天后"; } function dateDiffDays(now, date){ var n = new Date(now.getFullYear(), now.getMonth(), now.getDate()); var d = new Date(date.getFullYear(), date.getMonth(), date.getDate()); var diff = parseInt((d - n)/(24 * 60 * 60 * 1000)); return diff; } /*==========================utils.js========================*/ var utils = { getEvent : function(ev) { return window.event ? window.event : (ev ? ev : null); }, getMousePosition : function(ev) { var evt = this.getEvent(ev); if (evt.pageX || evt.pageY) { return { x : evt.pageX, y : evt.pageY }; } return { x : evt.clientX + document.documentElement.scrollLeft - document.documentElement.clientLeft, y : evt.clientY + document.documentElement.scrollTop - document.documentElement.clientTop }; }, getClientWidth : function() { return $.browser.msie ? ieBody.clientWidth : window.innerWidth; }, getClientHeight : function() { return $.browser.msie ? ieBody.clientHeight : window.innerHeight; }, getRandomColor : function() { /* * * getRandomColor 从colors数组获取随机颜色 * * @return 对象,index:索引,value:颜色代码 * */ var index = Math.round(Math.random() * (colors.length - 1)); return { index : index, value : colors[index] }; }, /* * obj : DOM element */ getOffsetXY : function(obj, parentId) { /* * * getOffsetXY 获取相对坐标 * * @param obj id或者dom对象 @param parentId 父级id,如果不提供则为body * * @return 坐标对象,x、y * */ // var element; // if (typeof obj == 'object') { // element = obj; // } else { // element = document.getElementById(obj); // } // var element_X = element.offsetLeft; // var element_Y = element.offsetTop; // while (true) { // if ((!element.offsetParent) || (!element.offsetParent.style) // || (!!parentId && element.offsetParent.id == parentId)) { // break; // } // element_X += element.offsetParent.offsetLeft; // element_Y += element.offsetParent.offsetTop; // element = element.offsetParent; // } // element_X = element_X - document.body.scrollLeft; // element_Y = element_Y - document.body.scrollTop; // // return { // x : element_X, // y : element_Y // }; var pos= {}; if(parentId) { pos = $(obj).position(); return { x : pos.left, y : pos.top }; } pos = $(obj).offset(); return { x : pos.left, y : pos.top }; }, hideDialog:function(id){ for(var i=0;i01,5->05...10->10 if (num<10) return "0"+num; return num; }, copy: function(date) { // 获取时间的副本 return new Date(date.valueOf()); }, getChinaNum : function(Num) { //农历的每月开头 var monthEn; switch(Num) { case 1 : monthEn = "一"; break; case 2 : monthEn = "二"; break; case 3 : monthEn = "三"; break; case 4 : monthEn = "四"; break; case 5 : monthEn = "五"; break; case 6 : monthEn = "六"; break; case 7 : monthEn = "七"; break; case 8 : monthEn = "八"; break; case 9 : monthEn = "九"; break; case 10 : monthEn = "十"; break; case 11 : monthEn = "十一"; break; case 12 : monthEn = "腊"; break; } return monthEn; }, getLundarMD : function(md,split){ var month=''; var day=''; if(!split){ month = md.substr(0,2); day = md.substr(2,2); }else{ var arr = md.split(split); month = arr[0]; day = arr[1]; } return this.getChinaNum(parseFloat(month))+"月"+cDay(parseFloat(day)); }, getDayNameBrief: function(day_index) { var day_name = ['SUN','MON','TUE','WED','THU','FRI','SAT']; return day_name[day_index]; }, daynameToIndex: function(dayname) { var dayname_index_map = {'SUN':0,'MON':1,'TUE':2,'WED':3,'THU':4,'FRI':5,'SAT':6}; return dayname_index_map[dayname]; }, /* * date_time所在日期为当月第几周 */ getWeekOfMonth: function(date_time, start_on_monday) { var date = this.copy(date_time); return Math.floor((this.date_part(date).getTime() - this.month_view_start(date, start_on_monday).getTime())/604800000) + 1; }, lunar_year : function(date) { //获取阴历年份的名称 { 2012 -> 辛卯年【兔年】 } var l_year = date.getFullYear()+'年'+(date.getMonth()+1)+'月 '+cyclical(date.getFullYear() - 1900 + 36) + Animals[(date.getFullYear() - 4) % 12] + '年'; return l_year; }, lunar_Info : function(date) { var cld = cacheMgr.getCld(date.getFullYear(), date.getMonth()); var day = date.getDate(); var cld_day = cld[day - 1]; var lunar_detail = { l_day : "", l_month : "", l_day_full:"" }; lunar_detail.l_day = cDay(cld_day.lDay); lunar_detail.l_month = cld_day.lMonth; lunar_detail.color = ""; var s,s2; s=cld_day.lunarFestival; if(s.length>0) { // 农历节日 if(s.length>6) { s2 = s.toString(); s = s.substr(0, 4)+'...'; } lunar_detail.color = "#32CD32"; } else { // 廿四节气 s=cld_day.solarTerms; s2=s.toString(); if(s.length>0) { lunar_detail.color = "#32CD32"; if((s =='清明')||(s =='芒种')||(s =='夏至')||(s =='冬至')) { lunar_detail.color = "#32CD32"; if(s =='清明') s = '清明节'; } } /*else { // 公历节日 s=cld_day.solarFestival; s2 = s.toString(); if(s.length>0) { if(s.length>6) { s = s.substr(0, 4)+'..'; } lunar_detail.color = "#46BAEC"; } }*/ } lunar_detail.l_day_y = cDay(cld_day.lDay); if(s.length>0) { lunar_detail.l_day = s; lunar_detail.l_day_full = s2; } //var info = templates.getChinaNum(lunar_detail.l_month)+"月"+lunar_detail.l_day; //var info = lunar_detail.l_day; return lunar_detail; }, date_to_str: function(format,utc) { format=format.replace(/%[a-zA-Z]/g, function(a) { switch(a) { case "%d": return "\"+calwnl.date.to_fixed(date.getDate())+\""; case "%m": return "\"+calwnl.date.to_fixed((date.getMonth()+1))+\""; case "%j": return "\"+date.getDate()+\""; case "%n": return "\"+(date.getMonth()+1)+\""; case "%y": return "\"+calwnl.date.to_fixed(date.getYear()%100)+\""; case "%Y": return "\"+date.getFullYear()+\""; case "%D": return "\"+calwnl.locale.date.day_short[date.getDay()]+\""; case "%l": return "\"+calwnl.locale.date.day_full[date.getDay()]+\""; case "%M": return "\"+calwnl.locale.date.month_short[date.getMonth()]+\""; case "%F": return "\"+calwnl.locale.date.month_full[date.getMonth()]+\""; case "%h": return "\"+calwnl.date.to_fixed((date.getHours()+11)%12+1)+\""; case "%H": return "\"+calwnl.date.to_fixed(date.getHours())+\""; case "%i": return "\"+calwnl.date.to_fixed(date.getMinutes())+\""; case "%a": return "\"+(date.getHours()>11?\"pm\":\"am\")+\""; case "%A": return "\"+(date.getHours()>11?\"PM\":\"AM\")+\""; case "%s": return "\"+calwnl.date.to_fixed(date.getSeconds())+\""; default: return a; } }); if (utc) format=format.replace(/date\.get/g,"date.getUTC"); return new Function("date","return \""+format+"\";"); }, numToWeek: function(inStr) { switch (inStr) { case 1: return '一'; case 2: return '二'; case 3: return '三'; case 4: return '四'; case 5: return '五'; case 6: return '六'; case 0: return '日'; } }, str_to_date: function(format,utc) { var splt="var temp=date.split(/[^0-9a-zA-Z]+/g);"; var mask=format.match(/%[a-zA-Z]/g); for (var i=0; i50?1900:2000);"; break; case "%h": case "%H": splt+="set[3]=temp["+i+"]||0;"; break; case "%i": splt+="set[4]=temp["+i+"]||0;"; break; case "%Y": splt+="set[0]=temp["+i+"]||0;"; break; case "%a": case "%A": splt+="set[3]=set[3]%12+((temp["+i+"]||'').toLowerCase()=='am'?0:12);"; break; case "%s": splt+="set[5]=temp["+i+"]||0;"; break; } } var code ="set[0],set[1],set[2],set[3],set[4],set[5]"; if (utc) code =" Date.UTC("+code+")"; return new Function("date","var set=[0,0,0,0,0,0]; "+splt+" return new Date("+code+");"); } }; calwnl.templates= {}; calwnl.config= { default_date: "%Y-%m-%d %H:%i", month_date: "%F %Y", load_date: "%Y-%m-%d", week_date: "%l", day_date: "%D, %F %j", hour_date: "%H:%i", month_day : "%d", xml_date:"%Y/%m/%d %H:%i", api_date:"%Y-%m-%d %H:%i", server_utc:false }; calwnl.init_templates= function() { var d=calwnl.date.date_to_str; var c=calwnl.config; var f = function(a,b) { for (var c in b) if (!a[c]) a[c]=b[c]; }; f(calwnl.templates, { day_date:d(c.default_date), month_date:d(c.month_date), week_date: function(d1,d2) { return calwnl.templates.day_date(d1)+" – "+calwnl.templates.day_date(calwnl.date.add(d2,-1,"day")); }, day_scale_date:d(c.default_date), month_scale_date:d(c.week_date), week_scale_date:d(c.day_date), hour_scale:d(c.hour_date), time_picker:d(c.hour_date), event_date:d(c.hour_date), month_day:d(c.month_day), xml_date:calwnl.date.str_to_date(c.xml_date,c.server_utc), load_format:d(c.load_date,c.server_utc), xml_format:d(c.xml_date,c.server_utc), api_date:calwnl.date.str_to_date(c.api_date), event_header: function(start,end,ev) { return calwnl.templates.event_date(start)+" - "+calwnl.templates.event_date(end); }, event_text: function(start,end,ev) { return ev.text; }, event_class: function(start,end,ev) { return ""; }, month_date_class: function(d) { return ""; }, week_date_class: function(d) { return ""; }, event_bar_date: function(start,end,ev) { return calwnl.templates.event_date(start)+" "; }, event_bar_text: function(start,end,ev) { return ev.text; } }); }; /*==================================语言处理============================*/ calwnl.locale= { date: { month_full: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"], month_short: ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"], day_full: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"], day_short: ["日", "一", "二", "三", "四", "五", "六"] } }; /*============================== JCT模版的封装 ===========================*/ var tplMgr = { tplMap : {}, getInstance : function(id) { var instance = this.tplMap[id]; if (!instance) { instance = new jCT($.dom(id).value); instance.Build(); this.tplMap[id] = instance; } return instance; }, getTemplate : function(id) { var element = $.dom(id); var content = element.value; // Like textarea.value. if (content == null) content = element.innerHTML; // Like textarea.innerHTML. content = content.replace(/</g, "<").replace(/>/g, ">"); return content; }, loadTemplate : function(id, url, callback) { if ($('textarea[id=' + id + ']').length > 0) { // 如果已经载入 if (callback) { callback(); } } else { // utils.showLoadingShadow(); $.get(url, { t : Math.ceil(Math.random() * 100) }, function(data) { // var tpl = data.replace(//g, // '>'); $('') .appendTo('body').val(data); if (callback) { callback(); } }); } } }; /*===============================dialog========================*/ var dialogMgr = { dialog : null, option : null, moving : false, pos : null, show : function(el, options) { var op = { width : 428, title : '', draggable : true // 默认对话框允许点击标题栏拖动 }; var options = options || {}; for (var p in options) { op[p] = options[p]; } if (this.dialog) { this.hide(); } this.option = op; this.dialog = $.dom(el); var width = this.option.width; var w = utils.getClientWidth(); var left = 0; if (w > width) { left = (w - width) / 2; } this.dialog.style.left = left + 'px'; var scrollTop = document.body.scrollTop || document.documentElement.scrollTop; var top = 30 + scrollTop; this.dialog.style.top = top + 'px'; }, hide : function() { if (this.dialog) { $(this.dialog).hide(); if (this.option.hideCallback) { try { this.option.hideCallback(); } catch (ex) { } } this.option = null; this.dialog = null; this.moving = false; this.pos = null; } } }; /*================ 日历实用类 ==========================*/ var CalUtil = { /* * 返回一个对象,包含date所在月份的月视图的第一天和最后一天的日期,以及显示在月视图中的行数{start:..., end:..., row:...} */ monthViewInfo : function(date, startOnMonday) { var dateUtil = calwnl.date; var info = {}; var s_date = dateUtil.copy(date); s_date = dateUtil.month_view_start(s_date, startOnMonday); info.start = dateUtil.copy(dateUtil.week_start(s_date, startOnMonday)); var e_date = dateUtil.copy(date); e_date.setMonth(date.getMonth() + 1); e_date.setDate(1); info.row = Math.ceil((e_date.valueOf()-s_date.valueOf()) / 604800000); info.end = dateUtil.add(info.start, 7*info.row, 'day'); return info; } }; /** * Cookie plugin * * Copyright (c) 2006 Klaus Hartl (stilbuero.de) * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * */ /** * Create a cookie with the given name and value and other optional parameters. * * @example $.cookie('the_cookie', 'the_value'); * @desc Set the value of a cookie. * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true }); * @desc Create a cookie with all available options. * @example $.cookie('the_cookie', 'the_value'); * @desc Create a session cookie. * @example $.cookie('the_cookie', null); * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain * used when the cookie was set. * * @param String name The name of the cookie. * @param String value The value of the cookie. * @param Object options An object literal containing key/value pairs to provide optional cookie attributes. * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object. * If a negative value is specified (e.g. a date in the past), the cookie will be deleted. * If set to null or omitted, the cookie will be a session cookie and will not be retained * when the the browser exits. * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie). * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie). * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will * require a secure protocol (like HTTPS). * @type undefined * * @name $.cookie * @cat Plugins/Cookie * @author Klaus Hartl/klaus.hartl@stilbuero.de */ /** * Get the value of a cookie with the given name. * * @example $.cookie('the_cookie'); * @desc Get the value of a cookie. * * @param String name The name of the cookie. * @return The value of the cookie. * @type String * * @name $.cookie * @cat Plugins/Cookie * @author Klaus Hartl/klaus.hartl@stilbuero.de */ jQuery.cookie = function(name, value, options) { if (typeof value != 'undefined') { // name and value given, set cookie options = options || {}; if (value === null) { value = ''; options.expires = -1; } var expires = ''; if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { var date; if (typeof options.expires == 'number') { date = new Date(); date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); } else { date = options.expires; } expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE } // CAUTION: Needed to parenthesize options.path and options.domain // in the following expressions, otherwise they evaluate to undefined // in the packed version for some reason... var path = options.path ? '; path=' + (options.path) : ''; var domain = options.domain ? '; domain=' + (options.domain) : ''; var secure = options.secure ? '; secure' : ''; document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); } else { // only name given, get cookie var cookieValue = null; if (document.cookie && document.cookie != '') { var cookies = document.cookie.split(';'); for (var i = 0; i < cookies.length; i++) { var cookie = jQuery.trim(cookies[i]); // Does this cookie string begin with the name we want? if (cookie.substring(0, name.length + 1) == (name + '=')) { cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); break; } } } return cookieValue; } }; var colors = ['#CC3333', '#DD4477', '#994499', '#6633CC', '#336699', '#3366CC', '#22AA99', '#329262', '#109618', '#66AA00', '#AAAA11', '#D6AE00', '#EE8800', '#DD5511', '#A87070', '#8C6D8C', '#627487', '#7083A8', '#5C8D87', '#898951', '#B08B59']; //dataHandler.js /*=============== 数据处理 DataHandler ================*/ var DataHandler = { /* * 记录缓存中数据的时间范围 XXX xj: 似乎yzm修改过缓存记录方式之后此数据已经无用了 */ cachedData : { from : new Date(), to : new Date() }, loadCld : {}, getLoadCld : function(dateStart, dateEnd,cld){ var sel = []; var str = getDateKey(dateStart)+"-"+getDateKey(dateEnd); for(var i=0;i0) return sel.join(","); else return false; }, /* * 缓存中format以后的数据,格式见formatSchData */ resultData: {}, /* * id为键,日程简介为值 */ resultDataById: {}, /* * 根据起始时间取日程数据,若缓存中不存在所需数据,则ajax请求并入缓存,若已存在,则数据请求无动作;若callback存在,调用之 * dateStart, dateEnd : Date * callback : function */ getSchByPeriod : function(dateStart, dateEnd, callback) { var s_time = dateStart, e_time = dateEnd; if (dateStart >= this.cachedData.from) { s_time = this.cachedData.to; } if (dateEnd <= this.cachedData.to) { e_time = this.cachedData.from; } var cld = calendarHandler.getSelectedArray(); var cldStr = DataHandler.getLoadCld(dateStart, dateEnd,cld); if(cldStr) { // 杨:获取当前选中的日历id $.ajax({ url: '/schedule/list.do', async: true, type: 'post', dataType: 'json', data: { fromDate: calwnl.templates.load_format(dateStart), toDate: calwnl.templates.load_format(dateEnd), timeZone: - (new Date()).getTimezoneOffset() / 60, calendarId: cldStr }, success: function(result) { for(var i=0;i s_time) DataHandler.cachedData.from = s_time; if(DataHandler.cachedData.to < e_time) DataHandler.cachedData.to = e_time; if(callback) { callback(); } } }); } else { if(callback) { callback(); } } }, /* * 获取date所在月份月视图区域内数据并显示,若缓存中存在所需数据,则返回缓存中数据,否则ajax请求数据 * date : Date * callback : function * startOnMonday : 周一作为第一天,为true, 否则为false */ getSchByMonth : function(date, callback, startOnMonday) { var s_date = calwnl.date.month_view_start(date, startOnMonday); var e_date = calwnl.date.add(s_date, CalUtil.monthViewInfo(date, startOnMonday).row*7, 'day'); this.getSchByPeriod(s_date, e_date, callback); }, /* * 此方法是从格式化的日程数据中获取一段时间的日程并返回规定的数据格式 * 具体的数据格式如下 * { * "d2011-05-01":{ * schList:[{日程信息}], // 该天的日程列表,todo:跨天日程的处理方式,重复日程, * num: // 日程的条数 * }, * "d2011-05-02":{ * schList:[] * num: // 日程的条数 * }, * maxNum: // 算出最多日程的条数 方便月视图显示日程 * } * * sTime, eTime : Date OR string */ getSchedulesByRange: function(sTime,eTime,data,cld) { var result= {}; var dataSch = data||DataHandler.resultData; if(typeof sTime=="string") { sTime = calwnl.templates.api_date(sTime); } if(typeof eTime=="string") { eTime = calwnl.templates.api_date(eTime); } sTime = calwnl.date.date_part(sTime); eTime = calwnl.date.date_part(eTime); for(;sTime<=eTime;) { var k = "d"+getDateKey(sTime); result[k]= { schList:[], num:0 }; if(dataSch[k]) { var schList_temp = []; for(var j = 0; jmaxNum) maxNum = k.num; } result.maxNum = maxNum; return JSON.parse(JSON.stringify(result)); //make a copy of data to keep original data safe }, /* * 为了提高日程数据的处理效率,减少重复处理,将日程数据格式化为以下模式 * { * "d2011-05-01":{ * schList:[{日程信息}] // 该天的日程列表,日程列表是排好序的,排序规则:1、按照时间排序,如果时间相同则按照日历id、日程id或者可以是日程的添加时间;todo:跨天日程的处理方式,重复日程, * }, * "d2011-05-02":{ * schList:[] * } * } * * data : Object * dateScope : Date */ formatSchData : function(data,dateScope) { var result = {}; /* * 注:对于数组的操作,尽量少用for(var i in data) 模式,因为此模式不仅会操作数组中的数据,同时会操作数组对象的其他属性, * 此处只需要遍历一遍日程列表即可,但是需要注意对跨天日程的拆分,需要添加三个字段 1、cross_st 2、cross_et,3、是否显示isDisplay */ for(var i=0;i=eTime) { var key = "d"+getDateKey(sTime); if(!result[key]) result[key]= { schList:[] }; result[key].schList.push(sch); } else { var s_t = calwnl.date.copy(sTime); for(;s_t 0){ callback(calwnl.templates.api_date(k)); } } } }); }, dataType: 'json' }); }, cutByRealLength=function(str,size){ var totalCount=0; var i; for(i=0;i=0x0001&&c<=0x007e)||(0xff60<=c&&c<=0xff9f)){ totalCount++; }else{ totalCount+=2; }if(totalCount>=size){ return str.substring(0,i+1); } } return str; }; var UI={ //显示日程 drawSch:function(schList){ $("#taskList").children().remove(); var schs = []; if(schList.length>0){ for(var i = 0; i < 3 && i < schList.length; i++){ var showTxt=cutByRealLength(schList[i].text,10); if(showTxt.length"); schs.push("
"); if(! schList[i].allday_event){ schs.push("
" + showTime + "
"); schs.push("
" + showTxt + "
"); }else{ schs.push("
" + showTxt + "
"); } schs.push(""); } } $("#taskList").html(schs.join('')); } }; var calendarHandler={ init:function(id){ if(typeof id == 'number') calendarId=id; else if(typeof id == 'string') calendarId=parseInt(id); navDate=seletedDate=new Date(); calwnl.init_templates(); }, //根据calendarId变量,判断是否登陆 isLogin:function(){ return !!calendarId; }, //dataHandler调用,返回选中的日历id getSelectedArray:function(){ var t=new Array(); t.push(calendarId); return t; }, //准备特定月份的数据 prepareData4:function(year,month , callback){ var date=new Date(); date.setYear(year); date.setMonth(month-1); date.setDate(1); setNavDate(date); getCurrentMonthViewData(function(){ for(var key in schData){ if(key!="maxNum"){ var num = schData[key].num; var k= key.replace(reg,function(all,year,month,date){ return year+"-"+month.replace(r2,"")+"-"+date.replace(r2,""); }); if(num > 0){ var tttt = calwnl.templates.api_date(k); callback(tttt); } } } //callback(); }); }, //获取seletedDate getSelectedDate:function(){ return seletedDate; }, //设置seletedDate setSelectedDate:function(date){ if(typeof date == "string") seletedDate = calwnl.templates.api_date(date); else if(date instanceof Date) seletedDate = date; }, //获取hoverDate对应的日程数据 getSch:function(){ return schData["d"+getDateKey(hoverDate)]; }, //添加日程 addSch:function(text,allday,hour,second,callback){ creatSch(text,allday,hour,second,callback); }, //显示日程 drawSch:function(){ if(this.isLogin()){ UI.drawSch(this.getSch().schList); } }, //设置hoverDate setHoverDate:function(date){ if(typeof date == "string") hoverDate = calwnl.templates.api_date(date); else if(date instanceof Date) hoverDate = date; } }; //公开calendarHandler对象 if(window.calendarHandler){ window._calendarHandler=window.calendarHandler; } window.calendarHandler=calendarHandler; })(window);