Calendar.js 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466
  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. ;
  773. if( !this.options.secondEnable ){
  774. var div = this.contentTimeTable.getElement(".MWF_calendar_time_s");
  775. if( div )div.hide();
  776. div = this.contentTimeTable.getElement(".MWF_calendar_time_show_s");
  777. if( div )div.hide();
  778. }
  779. this.itmeHNode = this.contentTimeTable.getElement(".MWF_calendar_time_h_slider");
  780. this.itmeMNode = this.contentTimeTable.getElement(".MWF_calendar_time_m_slider");
  781. this.itmeSNode = this.contentTimeTable.getElement(".MWF_calendar_time_s_slider");
  782. this.timeShowNode = this.contentTimeTable.getElement(".MWF_calendar_time_show");
  783. this.timeShowNode.addEvent("click", function(){
  784. this._selectTime();
  785. }.bind(this));
  786. this.showHNode = this.contentTimeTable.getElement(".MWF_calendar_time_show_h");
  787. this.showMNode = this.contentTimeTable.getElement(".MWF_calendar_time_show_m");
  788. this.showSNode = this.contentTimeTable.getElement(".MWF_calendar_time_show_s");
  789. this.showActionNode = this.contentTimeTable.getElement(".MWF_calendar_action_show");
  790. var calendar = this;
  791. if ( COMMON.Browser.Platform.isMobile ){
  792. //this.itmeHNode.empty();
  793. //this.itmeHNode.removeClass("calendarTimeSlider");
  794. //this.itmeHNode.setStyles(this.css.calendarTimeSliderNoStyle);
  795. //var sel = new Element("select").inject(this.itmeHNode);
  796. //for (i=0; i<=23; i++){
  797. // var v = (i<10) ? "0"+i: i;
  798. // var o = new Element("option", {
  799. // "value": v,
  800. // "text": v
  801. // }).inject(sel);
  802. // if (h==i) o.set("selected", true);
  803. //}
  804. //sel.addEvent("change", function(){
  805. // calendar.showHNode.set("text", this.options[this.selectedIndex].get("value"));
  806. //});
  807. //this.showHNode.set("text", sel.options[sel.selectedIndex].get("value"));
  808. //
  809. //this.itmeMNode.empty();
  810. //this.itmeMNode.removeClass("calendarTimeSlider");
  811. //this.itmeMNode.setStyles(this.css.calendarTimeSliderNoStyle);
  812. //sel = new Element("select").inject(this.itmeMNode);
  813. //for (i=0; i<=59; i++){
  814. // var v = (i<10) ? "0"+i: i;
  815. // var o = new Element("option", {
  816. // "value": v,
  817. // "text": v
  818. // }).inject(sel);
  819. // if (m==i) o.set("selected", true);
  820. //}
  821. //sel.addEvent("change", function(){
  822. // calendar.showMNode.set("text", this.options[this.selectedIndex].get("value"));
  823. //});
  824. //this.showMNode.set("text", sel.options[sel.selectedIndex].get("value"));
  825. }else{
  826. var hSlider = new Slider(this.itmeHNode, this.itmeHNode.getFirst(), {
  827. range: [0, 23],
  828. initialStep: h.toInt(),
  829. onChange: function(value){
  830. var tmp = (value.toInt().toString());
  831. if (tmp.length<2){
  832. tmp = "0"+tmp
  833. }
  834. this.showHNode.set("text", tmp);
  835. this.itmeHNode.getFirst().set("text", tmp);
  836. }.bind(this)
  837. });
  838. this.itmeHNode.getFirst().set("text", h);
  839. var mSlider = new Slider(this.itmeMNode, this.itmeMNode.getFirst(), {
  840. range: [0, 59],
  841. initialStep: m.toInt(),
  842. onChange: function(value){
  843. var tmp = (value.toInt().toString());
  844. if (tmp.length<2){
  845. tmp = "0"+tmp
  846. }
  847. this.showMNode.set("text", tmp);
  848. this.itmeMNode.getFirst().set("text", tmp);
  849. }.bind(this)
  850. });
  851. this.itmeMNode.getFirst().set("text", m);
  852. if( this.options.secondEnable && this.itmeSNode ){
  853. var sSlider = new Slider(this.itmeSNode, this.itmeSNode.getFirst(), {
  854. range: [0, 59],
  855. initialStep: parseInt(s),
  856. onChange: function(value){
  857. var tmp = (value.toInt().toString());
  858. if (tmp.length<2){
  859. tmp = "0"+tmp
  860. }
  861. this.showSNode.set("text", tmp);
  862. this.itmeSNode.getFirst().set("text", tmp);
  863. }.bind(this)
  864. });
  865. this.itmeSNode.getFirst().set("text", s);
  866. }
  867. }
  868. this.showHNode.set("text", this.addZero( h.toInt(), 2) );
  869. this.showMNode.set("text", this.addZero( m.toInt(), 2));
  870. if( this.options.secondEnable && this.showSNode ){
  871. this.showSNode.set("text", this.addZero( s.toInt(), 2) );
  872. }
  873. if (!this.okButton){
  874. this.okButton = new Element("button", {"text": "确定"}).inject(this.showActionNode);
  875. this.okButton.addEvent("click", function(){
  876. this._selectTime();
  877. this.hide();
  878. }.bind(this));
  879. this.okButton.setStyles(this.css.calendarActionShowButton);
  880. }
  881. if (!this.clearButton){
  882. this.clearButton = new Element("button", {"text": "清除"}).inject(this.showActionNode);
  883. this.clearButton.addEvent("click", function(){
  884. var t = this.node.get("value");
  885. this.node.set("value", "");
  886. if( t )this.fireEvent("change");
  887. this.fireEvent("clear");
  888. this.hide();
  889. }.bind(this));
  890. this.clearButton.setStyles(this.css.calendarActionShowButton);
  891. }
  892. },
  893. addZero : function( str, length ){
  894. var zero = "";
  895. str = str.toString();
  896. for( var i=0; i<length; i++ ){
  897. zero = zero + "0";
  898. }
  899. var s = zero + str;
  900. return s.substr(s.length - length, length );
  901. },
  902. _selectTime: function(){
  903. var date = this.currentTextNode.retrieve("date");
  904. var h = this.selectedHour || this.showHNode.get("text");
  905. var m = this.selectedMinute || this.showMNode.get("text");
  906. date.setHours(h);
  907. date.setMinutes(m);
  908. if( this.options.secondEnable && ( this.selectedSecond || this.showSNode) ){
  909. var s = this.selectedSecond || this.showSNode.get("text");
  910. date.setSeconds(s);
  911. }
  912. if (!this.options.beforeCurrent){
  913. var now = new Date();
  914. if (date.getTime()-now.getTime()<0){
  915. alert("选择的日期必须大于当前日期!");
  916. this.node.focus();
  917. return false;
  918. }
  919. }
  920. var dv = date.format(this.options.format);
  921. if (this.fireEvent("queryComplate", [dv, date])){
  922. var t = this.node.get("value");
  923. this.options.defaultTime = ""+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
  924. this.node.set("value", dv);
  925. // this.node.focus();
  926. this.hide();
  927. if (t!=dv) this.fireEvent("change", [dv, date, t]);
  928. this.fireEvent("complate", [dv, date]);
  929. }
  930. },
  931. _selectDate: function(dateStr){
  932. var date = new Date(dateStr);
  933. this.options.baseDate = date;
  934. var dv = date.format(this.options.format);
  935. if (this.options.isTime){
  936. this.changeViewToTime(date);
  937. }else{
  938. if (!this.options.beforeCurrent){
  939. var now = new Date();
  940. date.setHours(23,59,59);
  941. if (date.getTime()-now.getTime()<0){
  942. alert("选择的日期必须大于当前日期!");
  943. this.node.focus();
  944. return false;
  945. }
  946. }
  947. if (this.fireEvent("queryComplate", [dv, date])){
  948. var t = this.node.get("value");
  949. this.node.set("value", dv);
  950. this.hide();
  951. if (t!=dv) this.fireEvent("change", [dv, date, t]);
  952. this.fireEvent("complate", [dv, date, t]);
  953. }
  954. }
  955. },
  956. _setDayWeekTitleTh: function(table){
  957. var dayTable = table || this.contentTable;
  958. var thead = dayTable.getElement("thead");
  959. var cells = thead.getElements("th");
  960. if (this.css.calendarDaysContentTh) cells.setStyles(this.css.calendarDaysContentTh);
  961. //var days_abbr = Locale.get("Date").days_abbr;
  962. var days_abbr = o2.LP.widget.days_abbr;
  963. cells.each(function(item, idx){
  964. item.set("text", days_abbr[idx]);
  965. });
  966. return cells;
  967. },
  968. createContainer: function(){
  969. var div = null;
  970. var request = new Request.HTML({
  971. url: this.options.containerPath,
  972. method: "GET",
  973. async: false,
  974. onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
  975. div = responseTree[0];
  976. }
  977. });
  978. request.send();
  979. //this.containerNode = div.getElement(".MWF_calendar_container");
  980. this.titleNode = div.getElement(".MWF_calendar_title");
  981. this.prevNode = div.getElement(".MWF_calendar_prev");
  982. this.currentNode = div.getElement(".MWF_calendar_current");
  983. this.currentTextNode = div.getElement(".MWF_calendar_currentText");
  984. this.nextNode = div.getElement(".MWF_calendar_next");
  985. this.contentNode = div.getElement(".MWF_calendar_content");
  986. this.contentDateNode = div.getElement(".MWF_calendar_content_date");
  987. this.contentTimeNode = div.getElement(".MWF_calendar_content_time");
  988. this.buttonArea = div.getElement(".MWF_calendar_button_area");
  989. this.bottomNode = div.getElement(".MWF_calendar_bottom");
  990. div.setStyles(this.css.container);
  991. this.titleNode.setStyles(this.css.dateTitle);
  992. this.prevNode.setStyles(this.css.datePrev);
  993. this.currentNode.setStyles(this.css.dateCurrent);
  994. this.currentTextNode.setStyles(this.css.dateCurrentText);
  995. this.nextNode.setStyles(this.css.dateNext);
  996. this.contentNode.setStyles(this.css.calendarContent);
  997. if(this.buttonArea)this.buttonArea.setStyles(this.css.buttonArea);
  998. this.bottomNode.setStyles(this.css.dateBottom);
  999. return div;
  1000. },
  1001. createContentTable: function(){
  1002. var table = null;
  1003. var request = new Request.HTML({
  1004. url: this.options[this.currentView+"Path"],
  1005. method: "GET",
  1006. async: false,
  1007. onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
  1008. table = responseTree[0];
  1009. }
  1010. });
  1011. request.send();
  1012. var tbody = table.getElement("tbody");
  1013. if (tbody){
  1014. var tds = tbody.getElements("td");
  1015. var calendar = this;
  1016. tds.addEvent("click", function(){
  1017. switch (calendar.currentView) {
  1018. case "day" :
  1019. calendar._selectDate(this.retrieve("dateValue"), this);
  1020. break;
  1021. case "month" :
  1022. calendar.changeViewToDay(this.retrieve("year"), this.retrieve("month"));
  1023. break;
  1024. case "year" :
  1025. calendar.changeViewToMonth(this.retrieve("year"));
  1026. break;
  1027. case "time" :
  1028. //nothing
  1029. break;
  1030. default :
  1031. //nothing;
  1032. }
  1033. });
  1034. switch (this.currentView) {
  1035. case "day" :
  1036. if (!table.display) table.display="";
  1037. if (!table.style.display) table.style.display="";
  1038. table.setStyles(this.css.calendarDaysContent);
  1039. tds.setStyles(this.css.calendarDaysContentTd);
  1040. break;
  1041. case "month" :
  1042. table.setStyles(this.css.calendarMonthsContent);
  1043. tds.setStyles(this.css.calendarMonthsContentTd);
  1044. break;
  1045. case "year" :
  1046. this.yearLength = tds.length;
  1047. table.setStyles(this.css.calendarYearsContent);
  1048. tds.setStyles(this.css.calendarYearsContentTd);
  1049. break;
  1050. case "time" :
  1051. if( this.options.style.indexOf("mobile") > -1 ){
  1052. var nodes = table.getElements(".calendarTimeContent_mobile");
  1053. if (nodes.length) nodes.setStyles(this.css.calendarTimeContent_mobile);
  1054. nodes = table.getElements(".calendarTimeFixWidthNode_mobile");
  1055. if (nodes.length) nodes.setStyles(this.css.calendarTimeFixWidthNode_mobile);
  1056. nodes = table.getElements(".calendarTimeWheels_mobile");
  1057. if (nodes.length) nodes.setStyles(this.css.calendarTimeWheels_mobile);
  1058. nodes = table.getElements(".calendarTimeWheel_mobile");
  1059. if (nodes.length) nodes.setStyles(this.css.calendarTimeWheel_mobile);
  1060. nodes = table.getElements(".calendarTimeSelectContainer_mobile");
  1061. if (nodes.length) nodes.setStyles(this.css.calendarTimeSelectContainer_mobile);
  1062. nodes = table.getElements(".calendarTimeSelectLine_mobile");
  1063. if (nodes.length) nodes.setStyles(this.css.calendarTimeSelectLine_mobile);
  1064. nodes = table.getElements(".calendarTimeShadowMask_mobile");
  1065. if (nodes.length) nodes.setStyles(this.css.calendarTimeShadowMask_mobile);
  1066. var node = table.getElement(".MWF_calendar_action_show");
  1067. if (node){
  1068. node.setStyles(this.css.calendarActionShow);
  1069. //var buttons = node.getElements("button");
  1070. //buttons.setStyles(this.css.calendarActionShowButton);
  1071. }
  1072. }else{
  1073. var nodes = table.getElements(".calendarTimeArea");
  1074. if (nodes.length) nodes.setStyles(this.css.calendarTimeArea);
  1075. nodes = table.getElements(".calendarTimeSlider");
  1076. if (nodes.length) nodes.setStyles(this.css.calendarTimeSlider);
  1077. nodes = table.getElements(".calendarTimeSliderKnob");
  1078. if (nodes.length) nodes.setStyles(this.css.calendarTimeSliderKnob);
  1079. nodes = table.getElements(".calendarTimeShow");
  1080. if (nodes.length) nodes.setStyles(this.css.calendarTimeShow);
  1081. nodes = table.getElements(".calendarTimeShowItem");
  1082. if (nodes.length) nodes.setStyles(this.css.calendarTimeShowItem);
  1083. var node = table.getElement(".MWF_calendar_action_show");
  1084. if (node){
  1085. node.setStyles(this.css.calendarActionShow);
  1086. var buttons = node.getElements("button");
  1087. buttons.setStyles(this.css.calendarActionShowButton);
  1088. }
  1089. }
  1090. break;
  1091. default :
  1092. //nothing;
  1093. }
  1094. tds.addEvent("mouseover", function(){
  1095. this.setStyle("border", "1px solid #999999");
  1096. });
  1097. tds.addEvent("mouseout", function(){
  1098. this.setStyle("border", "1px solid #FFF");
  1099. });
  1100. }else{
  1101. switch (this.currentView) {
  1102. case "day" :
  1103. table.setStyles(this.css.calendarDaysContent);
  1104. tds.setStyles(this.css.calendarDaysContentTd);
  1105. break;
  1106. case "month" :
  1107. table.setStyles(this.css.calendarMonthsContent);
  1108. tds.setStyles(this.css.calendarMonthsContentTd);
  1109. break;
  1110. case "year" :
  1111. this.yearLength = tds.length;
  1112. table.setStyles(this.css.calendarYearsContent);
  1113. tds.setStyles(this.css.calendarYearsContentTd);
  1114. break;
  1115. case "time" :
  1116. if( this.options.style.indexOf("mobile") > -1 ){
  1117. var nodes = table.getElements(".calendarTimeContent_mobile");
  1118. if (nodes.length) nodes.setStyles(this.css.calendarTimeContent_mobile);
  1119. nodes = table.getElements(".calendarTimeFixWidthNode_mobile");
  1120. if (nodes.length) nodes.setStyles(this.css.calendarTimeFixWidthNode_mobile);
  1121. nodes = table.getElements(".calendarTimeWheels_mobile");
  1122. if (nodes.length) nodes.setStyles(this.css.calendarTimeWheels_mobile);
  1123. nodes = table.getElements(".calendarTimeWheel_mobile");
  1124. if (nodes.length) nodes.setStyles(this.css.calendarTimeWheel_mobile);
  1125. nodes = table.getElements(".calendarTimeSelectContainer_mobile");
  1126. if (nodes.length) nodes.setStyles(this.css.calendarTimeSelectContainer_mobile);
  1127. nodes = table.getElements(".calendarTimeSelectLine_mobile");
  1128. if (nodes.length) nodes.setStyles(this.css.calendarTimeSelectLine_mobile);
  1129. nodes = table.getElements(".calendarTimeShadowMask_mobile");
  1130. if (nodes.length) nodes.setStyles(this.css.calendarTimeShadowMask_mobile);
  1131. var node = table.getElement(".MWF_calendar_action_show");
  1132. if (node){
  1133. node.setStyles(this.css.calendarActionShow);
  1134. //var buttons = node.getElements("button");
  1135. //buttons.setStyles(this.css.calendarActionShowButton);
  1136. }
  1137. }else{
  1138. var nodes = table.getElements(".calendarTimeArea");
  1139. if (nodes.length) nodes.setStyles(this.css.calendarTimeArea);
  1140. nodes = table.getElements(".calendarTimeSlider");
  1141. if (nodes.length) nodes.setStyles(this.css.calendarTimeSlider);
  1142. nodes = table.getElements(".calendarTimeSliderKnob");
  1143. if (nodes.length) nodes.setStyles(this.css.calendarTimeSliderKnob);
  1144. nodes = table.getElements(".calendarTimeShow");
  1145. if (nodes.length) nodes.setStyles(this.css.calendarTimeShow);
  1146. nodes = table.getElements(".calendarTimeShowItem");
  1147. if (nodes.length) nodes.setStyles(this.css.calendarTimeShowItem);
  1148. var node = table.getElement(".MWF_calendar_action_show");
  1149. if (node){
  1150. node.setStyles(this.css.calendarActionShow);
  1151. var buttons = node.getElements("button");
  1152. buttons.setStyles(this.css.calendarActionShowButton);
  1153. }
  1154. }
  1155. break;
  1156. default :
  1157. //nothing;
  1158. }
  1159. }
  1160. return table;
  1161. }
  1162. });
  1163. o2.Calendar.MobileSelect = new Class({
  1164. Implements: [Options, Events],
  1165. options: {
  1166. "lineHeight" : 40, //每个item的高度
  1167. "itemSize" : 0, //item数量
  1168. "ratio" : 1, //滑动距离倍率
  1169. "itemIndex" : 0
  1170. },
  1171. initialize: function (wheelNode, options) {
  1172. this.setOptions( options );
  1173. this.wheelNode = wheelNode;
  1174. this.sliderNode = wheelNode.getFirst();
  1175. },
  1176. load : function(){
  1177. var _this = this;
  1178. this.curDistance = 0;
  1179. this.sliderNode.style.transform = "translate3d(0px, 80px, 0px)";
  1180. this.wheelNode.addEventListener('touchstart', function () {
  1181. _this.touch(event);
  1182. }, false);
  1183. this.wheelNode.addEventListener('touchend', function () {
  1184. _this.touch(event);
  1185. }, false);
  1186. this.wheelNode.addEventListener('touchmove', function () {
  1187. _this.touch(event);
  1188. }, false);
  1189. this.locatePostion( this.options.itemIndex );
  1190. },
  1191. touch: function (ev) {
  1192. var sliderNode = this.sliderNode;
  1193. ev = ev || window.event;
  1194. switch (ev.type) {
  1195. case "touchstart":
  1196. this.startTime = new Date();
  1197. this.startY = event.touches[0].clientY;
  1198. this.oldMoveY = this.startY;
  1199. break;
  1200. case "touchend":
  1201. this.moveEndY = event.changedTouches[0].clientY;
  1202. this.overTime = new Date();
  1203. var speed = (this.moveEndY - this.startY) / ( this.overTime - this.startTime );
  1204. var ratio = 1;
  1205. if( Math.abs(speed) > 0.7 ){
  1206. ratio = 5;
  1207. }else if( Math.abs(speed) < 0.2 ){
  1208. ratio = 0.7
  1209. }
  1210. this.offsetSum = ( this.moveEndY - this.startY ) * this.options.ratio * ratio;
  1211. this.updateCurDistance();
  1212. this.curDistance = this.fixPosition(this.curDistance);
  1213. this.movePosition( this.curDistance );
  1214. this.oversizeBorder = - ( this.options.itemSize - 3) * this.options.lineHeight;
  1215. if (this.curDistance + this.offsetSum > 2 * this.options.lineHeight) {
  1216. this.curDistance = 2 * this.options.lineHeight;
  1217. setTimeout(function () {
  1218. this.movePosition( this.curDistance );
  1219. }.bind(this), 100);
  1220. } else if (this.curDistance + this.offsetSum < this.oversizeBorder) {
  1221. this.curDistance = this.oversizeBorder;
  1222. setTimeout(function () {
  1223. this.movePosition( this.curDistance );
  1224. }.bind(this), 100);
  1225. }
  1226. this.fireEvent( "change", [this.getCurIndex()] );
  1227. break;
  1228. case "touchmove":
  1229. ev.preventDefault();
  1230. this.moveY = event.touches[0].clientY;
  1231. this.overTime = new Date();
  1232. var speed = (this.moveY - this.oldMoveY) / ( this.overTime - this.oldOverTime );
  1233. var ratio = 1;
  1234. if( Math.abs(speed) > 0.7 ){
  1235. ratio = 5;
  1236. }else if( Math.abs(speed) < 0.2 ){
  1237. ratio = 0.7
  1238. }
  1239. this.offset = ( this.moveY - this.oldMoveY ) * this.options.ratio * ratio;
  1240. this.updateCurDistance();
  1241. this.curDistance = this.curDistance + this.offset;
  1242. this.movePosition( this.curDistance );
  1243. this.oldMoveY = this.moveY;
  1244. this.oldOverTime = this.overTime;
  1245. break;
  1246. }
  1247. },
  1248. calcDistance: function (index) {
  1249. return 2 * this.options.lineHeight - index * this.options.lineHeight;
  1250. },
  1251. setCurDistance: function ( index ) {
  1252. this.curDistance = this.calcDistance( index );
  1253. this.movePosition( this.curDistance );
  1254. },
  1255. fixPosition: function (distance) {
  1256. return -(this.getIndex(distance) - 2) * this.options.lineHeight;
  1257. },
  1258. getCurIndex : function(){
  1259. return this.getIndex( this.curDistance );
  1260. },
  1261. getIndex: function (distance) {
  1262. return Math.round((2 * this.options.lineHeight - distance) / this.options.lineHeight);
  1263. },
  1264. movePosition: function ( distance) {
  1265. this.sliderNode.style.webkitTransform = 'translate3d(0,' + distance + 'px, 0)';
  1266. this.sliderNode.style.transform = 'translate3d(0,' + distance + 'px, 0)';
  1267. },
  1268. locatePostion: function ( index ) {
  1269. this.curDistance = this.calcDistance(index);
  1270. this.movePosition( this.curDistance );
  1271. },
  1272. updateCurDistance: function () {
  1273. this.curDistance = parseInt(this.sliderNode.style.transform.split(',')[1]);
  1274. },
  1275. getDistance: function () {
  1276. return parseInt(this.sliderNode.style.transform.split(',')[1]);
  1277. }
  1278. });