Calendar.js 44 KB

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