6c8b27c8645f5c4635b8b045ad2be1c2f5f769f0.svn-base 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068
  1. //json.js
  2. /*
  3. Copyright (c) 2005 JSON.org
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The Software shall be used for Good, not Evil.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. SOFTWARE.
  18. */
  19. /*
  20. The global object JSON contains two methods.
  21. JSON.stringify(value) takes a JavaScript value and produces a JSON text.
  22. The value must not be cyclical.
  23. JSON.parse(text) takes a JSON text and produces a JavaScript value. It will
  24. return false if there is an error.
  25. */
  26. var JSON = function () {
  27. var m = {
  28. '\b': '\\b',
  29. '\t': '\\t',
  30. '\n': '\\n',
  31. '\f': '\\f',
  32. '\r': '\\r',
  33. '"' : '\\"',
  34. '\\': '\\\\'
  35. },
  36. s = {
  37. 'boolean': function (x) {
  38. return String(x);
  39. },
  40. number: function (x) {
  41. return isFinite(x) ? String(x) : 'null';
  42. },
  43. string: function (x) {
  44. if (/["\\\x00-\x1f]/.test(x)) {
  45. x = x.replace(/([\x00-\x1f\\"])/g, function(a, b) {
  46. var c = m[b];
  47. if (c) {
  48. return c;
  49. }
  50. c = b.charCodeAt();
  51. return '\\u00' +
  52. Math.floor(c / 16).toString(16) +
  53. (c % 16).toString(16);
  54. });
  55. }
  56. return '"' + x + '"';
  57. },
  58. object: function (x) {
  59. if (x) {
  60. var a = [], b, f, i, l, v;
  61. if (x instanceof Array) {
  62. a[0] = '[';
  63. l = x.length;
  64. for (i = 0; i < l; i += 1) {
  65. v = x[i];
  66. f = s[typeof v];
  67. if (f) {
  68. v = f(v);
  69. if (typeof v == 'string') {
  70. if (b) {
  71. a[a.length] = ',';
  72. }
  73. a[a.length] = v;
  74. b = true;
  75. }
  76. }
  77. }
  78. a[a.length] = ']';
  79. } else if (x instanceof Object) {
  80. a[0] = '{';
  81. for (i in x) {
  82. v = x[i];
  83. f = s[typeof v];
  84. if (f) {
  85. v = f(v);
  86. if (typeof v == 'string') {
  87. if (b) {
  88. a[a.length] = ',';
  89. }
  90. a.push(s.string(i), ':', v);
  91. b = true;
  92. }
  93. }
  94. }
  95. a[a.length] = '}';
  96. } else {
  97. return;
  98. }
  99. return a.join('');
  100. }
  101. return 'null';
  102. }
  103. };
  104. return {
  105. copyright: '(c)2005 JSON.org',
  106. license: 'http://www.crockford.com/JSON/license.html',
  107. /*
  108. Stringify a JavaScript value, producing a JSON text.
  109. */
  110. stringify: function (v) {
  111. var f = s[typeof v];
  112. if (f) {
  113. v = f(v);
  114. if (typeof v == 'string') {
  115. return v;
  116. }
  117. }
  118. return null;
  119. },
  120. /*
  121. Parse a JSON text, producing a JavaScript value.
  122. It returns false if there is a syntax error.
  123. */
  124. parse: function (text) {
  125. try {
  126. return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
  127. text.replace(/"(\\.|[^"\\])*"/g, ''))) &&
  128. eval('(' + text + ')');
  129. } catch (e) {
  130. return false;
  131. }
  132. }
  133. };
  134. }();
  135. // --calendarObj.js
  136. //日期资料
  137. var lunarInfo=new Array(
  138. 0x4bd8,0x4ae0,0xa570,0x54d5,0xd260,0xd950,0x5554,0x56af,0x9ad0,0x55d2,
  139. 0x4ae0,0xa5b6,0xa4d0,0xd250,0xd295,0xb54f,0xd6a0,0xada2,0x95b0,0x4977,
  140. 0x497f,0xa4b0,0xb4b5,0x6a50,0x6d40,0xab54,0x2b6f,0x9570,0x52f2,0x4970,
  141. 0x6566,0xd4a0,0xea50,0x6a95,0x5adf,0x2b60,0x86e3,0x92ef,0xc8d7,0xc95f,
  142. 0xd4a0,0xd8a6,0xb55f,0x56a0,0xa5b4,0x25df,0x92d0,0xd2b2,0xa950,0xb557,
  143. 0x6ca0,0xb550,0x5355,0x4daf,0xa5b0,0x4573,0x52bf,0xa9a8,0xe950,0x6aa0,
  144. 0xaea6,0xab50,0x4b60,0xaae4,0xa570,0x5260,0xf263,0xd950,0x5b57,0x56a0,
  145. 0x96d0,0x4dd5,0x4ad0,0xa4d0,0xd4d4,0xd250,0xd558,0xb540,0xb6a0,0x95a6,
  146. 0x95bf,0x49b0,0xa974,0xa4b0,0xb27a,0x6a50,0x6d40,0xaf46,0xab60,0x9570,
  147. 0x4af5,0x4970,0x64b0,0x74a3,0xea50,0x6b58,0x5ac0,0xab60,0x96d5,0x92e0,
  148. 0xc960,0xd954,0xd4a0,0xda50,0x7552,0x56a0,0xabb7,0x25d0,0x92d0,0xcab5,
  149. 0xa950,0xb4a0,0xbaa4,0xad50,0x55d9,0x4ba0,0xa5b0,0x5176,0x52bf,0xa930,
  150. 0x7954,0x6aa0,0xad50,0x5b52,0x4b60,0xa6e6,0xa4e0,0xd260,0xea65,0xd530,
  151. 0x5aa0,0x76a3,0x96d0,0x4afb,0x4ad0,0xa4d0,0xd0b6,0xd25f,0xd520,0xdd45,
  152. 0xb5a0,0x56d0,0x55b2,0x49b0,0xa577,0xa4b0,0xaa50,0xb255,0x6d2f,0xada0,
  153. 0x4b63,0x937f,0x49f8,0x4970,0x64b0,0x68a6,0xea5f,0x6b20,0xa6c4,0xaaef,
  154. 0x92e0,0xd2e3,0xc960,0xd557,0xd4a0,0xda50,0x5d55,0x56a0,0xa6d0,0x55d4,
  155. 0x52d0,0xa9b8,0xa950,0xb4a0,0xb6a6,0xad50,0x55a0,0xaba4,0xa5b0,0x52b0,
  156. 0xb273,0x6930,0x7337,0x6aa0,0xad50,0x4b55,0x4b6f,0xa570,0x54e4,0xd260,
  157. 0xe968,0xd520,0xdaa0,0x6aa6,0x56df,0x4ae0,0xa9d4,0xa4d0,0xd150,0xf252,
  158. 0xd520);
  159. var solarMonth=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
  160. var Gan=new Array("甲","乙","丙","丁","戊","己","庚","辛","壬","癸");
  161. var Zhi=new Array("子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥");
  162. var Animals=new Array("鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪");
  163. var solarTerm = new Array("小寒","大寒","立春","雨水","惊蛰","春分","清明","谷雨","立夏","小满","芒种","夏至","小暑","大暑","立秋","处暑","白露","秋分","寒露","霜降","立冬","小雪","大雪","冬至");
  164. 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);
  165. var nStr1 = new Array('日','一','二','三','四','五','六','七','八','九','十');
  166. var nStr2 = new Array('初','十','廿','卅','□');
  167. var monthName = new Array("JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC");
  168. var cmonthName = new Array('正','二','三','四','五','六','七','八','九','十','十一','腊');
  169. //公历节日 *表示放假日
  170. var sFtv = new Array(
  171. "0101*元旦",
  172. "0210 气象节",
  173. "0214 情人节",
  174. "0303 爱耳日",
  175. "0308 妇女节",
  176. "0312 植树节",
  177. "0314 国际警察节",
  178. "0315 国际消费者权益日",
  179. "0323 世界气象日",
  180. "0401 愚人节",
  181. "0422 地球日",
  182. "0501 劳动节",
  183. "0512 护士节",
  184. "0515 国际家庭日",
  185. "0519 中国旅游日",
  186. "0504 青年节",
  187. "0531 无烟日",
  188. "0601 儿童节",
  189. "0605 世界环境日",
  190. "0626 国际反毒品日",
  191. //"0606 爱眼日",
  192. "0701 建党日",
  193. "0707 七七事变",
  194. "0711 中国航海日",
  195. "0801 建军节",
  196. "0805 里约热内卢奥运会",
  197. "0815 日本投降日",
  198. "0903 抗战胜利日",
  199. "0910 教师节",
  200. "0920 爱牙日",
  201. "0930 烈士纪念日",
  202. "0910 教师节",
  203. "0918 九·一八事变纪念日",
  204. "1001*国庆节",
  205. "1009 重阳节",
  206. "1031 万圣节",
  207. "1016 世界粮食日",
  208. "1108 记者节",
  209. "1111 光棍节",
  210. "1117 国际大学生节",
  211. "1201 艾滋病日",
  212. "1210 世界人权日",
  213. "1213 南京大屠杀纪念日",
  214. "1220 澳门回归纪念日",
  215. "1224 平安夜",
  216. "1225 圣诞节");
  217. //某月的第几个星期几。 5,6,7,8 表示到数第 1,2,3,4 个星期几
  218. var wFtv = new Array(
  219. //一月的最后一个星期日(月倒数第一个星期日)
  220. "0508 母亲节",
  221. "0619 父亲节",
  222. "1124 感恩节");
  223. //农历节日
  224. var lFtv = new Array(
  225. "0101*春节",
  226. "0115 元宵节",
  227. "0202 龙抬头",
  228. "0505 端午节",
  229. "0707 七夕",
  230. "0715 中元节",
  231. "0815 中秋节",
  232. "0909 重阳节",
  233. "1208 腊八节",
  234. "1223 北方小年",
  235. "1224 南方小年",
  236. "0100*除夕");
  237. /*****************************************************************************
  238. 日期计算
  239. *****************************************************************************/
  240. //====================================== 返回农历 y年的总天数
  241. function lYearDays(y) {
  242. var i, sum = 348;
  243. for(i=0x8000; i>0x8; i>>=1) sum += (lunarInfo[y-1900] & i)? 1: 0;
  244. return(sum+leapDays(y));
  245. }
  246. //====================================== 返回农历 y年闰月的天数
  247. function leapDays(y) {
  248. if(leapMonth(y)) return( (lunarInfo[y-1899]&0xf)==0xf? 30: 29);
  249. else return(0);
  250. }
  251. //====================================== 返回农历 y年闰哪个月 1-12 , 没闰返回 0
  252. function leapMonth(y) {
  253. var lm = lunarInfo[y-1900] & 0xf;
  254. return(lm==0xf?0:lm);
  255. }
  256. //====================================== 返回农历 y年m月的总天数
  257. function monthDays(y,m) {
  258. return( (lunarInfo[y-1900] & (0x10000>>m))? 30: 29 );
  259. }
  260. //====================================== 算出农历, 传入日期控件, 返回农历日期控件
  261. // 该控件属性有 .year .month .day .isLeap
  262. function Lunar(objDate) {
  263. var i, leap=0, temp=0;
  264. var offset = (Date.UTC(objDate.getFullYear(),objDate.getMonth(),objDate.getDate()) - Date.UTC(1900,0,31))/86400000;
  265. for(i=1900; i<2100 && offset>0; i++) { temp=lYearDays(i); offset-=temp; }
  266. if(offset<0) { offset+=temp; i--; }
  267. this.year = i;
  268. leap = leapMonth(i); //闰哪个月
  269. this.isLeap = false;
  270. for(i=1; i<13 && offset>0; i++) {
  271. //闰月
  272. if(leap>0 && i==(leap+1) && this.isLeap==false)
  273. { --i; this.isLeap = true; temp = leapDays(this.year); }
  274. else
  275. { temp = monthDays(this.year, i); }
  276. //解除闰月
  277. if(this.isLeap==true && i==(leap+1)) this.isLeap = false;
  278. offset -= temp;
  279. }
  280. if(offset==0 && leap>0 && i==leap+1)
  281. if(this.isLeap)
  282. { this.isLeap = false; }
  283. else
  284. { this.isLeap = true; --i; }
  285. if(offset<0){ offset += temp; --i; }
  286. this.month = i;
  287. this.day = offset + 1;
  288. }
  289. function getSolarDate(lyear, lmonth, lday, isLeap) {
  290. var offset = 0;
  291. // increment year
  292. for(var i = 1900; i < lyear; i++) {
  293. offset += lYearDays(i);
  294. }
  295. // increment month
  296. // add days in all months up to the current month
  297. for (var i = 1; i < lmonth; i++) {
  298. // add extra days for leap month
  299. if (i == leapMonth(lyear)) {
  300. offset += leapDays(lyear);
  301. }
  302. offset += monthDays(lyear, i);
  303. }
  304. // if current month is leap month, add days in normal month
  305. if (isLeap) {
  306. offset += monthDays(lyear, i);
  307. }
  308. // increment
  309. offset += parseInt(lday) - 1;
  310. var baseDate = new Date(1900,0,31);
  311. var solarDate = new Date(baseDate.valueOf() + offset * 86400000);
  312. return solarDate;
  313. }
  314. //==============================返回公历 y年某m+1月的天数
  315. function solarDays(y,m) {
  316. if(m==1)
  317. return(((y%4 == 0) && (y%100 != 0) || (y%400 == 0))? 29: 28);
  318. else
  319. return(solarMonth[m]);
  320. }
  321. //============================== 传入 offset 返回干支, 0=甲子
  322. function cyclical(num) {
  323. return(Gan[num%10]+Zhi[num%12]);
  324. }
  325. //============================== 阴历属性
  326. function calElement(sYear,sMonth,sDay,week,lYear,lMonth,lDay,isLeap,cYear,cMonth,cDay,cMnum,cDnum) {
  327. this.isToday = false;
  328. //瓣句
  329. this.sYear = sYear; //公元年4位数字
  330. this.sMonth = sMonth; //公元月数字
  331. this.sDay = sDay; //公元日数字
  332. this.week = week; //星期, 1个中文
  333. //农历
  334. this.lYear = lYear; //公元年4位数字
  335. this.lMonth = lMonth; //农历月数字
  336. this.lDay = lDay; //农历日数字
  337. this.isLeap = isLeap; //是否为农历闰月?
  338. //八字
  339. this.cYear = cYear; //年柱, 2个中文
  340. this.cMonth = cMonth; //月柱, 2个中文
  341. this.cDay = cDay; //日柱, 2个中文
  342. this.color = '';
  343. this.lunarFestival = ''; //农历节日
  344. this.solarFestival = ''; //公历节日
  345. this.solarTerms = ''; //节气
  346. this.cMnumber=cMnum;
  347. this.cDnumber=cDnum;
  348. }
  349. //===== 某年的第n个节气为几日(从0小寒起算)
  350. function sTerm(y,n) {
  351. if(!!jieqiJson["y"+y])
  352. return jieqiJson["y"+y][n];
  353. var offDate = new Date( ( 31556925974.7*(y-1900) + sTermInfo[n]*60000 ) + Date.UTC(1900,0,6,2,5) );
  354. return(offDate.getDate());
  355. }
  356. //============================== 返回阴历控件 (y年,m+1月)
  357. /*
  358. 功能说明: 返回整个月的日期资料控件
  359. 使用方式: OBJ = new calendar(年,零起算月);
  360. OBJ.length 返回当月最大日
  361. OBJ.firstWeek 返回当月一日星期
  362. 由 OBJ[日期].属性名称 即可取得各项值
  363. OBJ[日期].isToday 返回是否为今日 true 或 false
  364. 其他 OBJ[日期] 属性参见 calElement() 中的注解
  365. */
  366. function calendar(y,m) {
  367. var sDObj, lDObj, lY, lM, lD=1, lL, lX=0, tmp1, tmp2, tmp3;
  368. var cY, cM, cD; //年柱,月柱,日柱
  369. var lDPOS = new Array(3);
  370. var n = 0;
  371. var firstLM = 0;
  372. sDObj = new Date(y,m,1,0,0,0,0); //当月一日日期
  373. this.length = solarDays(y,m); //公历当月天数
  374. this.firstWeek = sDObj.getDay(); //公历当月1日星期几
  375. ////////年柱 1900年立春后为庚子年(60进制36)
  376. if(m<2) cY=cyclical(y-1900+36-1); //当m为1时,应计算前一年的阴历
  377. else cY=cyclical(y-1900+36);
  378. var term2=sTerm(y,2); //立春日期
  379. ////////月柱 1900年1月小寒以前为 丙子月(60进制12)
  380. var firstNode = sTerm(y,m*2); //返回当月「节」为几日开始
  381. var cMnum=(y-1900)*12+m+12;
  382. cM = cyclical(cMnum);
  383. //当月一日与 1900/1/1 相差天数
  384. //1900/1/1与 1970/1/1 相差25567日, 1900/1/1 日柱为甲戌日(60进制10)
  385. var dayCyclical = Date.UTC(y,m,1,0,0,0,0)/86400000+25567+10;
  386. for(var i=0;i<this.length;i++) {
  387. if(lD>lX) {
  388. sDObj = new Date(y,m,i+1); //当月一日日期
  389. lDObj = new Lunar(sDObj); //农历
  390. lY = lDObj.year; //农历年
  391. lM = lDObj.month; //农历月
  392. lD = lDObj.day; //农历日
  393. lL = lDObj.isLeap; //农历是否闰月
  394. lX = lL? leapDays(lY): monthDays(lY,lM); //农历当月最后一天
  395. if(n==0) firstLM = lM;
  396. lDPOS[n++] = i-lD+1;
  397. }
  398. //依节气调整二月分的年柱, 以立春为界
  399. if(m==1 && (i+1)==term2) cY=cyclical(y-1900+36);
  400. //依节气月柱, 以「节」为界
  401. if((i+1)==firstNode) cM = cyclical((y-1900)*12+m+13);
  402. //日柱
  403. var cDnum=dayCyclical+i;
  404. if((i+1)>=firstNode){
  405. cMnum=(y-1900)*12+m+13;
  406. }
  407. cD = cyclical(cDnum);
  408. //sYear,sMonth,sDay,week,
  409. //lYear,lMonth,lDay,isLeap,
  410. //cYear,cMonth,cDay
  411. this[i] = new calElement(y, m+1, i+1, nStr1[(i+this.firstWeek)%7],
  412. lY, lM, lD++, lL,
  413. cY ,cM, cD,cMnum,cDnum);
  414. }
  415. //节气
  416. tmp1=sTerm(y,m*2 )-1;
  417. tmp2=sTerm(y,m*2+1)-1;
  418. this[tmp1].solarTerms = solarTerm[m*2];
  419. this[tmp2].solarTerms = solarTerm[m*2+1];
  420. //if(m==3) this[tmp1].color = 'red'; //清明颜色
  421. //公历节日
  422. for(var i= 0; i < sFtv.length ; i++){
  423. if(sFtv[i].match(/^(\d{2})(\d{2})([\s\*])(.+)$/))
  424. if(Number(RegExp.$1)==(m+1)) {
  425. this[Number(RegExp.$2)-1].solarFestival += RegExp.$4 + ' ';
  426. if(RegExp.$3=='*') this[Number(RegExp.$2)-1].color = 'red';
  427. }
  428. }
  429. //月周节日
  430. for(var i=0;i < wFtv.length;i++)
  431. if(wFtv[i].match(/^(\d{2})(\d)(\d)([\s\*])(.+)$/))
  432. if(Number(RegExp.$1)==(m+1)) {
  433. tmp1=Number(RegExp.$2);
  434. tmp2=Number(RegExp.$3);
  435. if(tmp1<5)
  436. this[((this.firstWeek>tmp2)?7:0) + 7*(tmp1-1) + tmp2 - this.firstWeek].solarFestival += RegExp.$5 + ' ';
  437. else {
  438. tmp1 -= 5;
  439. tmp3 = (this.firstWeek+this.length-1)%7; //当月最后一天星期?
  440. this[this.length - tmp3 - 7*tmp1 + tmp2 - (tmp2>tmp3?7:0) - 1 ].solarFestival += RegExp.$5 + ' ';
  441. }
  442. }
  443. //农历节日
  444. for(var i=0;i < lFtv.length;i++)
  445. if(lFtv[i].match(/^(\d{2})(.{2})([\s\*])(.+)$/)) {
  446. tmp1=Number(RegExp.$1)-firstLM;
  447. if(tmp1==-11) tmp1=1;
  448. if(tmp1 >=0 && tmp1<n) {
  449. tmp2 = lDPOS[tmp1] + Number(RegExp.$2) -1;
  450. if( tmp2 >= 0 && tmp2<this.length && this[tmp2].isLeap!=true) {
  451. this[tmp2].lunarFestival += RegExp.$4 + ' ';
  452. if(RegExp.$3=='*') this[tmp2].color = 'red';
  453. }
  454. }
  455. }
  456. //复活节只出现在3或4月
  457. // if(m==2 || m==3) {
  458. // var estDay = new easter(y);
  459. // if(m == estDay.m)
  460. // this[estDay.d-1].solarFestival = this[estDay.d-1].solarFestival+' 复活节 Easter Sunday';
  461. // }
  462. //黑色星期五
  463. // if((this.firstWeek+12)%7==5)
  464. // this[12].solarFestival += '黑色星期五';
  465. //今日
  466. //if(y==g_tY && m==g_tM) {this[g_tD-1].isToday = true;}
  467. }
  468. //======================================= 返回该年的复活节(春分后第一次满月周后的第一主日)
  469. function easter(y) {
  470. var term2=sTerm(y,5); //取得春分日期
  471. var dayTerm2 = new Date(Date.UTC(y,2,term2,0,0,0,0)); //取得春分的公历日期控件(春分一定出现在3月)
  472. var lDayTerm2 = new Lunar(dayTerm2); //取得取得春分农历
  473. if(lDayTerm2.day<15) //取得下个月圆的相差天数
  474. var lMlen= 15-lDayTerm2.day;
  475. else
  476. var lMlen= (lDayTerm2.isLeap? leapDays(y): monthDays(y,lDayTerm2.month)) - lDayTerm2.day + 15;
  477. //一天等于 1000*60*60*24 = 86400000 毫秒
  478. var l15 = new Date(dayTerm2.getTime() + 86400000*lMlen ); //求出第一次月圆为公历几日
  479. var dayEaster = new Date(l15.getTime() + 86400000*( 7-l15.getUTCDay() ) ); //求出下个周日
  480. this.m = dayEaster.getUTCMonth();
  481. this.d = dayEaster.getUTCDate();
  482. }
  483. //====================== 中文日期//农历日期
  484. function cDay(d){
  485. var s;
  486. switch (d) {
  487. case 10:
  488. s = '初十'; break;
  489. case 20:
  490. s = '二十'; break;
  491. break;
  492. case 30:
  493. s = '三十'; break;
  494. break;
  495. default :
  496. s = nStr2[Math.floor(d/10)];
  497. s += nStr1[d%10];
  498. }
  499. return(s);
  500. }
  501. var worktime = {};
  502. //--workTime.js
  503. worktime.years= [2016];
  504. worktime.y2016 = JSON.parse('{"d0101":{"w":"假"},"d0102":{"w":"假"},"d0103":{"w":"假"},"d0206":{"w":"班"},"d0207":{"w":"假"},"d0208":{"w":"假"},"d0209":{"w":"假"},"d0210":{"w":"假"},"d0211":{"w":"假"},"d0212":{"w":"假"},"d0213":{"w":"假"},"d0214":{"w":"班"},"d0402":{"w":"假"},"d0403":{"w":"假"},"d0404":{"w":"假"},"d0430":{"w":"假"},"d0501":{"w":"假"},"d0502":{"w":"假"},"d0609":{"w":"假"},"d0610":{"w":"假"},"d0611":{"w":"假"},"d0612":{"w":"班"},"d0915":{"w":"假"},"d0916":{"w":"假"},"d0917":{"w":"假"},"d0918":{"w":"班"},"d1001":{"w":"假"},"d1002":{"w":"假"},"d1003":{"w":"假"},"d1004":{"w":"假"},"d1005":{"w":"假"},"d1006":{"w":"假"},"d1007":{"w":"假"},"d1008":{"w":"班"},"d1009":{"w":"班"}}');
  505. worktime.y2016.workRestStr = 'd0101 d0102 d0103 d0206 d0207 d0208 d0209 d0210 d0211 d0212 d0213 d0214 d0402 d0403 d0404 d0430 d0501 d0502 d0609 d0610 d0611 d0612 d0915 d0916 d0917 d0918 d1001 d1002 d1003 d1004 d1005 d1006 d1007 d1008 d1009';
  506. /*worktime.years= [2011,2012,2013,2014];
  507. worktime.y2011 = JSON.parse('{"d0402":{"w":"班"},"d0403":{"w":"假"},"d0404":{"w":"假"},"d0405":{"w":"假"},"d0430":{"w":"假"},"d0501":{"w":"假"},"d0502":{"w":"假"},"d0604":{"w":"假"},"d0605":{"w":"假"},"d0606":{"w":"假"},"d0910":{"w":"假"},"d0911":{"w":"假"},"d0912":{"w":"假"},"d1001":{"w":"假"},"d1002":{"w":"假"},"d1003":{"w":"假"},"d1004":{"w":"假"},"d1005":{"w":"假"},"d1006":{"w":"假"},"d1007":{"w":"假"},"d1008":{"w":"班"},"d1009":{"w":"班"},"d1231":{"w":"班"}}');
  508. worktime.y2011.workRestStr = 'd0402 d0403 d0404 d0405 d0430 d0501 d0502 d0604 d0605 d0606 d0910 d0911 d0912 d1001 d1002 d1003 d1004 d1005 d1006 d1007 d1008 d1009 d1231';
  509. worktime.y2012 = JSON.parse('{"d0101":{"w":"假"},"d0102":{"w":"假"},"d0103":{"w":"假"},"d0121":{"w":"班"},"d0122":{"w":"假"},"d0123":{"w":"假"},"d0124":{"w":"假"},"d0125":{"w":"假"},"d0126":{"w":"假"},"d0127":{"w":"假"},"d0128":{"w":"假"},"d0129":{"w":"班"},"d0331":{"w":"班"},"d0401":{"w":"班"},"d0402":{"w":"假"},"d0403":{"w":"假"},"d0404":{"w":"假"},"d0428":{"w":"班"},"d0429":{"w":"假"},"d0430":{"w":"假"},"d0501":{"w":"假"},"d0622":{"w":"假"},"d0623":{"w":"假"},"d0624":{"w":"假"},"d0929":{"w":"班"},"d0930":{"w":"假"},"d1001":{"w":"假"},"d1002":{"w":"假"},"d1003":{"w":"假"},"d1004":{"w":"假"},"d1005":{"w":"假"},"d1006":{"w":"假"},"d1007":{"w":"假"}}');
  510. worktime.y2012.workRestStr = 'd0101 d0102 d0103 d0121 d0122 d0123 d0124 d0125 d0126 d0127 d0128 d0129 d0331 d0401 d0402 d0403 d0404 d0428 d0429 d0430 d0501 d0622 d0623 d0624 d0929 d0930 d1001 d1002 d1003 d1004 d1005 d1006 d1007';
  511. //
  512. worktime.y2013 = JSON.parse('{"d0101":{"w":"假"},"d0102":{"w":"假"},"d0103":{"w":"假"},"d0105":{"w":"班"},"d0106":{"w":"班"},"d0209":{"w":"假"},"d0210":{"w":"假"},"d0211":{"w":"假"},"d0212":{"w":"假"},"d0213":{"w":"假"},"d0214":{"w":"假"},"d0215":{"w":"假"},"d0216":{"w":"班"},"d0217":{"w":"班"},"d0404":{"w":"假"},"d0405":{"w":"假"},"d0406":{"w":"假"},"d0407":{"w":"班"},"d0427":{"w":"班"},"d0428":{"w":"班"},"d0429":{"w":"假"},"d0430":{"w":"假"},"d0501":{"w":"假"},"d0608":{"w":"班"},"d0609":{"w":"班"},"d0610":{"w":"假"},"d0611":{"w":"假"},"d0612":{"w":"假"},"d0919":{"w":"假"},"d0920":{"w":"假"},"d0921":{"w":"假"},"d0922":{"w":"班"},"d0929":{"w":"班"},"d1001":{"w":"假"},"d1002":{"w":"假"},"d1003":{"w":"假"},"d1004":{"w":"假"},"d1005":{"w":"假"},"d1006":{"w":"假"},"d1007":{"w":"假"},"d1012":{"w":"班"}}');
  513. worktime.y2013.workRestStr = 'd0101 d0102 d0103 d0105 d0106 d0209 d0210 d0211 d0212 d0213 d0214 d0215 d0216 d0217 d0404 d0405 d0406 d0407 d0427 d0428 d0429 d0430 d0501 d0608 d0609 d0610 d0611 d0612 d0919 d0920 d0921 d0922 d0929 d1001 d1002 d1003 d1004 d1005 d1006 d1007 d1012';
  514. *///
  515. //worktime.y2014 = JSON.parse('{"d0101":{"w":"假"},"d0126":{"w":"班"},"d0131":{"w":"假"},"d0201":{"w":"假"},"d0202":{"w":"假"},"d0203":{"w":"假"},"d0204":{"w":"假"},"d0205":{"w":"假"},"d0206":{"w":"假"},"d0208":{"w":"班"},"d0405":{"w":"假"},"d0406":{"w":"假"},"d0407":{"w":"假"},"d0501":{"w":"假"},"d0502":{"w":"假"},"d0503":{"w":"假"},"d0504":{"w":"班"},"d0602":{"w":"假"},"d0908":{"w":"假"},"d0928":{"w":"班"},"d1001":{"w":"假"},"d1002":{"w":"假"},"d1003":{"w":"假"},"d1004":{"w":"假"},"d1005":{"w":"假"},"d1006":{"w":"假"},"d1007":{"w":"假"},"d1011":{"w":"班"}}');
  516. //worktime.y2014.workRestStr = 'd0101 d0126 d0131 d0201 d0202 d0203 d0204 d0205 d0206 d0208 d0405 d0406 d0407 d0501 d0502 d0503 d0504 d0602 d0908 d0928 d1001 d1002 d1003 d1004 d1005 d1006 d1007 d1011';
  517. //
  518. $.ajax({
  519. url: "http://static.etouch.cn/apis/holiday-in-law.jsonp",
  520. dataType: "jsonp",
  521. jsonp: "aaa"
  522. });
  523. function cbreturn(data){
  524. var cnArr = data.holidays.cn;
  525. for(var i=0;i<cnArr.length;i++){
  526. var year = cnArr[i].date.toString().substr(0,4);
  527. var yyearJson = worktime["y"+year];
  528. if(!!yyearJson){
  529. yyearJson["workRestStr"] += "d"+cnArr[i].date.toString().replace(year,"")+" ";
  530. if(cnArr[i].status == 0){
  531. yyearJson["d"+cnArr[i].date.toString().replace(year,"")] = {"w":"假"}
  532. }else{
  533. yyearJson["d"+cnArr[i].date.toString().replace(year,"")] = {"w":"班"}
  534. }
  535. }else{
  536. worktime.years.push(year);
  537. worktime["y"+year] = {};
  538. yyearJson = worktime["y"+year];
  539. yyearJson["workRestStr"] = "d"+cnArr[i].date.toString().replace(year,"")+" ";
  540. if(cnArr[i].status == 0){
  541. yyearJson["d"+cnArr[i].date.toString().replace(year,"")] = {"w":"假"}
  542. }else{
  543. yyearJson["d"+cnArr[i].date.toString().replace(year,"")] = {"w":"班"}
  544. }
  545. }
  546. }
  547. //
  548. calander.init();
  549. }
  550. var jieqiJson = {}
  551. jieqiJson.y2016 = [6,20,4,19,5,20,4,19,5,20,5,21,7,22,7,23,7,22,8,23,7,22,7,21];
  552. jieqiJson.y2015 = [6,20,4,19,6,21,5,20,6,21,6,22,7,23,8,23,8,23,8,24,8,22,7,22];
  553. jieqiJson.y2014 = [5,20,4,19,6,21,5,20,5,21,6,21,7,23,7,23,8,23,8,23,7,22,7,22];
  554. jieqiJson.y2013 = [5,20,4,18,5,20,4,20,5,21,5,21,7,22,7,23,7,23,8,23,7,22,7,22];
  555. /*var festival_main = {
  556. "2012_01_01":"元旦",
  557. "2012_01_23":"春节" ,
  558. "2012_04_04":"清明节" ,
  559. "2012_05_01":"劳动节" ,
  560. "2012_06_23":"端午节",
  561. "2012_09_30":"中秋节",
  562. "2012_10_01":"国庆节"
  563. };*/
  564. //var qmj = "2013/04/0" + sTerm(new Date().getFullYear(),6);
  565. /*var festival_main = {
  566. "2013/01/01":"元旦",
  567. "*2013/01/01":"春节",
  568. "2013/04/04":"清明节" ,
  569. "2013/05/01":"劳动节" ,
  570. "*2013/05/05":"端午节",
  571. "*2013/08/15":"中秋节",
  572. "2013/10/01":"国庆节"
  573. };*/
  574. /*var festival_main = {
  575. "2015/01/01":"元旦",
  576. "2015/02/19":"春节",
  577. "2014/04/05":"清明节" ,
  578. "2014/05/01":"劳动节" ,
  579. "2014/06/02":"端午节",
  580. "2014/09/08":"中秋节",
  581. "2014/10/01":"国庆节"
  582. };*/
  583. var festival_main = {
  584. "2016/01/01":"元旦",
  585. "2016/02/08":"春节",
  586. "2016/02/22":"元宵节",
  587. "2016/04/04":"清明节" ,
  588. "2016/05/01":"劳动节" ,
  589. "2016/06/09":"端午节",
  590. "2016/09/15":"中秋节",
  591. "2016/10/01":"国庆节"
  592. };
  593. /*if(!festival_main[qmj]){
  594. delete festival_main["2013/04/04"];
  595. festival_main[qmj]="清明节";
  596. }*/
  597. //--common.js
  598. /*======================一些公共的方法========================*/
  599. $.dom = function(elementId) {
  600. return document.getElementById(elementId);
  601. };
  602. //设置stringBuffer
  603. function StringBuffer() {
  604. this._strings = new Array();
  605. };
  606. StringBuffer.prototype.append = function(str) {
  607. this._strings.push(str);
  608. return this;
  609. };
  610. StringBuffer.prototype.toString = function() {
  611. var str = arguments.length == 0 ? '' : arguments[0];
  612. return this._strings.join(str);
  613. };
  614. String.prototype.leftpad = function(len, str) {
  615. if (!str) {
  616. str = '0';
  617. }
  618. var s = '';
  619. for (var i = 0; i < len - this.length; i++) {
  620. s += str;
  621. }
  622. return s + this;
  623. };
  624. String.prototype.htmlspecialchars = function(){
  625. //return this.replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&acute;").replace(/&/g, "&amp;");
  626. return this;
  627. };
  628. function getMonthKey(year, month) { // 传入的month为0-11的数值 -> (1->01,2->02...11->11)
  629. return year.toString() + (month + 1).toString().leftpad(2); // 返回yyyyMM格式的字符串
  630. }
  631. function getDateKey(date) {
  632. return date.getFullYear().toString() +"-"+(date.getMonth() + 1).toString().leftpad(2)+"-"+date.getDate().toString().leftpad(2); // 返回yyyy-MM-dd格式的字符串
  633. }
  634. function is_leap_year(cur_year){ //判断年份是否为闰年,是则返回1,否则返回0
  635. if(cur_year % 400 == 0 || (cur_year % 100 !=0 && cur_year % 4 == 0)) return 1;
  636. return 0;
  637. }
  638. function getDaysByMonth(date){
  639. var days = [[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
  640. [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]];
  641. return days[is_leap_year(date.getFullYear())][date.getMonth()];
  642. }
  643. function dateDiff(now, date){
  644. var diff = dateDiffDays(now, date);
  645. if(diff == 0) return "今天";
  646. else if(diff < 0) return (0-diff) + "天前";
  647. else return diff + "天后";
  648. }
  649. function dateDiffDays(now, date){
  650. var n = new Date(now.getFullYear(), now.getMonth(), now.getDate());
  651. var d = new Date(date.getFullYear(), date.getMonth(), date.getDate());
  652. var diff = parseInt((d - n)/(24 * 60 * 60 * 1000));
  653. return diff;
  654. }
  655. /*==========================utils.js========================*/
  656. var utils = {
  657. getEvent : function(ev) {
  658. return window.event ? window.event : (ev ? ev : null);
  659. },
  660. getMousePosition : function(ev) {
  661. var evt = this.getEvent(ev);
  662. if (evt.pageX || evt.pageY) {
  663. return {
  664. x : evt.pageX,
  665. y : evt.pageY
  666. };
  667. }
  668. return {
  669. x : evt.clientX + document.documentElement.scrollLeft
  670. - document.documentElement.clientLeft,
  671. y : evt.clientY + document.documentElement.scrollTop
  672. - document.documentElement.clientTop
  673. };
  674. },
  675. getClientWidth : function() {
  676. return $.browser.msie ? ieBody.clientWidth : window.innerWidth;
  677. },
  678. getClientHeight : function() {
  679. return $.browser.msie ? ieBody.clientHeight : window.innerHeight;
  680. },
  681. getRandomColor : function() {
  682. /*
  683. *
  684. * getRandomColor 从colors数组获取随机颜色
  685. *
  686. * @return 对象,index:索引,value:颜色代码
  687. *
  688. */
  689. var index = Math.round(Math.random() * (colors.length - 1));
  690. return {
  691. index : index,
  692. value : colors[index]
  693. };
  694. },
  695. /*
  696. * obj : DOM element
  697. */
  698. getOffsetXY : function(obj, parentId) {
  699. /*
  700. *
  701. * getOffsetXY 获取相对坐标
  702. *
  703. * @param obj id或者dom对象 @param parentId 父级id,如果不提供则为body
  704. *
  705. * @return 坐标对象,x、y
  706. *
  707. */
  708. // var element;
  709. // if (typeof obj == 'object') {
  710. // element = obj;
  711. // } else {
  712. // element = document.getElementById(obj);
  713. // }
  714. // var element_X = element.offsetLeft;
  715. // var element_Y = element.offsetTop;
  716. // while (true) {
  717. // if ((!element.offsetParent) || (!element.offsetParent.style)
  718. // || (!!parentId && element.offsetParent.id == parentId)) {
  719. // break;
  720. // }
  721. // element_X += element.offsetParent.offsetLeft;
  722. // element_Y += element.offsetParent.offsetTop;
  723. // element = element.offsetParent;
  724. // }
  725. // element_X = element_X - document.body.scrollLeft;
  726. // element_Y = element_Y - document.body.scrollTop;
  727. //
  728. // return {
  729. // x : element_X,
  730. // y : element_Y
  731. // };
  732. var pos= {};
  733. if(parentId) {
  734. pos = $(obj).position();
  735. return {
  736. x : pos.left,
  737. y : pos.top
  738. };
  739. }
  740. pos = $(obj).offset();
  741. return {
  742. x : pos.left,
  743. y : pos.top
  744. };
  745. },
  746. hideDialog:function(id){
  747. for(var i=0;i<id.length;i++)
  748. {
  749. $("#"+id[i]).hide();
  750. $(document).unbind("mousedown."+id[i]);
  751. }
  752. },
  753. mousedown_hide_ele : function(id,parent_id,descard_id) { // 实现鼠标点击其他地方,关闭对话框,
  754. $(document).bind("mousedown."+id, function(r) {
  755. var p = r.target;
  756. var q = document.getElementById(id);
  757. while (true) {
  758. if (p == q) {
  759. return true;
  760. } else {
  761. try {
  762. if (p.id == parent_id) { // 此处需要修改,有的情况下会出现脚本停止响应的现象(p == document)
  763. $(document).unbind("mousedown."+id);
  764. $("#"+id).hide();
  765. return false;
  766. } else {
  767. if(p.id==descard_id){
  768. return;
  769. }
  770. p = $(p).parent()[0];
  771. }
  772. } catch(e) {
  773. return false;
  774. }
  775. }
  776. }
  777. });
  778. }
  779. };
  780. /*==============cacheMgr,在calwnl中用到===============*/
  781. var cacheMgr = {
  782. cldCache : {}, // 注意!这里存的是calendarObj.js中定义的calendar对象,不是数据文件载入的cldObj
  783. getCld : function(year, month) {
  784. var key = getMonthKey(year, month);
  785. var cld = this.cldCache[key];
  786. if (typeof cld == 'undefined') {
  787. cld = new calendar(year, month);
  788. this.cldCache[key] = cld;
  789. }
  790. return cld;
  791. }
  792. };
  793. /*==========================时间处理===========================*/
  794. /*
  795. %e Day of the month without leading zeros (01..31)
  796. %d Day of the month, 2 digits with leading zeros (01..31)
  797. %j Day of the year, 3 digits with leading zeros (001..366)
  798. %a A textual representation of a day, two letters
  799. %W A full textual representation of the day of the week
  800. %c Numeric representation of a month, without leading zeros (0..12)
  801. %m Numeric representation of a month, with leading zeros (00..12)
  802. %b A short textual representation of a month, three letters (Jan..Dec)
  803. %M A full textual representation of a month, such as January or March (January..December)
  804. %y A two digit representation of a year (93..03)
  805. %Y A full numeric representation of a year, 4 digits (1993..03)
  806. */
  807. var calwnl = {};
  808. calwnl.date= {
  809. date_part: function(date) { //返回当前时间的日期部分,时间部分则全为零(Mon Jun 18 2012 14:18:46 GMT+0800 为 Mon Jun 18 2012 00:00:00 GMT+0800 )
  810. date.setHours(0);
  811. date.setMinutes(0);
  812. date.setSeconds(0);
  813. date.setMilliseconds(0);
  814. return date;
  815. },
  816. month_day : function(date) { //从 Date 对象返回一个月中的某一天 (1 ~ 31)。
  817. var d = date || new Date();
  818. return d.getDate();
  819. },
  820. time_part: function(date) { //获取这个时间点,在当天的秒数( 如:14:18:16 转换成秒数为51526.47199988365 小数点后面的为毫秒尾数)
  821. return (date.valueOf()/1000 - date.getTimezoneOffset()*60)%86400;
  822. },
  823. week_start: function(date,start_on_monday) { //此方法是设设置本星期的起始是哪一天,即本星期一是本月哪一天(返回值:Date)
  824. var shift=date.getDay(); //此方法的目的是,获取当前日期所在星期中星期一是哪个日期
  825. if (start_on_monday) {
  826. if (shift==0)
  827. shift=6;
  828. else
  829. shift--;
  830. }//从 Date 对象返回一周中的某一天 (0 ~ 6)。start_on_monday为ture时 0-6 表示为从星期一到星期日
  831. return this.date_part(this.add(date,-1*shift,"day"));
  832. },
  833. month_start: function(date) { //方法返回的是一个时间为零,日期为本月的第一天的Date对象。(目的返回本月的第一天)
  834. date.setDate(1);
  835. return this.date_part(date);
  836. },
  837. month_view_start : function(date, start_on_monday) { //返回月初即月的1号,所在的星期的星期一是哪一天
  838. return this.week_start(this.month_start(date), start_on_monday);
  839. },
  840. year_start: function(date) { //返回本年的第一天({Mon Jun 18 2012 00:18:46 GMT+0800} 会转化为 {Sun Jan 01 2012 00:18:46 GMT+0800} ** 注意一点哦,星期回随着时间的变化而发生变化哦~)
  841. date.setMonth(0);
  842. return this.month_start(date);
  843. },
  844. day_start: function(date) {
  845. return this.date_part(date);
  846. },
  847. add: function(date,inc,mode) { //
  848. var ndate=new Date(date.valueOf());
  849. switch(mode) {
  850. case "day": //设置本星期的起始是哪一天,即本星期一是本月哪一天
  851. ndate.setDate(ndate.getDate()+inc);
  852. break;
  853. case "week":
  854. ndate.setDate(ndate.getDate()+7*inc);
  855. break;
  856. case "month":
  857. ndate.setMonth(ndate.getMonth()+inc);
  858. break;
  859. case "year":
  860. ndate.setYear(ndate.getFullYear()+inc);
  861. break;
  862. case "hour":
  863. ndate.setHours(ndate.getHours()+inc);
  864. break;
  865. case "minute":
  866. ndate.setMinutes(ndate.getMinutes()+inc);
  867. break;
  868. default:
  869. return defaults.date["add_"+mode](date,inc,mode);
  870. }
  871. return ndate;
  872. },
  873. to_fixed: function(num) { //1->01,5->05...10->10
  874. if (num<10)
  875. return "0"+num;
  876. return num;
  877. },
  878. copy: function(date) { // 获取时间的副本
  879. return new Date(date.valueOf());
  880. },
  881. getChinaNum : function(Num) { //农历的每月开头
  882. var monthEn;
  883. switch(Num) {
  884. case 1 :
  885. monthEn = "一";
  886. break;
  887. case 2 :
  888. monthEn = "二";
  889. break;
  890. case 3 :
  891. monthEn = "三";
  892. break;
  893. case 4 :
  894. monthEn = "四";
  895. break;
  896. case 5 :
  897. monthEn = "五";
  898. break;
  899. case 6 :
  900. monthEn = "六";
  901. break;
  902. case 7 :
  903. monthEn = "七";
  904. break;
  905. case 8 :
  906. monthEn = "八";
  907. break;
  908. case 9 :
  909. monthEn = "九";
  910. break;
  911. case 10 :
  912. monthEn = "十";
  913. break;
  914. case 11 :
  915. monthEn = "十一";
  916. break;
  917. case 12 :
  918. monthEn = "腊";
  919. break;
  920. }
  921. return monthEn;
  922. },
  923. getLundarMD : function(md,split){
  924. var month='';
  925. var day='';
  926. if(!split){
  927. month = md.substr(0,2);
  928. day = md.substr(2,2);
  929. }else{
  930. var arr = md.split(split);
  931. month = arr[0];
  932. day = arr[1];
  933. }
  934. return this.getChinaNum(parseFloat(month))+"月"+cDay(parseFloat(day));
  935. },
  936. getDayNameBrief: function(day_index) {
  937. var day_name = ['SUN','MON','TUE','WED','THU','FRI','SAT'];
  938. return day_name[day_index];
  939. },
  940. daynameToIndex: function(dayname) {
  941. var dayname_index_map = {'SUN':0,'MON':1,'TUE':2,'WED':3,'THU':4,'FRI':5,'SAT':6};
  942. return dayname_index_map[dayname];
  943. },
  944. /*
  945. * date_time所在日期为当月第几周
  946. */
  947. getWeekOfMonth: function(date_time, start_on_monday) {
  948. var date = this.copy(date_time);
  949. return Math.floor((this.date_part(date).getTime() - this.month_view_start(date, start_on_monday).getTime())/604800000) + 1;
  950. },
  951. lunar_year : function(date) { //获取阴历年份的名称 { 2012 -> 辛卯年【兔年】 }
  952. var l_year = date.getFullYear()+'年'+(date.getMonth()+1)+'月 '+cyclical(date.getFullYear() - 1900 + 36) + Animals[(date.getFullYear() - 4) % 12] + '年';
  953. return l_year;
  954. },
  955. lunar_Info : function(date) {
  956. var cld = cacheMgr.getCld(date.getFullYear(), date.getMonth());
  957. var day = date.getDate();
  958. var cld_day = cld[day - 1];
  959. var lunar_detail = {
  960. l_day : "",
  961. l_month : "",
  962. l_day_full:""
  963. };
  964. lunar_detail.l_day = cDay(cld_day.lDay);
  965. lunar_detail.l_month = cld_day.lMonth;
  966. lunar_detail.color = "";
  967. var s,s2;
  968. s=cld_day.lunarFestival;
  969. if(s.length>0) { // 农历节日
  970. if(s.length>6) {
  971. s2 = s.toString();
  972. s = s.substr(0, 4)+'...';
  973. }
  974. lunar_detail.color = "#32CD32";
  975. } else { // 廿四节气
  976. s=cld_day.solarTerms;
  977. s2=s.toString();
  978. if(s.length>0) {
  979. lunar_detail.color = "#32CD32";
  980. if((s =='清明')||(s =='芒种')||(s =='夏至')||(s =='冬至')) {
  981. lunar_detail.color = "#32CD32";
  982. if(s =='清明')
  983. s = '清明节';
  984. }
  985. }
  986. /*else
  987. { // 公历节日
  988. s=cld_day.solarFestival;
  989. s2 = s.toString();
  990. if(s.length>0) {
  991. if(s.length>6)
  992. {
  993. s = s.substr(0, 4)+'..';
  994. }
  995. lunar_detail.color = "#46BAEC";
  996. }
  997. }*/
  998. }
  999. lunar_detail.l_day_y = cDay(cld_day.lDay);
  1000. if(s.length>0) {
  1001. lunar_detail.l_day = s;
  1002. lunar_detail.l_day_full = s2;
  1003. }
  1004. //var info = templates.getChinaNum(lunar_detail.l_month)+"月"+lunar_detail.l_day;
  1005. //var info = lunar_detail.l_day;
  1006. return lunar_detail;
  1007. },
  1008. date_to_str: function(format,utc) {
  1009. format=format.replace(/%[a-zA-Z]/g, function(a) {
  1010. switch(a) {
  1011. case "%d":
  1012. return "\"+calwnl.date.to_fixed(date.getDate())+\"";
  1013. case "%m":
  1014. return "\"+calwnl.date.to_fixed((date.getMonth()+1))+\"";
  1015. case "%j":
  1016. return "\"+date.getDate()+\"";
  1017. case "%n":
  1018. return "\"+(date.getMonth()+1)+\"";
  1019. case "%y":
  1020. return "\"+calwnl.date.to_fixed(date.getYear()%100)+\"";
  1021. case "%Y":
  1022. return "\"+date.getFullYear()+\"";
  1023. case "%D":
  1024. return "\"+calwnl.locale.date.day_short[date.getDay()]+\"";
  1025. case "%l":
  1026. return "\"+calwnl.locale.date.day_full[date.getDay()]+\"";
  1027. case "%M":
  1028. return "\"+calwnl.locale.date.month_short[date.getMonth()]+\"";
  1029. case "%F":
  1030. return "\"+calwnl.locale.date.month_full[date.getMonth()]+\"";
  1031. case "%h":
  1032. return "\"+calwnl.date.to_fixed((date.getHours()+11)%12+1)+\"";
  1033. case "%H":
  1034. return "\"+calwnl.date.to_fixed(date.getHours())+\"";
  1035. case "%i":
  1036. return "\"+calwnl.date.to_fixed(date.getMinutes())+\"";
  1037. case "%a":
  1038. return "\"+(date.getHours()>11?\"pm\":\"am\")+\"";
  1039. case "%A":
  1040. return "\"+(date.getHours()>11?\"PM\":\"AM\")+\"";
  1041. case "%s":
  1042. return "\"+calwnl.date.to_fixed(date.getSeconds())+\"";
  1043. default:
  1044. return a;
  1045. }
  1046. });
  1047. if (utc)
  1048. format=format.replace(/date\.get/g,"date.getUTC");
  1049. return new Function("date","return \""+format+"\";");
  1050. },
  1051. numToWeek: function(inStr) {
  1052. switch (inStr) {
  1053. case 1:
  1054. return '一';
  1055. case 2:
  1056. return '二';
  1057. case 3:
  1058. return '三';
  1059. case 4:
  1060. return '四';
  1061. case 5:
  1062. return '五';
  1063. case 6:
  1064. return '六';
  1065. case 0:
  1066. return '日';
  1067. }
  1068. },
  1069. str_to_date: function(format,utc) {
  1070. var splt="var temp=date.split(/[^0-9a-zA-Z]+/g);";
  1071. var mask=format.match(/%[a-zA-Z]/g);
  1072. for (var i=0; i<mask.length; i++) {
  1073. switch(mask[i]) {
  1074. case "%j":
  1075. case "%d":
  1076. splt+="set[2]=temp["+i+"]||0;";
  1077. break;
  1078. case "%n":
  1079. case "%m":
  1080. splt+="set[1]=(temp["+i+"]||1)-1;";
  1081. break;
  1082. case "%y":
  1083. splt+="set[0]=temp["+i+"]*1+(temp["+i+"]>50?1900:2000);";
  1084. break;
  1085. case "%h":
  1086. case "%H":
  1087. splt+="set[3]=temp["+i+"]||0;";
  1088. break;
  1089. case "%i":
  1090. splt+="set[4]=temp["+i+"]||0;";
  1091. break;
  1092. case "%Y":
  1093. splt+="set[0]=temp["+i+"]||0;";
  1094. break;
  1095. case "%a":
  1096. case "%A":
  1097. splt+="set[3]=set[3]%12+((temp["+i+"]||'').toLowerCase()=='am'?0:12);";
  1098. break;
  1099. case "%s":
  1100. splt+="set[5]=temp["+i+"]||0;";
  1101. break;
  1102. }
  1103. }
  1104. var code ="set[0],set[1],set[2],set[3],set[4],set[5]";
  1105. if (utc)
  1106. code =" Date.UTC("+code+")";
  1107. return new Function("date","var set=[0,0,0,0,0,0]; "+splt+" return new Date("+code+");");
  1108. }
  1109. };
  1110. calwnl.templates= {};
  1111. calwnl.config= {
  1112. default_date: "%Y-%m-%d %H:%i",
  1113. month_date: "%F %Y",
  1114. load_date: "%Y-%m-%d",
  1115. week_date: "%l",
  1116. day_date: "%D, %F %j",
  1117. hour_date: "%H:%i",
  1118. month_day : "%d",
  1119. xml_date:"%Y/%m/%d %H:%i",
  1120. api_date:"%Y-%m-%d %H:%i",
  1121. server_utc:false
  1122. };
  1123. calwnl.init_templates= function() {
  1124. var d=calwnl.date.date_to_str;
  1125. var c=calwnl.config;
  1126. var f = function(a,b) {
  1127. for (var c in b)
  1128. if (!a[c])
  1129. a[c]=b[c];
  1130. };
  1131. f(calwnl.templates, {
  1132. day_date:d(c.default_date),
  1133. month_date:d(c.month_date),
  1134. week_date: function(d1,d2) {
  1135. return calwnl.templates.day_date(d1)+" &ndash; "+calwnl.templates.day_date(calwnl.date.add(d2,-1,"day"));
  1136. },
  1137. day_scale_date:d(c.default_date),
  1138. month_scale_date:d(c.week_date),
  1139. week_scale_date:d(c.day_date),
  1140. hour_scale:d(c.hour_date),
  1141. time_picker:d(c.hour_date),
  1142. event_date:d(c.hour_date),
  1143. month_day:d(c.month_day),
  1144. xml_date:calwnl.date.str_to_date(c.xml_date,c.server_utc),
  1145. load_format:d(c.load_date,c.server_utc),
  1146. xml_format:d(c.xml_date,c.server_utc),
  1147. api_date:calwnl.date.str_to_date(c.api_date),
  1148. event_header: function(start,end,ev) {
  1149. return calwnl.templates.event_date(start)+" - "+calwnl.templates.event_date(end);
  1150. },
  1151. event_text: function(start,end,ev) {
  1152. return ev.text;
  1153. },
  1154. event_class: function(start,end,ev) {
  1155. return "";
  1156. },
  1157. month_date_class: function(d) {
  1158. return "";
  1159. },
  1160. week_date_class: function(d) {
  1161. return "";
  1162. },
  1163. event_bar_date: function(start,end,ev) {
  1164. return calwnl.templates.event_date(start)+" ";
  1165. },
  1166. event_bar_text: function(start,end,ev) {
  1167. return ev.text;
  1168. }
  1169. });
  1170. };
  1171. /*==================================语言处理============================*/
  1172. calwnl.locale= {
  1173. date: {
  1174. month_full: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
  1175. month_short: ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"],
  1176. day_full: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
  1177. day_short: ["日", "一", "二", "三", "四", "五", "六"]
  1178. }
  1179. };
  1180. /*============================== JCT模版的封装 ===========================*/
  1181. var tplMgr = {
  1182. tplMap : {},
  1183. getInstance : function(id) {
  1184. var instance = this.tplMap[id];
  1185. if (!instance) {
  1186. instance = new jCT($.dom(id).value);
  1187. instance.Build();
  1188. this.tplMap[id] = instance;
  1189. }
  1190. return instance;
  1191. },
  1192. getTemplate : function(id) {
  1193. var element = $.dom(id);
  1194. var content = element.value; // Like textarea.value.
  1195. if (content == null)
  1196. content = element.innerHTML; // Like textarea.innerHTML.
  1197. content = content.replace(/&lt;/g, "<").replace(/&gt;/g, ">");
  1198. return content;
  1199. },
  1200. loadTemplate : function(id, url, callback) {
  1201. if ($('textarea[id=' + id + ']').length > 0) { // 如果已经载入
  1202. if (callback) {
  1203. callback();
  1204. }
  1205. } else {
  1206. // utils.showLoadingShadow();
  1207. $.get(url, {
  1208. t : Math.ceil(Math.random() * 100)
  1209. }, function(data) {
  1210. // var tpl = data.replace(/</g, '&lt;').replace(/>/g,
  1211. // '&gt;');
  1212. $('<textarea id="' + id
  1213. + '" style="display:none"></textarea>')
  1214. .appendTo('body').val(data);
  1215. if (callback) {
  1216. callback();
  1217. }
  1218. });
  1219. }
  1220. }
  1221. };
  1222. /*===============================dialog========================*/
  1223. var dialogMgr = {
  1224. dialog : null,
  1225. option : null,
  1226. moving : false,
  1227. pos : null,
  1228. show : function(el, options) {
  1229. var op = {
  1230. width : 428,
  1231. title : '',
  1232. draggable : true
  1233. // 默认对话框允许点击标题栏拖动
  1234. };
  1235. var options = options || {};
  1236. for (var p in options) {
  1237. op[p] = options[p];
  1238. }
  1239. if (this.dialog) {
  1240. this.hide();
  1241. }
  1242. this.option = op;
  1243. this.dialog = $.dom(el);
  1244. var width = this.option.width;
  1245. var w = utils.getClientWidth();
  1246. var left = 0;
  1247. if (w > width) {
  1248. left = (w - width) / 2;
  1249. }
  1250. this.dialog.style.left = left + 'px';
  1251. var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
  1252. var top = 30 + scrollTop;
  1253. this.dialog.style.top = top + 'px';
  1254. },
  1255. hide : function() {
  1256. if (this.dialog) {
  1257. $(this.dialog).hide();
  1258. if (this.option.hideCallback) {
  1259. try {
  1260. this.option.hideCallback();
  1261. } catch (ex) {
  1262. }
  1263. }
  1264. this.option = null;
  1265. this.dialog = null;
  1266. this.moving = false;
  1267. this.pos = null;
  1268. }
  1269. }
  1270. };
  1271. /*================ 日历实用类 ==========================*/
  1272. var CalUtil = {
  1273. /*
  1274. * 返回一个对象,包含date所在月份的月视图的第一天和最后一天的日期,以及显示在月视图中的行数{start:..., end:..., row:...}
  1275. */
  1276. monthViewInfo : function(date, startOnMonday) {
  1277. var dateUtil = calwnl.date;
  1278. var info = {};
  1279. var s_date = dateUtil.copy(date);
  1280. s_date = dateUtil.month_view_start(s_date, startOnMonday);
  1281. info.start = dateUtil.copy(dateUtil.week_start(s_date, startOnMonday));
  1282. var e_date = dateUtil.copy(date);
  1283. e_date.setMonth(date.getMonth() + 1);
  1284. e_date.setDate(1);
  1285. info.row = Math.ceil((e_date.valueOf()-s_date.valueOf()) / 604800000);
  1286. info.end = dateUtil.add(info.start, 7*info.row, 'day');
  1287. return info;
  1288. }
  1289. };
  1290. /**
  1291. * Cookie plugin
  1292. *
  1293. * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
  1294. * Dual licensed under the MIT and GPL licenses:
  1295. * http://www.opensource.org/licenses/mit-license.php
  1296. * http://www.gnu.org/licenses/gpl.html
  1297. *
  1298. */
  1299. /**
  1300. * Create a cookie with the given name and value and other optional parameters.
  1301. *
  1302. * @example $.cookie('the_cookie', 'the_value');
  1303. * @desc Set the value of a cookie.
  1304. * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
  1305. * @desc Create a cookie with all available options.
  1306. * @example $.cookie('the_cookie', 'the_value');
  1307. * @desc Create a session cookie.
  1308. * @example $.cookie('the_cookie', null);
  1309. * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
  1310. * used when the cookie was set.
  1311. *
  1312. * @param String name The name of the cookie.
  1313. * @param String value The value of the cookie.
  1314. * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
  1315. * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
  1316. * If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
  1317. * If set to null or omitted, the cookie will be a session cookie and will not be retained
  1318. * when the the browser exits.
  1319. * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
  1320. * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
  1321. * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
  1322. * require a secure protocol (like HTTPS).
  1323. * @type undefined
  1324. *
  1325. * @name $.cookie
  1326. * @cat Plugins/Cookie
  1327. * @author Klaus Hartl/klaus.hartl@stilbuero.de
  1328. */
  1329. /**
  1330. * Get the value of a cookie with the given name.
  1331. *
  1332. * @example $.cookie('the_cookie');
  1333. * @desc Get the value of a cookie.
  1334. *
  1335. * @param String name The name of the cookie.
  1336. * @return The value of the cookie.
  1337. * @type String
  1338. *
  1339. * @name $.cookie
  1340. * @cat Plugins/Cookie
  1341. * @author Klaus Hartl/klaus.hartl@stilbuero.de
  1342. */
  1343. jQuery.cookie = function(name, value, options) {
  1344. if (typeof value != 'undefined') { // name and value given, set cookie
  1345. options = options || {};
  1346. if (value === null) {
  1347. value = '';
  1348. options.expires = -1;
  1349. }
  1350. var expires = '';
  1351. if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
  1352. var date;
  1353. if (typeof options.expires == 'number') {
  1354. date = new Date();
  1355. date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
  1356. } else {
  1357. date = options.expires;
  1358. }
  1359. expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
  1360. }
  1361. // CAUTION: Needed to parenthesize options.path and options.domain
  1362. // in the following expressions, otherwise they evaluate to undefined
  1363. // in the packed version for some reason...
  1364. var path = options.path ? '; path=' + (options.path) : '';
  1365. var domain = options.domain ? '; domain=' + (options.domain) : '';
  1366. var secure = options.secure ? '; secure' : '';
  1367. document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
  1368. } else { // only name given, get cookie
  1369. var cookieValue = null;
  1370. if (document.cookie && document.cookie != '') {
  1371. var cookies = document.cookie.split(';');
  1372. for (var i = 0; i < cookies.length; i++) {
  1373. var cookie = jQuery.trim(cookies[i]);
  1374. // Does this cookie string begin with the name we want?
  1375. if (cookie.substring(0, name.length + 1) == (name + '=')) {
  1376. cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
  1377. break;
  1378. }
  1379. }
  1380. }
  1381. return cookieValue;
  1382. }
  1383. };
  1384. var colors = ['#CC3333', '#DD4477', '#994499', '#6633CC', '#336699', '#3366CC',
  1385. '#22AA99', '#329262', '#109618', '#66AA00', '#AAAA11', '#D6AE00',
  1386. '#EE8800', '#DD5511', '#A87070', '#8C6D8C', '#627487', '#7083A8',
  1387. '#5C8D87', '#898951', '#B08B59'];
  1388. //dataHandler.js
  1389. /*=============== 数据处理 DataHandler ================*/
  1390. var DataHandler = {
  1391. /*
  1392. * 记录缓存中数据的时间范围 XXX xj: 似乎yzm修改过缓存记录方式之后此数据已经无用了
  1393. */
  1394. cachedData : {
  1395. from : new Date(),
  1396. to : new Date()
  1397. },
  1398. loadCld : {},
  1399. getLoadCld : function(dateStart, dateEnd,cld){
  1400. var sel = [];
  1401. var str = getDateKey(dateStart)+"-"+getDateKey(dateEnd);
  1402. for(var i=0;i<cld.length;i++)
  1403. {
  1404. var signal = str+"-"+cld[i];
  1405. if(typeof DataHandler.loadCld[signal] == 'undefined')
  1406. {
  1407. sel.push(cld[i]);
  1408. DataHandler.loadCld[signal] = {};
  1409. }
  1410. }
  1411. if(sel.length>0)
  1412. return sel.join(",");
  1413. else
  1414. return false;
  1415. },
  1416. /*
  1417. * 缓存中format以后的数据,格式见formatSchData
  1418. */
  1419. resultData: {},
  1420. /*
  1421. * id为键,日程简介为值
  1422. */
  1423. resultDataById: {},
  1424. /*
  1425. * 根据起始时间取日程数据,若缓存中不存在所需数据,则ajax请求并入缓存,若已存在,则数据请求无动作;若callback存在,调用之
  1426. * dateStart, dateEnd : Date
  1427. * callback : function
  1428. */
  1429. getSchByPeriod : function(dateStart, dateEnd, callback) {
  1430. var s_time = dateStart, e_time = dateEnd;
  1431. if (dateStart >= this.cachedData.from) {
  1432. s_time = this.cachedData.to;
  1433. }
  1434. if (dateEnd <= this.cachedData.to) {
  1435. e_time = this.cachedData.from;
  1436. }
  1437. var cld = calendarHandler.getSelectedArray();
  1438. var cldStr = DataHandler.getLoadCld(dateStart, dateEnd,cld);
  1439. if(cldStr) {
  1440. // 杨:获取当前选中的日历id
  1441. $.ajax({
  1442. url: '/schedule/list.do',
  1443. async: true,
  1444. type: 'post',
  1445. dataType: 'json',
  1446. data: {
  1447. fromDate: calwnl.templates.load_format(dateStart),
  1448. toDate: calwnl.templates.load_format(dateEnd),
  1449. timeZone: - (new Date()).getTimezoneOffset() / 60,
  1450. calendarId: cldStr
  1451. },
  1452. success: function(result) {
  1453. for(var i=0;i<result.length;i++)
  1454. {
  1455. var cldObj = result[i];
  1456. DataHandler.formatSchData(cldObj.schlist, e_time);
  1457. }
  1458. if(DataHandler.cachedData.from > s_time)
  1459. DataHandler.cachedData.from = s_time;
  1460. if(DataHandler.cachedData.to < e_time)
  1461. DataHandler.cachedData.to = e_time;
  1462. if(callback) {
  1463. callback();
  1464. }
  1465. }
  1466. });
  1467. } else {
  1468. if(callback) {
  1469. callback();
  1470. }
  1471. }
  1472. },
  1473. /*
  1474. * 获取date所在月份月视图区域内数据并显示,若缓存中存在所需数据,则返回缓存中数据,否则ajax请求数据
  1475. * date : Date
  1476. * callback : function
  1477. * startOnMonday : 周一作为第一天,为true, 否则为false
  1478. */
  1479. getSchByMonth : function(date, callback, startOnMonday) {
  1480. var s_date = calwnl.date.month_view_start(date, startOnMonday);
  1481. var e_date = calwnl.date.add(s_date, CalUtil.monthViewInfo(date, startOnMonday).row*7, 'day');
  1482. this.getSchByPeriod(s_date, e_date, callback);
  1483. },
  1484. /*
  1485. * 此方法是从格式化的日程数据中获取一段时间的日程并返回规定的数据格式
  1486. * 具体的数据格式如下
  1487. * {
  1488. * "d2011-05-01":{
  1489. * schList:[{日程信息}], // 该天的日程列表,todo:跨天日程的处理方式,重复日程,
  1490. * num: // 日程的条数
  1491. * },
  1492. * "d2011-05-02":{
  1493. * schList:[]
  1494. * num: // 日程的条数
  1495. * },
  1496. * maxNum: // 算出最多日程的条数 方便月视图显示日程
  1497. * }
  1498. *
  1499. * sTime, eTime : Date OR string
  1500. */
  1501. getSchedulesByRange: function(sTime,eTime,data,cld) {
  1502. var result= {};
  1503. var dataSch = data||DataHandler.resultData;
  1504. if(typeof sTime=="string") {
  1505. sTime = calwnl.templates.api_date(sTime);
  1506. }
  1507. if(typeof eTime=="string") {
  1508. eTime = calwnl.templates.api_date(eTime);
  1509. }
  1510. sTime = calwnl.date.date_part(sTime);
  1511. eTime = calwnl.date.date_part(eTime);
  1512. for(;sTime<=eTime;) {
  1513. var k = "d"+getDateKey(sTime);
  1514. result[k]= {
  1515. schList:[],
  1516. num:0
  1517. };
  1518. if(dataSch[k]) {
  1519. var schList_temp = [];
  1520. for(var j = 0; j<dataSch[k].schList.length;j++)
  1521. {
  1522. var sch_t = dataSch[k].schList[j];
  1523. for(var q = 0;q<cld.length;q++)
  1524. {
  1525. if(sch_t.cid==cld[q])
  1526. {
  1527. schList_temp.push(sch_t);
  1528. break;
  1529. }
  1530. }
  1531. }
  1532. result[k].schList = schList_temp;
  1533. result[k].num = schList_temp.length;
  1534. }
  1535. sTime = calwnl.date.add(sTime,1,"day");
  1536. }
  1537. var maxNum = 0;
  1538. for(var i in result) {
  1539. var k = result[i];
  1540. if(k.num>maxNum)
  1541. maxNum = k.num;
  1542. }
  1543. result.maxNum = maxNum;
  1544. return JSON.parse(JSON.stringify(result)); //make a copy of data to keep original data safe
  1545. },
  1546. /*
  1547. * 为了提高日程数据的处理效率,减少重复处理,将日程数据格式化为以下模式
  1548. * {
  1549. * "d2011-05-01":{
  1550. * schList:[{日程信息}] // 该天的日程列表,日程列表是排好序的,排序规则:1、按照时间排序,如果时间相同则按照日历id、日程id或者可以是日程的添加时间;todo:跨天日程的处理方式,重复日程,
  1551. * },
  1552. * "d2011-05-02":{
  1553. * schList:[]
  1554. * }
  1555. * }
  1556. *
  1557. * data : Object
  1558. * dateScope : Date
  1559. */
  1560. formatSchData : function(data,dateScope) {
  1561. var result = {};
  1562. /*
  1563. * 注:对于数组的操作,尽量少用for(var i in data) 模式,因为此模式不仅会操作数组中的数据,同时会操作数组对象的其他属性,
  1564. * 此处只需要遍历一遍日程列表即可,但是需要注意对跨天日程的拆分,需要添加三个字段 1、cross_st 2、cross_et,3、是否显示isDisplay
  1565. */
  1566. for(var i=0;i<data.length;i++) {
  1567. var sch = data[i];
  1568. if('' == sch.text) sch.text = '(无标题)';
  1569. var sTime = calwnl.templates.api_date(sch.start_time);
  1570. var eTime = new Date(sTime.valueOf()+sch.duration*1000);
  1571. var sTemp = calwnl.date.copy(sTime);
  1572. var sideTime = calwnl.date.add(calwnl.date.date_part(sTemp),1,"day");
  1573. sch.isDisplay = 0;
  1574. if(sideTime>=eTime) {
  1575. var key = "d"+getDateKey(sTime);
  1576. if(!result[key])
  1577. result[key]= {
  1578. schList:[]
  1579. };
  1580. result[key].schList.push(sch);
  1581. } else {
  1582. var s_t = calwnl.date.copy(sTime);
  1583. for(;s_t<eTime&&s_t<dateScope;) // 此处应当避免没有必要阶段性日程划分;TODO:对日程进行排序
  1584. {
  1585. var k = "d"+getDateKey(s_t);
  1586. var sch_temp = DataHandler.copySch(sch);
  1587. sch_temp.cross_st = calwnl.templates.day_date(s_t)+":00";
  1588. var e_t = calwnl.date.add(calwnl.date.date_part(s_t),1,"day");
  1589. if(e_t<=eTime)
  1590. sch_temp.cross_et = calwnl.templates.day_date(e_t)+":00";
  1591. else
  1592. sch_temp.cross_et = calwnl.templates.day_date(eTime)+":00";
  1593. if(!result[k])
  1594. result[k]= {
  1595. schList:[]
  1596. };
  1597. result[k].schList.push(sch_temp);
  1598. s_t = e_t;
  1599. }
  1600. }
  1601. }
  1602. DataHandler.mergeData(DataHandler.resultData, result);
  1603. DataHandler.formatSchDataById(data);
  1604. },
  1605. /*
  1606. * 为了提高日程数据的处理效率,减少重复处理,将日程数据格式化为以下形式(作用待评估,暂时保留)
  1607. * {
  1608. * "1234":{日程信息}, //id 为key的日程的信息
  1609. * "1235":{}
  1610. * ... ...
  1611. * }
  1612. */
  1613. formatSchDataById : function(data) {
  1614. var result = {};
  1615. for(var i=0;i<data.length;i++) {
  1616. result[data[i].id] = data[i];
  1617. }
  1618. $.extend(true, DataHandler.resultDataById, result);
  1619. },
  1620. /*
  1621. * 将source中的日程数据合并到target中
  1622. * 基于DataHandler.resultData的数据结构
  1623. */
  1624. mergeData: function (target, source) {
  1625. for(var dailySch in source) {
  1626. if(target[dailySch]) {
  1627. var src = source[dailySch]['schList'];
  1628. var tgt = target[dailySch]['schList'];
  1629. for(var i = 0; i < src.length; ++i) {
  1630. var flag = false;
  1631. for(var j = 0; j < tgt.length; ++j) {
  1632. if(tgt[j].id == src[i].id) {
  1633. tgt[j] = src[i];
  1634. flag = true;
  1635. break;
  1636. }
  1637. }
  1638. if(!flag) {
  1639. tgt.push(src[i]);
  1640. }
  1641. }
  1642. } else {
  1643. target[dailySch] = source[dailySch];
  1644. }
  1645. //对日程排序按开始时间排序
  1646. target[dailySch].schList.sort(function(a, b) {
  1647. if(a.allday_event) return -1;
  1648. if(b.allday_event) return 1;
  1649. var a_stime = calwnl.templates.api_date(a.start_time).getTime();
  1650. var b_stime = calwnl.templates.api_date(b.start_time).getTime();
  1651. return (a_stime - b_stime);
  1652. });
  1653. }
  1654. },
  1655. /*
  1656. * 根据日程id在缓存中删除日程
  1657. */
  1658. delSchById: function(id) {
  1659. for (var dailySch in DataHandler.resultData) {
  1660. var schList = DataHandler.resultData[dailySch]['schList'];
  1661. for (var i = 0; i < schList.length; ++i) {
  1662. if (schList[i].id == id) {
  1663. schList.splice(i, 1);
  1664. --i;
  1665. }
  1666. }
  1667. }
  1668. delete DataHandler.resultDataById[id];
  1669. },
  1670. /*
  1671. * 根据日程id在缓存中更新数据
  1672. * sch : Obj
  1673. * dateScope : Date
  1674. */
  1675. updateSch: function(schList, dateScope) {
  1676. DataHandler.delSchById(schList[0].id);
  1677. DataHandler.formatSchData(schList, dateScope);
  1678. },
  1679. /*
  1680. * 克隆日程
  1681. */
  1682. copySch : function(sch) {
  1683. var t = function() {
  1684. };
  1685. t.prototype = sch;
  1686. return new t();
  1687. }
  1688. };
  1689. //calendarHandler.js
  1690. (function(window){
  1691. /*
  1692. * 私有变量
  1693. */
  1694. var startOnMonday=true,
  1695. reg=/^d(\d{4})-(\d{2})-(\d{2})/,
  1696. r2=/^0/,
  1697. calendarId=null, //当前用户的主日历id
  1698. navDate=null, // 当前月份的第一天
  1699. seletedDate=null, //当前选择的日期
  1700. hoverDate = null, //hover的日期
  1701. schData=null; //用户的日程数据
  1702. /*
  1703. * 私有方法
  1704. */
  1705. var log=function(message){
  1706. },
  1707. //设置NavDate
  1708. setNavDate=function(date){
  1709. if(date instanceof Date)
  1710. navDate=date;
  1711. else
  1712. navDate=null;
  1713. },
  1714. //获取navaDate所在月份的数据,赋值给schData
  1715. getCurrentMonthViewData=function(callback){
  1716. if(navDate){
  1717. DataHandler.getSchByMonth(navDate, function(){
  1718. var monthInfo = CalUtil.monthViewInfo(navDate,startOnMonday);
  1719. var s=monthInfo.start,
  1720. e=monthInfo.end;
  1721. var cld=new Array();
  1722. cld.push(calendarId);
  1723. schData = DataHandler.getSchedulesByRange(s,e,DataHandler.resultData,cld);
  1724. if(callback){
  1725. callback();
  1726. }
  1727. }, startOnMonday);
  1728. }
  1729. },
  1730. //添加日程
  1731. creatSch=function(text,allday,hour,second,callback){
  1732. var sch = {};
  1733. sch.schTitle = text;
  1734. sch.alldayEvent = allday;
  1735. if(allday) {
  1736. sch.startTime = getDateKey(seletedDate) + ' ' + '09:00:00';
  1737. } else {
  1738. hour = hour + "";
  1739. second = second + "";
  1740. sch.startTime = getDateKey(seletedDate) + ' ' + hour.leftpad(2) + ':' + second.leftpad(2) + ":00";
  1741. }
  1742. sch['timeZone'] = - (new Date()).getTimezoneOffset() / 60;
  1743. // dialog内添加的都是简单日程(不重复,不跨天)
  1744. var dateScope = calwnl.date.add(calwnl.templates.api_date(sch.startTime), 1, 'day');
  1745. $.ajax({
  1746. type: 'post',
  1747. data: sch,
  1748. url: '/schedule/update.do',
  1749. success: function(result) {
  1750. for(var i=0;i<result.length;i++)
  1751. {
  1752. var cldObj = result[i];
  1753. DataHandler.formatSchData(cldObj.schlist, dateScope);
  1754. }
  1755. getCurrentMonthViewData(function(){
  1756. for(var key in schData){
  1757. if(key!="maxNum"){
  1758. var num = schData[key].num;
  1759. var k= key.replace(reg,function(all,year,month,date){
  1760. return year+"-"+month.replace(r2,"")+"-"+date.replace(r2,"");
  1761. });
  1762. if(num > 0){
  1763. callback(calwnl.templates.api_date(k));
  1764. }
  1765. }
  1766. }
  1767. });
  1768. },
  1769. dataType: 'json'
  1770. });
  1771. },
  1772. cutByRealLength=function(str,size){
  1773. var totalCount=0;
  1774. var i;
  1775. for(i=0;i<str.length;i++){
  1776. var c=str.charCodeAt(i);
  1777. if((c>=0x0001&&c<=0x007e)||(0xff60<=c&&c<=0xff9f)){
  1778. totalCount++;
  1779. }else{
  1780. totalCount+=2;
  1781. }if(totalCount>=size){
  1782. return str.substring(0,i+1);
  1783. }
  1784. }
  1785. return str;
  1786. };
  1787. var UI={
  1788. //显示日程
  1789. drawSch:function(schList){
  1790. $("#taskList").children().remove();
  1791. var schs = [];
  1792. if(schList.length>0){
  1793. for(var i = 0; i < 3 && i < schList.length; i++){
  1794. var showTxt=cutByRealLength(schList[i].text,10);
  1795. if(showTxt.length<schList[i].text.length){
  1796. showTxt+="...";
  1797. }
  1798. var showTime = "&nbsp;";
  1799. if(! schList[i].allday_event){
  1800. var raw = schList[i].start_time.split(' ')[1].split(':');
  1801. raw.splice(2);
  1802. showTime = raw.join(':') + "&nbsp;";
  1803. }
  1804. //var showTime = schList[i].start_time + schList[i];
  1805. //alert(showTime);
  1806. schs.push("<div class='workitem'>");
  1807. schs.push("<div class='tastWorkDot'></div>");
  1808. if(! schList[i].allday_event){
  1809. schs.push("<div class='taskWorkTime'>" + showTime + "</div>");
  1810. schs.push("<div style='margin-left:5px;'>" + showTxt + "</div>");
  1811. }else{
  1812. schs.push("<div style='margin-left:11px;'>" + showTxt + "</div>");
  1813. }
  1814. schs.push("</div>");
  1815. }
  1816. }
  1817. $("#taskList").html(schs.join(''));
  1818. }
  1819. };
  1820. var calendarHandler={
  1821. init:function(id){
  1822. if(typeof id == 'number')
  1823. calendarId=id;
  1824. else if(typeof id == 'string')
  1825. calendarId=parseInt(id);
  1826. navDate=seletedDate=new Date();
  1827. calwnl.init_templates();
  1828. },
  1829. //根据calendarId变量,判断是否登陆
  1830. isLogin:function(){
  1831. return !!calendarId;
  1832. },
  1833. //dataHandler调用,返回选中的日历id
  1834. getSelectedArray:function(){
  1835. var t=new Array();
  1836. t.push(calendarId);
  1837. return t;
  1838. },
  1839. //准备特定月份的数据
  1840. prepareData4:function(year,month , callback){
  1841. var date=new Date();
  1842. date.setYear(year);
  1843. date.setMonth(month-1);
  1844. date.setDate(1);
  1845. setNavDate(date);
  1846. getCurrentMonthViewData(function(){
  1847. for(var key in schData){
  1848. if(key!="maxNum"){
  1849. var num = schData[key].num;
  1850. var k= key.replace(reg,function(all,year,month,date){
  1851. return year+"-"+month.replace(r2,"")+"-"+date.replace(r2,"");
  1852. });
  1853. if(num > 0){
  1854. var tttt = calwnl.templates.api_date(k);
  1855. callback(tttt);
  1856. }
  1857. }
  1858. }
  1859. //callback();
  1860. });
  1861. },
  1862. //获取seletedDate
  1863. getSelectedDate:function(){
  1864. return seletedDate;
  1865. },
  1866. //设置seletedDate
  1867. setSelectedDate:function(date){
  1868. if(typeof date == "string")
  1869. seletedDate = calwnl.templates.api_date(date);
  1870. else if(date instanceof Date)
  1871. seletedDate = date;
  1872. },
  1873. //获取hoverDate对应的日程数据
  1874. getSch:function(){
  1875. return schData["d"+getDateKey(hoverDate)];
  1876. },
  1877. //添加日程
  1878. addSch:function(text,allday,hour,second,callback){
  1879. creatSch(text,allday,hour,second,callback);
  1880. },
  1881. //显示日程
  1882. drawSch:function(){
  1883. if(this.isLogin()){
  1884. UI.drawSch(this.getSch().schList);
  1885. }
  1886. },
  1887. //设置hoverDate
  1888. setHoverDate:function(date){
  1889. if(typeof date == "string")
  1890. hoverDate = calwnl.templates.api_date(date);
  1891. else if(date instanceof Date)
  1892. hoverDate = date;
  1893. }
  1894. };
  1895. //公开calendarHandler对象
  1896. if(window.calendarHandler){
  1897. window._calendarHandler=window.calendarHandler;
  1898. }
  1899. window.calendarHandler=calendarHandler;
  1900. })(window);