Calendar.js 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465
  1. o2.widget = o2.widget || {};
  2. o2.widget.Calendar = o2.Calendar = new Class({
  3. Implements: [Options, Events],
  4. Extends: o2.widget.Common,
  5. options: {
  6. "style": "default",
  7. "path": o2.session.path+"/widget/$Calendar/" ,
  8. "defaultView": "day", //day, month, year
  9. "baseDate": new Date(),
  10. "secondEnable" : false,
  11. "isTime": false,
  12. "isMulti": false,
  13. "before": null,
  14. "after": null,
  15. "timeOnly": false,
  16. "defaultDate": new Date(),
  17. "beforeCurrent": true,
  18. "range": false,
  19. "rangeNodes": [],
  20. "rangeRule": "asc", //asc + , des -
  21. "target": null
  22. },
  23. initialize: function(node, options){
  24. Locale.use("zh-CHS");
  25. this.setOptions(options);
  26. this.options.defaultTime = ""+this.options.baseDate.getHours()+":"+this.options.baseDate.getMinutes()+":"+this.options.baseDate.getSeconds();
  27. this.path = o2.session.path+"/widget/$Calendar/";
  28. this.cssPath = o2.session.path+"/widget/$Calendar/"+this.options.style+"/css.wcss";
  29. this._loadCss();
  30. // this.options.containerPath = this.path+this.style+"/container.html";
  31. // this.options.dayPath = this.path+this.style+"/day.html";
  32. // this.options.monthPath = this.path+this.style+"/month.html";
  33. // this.options.yearPath = this.path+this.style+"/year.html";
  34. // this.options.timePath = this.path+this.style+"/time.html";
  35. if (!this.options.format){
  36. if (this.options.isTime){
  37. //this.options.format = Locale.get("Date").shortDate + " " + Locale.get("Date").shortTime;
  38. if(this.options.timeOnly){
  39. this.options.format="%H:%M";
  40. }
  41. else{
  42. this.options.format = Locale.get("Date").shortDate + " " + "%H:%M";
  43. }
  44. }else{
  45. this.options.format = Locale.get("Date").shortDate;
  46. }
  47. }
  48. this.options.containerPath = this.options.path+this.options.style+"/container.html";
  49. this.options.dayPath = this.options.path+this.options.style+"/day.html";
  50. this.options.monthPath = this.options.path+this.options.style+"/month.html";
  51. this.options.yearPath = this.options.path+this.options.style+"/year.html";
  52. this.options.timePath = this.options.path+this.options.style+"/time.html";
  53. this.today = new Date();
  54. this.currentView = this.options.defaultView;
  55. this.node = $(node);
  56. this.visible = false;
  57. this.container = this.createContainer();
  58. this.container.inject((this.options.target) || $(document.body));
  59. this.contentTable = this.createContentTable();
  60. this.contentTable.inject(this.contentDateNode);
  61. this.addEvents();
  62. this.container.set({
  63. styles: {
  64. "display": "none",
  65. "opacity": 1
  66. }
  67. });
  68. this.fireEvent("init");
  69. //this.move = true;
  70. //this.containerDrag = new Drag.Move(this.container);
  71. if( layout.mobile ){
  72. this.maskNode = new Element("div.maskNode",{
  73. styles : {
  74. "width": "100%",
  75. "height": "100%",
  76. "opacity": 0.6,
  77. "position": "absolute",
  78. "background-color": "#CCC",
  79. "top": "0px",
  80. "left": "0px",
  81. "z-index" : 150,
  82. "-webkit-user-select": "none",
  83. "-moz-user-select": "none",
  84. "user-select" : "none"
  85. },
  86. events : {
  87. "touchmove" : function(ev){
  88. ev.stopPropagation();
  89. ev.preventDefault();
  90. }
  91. }
  92. }).inject((this.options.target) || $(document.body));
  93. this.container.addEvents({
  94. "touchmove" : function(ev){
  95. ev.stopPropagation();
  96. ev.preventDefault();
  97. },
  98. "touchend" : function(ev){
  99. ev.stopPropagation();
  100. //ev.preventDefault();
  101. }
  102. })
  103. }
  104. },
  105. addEvents: function(){
  106. this.node.addEvent("focus", function(){
  107. this.show();
  108. }.bind(this));
  109. this.node.addEvent("click", function(){
  110. this.show();
  111. }.bind(this));
  112. this.prevNode.addEvent("click", function(){
  113. this.getPrev();
  114. }.bind(this));
  115. this.nextNode.addEvent("click", function(){
  116. this.getNext();
  117. }.bind(this));
  118. this.currentTextNode.addEvent("click", function(){
  119. this.changeView();
  120. }.bind(this));
  121. if( !layout.mobile ){
  122. this.titleNode.addEvent("mousedown", function(){
  123. this.move();
  124. }.bind(this));
  125. this.titleNode.addEvent("mouseup", function(){
  126. this.unmove();
  127. }.bind(this));
  128. }
  129. document.addEvent('mousedown', this.outsideClick.bind(this));
  130. },
  131. move: function(){
  132. this.containerDrag = new Drag.Move(this.container, {
  133. "onDrag": function(e){
  134. if (this.iframe){
  135. var p = this.container.getPosition();
  136. this.iframe.setStyles({
  137. "top": ""+p.y+"px",
  138. "left": ""+p.x+"px"
  139. });
  140. }
  141. }.bind(this)
  142. });
  143. },
  144. unmove: function(){
  145. this.container.removeEvents("mousedown");
  146. this.titleNode.addEvent("mousedown", function(){
  147. this.move();
  148. }.bind(this));
  149. },
  150. changeView: function(){
  151. var view = "day";
  152. switch (this.currentView) {
  153. case "day" :
  154. this.changeViewToMonth();
  155. break;
  156. case "month" :
  157. this.changeViewToYear();
  158. break;
  159. case "year" :
  160. this.changeViewToDay();
  161. break;
  162. case "time" :
  163. this.changeViewToDay();
  164. //this.changeViewToDay();
  165. break;
  166. default :
  167. //nothing;
  168. }
  169. },
  170. changeViewToMonth: function(year){
  171. this.currentView = "month";
  172. if (!this.contentMonthTable){
  173. this.contentMonthTable = this.createContentTable();
  174. this.contentMonthTable.inject(this.contentDateNode);
  175. }
  176. if (this.contentTable) this.contentTable.setStyle("display", "none");
  177. if (this.contentYearTable) this.contentYearTable.setStyle("display", "none");
  178. if (this.contentTimeTable) this.contentTimeTable.setStyle("display", "none");
  179. // if (this.contentMonthTable) this.contentMonthTable.setStyle("display", "block");
  180. if (this.contentMonthTable) this.contentMonthTable.setStyle("display", "table");
  181. var year = (year!=undefined) ? year : this.currentTextNode.retrieve("year");
  182. var month = this.currentTextNode.retrieve("month");
  183. this.showMonth(year, month);
  184. this.fireEvent("changeViewToMonth");
  185. },
  186. changeViewToYear: function(year){
  187. this.currentView = "year";
  188. if (!this.contentYearTable){
  189. this.contentYearTable = this.createContentTable();
  190. this.contentYearTable.inject(this.contentDateNode);
  191. }
  192. if (this.contentTable) this.contentTable.setStyle("display", "none");
  193. if (this.contentMonthTable) this.contentMonthTable.setStyle("display", "none");
  194. if (this.contentTimeTable) this.contentTimeTable.setStyle("display", "none");
  195. // if (this.contentYearTable) this.contentYearTable.setStyle("display", "block");
  196. if (this.contentYearTable) this.contentYearTable.setStyle("display", "table");
  197. this.showYear(year);
  198. this.fireEvent("changeViewToYear");
  199. },
  200. changeViewToDay: function(year, month){
  201. this.currentView = "day";
  202. if (!this.contentTable){
  203. this.contentTable = this.createContentTable();
  204. this.contentTable.inject(this.contentDateNode);
  205. }
  206. if (this.contentMonthTable) this.contentMonthTable.setStyle("display", "none");
  207. if (this.contentYearTable) this.contentYearTable.setStyle("display", "none");
  208. if (this.contentTimeTable) this.contentTimeTable.setStyle("display", "none");
  209. // if (this.contentTable) this.contentTable.setStyle("display", "block");
  210. if (this.contentTable) this.contentTable.setStyle("display", "table");
  211. this.showDay(year, month);
  212. this.showMonthYearButton();
  213. this.fireEvent("changeViewToDay");
  214. },
  215. hideMonthYearButton : function(){
  216. if(this.clearButton_month){
  217. this.clearButton_month.hide();
  218. }
  219. },
  220. showMonthYearButton : function(){
  221. if( this.buttonArea && !this.clearButton_month ){
  222. this.container.setStyle("height","auto");
  223. this.clearButton_month = new Element("div", {"text": "清除"}).inject(this.buttonArea);
  224. this.clearButton_month.addEvent("click", function(){
  225. var t = this.node.get("value");
  226. this.node.set("value", "");
  227. if( t )this.fireEvent("change");
  228. this.fireEvent("clear");
  229. this.hide();
  230. }.bind(this));
  231. this.clearButton_month.setStyles(this.css.calendarMonthActionButton);
  232. }
  233. if(this.clearButton_month){
  234. this.clearButton_month.show();
  235. }
  236. },
  237. getNext: function(){
  238. switch (this.currentView) {
  239. case "time" :
  240. this.getNextDate();
  241. break;
  242. case "day" :
  243. this.getNextDay();
  244. break;
  245. case "month" :
  246. this.getNextMonth();
  247. break;
  248. case "year" :
  249. this.getNextYear();
  250. break;
  251. default :
  252. //nothing
  253. }
  254. },
  255. getPrev: function(){
  256. switch (this.currentView) {
  257. case "time" :
  258. this.getPrevDate();
  259. break;
  260. case "day" :
  261. this.getPrevDay();
  262. break;
  263. case "month" :
  264. this.getPrevMonth();
  265. break;
  266. case "year" :
  267. this.getPrevYear();
  268. break;
  269. default :
  270. //nothing
  271. }
  272. },
  273. getNextDate: function(){
  274. var date = this.currentTextNode.retrieve("date");
  275. // var year = this.currentTextNode.retrieve("year");
  276. // var month = this.currentTextNode.retrieve("month");
  277. // month--;
  278. // var day = this.currentTextNode.retrieve("day");
  279. // var date = new Date(year, month, day);
  280. date.increment("day", 1);
  281. this._setTimeTitle(null, date);
  282. },
  283. getPrevDate: function(){
  284. var date = this.currentTextNode.retrieve("date");
  285. date.increment("day", -1);
  286. this._setTimeTitle(null, date);
  287. },
  288. getNextDay: function(){
  289. var year = this.currentTextNode.retrieve("year");
  290. var month = this.currentTextNode.retrieve("month");
  291. month--;
  292. var date = new Date(year, month, 1);
  293. date.increment("month", 1);
  294. var thisYear = date.getFullYear();
  295. var thisMonth = date.getMonth();
  296. this._setDayTitle(null, thisYear, thisMonth);
  297. this._setDayDate(null,thisYear, thisMonth);
  298. this.fireEvent("changeViewToDay");
  299. },
  300. getPrevDay: function(){
  301. var year = this.currentTextNode.retrieve("year");
  302. var month = this.currentTextNode.retrieve("month");
  303. month--;
  304. var date = new Date(year, month, 1);
  305. date.increment("month", -1)
  306. var thisYear = date.getFullYear();
  307. var thisMonth = date.getMonth();
  308. this._setDayTitle(null, thisYear, thisMonth);
  309. this._setDayDate(null,thisYear, thisMonth);
  310. this.fireEvent("changeViewToDay");
  311. },
  312. getNextMonth: function(){
  313. var year = this.currentTextNode.retrieve("year");
  314. var date = new Date(year, 1, 1);
  315. date.increment("year", 1)
  316. var thisYear = date.getFullYear();
  317. this.showMonth(thisYear);
  318. this.fireEvent("changeViewToMonth");
  319. },
  320. getPrevMonth: function(){
  321. var year = this.currentTextNode.retrieve("year");
  322. var date = new Date(year, 1, 1);
  323. date.increment("year", -1)
  324. var thisYear = date.getFullYear();
  325. this.showMonth(thisYear);
  326. this.fireEvent("changeViewToMonth");
  327. },
  328. getNextYear: function(){
  329. var year = this.currentTextNode.retrieve("year");
  330. var date = new Date(year, 1, 1);
  331. date.increment("year", this.yearLength)
  332. var thisYear = date.getFullYear();
  333. this.showYear(thisYear);
  334. this.fireEvent("changeViewToYear");
  335. },
  336. getPrevYear: function(){
  337. var year = this.currentTextNode.retrieve("year");
  338. var date = new Date(year, 1, 1);
  339. date.increment("year", 0-this.yearLength)
  340. var thisYear = date.getFullYear();
  341. this.showYear(thisYear);
  342. this.fireEvent("changeViewToYear");
  343. },
  344. outsideClick: function(e) {
  345. if(this.visible) {
  346. var elementCoords = this.container.getCoordinates();
  347. var targetCoords = this.node.getCoordinates();
  348. if(((e.page.x < elementCoords.left || e.page.x > (elementCoords.left + elementCoords.width)) ||
  349. (e.page.y < elementCoords.top || e.page.y > (elementCoords.top + elementCoords.height))) &&
  350. ((e.page.x < targetCoords.left || e.page.x > (targetCoords.left + targetCoords.width)) ||
  351. (e.page.y < targetCoords.top || e.page.y > (targetCoords.top + targetCoords.height))) ) this.hide();
  352. }
  353. },
  354. hide: function(){
  355. if (this.visible){
  356. // if (!this.morph){
  357. // this.morph = new Fx.Morph(this.container, {"duration": 200});
  358. // }
  359. this.visible = false;
  360. // this.changeViewToDay();
  361. // this.morph.start({"opacity": 0}).chain(function(){
  362. this.container.setStyle("display", "none");
  363. if (this.iframe) this.iframe.destroy();
  364. if (layout.desktop.offices){
  365. Object.each(layout.desktop.offices, function(office){
  366. office.show();
  367. });
  368. }
  369. if( this.maskNode ){
  370. this.maskNode.hide();
  371. }
  372. // }.bind(this));
  373. this.fireEvent("hide");
  374. }
  375. },
  376. show: function(){
  377. ;
  378. if (!this.visible){
  379. var dStr = this.node.get("value");
  380. if (dStr && Date.isValid(dStr)){
  381. this.options.baseDate = Date.parse(dStr.substr(0,10));
  382. }
  383. if(this.options.timeOnly){
  384. this.currentView = "time";
  385. }
  386. else{
  387. this.currentView = this.options.defaultView;
  388. }
  389. switch (this.currentView) {
  390. case "day" :
  391. this.changeViewToDay();
  392. break;
  393. case "month" :
  394. this.showMonth();
  395. break;
  396. case "year" :
  397. this.showYear();
  398. break;
  399. case "time" :
  400. //this.showTime(this.options.baseDate);
  401. this.changeViewToTime(this.options.defaultDate);
  402. //this.changeViewToTime(this.options.baseDate);
  403. break;
  404. default :
  405. this.showDay();
  406. }
  407. // if (!this.morph){
  408. // this.morph = new Fx.Morph(this.container, {"duration": 200});
  409. // }
  410. this.container.setStyle("display", "block");
  411. if (this.container.position ){
  412. this.container.position({
  413. relativeTo: this.node,
  414. position: 'bottomLeft',
  415. edge: 'upperLeft'
  416. });
  417. // var offsetPNode = this.node.getOffsetParent();
  418. var cp = this.container.getPosition(this.options.target || null);
  419. var cSize = this.container.getSize();
  420. //var fp = (this.options.target) ? this.options.target.getPosition() : $(document.body).getPosition()
  421. var fsize = (this.options.target) ? this.options.target.getSize() : $(document.body).getSize();
  422. //if (cp.y+cSize.y>fsize.y+fp.y){
  423. if (cp.y+cSize.y>fsize.y){
  424. this.container.position({
  425. relativeTo: this.node,
  426. position: 'upperLeft',
  427. edge: 'bottomLeft'
  428. });
  429. }
  430. }else{
  431. var p = this.node.getPosition(this.options.target || null);
  432. var size = this.node.getSize();
  433. var containerSize = this.container.getSize();
  434. var bodySize = $(document.body).getSize();
  435. var left = p.x;
  436. if ((left + containerSize.x) > bodySize.x){
  437. left = bodySize.x - containerSize.x;
  438. }
  439. this.container.setStyle("top", p.y+size.y+2);
  440. this.container.setStyle("left", left);
  441. }
  442. // var p = this.container.getPosition();
  443. // var s = this.container.getSize();
  444. // var zidx = this.container.getStyle("z-index");
  445. // this.iframe = new Element("iframe", {"styles":{
  446. // "border": "0px",
  447. // "margin": "0px",
  448. // "padding": "0px",
  449. // "opacity": 0,
  450. // "z-index": (zidx) ? zidx-1 : 0,
  451. // "top": ""+p.y+"px",
  452. // "left": ""+p.x+"px",
  453. // "width": ""+s.x+"px",
  454. // "height": ""+s.y+"px",
  455. // "position": "absolute"
  456. // }}).inject(this.container, "before");
  457. if (layout.desktop.offices){
  458. Object.each(layout.desktop.offices, function(office){
  459. if (this.container.isOverlap(office.officeNode)){
  460. office.hide();
  461. }
  462. }.bind(this));
  463. }
  464. if( this.maskNode ){
  465. this.maskNode.show();
  466. }
  467. // this.morph.start({"opacity": 1}).chain(function(){
  468. this.visible = true;
  469. // }.bind(this));
  470. this.fireEvent("show");
  471. }
  472. },
  473. showYear: function(year){
  474. var thisYear = (year!=undefined) ? year : this.options.baseDate.getFullYear();
  475. var date = new Date(thisYear, 1, 1);
  476. date.increment("year", -2);
  477. var beginYear = date.getFullYear();
  478. date.increment("year", this.yearLength-1);
  479. var endYear = date.getFullYear();
  480. this._setYearTitle(null, beginYear, endYear, thisYear);
  481. this._setYearDate(null, beginYear, endYear, thisYear);
  482. this.showMonthYearButton();
  483. // if (!this.move){
  484. // this.move = true;
  485. // this.containerDrag = new Drag.Move(this.container);
  486. // }
  487. },
  488. _setYearTitle:function(node, beginYear, endYear, thisYear){
  489. var thisNode = node || this.currentTextNode;
  490. thisNode.set("text", beginYear+"-"+endYear);
  491. thisNode.store("year", thisYear);
  492. },
  493. _setYearDate: function(table, beginYear, endYear, year){
  494. var yearTable = table || this.contentYearTable;
  495. var thisYear = (year!=undefined) ? year : this.options.baseDate.getFullYear();
  496. var tbody = yearTable.getElement("tbody");
  497. var tds = tbody.getElements("td");
  498. tds.each(function(item, idx){
  499. var y = beginYear+idx;
  500. item.set("text", y);
  501. item.store("year", y);
  502. if (y==this.options.baseDate.getFullYear()){
  503. item.addClass("current_"+this.options.style);
  504. }else{
  505. item.removeClass("current_"+this.options.style);
  506. }
  507. }.bind(this));
  508. },
  509. showMonth: function(year, month){
  510. var thisYear = (year!=undefined) ? year : this.options.baseDate.getFullYear();
  511. var thisMonth = (month!=undefined) ? month : this.options.baseDate.getMonth();
  512. this._setMonthTitle(null, thisYear, thisMonth);
  513. this._setMonthDate(null, thisYear, thisMonth);
  514. this.showMonthYearButton();
  515. // if (!this.move){
  516. // this.move = true;
  517. // this.containerDrag = new Drag.Move(this.container);
  518. // }
  519. },
  520. _setMonthTitle:function(node, year){
  521. var thisYear = (year!=undefined) ? year : this.options.baseDate.getFullYear();
  522. var thisNode = node || this.currentTextNode;
  523. thisNode.set("text", thisYear);
  524. thisNode.store("year", thisYear);
  525. },
  526. _setMonthDate: function(table, year, month){
  527. //var months = Locale.get("Date").months;
  528. var months = o2.LP.widget.months;
  529. var monthTable = table || this.contentMonthTable;
  530. var thisYear = (year!=undefined) ? year : this.options.baseDate.getFullYear();
  531. var thisMonth = (month!=undefined) ? month : this.options.baseDate.getMonth();
  532. var tbody = monthTable.getElement("tbody");
  533. var tds = tbody.getElements("td");
  534. tds.each(function(item, idx){
  535. item.set("text", months[idx].substr(0,2));
  536. item.store("year", thisYear);
  537. item.store("month", idx);
  538. if ((thisYear==this.options.baseDate.getFullYear()) && (idx==this.options.baseDate.getMonth())){
  539. item.addClass("current_"+this.options.style);
  540. }else{
  541. item.removeClass("current_"+this.options.style);
  542. }
  543. }.bind(this));
  544. },
  545. showDay: function(year, month){
  546. this._setDayTitle(null, year, month);
  547. this._setDayWeekTitleTh();
  548. this._setDayDate(null, year, month);
  549. // if (!this.move){
  550. // this.move = true;
  551. // this.containerDrag = new Drag.Move(this.container);
  552. // }
  553. },
  554. _setDayTitle: function(node, year, month){
  555. var thisYear = (year!=undefined) ? year : this.options.baseDate.getFullYear();
  556. var thisMonth = (month!=undefined) ? month : this.options.baseDate.getMonth();
  557. thisMonth++;
  558. var text = thisYear+"年"+thisMonth+"月";
  559. var thisNode = node || this.currentTextNode;
  560. thisNode.set("text", text);
  561. thisNode.store("year", thisYear);
  562. thisNode.store("month", thisMonth);
  563. },
  564. _setDayDate: function(table, year, month){
  565. var dayTable = table || this.contentTable;
  566. var baseDate = this.options.baseDate;
  567. if ((year!=undefined) && (month!=undefined)){
  568. baseDate = new Date();
  569. baseDate.setDate(1);
  570. baseDate.setFullYear(year);
  571. baseDate.setMonth(month);
  572. }
  573. var tbody = dayTable.getElement("tbody");
  574. var tds = tbody.getElements("td");
  575. var firstDate = baseDate.clone();
  576. firstDate.setDate(1);
  577. var day = firstDate.getDay();
  578. var tmpDate = firstDate.clone();
  579. for (var i=day-1; i>=0; i--){
  580. tmpDate.increment("day", -1);
  581. tds[i].set("text", tmpDate.getDate());
  582. tds[i].addClass("gray_"+this.options.style);
  583. tds[i].setStyles(this.css["gray_"+this.options.style]);
  584. tds[i].store("dateValue", tmpDate.toString())
  585. }
  586. for (var i=day; i<tds.length; i++){
  587. tds[i].set("text", firstDate.getDate());
  588. if (firstDate.toString() == this.options.baseDate.toString()){
  589. tds[i].addClass("current_"+this.options.style);
  590. tds[i].setStyles(this.css["current_"+this.options.style]);
  591. tds[i].removeClass("past_"+this.options.style);
  592. tds[i].removeClass("gray_"+this.options.style);
  593. tds[i].setStyle("border", "1px solid #FFF");
  594. }else if (firstDate.getMonth()!=baseDate.getMonth()){
  595. tds[i].addClass("gray_"+this.options.style);
  596. tds[i].setStyles(this.css["gray_"+this.options.style]);
  597. tds[i].removeClass("current_"+this.options.style);
  598. tds[i].removeClass("past_"+this.options.style);
  599. tds[i].setStyle("border", "1px solid #FFF");
  600. }else{
  601. tds[i].setStyles(this.css["normal_"+this.options.style]);
  602. tds[i].removeClass("current_"+this.options.style);
  603. tds[i].removeClass("gray_"+this.options.style);
  604. tds[i].removeClass("past_"+this.options.style);
  605. tds[i].setStyle("border", "1px solid #FFF");
  606. }
  607. var tmp = firstDate.clone();
  608. if (tmp.clearTime().toString() == this.today.clearTime().toString()){
  609. tds[i].addClass("today_"+this.options.style);
  610. tds[i].removeClass("past_"+this.options.style);
  611. tds[i].setStyles(this.css["today_"+this.options.style]);
  612. tds[i].setStyle("border", "0px solid #AAA");
  613. }
  614. if (tmp.diff(this.today)>0){
  615. if (this.css["past_"+this.options.style]) tds[i].setStyles(this.css["past_"+this.options.style]);
  616. tds[i].addClass("past_"+this.options.style);
  617. }
  618. tds[i].store("dateValue", firstDate.toString())
  619. firstDate.increment("day", 1);
  620. }
  621. },
  622. changeViewToTime: function(date){
  623. this.currentView = "time";
  624. if (!this.contentTimeTable){
  625. this.contentTimeTable = this.createContentTable();
  626. this.contentTimeTable.inject(this.contentDateNode);
  627. }
  628. if (this.contentTable) this.contentTable.setStyle("display", "none");
  629. if (this.contentYearTable) this.contentYearTable.setStyle("display", "none");
  630. if (this.contentMonthTable) this.contentMonthTable.setStyle("display", "none");
  631. if (this.contentTimeTable) this.contentTimeTable.setStyle("display", "block");
  632. // if (this.contentTimeTable) this.contentTimeTable.setStyle("display", "table");
  633. var thisDate = date || this.options.baseDate;
  634. this.showTime(thisDate);
  635. this.hideMonthYearButton();
  636. },
  637. showTime: function(date){
  638. var thisHour = (date || this.options.baseDate).getHours();
  639. var thisMinutes = (date || this.options.baseDate).getMinutes();
  640. var thisSeconds = (date || this.options.baseDate).getSeconds();
  641. // var times = this.options.defaultTime.split(":");
  642. //
  643. // var thisHour = (times[0]) ? times[0] : "0";
  644. // var thisMinutes = (times[1]) ? times[1] : "0";
  645. // var thisSeconds = (times[2]) ? times[2] : "0";
  646. this._setTimeTitle(null, date);
  647. if( this.options.style.indexOf("mobile") > -1 ){
  648. this._setTimeDate_mobile(null, thisHour, thisMinutes, thisSeconds);
  649. }else{
  650. this._setTimeDate(null, thisHour, thisMinutes, thisSeconds);
  651. }
  652. // if (this.move){
  653. // this.move = false;
  654. // this.container.removeEvents("mousedown");
  655. // }
  656. },
  657. _setTimeTitle: function(node, date){
  658. var thisDate = date || this.options.baseDate;
  659. var thisNode = node || this.currentTextNode;
  660. var y = thisDate.getFullYear();
  661. var m = thisDate.getMonth()+1;
  662. var d = thisDate.getDate();
  663. var text = "" + y + "年" + m + "月" + d + "日";
  664. if (this.options.timeOnly){
  665. thisNode.hide();
  666. if (this.prevNode) this.prevNode.hide();
  667. if (this.nextNode) this.nextNode.hide();
  668. }
  669. thisNode.set("text", text);
  670. thisNode.store("date", date);
  671. },
  672. _setTimeDate_mobile: function(node, h, m, s){
  673. var _self = this;
  674. this.itmeHNode = this.contentTimeTable.getElement(".MWF_calendar_time_h");
  675. this.itmeMNode = this.contentTimeTable.getElement(".MWF_calendar_time_m");
  676. this.itmeSNode = this.contentTimeTable.getElement(".MWF_calendar_time_s");
  677. this.showActionNode = this.contentTimeTable.getElement(".MWF_calendar_action_show");
  678. var calendar = this;
  679. if( !this.hMobileSelect ){
  680. for( var i=0; i<24; i++ ){
  681. new Element("div",{
  682. "text" : this.addZero(i, 2 ),
  683. "styles" : this.css.calendarTimeSelectItem_mobile
  684. }).inject( this.itmeHNode );
  685. }
  686. this.selectedHour = this.addZero(h, 2 );
  687. this.hMobileSelect = new o2.Calendar.MobileSelect( this.itmeHNode.getParent(), {
  688. "lineHeight" : 40,
  689. "itemSize" : 24,
  690. "itemIndex" : parseInt(h),
  691. "onChange": function(value){
  692. this.selectedHour = this.addZero(value, 2 );
  693. //this.showHNode.set("text", this.addZero(i, 2 ));
  694. //this.itmeHNode.getFirst().set("text", this.addZero(i, 2 ));
  695. }.bind(this)
  696. });
  697. this.hMobileSelect.load();
  698. }
  699. if( !this.mMobileSelect ) {
  700. for (var i = 0; i < 60; i++) {
  701. new Element("div", {
  702. "text": this.addZero(i, 2),
  703. "styles": this.css.calendarTimeSelectItem_mobile
  704. }).inject(this.itmeMNode);
  705. }
  706. this.selectedMinute = this.addZero(m, 2);
  707. this.mMobileSelect = new o2.Calendar.MobileSelect(this.itmeMNode.getParent(), {
  708. "lineHeight": 40,
  709. "itemSize": 60,
  710. "itemIndex": parseInt(m),
  711. "onChange": function (value) {
  712. this.selectedMinute = this.addZero(value, 2);
  713. //this.showHNode.set("text", this.addZero(i, 2 ));
  714. //this.itmeHNode.getFirst().set("text", this.addZero(i, 2 ));
  715. }.bind(this)
  716. });
  717. this.mMobileSelect.load();
  718. }
  719. if(this.options.secondEnable ){
  720. if(!this.sMobileSelect){
  721. for( var i=0; i<60; i++ ){
  722. new Element("div",{
  723. "text" : this.addZero(i, 2 ),
  724. "styles" : this.css.calendarTimeSelectItem_mobile
  725. }).inject( this.itmeSNode );
  726. }
  727. this.selectedSecond = this.addZero(s, 2 );
  728. this.sMobileSelect = new o2.Calendar.MobileSelect( this.itmeSNode.getParent(), {
  729. "lineHeight" : 40,
  730. "itemSize" : 60,
  731. "itemIndex" : parseInt(s),
  732. "onChange": function(value){
  733. this.selectedSecond = this.addZero(value, 2 );
  734. //this.showHNode.set("text", this.addZero(i, 2 ));
  735. //this.itmeHNode.getFirst().set("text", this.addZero(i, 2 ));
  736. }.bind(this)
  737. });
  738. this.sMobileSelect.load();
  739. }
  740. }else{
  741. this.itmeSNode.hide();
  742. }
  743. if( this.options.secondEnable ){
  744. this.contentTimeTable.getElements(".calendarTimeWheel_mobile").setStyle("width","33.3%");
  745. }else{
  746. this.contentTimeTable.getElements(".calendarTimeWheel_mobile").setStyle("width","50%");
  747. }
  748. if( this.options.secondEnable && this.showSNode ){
  749. this.showSNode.set("text", this.addZero( s.toInt(), 2) );
  750. }
  751. if (!this.okButton){
  752. this.okButton = new Element("button", {"text": "确定"}).inject(this.showActionNode);
  753. this.okButton.addEvent("click", function(){
  754. this._selectTime();
  755. this.hide();
  756. }.bind(this));
  757. this.okButton.setStyles(this.css.calendarActionShowButton_mobile_ok);
  758. }
  759. if (!this.clearButton){
  760. this.clearButton = new Element("button", {"text": "清除"}).inject(this.showActionNode);
  761. this.clearButton.addEvent("click", function(){
  762. var t = this.node.get("value");
  763. this.node.set("value", "");
  764. if( t )this.fireEvent("change");
  765. this.fireEvent("clear");
  766. this.hide();
  767. }.bind(this));
  768. this.clearButton.setStyles(this.css.calendarActionShowButton_mobile_cancel);
  769. }
  770. },
  771. _setTimeDate: function(node, h, m, s){
  772. if( !this.options.secondEnable ){
  773. var div = this.contentTimeTable.getElement(".MWF_calendar_time_s");
  774. if( div )div.hide();
  775. div = this.contentTimeTable.getElement(".MWF_calendar_time_show_s");
  776. if( div )div.hide();
  777. }
  778. this.itmeHNode = this.contentTimeTable.getElement(".MWF_calendar_time_h_slider");
  779. this.itmeMNode = this.contentTimeTable.getElement(".MWF_calendar_time_m_slider");
  780. this.itmeSNode = this.contentTimeTable.getElement(".MWF_calendar_time_s_slider");
  781. this.timeShowNode = this.contentTimeTable.getElement(".MWF_calendar_time_show");
  782. this.timeShowNode.addEvent("click", function(){
  783. this._selectTime();
  784. }.bind(this));
  785. this.showHNode = this.contentTimeTable.getElement(".MWF_calendar_time_show_h");
  786. this.showMNode = this.contentTimeTable.getElement(".MWF_calendar_time_show_m");
  787. this.showSNode = this.contentTimeTable.getElement(".MWF_calendar_time_show_s");
  788. this.showActionNode = this.contentTimeTable.getElement(".MWF_calendar_action_show");
  789. var calendar = this;
  790. if ( COMMON.Browser.Platform.isMobile ){
  791. //this.itmeHNode.empty();
  792. //this.itmeHNode.removeClass("calendarTimeSlider");
  793. //this.itmeHNode.setStyles(this.css.calendarTimeSliderNoStyle);
  794. //var sel = new Element("select").inject(this.itmeHNode);
  795. //for (i=0; i<=23; i++){
  796. // var v = (i<10) ? "0"+i: i;
  797. // var o = new Element("option", {
  798. // "value": v,
  799. // "text": v
  800. // }).inject(sel);
  801. // if (h==i) o.set("selected", true);
  802. //}
  803. //sel.addEvent("change", function(){
  804. // calendar.showHNode.set("text", this.options[this.selectedIndex].get("value"));
  805. //});
  806. //this.showHNode.set("text", sel.options[sel.selectedIndex].get("value"));
  807. //
  808. //this.itmeMNode.empty();
  809. //this.itmeMNode.removeClass("calendarTimeSlider");
  810. //this.itmeMNode.setStyles(this.css.calendarTimeSliderNoStyle);
  811. //sel = new Element("select").inject(this.itmeMNode);
  812. //for (i=0; i<=59; i++){
  813. // var v = (i<10) ? "0"+i: i;
  814. // var o = new Element("option", {
  815. // "value": v,
  816. // "text": v
  817. // }).inject(sel);
  818. // if (m==i) o.set("selected", true);
  819. //}
  820. //sel.addEvent("change", function(){
  821. // calendar.showMNode.set("text", this.options[this.selectedIndex].get("value"));
  822. //});
  823. //this.showMNode.set("text", sel.options[sel.selectedIndex].get("value"));
  824. }else{
  825. var hSlider = new Slider(this.itmeHNode, this.itmeHNode.getFirst(), {
  826. range: [0, 23],
  827. initialStep: h.toInt(),
  828. onChange: function(value){
  829. var tmp = (value.toInt().toString());
  830. if (tmp.length<2){
  831. tmp = "0"+tmp
  832. }
  833. this.showHNode.set("text", tmp);
  834. this.itmeHNode.getFirst().set("text", tmp);
  835. }.bind(this)
  836. });
  837. this.itmeHNode.getFirst().set("text", h);
  838. var mSlider = new Slider(this.itmeMNode, this.itmeMNode.getFirst(), {
  839. range: [0, 59],
  840. initialStep: m.toInt(),
  841. onChange: function(value){
  842. var tmp = (value.toInt().toString());
  843. if (tmp.length<2){
  844. tmp = "0"+tmp
  845. }
  846. this.showMNode.set("text", tmp);
  847. this.itmeMNode.getFirst().set("text", tmp);
  848. }.bind(this)
  849. });
  850. this.itmeMNode.getFirst().set("text", m);
  851. if( this.options.secondEnable && this.itmeSNode ){
  852. var sSlider = new Slider(this.itmeSNode, this.itmeSNode.getFirst(), {
  853. range: [0, 59],
  854. initialStep: parseInt(s),
  855. onChange: function(value){
  856. var tmp = (value.toInt().toString());
  857. if (tmp.length<2){
  858. tmp = "0"+tmp
  859. }
  860. this.showSNode.set("text", tmp);
  861. this.itmeSNode.getFirst().set("text", tmp);
  862. }.bind(this)
  863. });
  864. this.itmeSNode.getFirst().set("text", s);
  865. }
  866. }
  867. this.showHNode.set("text", this.addZero( h.toInt(), 2) );
  868. this.showMNode.set("text", this.addZero( m.toInt(), 2));
  869. if( this.options.secondEnable && this.showSNode ){
  870. this.showSNode.set("text", this.addZero( s.toInt(), 2) );
  871. }
  872. if (!this.okButton){
  873. this.okButton = new Element("button", {"text": "确定"}).inject(this.showActionNode);
  874. this.okButton.addEvent("click", function(){
  875. this._selectTime();
  876. this.hide();
  877. }.bind(this));
  878. this.okButton.setStyles(this.css.calendarActionShowButton);
  879. }
  880. if (!this.clearButton){
  881. this.clearButton = new Element("button", {"text": "清除"}).inject(this.showActionNode);
  882. this.clearButton.addEvent("click", function(){
  883. var t = this.node.get("value");
  884. this.node.set("value", "");
  885. if( t )this.fireEvent("change");
  886. this.fireEvent("clear");
  887. this.hide();
  888. }.bind(this));
  889. this.clearButton.setStyles(this.css.calendarActionShowButton);
  890. }
  891. },
  892. addZero : function( str, length ){
  893. var zero = "";
  894. str = str.toString();
  895. for( var i=0; i<length; i++ ){
  896. zero = zero + "0";
  897. }
  898. var s = zero + str;
  899. return s.substr(s.length - length, length );
  900. },
  901. _selectTime: function(){
  902. var date = this.currentTextNode.retrieve("date");
  903. var h = this.selectedHour || this.showHNode.get("text");
  904. var m = this.selectedMinute || this.showMNode.get("text");
  905. date.setHours(h);
  906. date.setMinutes(m);
  907. if( this.options.secondEnable && ( this.selectedSecond || this.showSNode) ){
  908. var s = this.selectedSecond || this.showSNode.get("text");
  909. date.setSeconds(s);
  910. }
  911. if (!this.options.beforeCurrent){
  912. var now = new Date();
  913. if (date.getTime()-now.getTime()<0){
  914. alert("选择的日期必须大于当前日期!");
  915. this.node.focus();
  916. return false;
  917. }
  918. }
  919. var dv = date.format(this.options.format);
  920. if (this.fireEvent("queryComplate", [dv, date])){
  921. var t = this.node.get("value");
  922. this.options.defaultTime = ""+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
  923. this.node.set("value", dv);
  924. // this.node.focus();
  925. this.hide();
  926. if (t!=dv) this.fireEvent("change", [dv, date, t]);
  927. this.fireEvent("complate", [dv, date]);
  928. }
  929. },
  930. _selectDate: function(dateStr){
  931. var date = new Date(dateStr);
  932. this.options.baseDate = date;
  933. var dv = date.format(this.options.format);
  934. if (this.options.isTime){
  935. this.changeViewToTime(date);
  936. }else{
  937. if (!this.options.beforeCurrent){
  938. var now = new Date();
  939. date.setHours(23,59,59);
  940. if (date.getTime()-now.getTime()<0){
  941. alert("选择的日期必须大于当前日期!");
  942. this.node.focus();
  943. return false;
  944. }
  945. }
  946. if (this.fireEvent("queryComplate", [dv, date])){
  947. var t = this.node.get("value");
  948. this.node.set("value", dv);
  949. this.hide();
  950. if (t!=dv) this.fireEvent("change", [dv, date, t]);
  951. this.fireEvent("complate", [dv, date, t]);
  952. }
  953. }
  954. },
  955. _setDayWeekTitleTh: function(table){
  956. var dayTable = table || this.contentTable;
  957. var thead = dayTable.getElement("thead");
  958. var cells = thead.getElements("th");
  959. if (this.css.calendarDaysContentTh) cells.setStyles(this.css.calendarDaysContentTh);
  960. //var days_abbr = Locale.get("Date").days_abbr;
  961. var days_abbr = o2.LP.widget.days_abbr;
  962. cells.each(function(item, idx){
  963. item.set("text", days_abbr[idx]);
  964. });
  965. return cells;
  966. },
  967. createContainer: function(){
  968. var div = null;
  969. var request = new Request.HTML({
  970. url: this.options.containerPath,
  971. method: "GET",
  972. async: false,
  973. onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
  974. div = responseTree[0];
  975. }
  976. });
  977. request.send();
  978. //this.containerNode = div.getElement(".MWF_calendar_container");
  979. this.titleNode = div.getElement(".MWF_calendar_title");
  980. this.prevNode = div.getElement(".MWF_calendar_prev");
  981. this.currentNode = div.getElement(".MWF_calendar_current");
  982. this.currentTextNode = div.getElement(".MWF_calendar_currentText");
  983. this.nextNode = div.getElement(".MWF_calendar_next");
  984. this.contentNode = div.getElement(".MWF_calendar_content");
  985. this.contentDateNode = div.getElement(".MWF_calendar_content_date");
  986. this.contentTimeNode = div.getElement(".MWF_calendar_content_time");
  987. this.buttonArea = div.getElement(".MWF_calendar_button_area");
  988. this.bottomNode = div.getElement(".MWF_calendar_bottom");
  989. div.setStyles(this.css.container);
  990. this.titleNode.setStyles(this.css.dateTitle);
  991. this.prevNode.setStyles(this.css.datePrev);
  992. this.currentNode.setStyles(this.css.dateCurrent);
  993. this.currentTextNode.setStyles(this.css.dateCurrentText);
  994. this.nextNode.setStyles(this.css.dateNext);
  995. this.contentNode.setStyles(this.css.calendarContent);
  996. if(this.buttonArea)this.buttonArea.setStyles(this.css.buttonArea);
  997. this.bottomNode.setStyles(this.css.dateBottom);
  998. return div;
  999. },
  1000. createContentTable: function(){
  1001. var table = null;
  1002. var request = new Request.HTML({
  1003. url: this.options[this.currentView+"Path"],
  1004. method: "GET",
  1005. async: false,
  1006. onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
  1007. table = responseTree[0];
  1008. }
  1009. });
  1010. request.send();
  1011. var tbody = table.getElement("tbody");
  1012. if (tbody){
  1013. var tds = tbody.getElements("td");
  1014. var calendar = this;
  1015. tds.addEvent("click", function(){
  1016. switch (calendar.currentView) {
  1017. case "day" :
  1018. calendar._selectDate(this.retrieve("dateValue"), this);
  1019. break;
  1020. case "month" :
  1021. calendar.changeViewToDay(this.retrieve("year"), this.retrieve("month"));
  1022. break;
  1023. case "year" :
  1024. calendar.changeViewToMonth(this.retrieve("year"));
  1025. break;
  1026. case "time" :
  1027. //nothing
  1028. break;
  1029. default :
  1030. //nothing;
  1031. }
  1032. });
  1033. switch (this.currentView) {
  1034. case "day" :
  1035. if (!table.display) table.display="";
  1036. if (!table.style.display) table.style.display="";
  1037. table.setStyles(this.css.calendarDaysContent);
  1038. tds.setStyles(this.css.calendarDaysContentTd);
  1039. break;
  1040. case "month" :
  1041. table.setStyles(this.css.calendarMonthsContent);
  1042. tds.setStyles(this.css.calendarMonthsContentTd);
  1043. break;
  1044. case "year" :
  1045. this.yearLength = tds.length;
  1046. table.setStyles(this.css.calendarYearsContent);
  1047. tds.setStyles(this.css.calendarYearsContentTd);
  1048. break;
  1049. case "time" :
  1050. if( this.options.style.indexOf("mobile") > -1 ){
  1051. var nodes = table.getElements(".calendarTimeContent_mobile");
  1052. if (nodes.length) nodes.setStyles(this.css.calendarTimeContent_mobile);
  1053. nodes = table.getElements(".calendarTimeFixWidthNode_mobile");
  1054. if (nodes.length) nodes.setStyles(this.css.calendarTimeFixWidthNode_mobile);
  1055. nodes = table.getElements(".calendarTimeWheels_mobile");
  1056. if (nodes.length) nodes.setStyles(this.css.calendarTimeWheels_mobile);
  1057. nodes = table.getElements(".calendarTimeWheel_mobile");
  1058. if (nodes.length) nodes.setStyles(this.css.calendarTimeWheel_mobile);
  1059. nodes = table.getElements(".calendarTimeSelectContainer_mobile");
  1060. if (nodes.length) nodes.setStyles(this.css.calendarTimeSelectContainer_mobile);
  1061. nodes = table.getElements(".calendarTimeSelectLine_mobile");
  1062. if (nodes.length) nodes.setStyles(this.css.calendarTimeSelectLine_mobile);
  1063. nodes = table.getElements(".calendarTimeShadowMask_mobile");
  1064. if (nodes.length) nodes.setStyles(this.css.calendarTimeShadowMask_mobile);
  1065. var node = table.getElement(".MWF_calendar_action_show");
  1066. if (node){
  1067. node.setStyles(this.css.calendarActionShow);
  1068. //var buttons = node.getElements("button");
  1069. //buttons.setStyles(this.css.calendarActionShowButton);
  1070. }
  1071. }else{
  1072. var nodes = table.getElements(".calendarTimeArea");
  1073. if (nodes.length) nodes.setStyles(this.css.calendarTimeArea);
  1074. nodes = table.getElements(".calendarTimeSlider");
  1075. if (nodes.length) nodes.setStyles(this.css.calendarTimeSlider);
  1076. nodes = table.getElements(".calendarTimeSliderKnob");
  1077. if (nodes.length) nodes.setStyles(this.css.calendarTimeSliderKnob);
  1078. nodes = table.getElements(".calendarTimeShow");
  1079. if (nodes.length) nodes.setStyles(this.css.calendarTimeShow);
  1080. nodes = table.getElements(".calendarTimeShowItem");
  1081. if (nodes.length) nodes.setStyles(this.css.calendarTimeShowItem);
  1082. var node = table.getElement(".MWF_calendar_action_show");
  1083. if (node){
  1084. node.setStyles(this.css.calendarActionShow);
  1085. var buttons = node.getElements("button");
  1086. buttons.setStyles(this.css.calendarActionShowButton);
  1087. }
  1088. }
  1089. break;
  1090. default :
  1091. //nothing;
  1092. }
  1093. tds.addEvent("mouseover", function(){
  1094. this.setStyle("border", "1px solid #999999");
  1095. });
  1096. tds.addEvent("mouseout", function(){
  1097. this.setStyle("border", "1px solid #FFF");
  1098. });
  1099. }else{
  1100. switch (this.currentView) {
  1101. case "day" :
  1102. table.setStyles(this.css.calendarDaysContent);
  1103. tds.setStyles(this.css.calendarDaysContentTd);
  1104. break;
  1105. case "month" :
  1106. table.setStyles(this.css.calendarMonthsContent);
  1107. tds.setStyles(this.css.calendarMonthsContentTd);
  1108. break;
  1109. case "year" :
  1110. this.yearLength = tds.length;
  1111. table.setStyles(this.css.calendarYearsContent);
  1112. tds.setStyles(this.css.calendarYearsContentTd);
  1113. break;
  1114. case "time" :
  1115. if( this.options.style.indexOf("mobile") > -1 ){
  1116. var nodes = table.getElements(".calendarTimeContent_mobile");
  1117. if (nodes.length) nodes.setStyles(this.css.calendarTimeContent_mobile);
  1118. nodes = table.getElements(".calendarTimeFixWidthNode_mobile");
  1119. if (nodes.length) nodes.setStyles(this.css.calendarTimeFixWidthNode_mobile);
  1120. nodes = table.getElements(".calendarTimeWheels_mobile");
  1121. if (nodes.length) nodes.setStyles(this.css.calendarTimeWheels_mobile);
  1122. nodes = table.getElements(".calendarTimeWheel_mobile");
  1123. if (nodes.length) nodes.setStyles(this.css.calendarTimeWheel_mobile);
  1124. nodes = table.getElements(".calendarTimeSelectContainer_mobile");
  1125. if (nodes.length) nodes.setStyles(this.css.calendarTimeSelectContainer_mobile);
  1126. nodes = table.getElements(".calendarTimeSelectLine_mobile");
  1127. if (nodes.length) nodes.setStyles(this.css.calendarTimeSelectLine_mobile);
  1128. nodes = table.getElements(".calendarTimeShadowMask_mobile");
  1129. if (nodes.length) nodes.setStyles(this.css.calendarTimeShadowMask_mobile);
  1130. var node = table.getElement(".MWF_calendar_action_show");
  1131. if (node){
  1132. node.setStyles(this.css.calendarActionShow);
  1133. //var buttons = node.getElements("button");
  1134. //buttons.setStyles(this.css.calendarActionShowButton);
  1135. }
  1136. }else{
  1137. var nodes = table.getElements(".calendarTimeArea");
  1138. if (nodes.length) nodes.setStyles(this.css.calendarTimeArea);
  1139. nodes = table.getElements(".calendarTimeSlider");
  1140. if (nodes.length) nodes.setStyles(this.css.calendarTimeSlider);
  1141. nodes = table.getElements(".calendarTimeSliderKnob");
  1142. if (nodes.length) nodes.setStyles(this.css.calendarTimeSliderKnob);
  1143. nodes = table.getElements(".calendarTimeShow");
  1144. if (nodes.length) nodes.setStyles(this.css.calendarTimeShow);
  1145. nodes = table.getElements(".calendarTimeShowItem");
  1146. if (nodes.length) nodes.setStyles(this.css.calendarTimeShowItem);
  1147. var node = table.getElement(".MWF_calendar_action_show");
  1148. if (node){
  1149. node.setStyles(this.css.calendarActionShow);
  1150. var buttons = node.getElements("button");
  1151. buttons.setStyles(this.css.calendarActionShowButton);
  1152. }
  1153. }
  1154. break;
  1155. default :
  1156. //nothing;
  1157. }
  1158. }
  1159. return table;
  1160. }
  1161. });
  1162. o2.Calendar.MobileSelect = new Class({
  1163. Implements: [Options, Events],
  1164. options: {
  1165. "lineHeight" : 40, //每个item的高度
  1166. "itemSize" : 0, //item数量
  1167. "ratio" : 1, //滑动距离倍率
  1168. "itemIndex" : 0
  1169. },
  1170. initialize: function (wheelNode, options) {
  1171. this.setOptions( options );
  1172. this.wheelNode = wheelNode;
  1173. this.sliderNode = wheelNode.getFirst();
  1174. },
  1175. load : function(){
  1176. var _this = this;
  1177. this.curDistance = 0;
  1178. this.sliderNode.style.transform = "translate3d(0px, 80px, 0px)";
  1179. this.wheelNode.addEventListener('touchstart', function () {
  1180. _this.touch(event);
  1181. }, false);
  1182. this.wheelNode.addEventListener('touchend', function () {
  1183. _this.touch(event);
  1184. }, false);
  1185. this.wheelNode.addEventListener('touchmove', function () {
  1186. _this.touch(event);
  1187. }, false);
  1188. this.locatePostion( this.options.itemIndex );
  1189. },
  1190. touch: function (ev) {
  1191. var sliderNode = this.sliderNode;
  1192. ev = ev || window.event;
  1193. switch (ev.type) {
  1194. case "touchstart":
  1195. this.startTime = new Date();
  1196. this.startY = event.touches[0].clientY;
  1197. this.oldMoveY = this.startY;
  1198. break;
  1199. case "touchend":
  1200. this.moveEndY = event.changedTouches[0].clientY;
  1201. this.overTime = new Date();
  1202. var speed = (this.moveEndY - this.startY) / ( this.overTime - this.startTime );
  1203. var ratio = 1;
  1204. if( Math.abs(speed) > 0.7 ){
  1205. ratio = 5;
  1206. }else if( Math.abs(speed) < 0.2 ){
  1207. ratio = 0.7
  1208. }
  1209. this.offsetSum = ( this.moveEndY - this.startY ) * this.options.ratio * ratio;
  1210. this.updateCurDistance();
  1211. this.curDistance = this.fixPosition(this.curDistance);
  1212. this.movePosition( this.curDistance );
  1213. this.oversizeBorder = - ( this.options.itemSize - 3) * this.options.lineHeight;
  1214. if (this.curDistance + this.offsetSum > 2 * this.options.lineHeight) {
  1215. this.curDistance = 2 * this.options.lineHeight;
  1216. setTimeout(function () {
  1217. this.movePosition( this.curDistance );
  1218. }.bind(this), 100);
  1219. } else if (this.curDistance + this.offsetSum < this.oversizeBorder) {
  1220. this.curDistance = this.oversizeBorder;
  1221. setTimeout(function () {
  1222. this.movePosition( this.curDistance );
  1223. }.bind(this), 100);
  1224. }
  1225. this.fireEvent( "change", [this.getCurIndex()] );
  1226. break;
  1227. case "touchmove":
  1228. ev.preventDefault();
  1229. this.moveY = event.touches[0].clientY;
  1230. this.overTime = new Date();
  1231. var speed = (this.moveY - this.oldMoveY) / ( this.overTime - this.oldOverTime );
  1232. var ratio = 1;
  1233. if( Math.abs(speed) > 0.7 ){
  1234. ratio = 5;
  1235. }else if( Math.abs(speed) < 0.2 ){
  1236. ratio = 0.7
  1237. }
  1238. this.offset = ( this.moveY - this.oldMoveY ) * this.options.ratio * ratio;
  1239. this.updateCurDistance();
  1240. this.curDistance = this.curDistance + this.offset;
  1241. this.movePosition( this.curDistance );
  1242. this.oldMoveY = this.moveY;
  1243. this.oldOverTime = this.overTime;
  1244. break;
  1245. }
  1246. },
  1247. calcDistance: function (index) {
  1248. return 2 * this.options.lineHeight - index * this.options.lineHeight;
  1249. },
  1250. setCurDistance: function ( index ) {
  1251. this.curDistance = this.calcDistance( index );
  1252. this.movePosition( this.curDistance );
  1253. },
  1254. fixPosition: function (distance) {
  1255. return -(this.getIndex(distance) - 2) * this.options.lineHeight;
  1256. },
  1257. getCurIndex : function(){
  1258. return this.getIndex( this.curDistance );
  1259. },
  1260. getIndex: function (distance) {
  1261. return Math.round((2 * this.options.lineHeight - distance) / this.options.lineHeight);
  1262. },
  1263. movePosition: function ( distance) {
  1264. this.sliderNode.style.webkitTransform = 'translate3d(0,' + distance + 'px, 0)';
  1265. this.sliderNode.style.transform = 'translate3d(0,' + distance + 'px, 0)';
  1266. },
  1267. locatePostion: function ( index ) {
  1268. this.curDistance = this.calcDistance(index);
  1269. this.movePosition( this.curDistance );
  1270. },
  1271. updateCurDistance: function () {
  1272. this.curDistance = parseInt(this.sliderNode.style.transform.split(',')[1]);
  1273. },
  1274. getDistance: function () {
  1275. return parseInt(this.sliderNode.style.transform.split(',')[1]);
  1276. }
  1277. });