dateyearmonth.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. define([], function(){
  2. var arrmonth=['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月']
  3. var arryear=[1,2,3,4,5,6,7,8,9,0]
  4. _CalF = {
  5. // 选择元素
  6. $:function(arg,context){
  7. var tagAll,n,eles=[],i,sub = arg.substring(1);
  8. context = context||document;
  9. if(typeof arg =='string'){
  10. switch(arg.charAt(0)){
  11. case '#':
  12. return document.getElementById(sub);
  13. break;
  14. case '.':
  15. if(context.getElementsByClassName) return context.getElementsByClassName(sub);
  16. tagAll = _CalF.$('*',context);
  17. n = tagAll.length;
  18. for(i = 0;i<n;i++){
  19. if(tagAll[i].className.indexOf(sub) > -1) eles.push(tagAll[i]);
  20. }
  21. return eles;
  22. break;
  23. default:
  24. return context.getElementsByTagName(arg);
  25. break;
  26. }
  27. }
  28. },
  29. // 绑定事件
  30. bind:function(node,type,handler){
  31. node.addEventListener?node.addEventListener(type, handler, false):node.attachEvent('on'+ type, handler);
  32. },
  33. getWidth:function(node){
  34. return node.offsetWidth;
  35. },
  36. // 获取元素位置
  37. getPos:function (node) {
  38. var scrollx = document.documentElement.scrollLeft || document.body.scrollLeft,
  39. scrollt = document.documentElement.scrollTop || document.body.scrollTop;
  40. pos = node.getBoundingClientRect();
  41. return {top:$(node).offset().top + $(node).outerHeight(), right:pos.right + scrollx, bottom:pos.bottom + scrollt, left:pos.left + scrollx, getWidth: this.getWidth(node)}
  42. },
  43. // 添加样式名
  44. addClass:function(c,node){
  45. node.className = node.className + ' ' + c;
  46. },
  47. // 移除样式名
  48. removeClass:function(c,node){
  49. var reg = new RegExp("(^|\\s+)" + c + "(\\s+|$)","g");
  50. node.className = node.className.replace(reg, '');
  51. },
  52. // 阻止冒泡
  53. stopPropagation:function(event){
  54. event = event || window.event;
  55. event.stopPropagation ? event.stopPropagation() : event.cancelBubble = true;
  56. },
  57. hasClass: function(className,node) {
  58. return node.className && new RegExp("(^|\\s)" + className + "(\\s|$)").test(node.className);
  59. }
  60. };
  61. var dateyearmonth = function(){
  62. this.initialize.apply(this, arguments);
  63. }
  64. dateyearmonth.prototype={
  65. constructor:dateyearmonth,
  66. initialize :function (options) {
  67. this.id = options.id; // input的ID
  68. this.input = _CalF.$('#'+ this.id); // 获取INPUT元素
  69. $('#'+this.id).attr('data-min-year',options.startYear);
  70. $('#'+this.id).attr('data-max-year',options.endYear);
  71. $('#'+this.id).attr('data-format',options.format);
  72. if(!$('#'+this.id+'_calendar').length){
  73. $('#'+this.id).after('<div class="kui-datepicker-range kui-absolute kui-datepicker-month-range" id="month_sum_calendar"></div>');
  74. }
  75. this.inputEvent(); // input的事件绑定,获取焦点事件
  76. },
  77. createContainer:function(){
  78. var odiv = _CalF.$('#kui_'+ this.id);
  79. var input = _CalF.$('#' + this.id),
  80. inputPos = _CalF.getPos(input);
  81. // 根据input的位置设置container;
  82. var x = inputPos.left;
  83. var y = inputPos.top;
  84. var w=inputPos.getWidth;
  85. var bodyw=document.body.clientWidth;
  86. if(!!odiv){
  87. odiv.parentNode.removeChild(odiv);
  88. }
  89. var container = this.container = document.createElement('div');
  90. container.className='kui-datepicker-range kui-absolute kui-datepicker-month-range';
  91. container.id='kui_'+ this.id;
  92. if(bodyw-x<container.offsetWidth){
  93. container.style.right=bodyw-x-w+"px";
  94. }else{
  95. container.style.left=x+"px";
  96. }
  97. container.style.top=y+"px";
  98. container.style.display = "block";
  99. document.body.appendChild(container);
  100. },
  101. // 渲染日期
  102. drawDate:function (vdate) {
  103. var ss =vdate.split("-");
  104. var selectHtml;
  105. var year,month;
  106. if(ss.length==1){
  107. var myDate = new Date();
  108. this.year=this.maxyear.toString();
  109. month=myDate.getMonth()+1;
  110. this.month =(month<10 ? "0"+month:month);
  111. vdate=this.year+'-'+this.month;
  112. }else{
  113. this.year=trim(ss[0]);
  114. this.month=trim(ss[1]);
  115. }
  116. selectHtml='<div class="kui-datepicker-begin">'
  117. +'<div class="kui-datepicker kui-relative kui-datepicker-month" >'
  118. +'<div class="kui-datepicker-monthcontainer ">'
  119. +'<div class="kui-datepicker-monthcontainer-inner">'
  120. +'<div class="kui-month-container ">'
  121. +this.createMonth(this.month)
  122. +'</div>'
  123. +'<div class="kui-year-container">'
  124. +'<div class="kui-year-nav"></div>'
  125. +'<div class="kui-yearlist">'
  126. +'<span class="prevyears iconfont icon-xiangzuo"></span>'
  127. +this.createYear(this.year,this.year)
  128. +'<span class="nextyears iconfont icon-goright"></span>'
  129. +'</div></div></div></div></div></div>'
  130. +'<div class="kui-datepicker-range-footer" style="padding-left:5px;padding-right:5px;">'
  131. +'<span class="pull-left">已选择:<label>'+vdate+'</label></span>'
  132. +'<button class="btn btn-white btn-sm select">确定</button>'
  133. +'<button class="btn btn-white btn-sm clean">取消</button></div>';
  134. this.container.innerHTML=selectHtml;
  135. this.btnMonth();
  136. this.btnYear();
  137. this.btnPrevYear();
  138. this.btnNextYear();
  139. this.outClick();
  140. this.btnClean();
  141. this.btnSelect();
  142. },
  143. drawDate1:function(vdate){
  144. var ss =vdate.split("-");
  145. if(ss.length==1){
  146. this.year1=this.year=this.maxyear.toString();
  147. this.month1=this.month =this.maxmonth;
  148. vdate=this.year+'-'+this.month+' - '+this.year1+'-'+this.month1;
  149. }else{
  150. this.year=trim(ss[0]);
  151. this.month=trim(ss[1]);
  152. this.year1=trim(ss[2]);
  153. this.month1=trim(ss[3]);
  154. }
  155. var odiv = _CalF.$('#kui_'+ this.id);
  156. var input = _CalF.$('#' + this.id),inputPos = _CalF.getPos(input);
  157. // 根据input的位置设置container;
  158. var x = inputPos.left;
  159. var y = inputPos.top;
  160. var w=inputPos.getWidth;
  161. var bodyw=document.body.clientWidth;
  162. if(!!odiv){
  163. odiv.parentNode.removeChild(odiv);
  164. }
  165. var container = this.container = document.createElement('div');
  166. container.className='kui-datepicker-range kui-absolute kui-datepicker-month-range';
  167. container.id='kui_'+ this.id;
  168. if(bodyw-x<container.offsetWidth){
  169. container.style.right=bodyw-x-w+"px";
  170. }else{
  171. container.style.left=x+"px";
  172. }
  173. container.style.top=y+"px";
  174. container.style.display = "block";
  175. var container_begin = this.container_begin = document.createElement('div');
  176. container_begin.className='kui-datepicker-begin';
  177. container_begin.innerHTML='<div class="kui-datepicker kui-relative kui-datepicker-month" >'
  178. +'<div class="kui-datepicker-monthcontainer ">'
  179. +'<div class="kui-datepicker-monthcontainer-inner">'
  180. +'<div class="kui-month-container">'
  181. +this.createMonth(this.month)
  182. +'</div>'
  183. +'<div class="kui-year-container">'
  184. +'<div class="kui-year-nav"></div>'
  185. +'<div class="kui-yearlist">'
  186. +'<span class="prevyears iconfont icon-xiangzuo"></span>'
  187. +this.createYear(this.year,this.year)
  188. +'<span class="nextyears iconfont icon-goright"></span>'
  189. +'</div></div></div></div></div>';
  190. this.container.appendChild(container_begin);
  191. var container_end = this.container_end = document.createElement('div');
  192. container_end.className='kui-datepicker-end';
  193. container_end.innerHTML='<div class="kui-datepicker kui-relative kui-datepicker-month"> '
  194. +'<div class="kui-datepicker-monthcontainer ">'
  195. +'<div class="kui-datepicker-monthcontainer-inner">'
  196. +'<div class="kui-month-container">'
  197. +this.createMonth(this.month1)
  198. +'</div>'
  199. +'<div class="kui-year-container">'
  200. +'<div class="kui-year-nav"></div>'
  201. +'<div class="kui-yearlist">'
  202. +'<span class="prevyears iconfont icon-xiangzuo"></span>'
  203. +this.createYear(this.year1,this.year1)
  204. +'<span class="nextyears iconfont icon-goright"></span>'
  205. +'</div></div></div></div></div>';
  206. this.container.appendChild(container_end);
  207. var container_footer = this.container_footer = document.createElement('div');
  208. container_footer.className='kui-datepicker-range-footer';
  209. container_footer.innerHTML='<div class="kui-datepicker-range-footer">'
  210. +'<span class="pull-left">已选择:<label>'+vdate+'</label></span>'
  211. +'<button class="btn btn-white btn-sm select">确定</button>'
  212. +'<button class="btn btn-white btn-sm clean">取消</button></div>';
  213. this.container.appendChild(container_footer);
  214. document.body.appendChild(container);
  215. this.btnMonth();
  216. this.btnYear();
  217. this.btnPrevYear();
  218. this.btnNextYear();
  219. this.outClick();
  220. this.btnClean();
  221. this.btnSelect();
  222. },
  223. // 表单的事件
  224. inputEvent:function(){
  225. var that = this;
  226. if(!!document.getElementById(that.id).getAttribute("data-min-year")){
  227. that.minyear=parseInt(document.getElementById(that.id).getAttribute("data-min-year"));
  228. }else{
  229. that.minyear=1901;
  230. }
  231. if(!!document.getElementById(that.id).getAttribute("data-max-year")){
  232. that.maxyear=parseInt(document.getElementById(that.id).getAttribute("data-max-year"));
  233. that.maxmonth='12';
  234. }else{
  235. var myDate = new Date();
  236. that.maxyear=parseInt(myDate.getFullYear().toString());
  237. var month=myDate.getMonth()+1;
  238. that.maxmonth =(month<10 ? "0"+month:month);
  239. }
  240. that.minmonth='01';
  241. _CalF.bind(this.input, 'focus',function(){
  242. var format=document.getElementById(that.id).getAttribute("data-format");
  243. var val=document.getElementById(that.id).value;
  244. if(format){
  245. if(format.split('-').length==2){
  246. that.createContainer();
  247. that.drawDate(val);
  248. }else{
  249. that.drawDate1(val);
  250. }
  251. }
  252. });
  253. },
  254. // 移除日期DIV.calendar
  255. removeDate:function(){
  256. this.container.innerHTML='';
  257. },
  258. btnPrevYear:function(){
  259. var that=this;
  260. if(document.getElementById(that.id).getAttribute("data-format").split('-').length==2){
  261. var _year=_CalF.$('.kui-yearlist',that.container)[0];
  262. var that=this;
  263. _year.querySelector('.prevyears').onclick=function(){
  264. var _spanlist=_CalF.$('.kui-year',_year);
  265. var minyear=parseInt(_spanlist[0].innerHTML);
  266. if(minyear>that.minyear){
  267. for(j=0;j<_spanlist.length;j++){
  268. _CalF.removeClass("kui-active-date",_spanlist[j]);
  269. if(minyear-10+j==that.year){
  270. _CalF.addClass("kui-active-date",_spanlist[j]);
  271. }
  272. _spanlist[j].innerHTML=minyear-10+j;
  273. }
  274. that.btnPrevYear();
  275. }
  276. }
  277. }else{
  278. var _year=_CalF.$('.kui-yearlist',that.container_begin)[0];
  279. _year.querySelector('.prevyears').onclick=function(){
  280. var _spanlist=_CalF.$('.kui-year',_year);
  281. var minyear=parseInt(_spanlist[0].innerHTML);
  282. if(minyear>that.minyear){
  283. for(j=0;j<_spanlist.length;j++){
  284. _CalF.removeClass("kui-active-date",_spanlist[j]);
  285. if(minyear-10+j==that.year){
  286. _CalF.addClass("kui-active-date",_spanlist[j]);
  287. }
  288. _spanlist[j].innerHTML=minyear-10+j;
  289. }
  290. that.btnPrevYear();
  291. }
  292. }
  293. var _year1=_CalF.$('.kui-yearlist',that.container_end)[0];
  294. _year1.querySelector('.prevyears').onclick=function(){
  295. var _spanlist=_CalF.$('.kui-year',_year1);
  296. var minyear=parseInt(_spanlist[0].innerHTML);
  297. if(minyear>that.minyear){
  298. for(j=0;j<_spanlist.length;j++){
  299. _CalF.removeClass("kui-active-date",_spanlist[j]);
  300. if(minyear-10+j==that.year){
  301. _CalF.addClass("kui-active-date",_spanlist[j]);
  302. }
  303. _spanlist[j].innerHTML=minyear-10+j;
  304. }
  305. that.btnPrevYear();
  306. }
  307. }
  308. }
  309. },
  310. btnNextYear:function(){
  311. var that=this;
  312. if(document.getElementById(that.id).getAttribute("data-format").split('-').length==2){
  313. var _year=_CalF.$('.kui-yearlist',that.container_begin)[0];
  314. _year.querySelector('.nextyears').onclick=function(){
  315. var _spanlist=_CalF.$('.kui-year',_year);
  316. var maxyear=parseInt(_spanlist[_spanlist.length-1].innerHTML);
  317. if(maxyear<that.maxyear){
  318. for(j=0;j<_spanlist.length;j++){
  319. _CalF.removeClass("kui-active-date",_spanlist[j]);
  320. if(maxyear+1+j==that.year){
  321. _CalF.addClass("kui-active-date",_spanlist[j]);
  322. }
  323. _spanlist[j].innerHTML=maxyear+1+j;
  324. }
  325. that.btnPrevYear();
  326. }
  327. }
  328. }else{
  329. var _year=_CalF.$('.kui-yearlist',that.container_begin)[0];
  330. _year.querySelector('.nextyears').onclick=function(){
  331. var _spanlist=_CalF.$('.kui-year',_year);
  332. var maxyear=parseInt(_spanlist[_spanlist.length-1].innerHTML);
  333. if(maxyear<that.maxyear){
  334. for(j=0;j<_spanlist.length;j++){
  335. _CalF.removeClass("kui-active-date",_spanlist[j]);
  336. if(maxyear+1+j==that.year){
  337. _CalF.addClass("kui-active-date",_spanlist[j]);
  338. }
  339. _spanlist[j].innerHTML=maxyear+1+j;
  340. }
  341. that.btnPrevYear();
  342. }
  343. }
  344. var _year1=_CalF.$('.kui-yearlist',that.container_end)[0];
  345. _year1.querySelector('.nextyears').onclick=function(){
  346. var _spanlist=_CalF.$('.kui-year',_year1);
  347. var maxyear=parseInt(_spanlist[_spanlist.length-1].innerHTML);
  348. if(maxyear<that.maxyear){
  349. for(j=0;j<_spanlist.length;j++){
  350. _CalF.removeClass("kui-active-date",_spanlist[j]);
  351. if(maxyear+1+j==that.year){
  352. _CalF.addClass("kui-active-date",_spanlist[j]);
  353. }
  354. _spanlist[j].innerHTML=maxyear+1+j;
  355. }
  356. that.btnPrevYear();
  357. }
  358. }
  359. }
  360. },
  361. btnMonth:function(){
  362. var that=this;
  363. if(document.getElementById(that.id).getAttribute("data-format").split('-').length==2){
  364. var _month = _CalF.$('.kui-month-container',that.container)[0];
  365. var _spanlist=_CalF.$('span',_month);
  366. for(i = 0;i<_spanlist.length;i++){
  367. _spanlist[i].onclick = function(){
  368. var monint=arrmonth.contains(this.innerHTML);
  369. var thatmonth=monint<10? "0"+monint:monint;
  370. var minyh=parseInt(that.year+thatmonth);
  371. if(minyh>=parseInt(that.minyear+that.minmonth)&&minyh<=parseInt(that.maxyear+that.maxmonth)){
  372. that.month=thatmonth;
  373. _CalF.$('label',that.container)[0].innerHTML= that.year + '-'+that.month;
  374. for(j=0;j<_spanlist.length;j++){
  375. _CalF.removeClass("kui-active-date",_spanlist[j]);
  376. }
  377. _CalF.addClass("kui-active-date",this);
  378. }
  379. }
  380. }
  381. }else{
  382. var _month = _CalF.$('.kui-month-container',that.container_begin)[0];
  383. var _spanlist=_CalF.$('span',_month);
  384. for(i = 0;i<_spanlist.length;i++){
  385. _spanlist[i].onclick = function(){
  386. var monint=arrmonth.contains(this.innerHTML);
  387. var thatmonth=monint<10? "0"+monint:monint;
  388. var minyh=parseInt(that.year+thatmonth);
  389. var maxyh=parseInt(that.year1+that.month1);
  390. if(minyh<=maxyh&&minyh>=parseInt(that.minyear+that.minmonth)){
  391. that.month=thatmonth;
  392. _CalF.$('label',that.container)[0].innerHTML= that.year+'-'+that.month+' - '+that.year1+'-'+that.month1;
  393. for(j=0;j<_spanlist.length;j++){
  394. _CalF.removeClass("kui-active-date",_spanlist[j]);
  395. }
  396. _CalF.addClass("kui-active-date",this);
  397. }
  398. }
  399. }
  400. var _month1 = _CalF.$('.kui-month-container',that.container_end)[0];
  401. var _spanlist1=_CalF.$('span',_month1);
  402. for(i = 0;i<_spanlist1.length;i++){
  403. _spanlist1[i].onclick = function(){
  404. var monint=arrmonth.contains(this.innerHTML);
  405. var thatmonth=monint<10? "0"+monint:monint;
  406. var minyh=parseInt(that.year+that.month);
  407. var maxyh=parseInt(that.year1+thatmonth);
  408. if(maxyh>=minyh&&maxyh<=parseInt(that.maxyear+that.maxmonth)){
  409. that.month1=thatmonth;
  410. _CalF.$('label',that.container)[0].innerHTML= that.year+'-'+that.month+' - '+that.year1+'-'+that.month1;
  411. for(j=0;j<_spanlist1.length;j++){
  412. _CalF.removeClass("kui-active-date",_spanlist1[j]);
  413. }
  414. _CalF.addClass("kui-active-date",this);
  415. }
  416. }
  417. }
  418. }
  419. },
  420. btnYear:function(){
  421. var that=this;
  422. if(document.getElementById(that.id).getAttribute("data-format").split('-').length==2){
  423. var _year=_CalF.$('.kui-yearlist',this.container)[0];
  424. var _yearlist=_CalF.$('.kui-year',_year);
  425. for(i=0;i<_yearlist.length;i++){
  426. _yearlist[i].onclick=function(){
  427. var yearint=this.innerHTML;
  428. var minyh=parseInt(yearint+that.month);
  429. if(minyh>=parseInt(that.minyear+that.minmonth)&&minyh<=parseInt(that.maxyear+that.maxmonth)){
  430. that.year=yearint;
  431. _CalF.$('label',that.container)[0].innerHTML= that.year + '-'+that.month;
  432. for(j=0;j<_yearlist.length;j++){
  433. _CalF.removeClass("kui-active-date",_yearlist[j]);
  434. }
  435. _CalF.addClass("kui-active-date",this);
  436. }
  437. }
  438. }
  439. }else{
  440. var _year=_CalF.$('.kui-yearlist',that.container_begin)[0];
  441. var _yearlist=_CalF.$('.kui-year',_year);
  442. for(i=0;i<_yearlist.length;i++){
  443. _yearlist[i].onclick=function(){
  444. var yearint=this.innerHTML;
  445. var minyh=parseInt(yearint+that.month);
  446. var maxyh=parseInt(that.year1+that.month1);
  447. if(minyh<=maxyh&&minyh>=parseInt(that.minyear+that.minmonth)){
  448. that.year=yearint;
  449. _CalF.$('label',that.container)[0].innerHTML= that.year+'-'+that.month+' - '+that.year1+'-'+that.month1;
  450. for(j=0;j<_yearlist.length;j++){
  451. _CalF.removeClass("kui-active-date",_yearlist[j]);
  452. }
  453. _CalF.addClass("kui-active-date",this);
  454. }
  455. }
  456. }
  457. var _year1=_CalF.$('.kui-yearlist',that.container_end)[0];
  458. var _yearlist1=_CalF.$('.kui-year',_year1);
  459. console.log(_yearlist1.length);
  460. for(i=0;i<_yearlist1.length;i++){
  461. _yearlist1[i].onclick=function(){
  462. var yearint=this.innerHTML;
  463. var minyh=parseInt(that.year+that.month);
  464. var maxyh=parseInt(yearint+that.month1);
  465. //console.log(minyh);
  466. //console.log(maxyh);
  467. if(maxyh>=minyh&&maxyh<=parseInt(that.maxyear+that.maxmonth)){
  468. that.year1=yearint;
  469. _CalF.$('label',that.container)[0].innerHTML= that.year+'-'+that.month+' - '+that.year1+'-'+that.month1;
  470. for(j=0;j<_yearlist1.length;j++){
  471. _CalF.removeClass("kui-active-date",_yearlist1[j]);
  472. }
  473. _CalF.addClass("kui-active-date",this);
  474. }
  475. }
  476. }
  477. }
  478. },
  479. btnSelect:function(){
  480. var _select = _CalF.$('.select',this.container)[0],
  481. that = this;
  482. _select.onclick = function(){
  483. var format=document.getElementById(that.id).getAttribute("data-format");
  484. if(format.split('-').length==2){
  485. that.input.value=that.year + '-'+that.month;
  486. that.removeDate();
  487. }else{
  488. that.input.value=that.year+'-'+that.month+' - '+that.year1+'-'+that.month1;
  489. that.removeDate();
  490. }
  491. };
  492. },
  493. btnClean:function(){
  494. var clean = _CalF.$('.clean',this.container)[0],
  495. that = this;
  496. clean.onclick = function(){
  497. that.removeDate();
  498. };
  499. },
  500. // 鼠标在对象区域外点击,移除日期层
  501. outClick:function(){
  502. var that = this;
  503. _CalF.bind(document, 'click',function(event){
  504. event = event || window.event;
  505. var target = event.target || event.srcElement;
  506. if(target == that.input) {
  507. return;
  508. }
  509. if(that.container.contains(target)){
  510. return;
  511. }
  512. that.removeDate();
  513. })
  514. },
  515. createMonth:function(month){
  516. var _mon=parseInt(month);
  517. var monstr='';
  518. for(i=0;i<arrmonth.length;i++){
  519. if(i+1==_mon){
  520. monstr+='<span class="kui-active-date">'+arrmonth[i]+'</span>';
  521. }else{
  522. monstr+='<span>'+arrmonth[i]+'</span>';
  523. }
  524. }
  525. return monstr;
  526. },
  527. createYear:function(year,activeyear){
  528. var _yea=year;
  529. var _yea_last=parseInt(_yea.charAt(_yea.length - 1));
  530. var yeastr='';
  531. _yea=parseInt(_yea);
  532. for(i=0;i<arryear.length;i++){
  533. var years;
  534. if(_yea_last==0){
  535. years=_yea+(arryear[i]==0?10:arryear[i])-10;
  536. }else{
  537. years=_yea+(arryear[i]==0?10:arryear[i])-_yea_last;
  538. }
  539. if(activeyear==years){
  540. yeastr+='<span class="kui-active-date kui-year">'+years+'</span>';
  541. }else{
  542. yeastr+='<span class="kui-year">'+years+'</span>';
  543. }
  544. }
  545. return yeastr;
  546. }
  547. };
  548. function trim(str) {
  549. return str.toString().replace(/^\s+|\s+$/g,'');
  550. }
  551. Array.prototype.contains = function (obj) {
  552. var i = this.length;
  553. while (i--) {
  554. if (this[i] === obj) {
  555. return i+1;
  556. }
  557. }
  558. return 0;
  559. }
  560. return dateyearmonth;
  561. });