jedate.js 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524
  1. /**
  2. @Name : jeDate v6.5.0 日期控件
  3. @Author: chen guojun
  4. @Date: 2018-04-30
  5. @QQ群:516754269
  6. @官网:http://www.jemui.com/ 或 https://github.com/singod/jeDate
  7. */
  8. ;(function(window, factory) {
  9. //amd
  10. if (typeof define === 'function' && define.amd) {
  11. define(factory);
  12. } else if (typeof exports === 'object') { //umd
  13. module.exports = factory();
  14. } else {
  15. window.jeDate = factory();
  16. }
  17. })(this, function() {
  18. var doc = document, win = window;
  19. var jet = {}, doc = document, regymdzz = "YYYY|MM|DD|hh|mm|ss|zz", gr = /\-/g,
  20. regymd = "YYYY|MM|DD|hh|mm|ss|zz".replace("|zz",""), parseInt = function (n) { return window.parseInt(n, 10);};
  21. var $Q = function (selector,content) {
  22. content = content || document;
  23. return selector.nodeType ? selector : content.querySelector(selector);
  24. };
  25. var jeDate = function(elem,options){
  26. var opts = typeof (options) === "function" ? options() : options;
  27. return new jeDatePick(elem,opts);
  28. };
  29. //日期控件版本
  30. jeDate.dateVer = "V6.5.0";
  31. //用一个或多个其他对象来扩展一个对象,返回被扩展的对象
  32. jeDate.extend = jet.extend = function () {
  33. var options, name, src, copy,deep = false, target = arguments[0], i = 1, length = arguments.length;
  34. if (typeof (target) === "boolean") deep = target, target = arguments[1] || {}, i = 2;
  35. if (typeof (target) !== "object" && typeof (target) !== "function") target = {};
  36. if (length === i) target = this, --i;
  37. for (; i < length; i++) {
  38. if ((options = arguments[i]) != null) {
  39. for (name in options) {
  40. src = target[name], copy = options[name];
  41. if (target === copy) continue;
  42. if (copy !== undefined) target[name] = copy;
  43. }
  44. }
  45. }
  46. return target;
  47. };
  48. //返回指定日期
  49. jeDate.nowDate = function (val,format) {
  50. format = format || 'YYYY-MM-DD hh:mm:ss';
  51. if (!isNaN(val)) val = {DD: val};
  52. return jet.parse(jet.getDateTime(val),format);
  53. };
  54. //日期转换
  55. jeDate.convert = function (obj) {
  56. obj.format = obj.format || 'YYYY-MM-DD hh:mm:ss';
  57. obj.addval = obj.addval || [];
  58. var mats = jet.reMatch(obj.format),objVal = {};
  59. jet.each(jet.reMatch(obj.val),function (i,cval) {
  60. objVal[mats[i]] = parseInt(cval);
  61. });
  62. var result = new DateTime(obj.addval,objVal), redate = {
  63. YYYY:result.GetYear(), MM:result.GetMonth(), DD:result.GetDate(),
  64. hh:result.GetHours(), mm:result.GetMinutes(), ss:result.GetSeconds()
  65. };
  66. return redate;
  67. };
  68. jeDate.valText = function (elem,value) {
  69. return jet.valText(elem,value);
  70. }
  71. //日期时间戳相互转换
  72. jeDate.timeStampDate = function (date,format) {
  73. format = format || 'YYYY-MM-DD hh:mm:ss';
  74. var dateTest = (/^(-)?\d{1,10}$/.test(date) || /^(-)?\d{1,13}$/.test(date));
  75. if(/^[1-9]*[1-9][0-9]*$/.test(date) && dateTest){
  76. var vdate = parseInt(date);
  77. if (/^(-)?\d{1,10}$/.test(vdate)) {
  78. vdate = vdate * 1000;
  79. } else if (/^(-)?\d{1,13}$/.test(vdate)) {
  80. vdate = vdate * 1000;
  81. } else if (/^(-)?\d{1,14}$/.test(vdate)) {
  82. vdate = vdate * 100;
  83. } else {
  84. alert("时间戳格式不正确");
  85. return;
  86. }
  87. var setdate = new Date(vdate);
  88. return jet.parse({
  89. YYYY:setdate.getFullYear(), MM:jet.digit(setdate.getMonth()+1), DD:jet.digit(setdate.getDate()) ,
  90. hh:jet.digit(setdate.getHours()), mm:jet.digit(setdate.getMinutes()), ss:jet.digit(setdate.getSeconds())
  91. }, format);
  92. }else {
  93. //将日期转换成时间戳
  94. var arrs = jet.reMatch(date),
  95. newdate = new Date(arrs[0],arrs[1]-1,arrs[2],arrs[3]||0,arrs[4]||0,arrs[5]||0),
  96. timeStr = Math.round(newdate.getTime() / 1000);
  97. return timeStr;
  98. }
  99. };
  100. //获取年月日星期
  101. jeDate.getLunar = function(obj){
  102. //如果为数字类型的日期对获取到日期的进行替换
  103. var lunars = jeLunar(obj.YYYY, parseInt(obj.MM) - 1, obj.DD);
  104. return{
  105. nM: lunars.lnongMonth, //农历月
  106. nD: lunars.lnongDate, //农历日
  107. cY: parseInt(lunars.solarYear), //阳历年
  108. cM: parseInt(lunars.solarMonth), //阳历月
  109. cD: parseInt(lunars.solarDate), //阳历日
  110. cW: lunars.inWeekDays, //汉字星期几
  111. nW: lunars.solarWeekDay //数字星期几
  112. };
  113. };
  114. //转换日期格式
  115. jeDate.parse = jet.parse = function(ymdhms, format) {
  116. return format.replace(new RegExp(regymdzz,"g"), function(str, index) {
  117. return str == "zz" ? "00":jet.digit(ymdhms[str]);
  118. });
  119. }
  120. //返回日期
  121. function DateTime(arr,valObj) {
  122. var that = this,newdate = new Date(), narr = ["FullYear","Month","Date","Hours","Minutes","Seconds"];
  123. var vb = jet.extend({YYYY:null,MM:null,DD:null,hh:newdate.getHours(),mm:newdate.getMinutes(),ss:newdate.getSeconds()},valObj);
  124. var ND = valObj == undefined ? newdate : new Date(vb.YYYY,vb.MM,vb.DD,vb.hh,vb.mm,vb.ss);
  125. if((arr||[]).length>0) jet.each(arr,function (i,par) {
  126. ND["set"+narr[i]](narr[i] == "Month" ? parseInt(par)-1:parseInt(par));
  127. });
  128. //返回一个数值相同的新DateTime对象
  129. that.reDate = function () {
  130. return new DateTime();
  131. };
  132. //返回此实例的Date值
  133. that.GetValue = function () {
  134. return ND;
  135. };
  136. //获取此实例所表示日期的年份部分。
  137. that.GetYear = function () {
  138. return ND.getFullYear();
  139. };
  140. //获取此实例所表示日期的月份部分。
  141. that.GetMonth = function () {
  142. return ND.getMonth() + 1;
  143. };
  144. //获取此实例所表示的日期为该月中的第几天。
  145. that.GetDate = function () {
  146. return ND.getDate();
  147. };
  148. //获取此实例所表示日期的小时部分。
  149. that.GetHours = function () {
  150. return ND.getHours();
  151. };
  152. //获取此实例所表示日期的分钟部分。
  153. that.GetMinutes = function () {
  154. return ND.getMinutes();
  155. };
  156. //获取此实例所表示日期的秒部分。
  157. that.GetSeconds = function () {
  158. return ND.getSeconds();
  159. };
  160. };
  161. jet.extend(jet,{
  162. isType : function (obj,type) {
  163. var firstUper = function (str) {
  164. str = str.toLowerCase();
  165. return str.replace(/\b(\w)|\s(\w)/g, function (m) {
  166. return m.toUpperCase();
  167. });
  168. }
  169. return Object.prototype.toString.call(obj) == "[object " + firstUper(type) + "]";
  170. },
  171. each : function (obj, callback, args) {
  172. var name, i = 0, length = obj.length, iselem = (length === undefined || obj === "function");
  173. if (iselem) {
  174. for (name in obj) { if (callback.call(obj[name], name, obj[name]) === false) { break } }
  175. } else {
  176. for (; i < length;) { if (callback.call(obj[i], i, obj[i++]) === false) { break } }
  177. }
  178. return obj;
  179. },
  180. on : function (elm, type, fn) {
  181. if (elm.addEventListener) {
  182. elm.addEventListener(type, fn, false);//DOM2.0
  183. return true;
  184. }else if (elm.attachEvent) {
  185. return elm.attachEvent("on" + type, fn);//IE5+
  186. }else {
  187. elm["on" + type] = fn;//DOM 0
  188. }
  189. },
  190. isObj : function (obj){
  191. for(var i in obj){return true;}
  192. return false;
  193. },
  194. trim : function (str){ return str.replace(/(^\s*)|(\s*$)/g, ""); },
  195. reMatch : function (str) {
  196. var smarr = [],maStr = "", parti = /(^\w{4}|\w{2}\B)/g;
  197. if(jet.isNum(str)){
  198. maStr = str.replace(parti,"$1-");
  199. }else{
  200. maStr = /^[A-Za-z]+$/.test(str) ? str.replace(parti,"$1-") : str;
  201. }
  202. jet.each(maStr.match(/\w+|d+/g),function (i,val) {
  203. smarr.push(jet.isNum(val) ? parseInt(val):val);
  204. });
  205. return smarr;
  206. },
  207. equals : function (arrA,arrB) {
  208. if (!arrB) return false;
  209. if (arrA.length != arrB.length) return false;
  210. for (var i = 0, l = arrA.length; i < l; i++) {
  211. if (arrA[i] instanceof Array && arrB[i] instanceof Array) {
  212. if (!arrA[i].equals(arrB[i])) return false;
  213. } else if (arrA[i] != arrB[i]) {
  214. return false;
  215. }
  216. }
  217. return true;
  218. },
  219. docScroll : function(type) {
  220. type = type ? "scrollLeft" :"scrollTop";
  221. return document.body[type] | document.documentElement[type];
  222. },
  223. docArea : function(type) {
  224. return document.documentElement[type ? "clientWidth" :"clientHeight"];
  225. },
  226. //补齐数位
  227. digit : function(num) {
  228. return num < 10 ? "0" + (num | 0) :num;
  229. },
  230. //判断是否为数字
  231. isNum : function(value){
  232. return /^[+-]?\d*\.?\d*$/.test(value) ? true : false;
  233. },
  234. //获取本月的总天数
  235. getDaysNum : function(y, m) {
  236. var num = 31,isLeap = (y % 100 !== 0 && y % 4 === 0) || (y % 400 === 0);
  237. switch (parseInt(m)) {
  238. case 2: num = isLeap ? 29 : 28; break;
  239. case 4: case 6: case 9: case 11: num = 30; break;
  240. }
  241. return num;
  242. },
  243. //获取月与年
  244. getYM : function(y, m, n) {
  245. var nd = new Date(y, m - 1);
  246. nd.setMonth(m - 1 + n);
  247. return {
  248. y: nd.getFullYear(),
  249. m: nd.getMonth() + 1
  250. };
  251. },
  252. //获取上个月
  253. prevMonth : function(y, m, n) {
  254. return jet.getYM(y, m, 0 - (n || 1));
  255. },
  256. //获取下个月
  257. nextMonth : function(y, m, n) {
  258. return jet.getYM(y, m, n || 1);
  259. },
  260. setCss:function(elem,obj) {
  261. for (var x in obj) elem.style[x] = obj[x];
  262. },
  263. html : function (elem,html) {
  264. return typeof html === "undefined" ? elem && elem.nodeType === 1 ? elem.innerHTML :undefined :typeof html !== "undefined" && html == true ? elem && elem.nodeType === 1 ? elem.outerHTML :undefined : elem.innerHTML = html;
  265. },
  266. // 读取设置节点文本内容
  267. text : function(elem,value) {
  268. var innText = document.all ? "innerText" :"textContent";
  269. return typeof value === "undefined" ? elem && elem.nodeType === 1 ? elem[innText] :undefined : elem[innText] = value;
  270. },
  271. //设置值
  272. val : function (elem,value) {
  273. if (typeof value === "undefined") {
  274. return elem && elem.nodeType === 1 && typeof elem.value !== "undefined" ? elem.value :undefined;
  275. }
  276. // 将value转化为string
  277. value = value == null ? "" :value + "";
  278. elem.value = value;
  279. },
  280. attr : function(elem,value){
  281. return elem.getAttribute(value);
  282. },
  283. hasClass : function (obj, cls) {
  284. return obj.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
  285. },
  286. stopPropagation : function (ev) {
  287. (ev && ev.stopPropagation) ? ev.stopPropagation() : window.event.cancelBubble = true;
  288. },
  289. template : function (str, data) {
  290. var strCell = !/[^\w\-\.:]/.test(str) ? document.getElementById(str).innerHTML : str;
  291. var keys = function (obj){
  292. var arr = [];
  293. for(arr[arr.length] in obj);
  294. return arr ;
  295. }, dataVar = function (obj) {
  296. var vars = '';
  297. for (var key in obj) {
  298. vars += 'var ' + key + '= $D["' + key + '"];';
  299. }
  300. return vars;
  301. }, compile = function (source,data) {
  302. var code = "var $out='" + source.replace(/[\r\n]/g, '').replace(/^(.+?)\{\%|\%\}(.+?)\{\%|\%\}(.+?)$/g, function (val) {
  303. return val.replace(/(['"])/g, '\\\$1');
  304. }).replace(/\{\%\s*=\s*(.+?)\%\}/g, "';$out+=$1;$out+='").replace(/\{\%(.+?)\%\}/g, "';$1;$out+='") + "';return new String($out);";
  305. var vars = dataVar(data), Render = new Function('$D',vars + code);
  306. return new Render(data) + '';
  307. };
  308. return compile(strCell,data);
  309. },
  310. //判断元素类型
  311. isValDiv : function(elem) {
  312. return /textarea|input/.test(elem.tagName.toLocaleLowerCase());
  313. },
  314. valText : function (elem,value) {
  315. var cell = $Q(elem) ,type = jet.isValDiv(cell) ? "val" : "text";
  316. if(value != undefined){
  317. jet[type](cell,value);
  318. }else{
  319. return jet[type](cell);
  320. }
  321. },
  322. isBool : function(obj){ return (obj == undefined || obj == true ? true : false); },
  323. //获取返回的日期
  324. getDateTime : function (obj) {
  325. var result = new DateTime(), objVal = jet.extend({YYYY:null,MM:null,DD:null,hh:0,mm:0,ss:0},obj),
  326. matArr = {YYYY:"FullYear",MM:"Month",DD:"Date",hh:"Hours",mm:"Minutes",ss:"Seconds"};
  327. jet.each(["ss","mm","hh","DD","MM","YYYY"],function (i,mat) {
  328. if (!jet.isNum(parseInt(objVal[mat]))) return null;
  329. var reVal = result.GetValue();
  330. if (parseInt(objVal[mat]) || parseInt(objVal[mat]) == 0){
  331. reVal["set"+matArr[mat]](result["Get"+matArr[mat]]() + (mat == "MM" ? -1 : 0) + parseInt(objVal[mat]));
  332. }
  333. });
  334. //获取格式化后的日期
  335. var redate = {
  336. YYYY:result.GetYear(), MM:result.GetMonth(), DD:result.GetDate(),
  337. hh:result.GetHours(), mm:result.GetMinutes(), ss:result.GetSeconds()
  338. };
  339. return redate;
  340. }
  341. });
  342. function jeDatePick(elem, options){
  343. var config = {
  344. language:{
  345. name : "cn",
  346. month : ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"],
  347. weeks : [ "日", "一", "二", "三", "四", "五", "六" ],
  348. times : ["小时","分钟","秒数"],
  349. timetxt: ["时间选择","开始时间","结束时间"],
  350. backtxt:"返回日期",
  351. clear : "清空",
  352. today : "现在",
  353. yes : "确定"
  354. },
  355. format:"YYYY-MM-DD hh:mm:ss", //日期格式
  356. minDate:"1900-01-01 00:00:00", //最小日期
  357. maxDate:"2099-12-31 23:59:59", //最大日期
  358. isShow:true, //是否显示为固定日历,为false的时候固定显示
  359. multiPane:true, //是否为双面板,为false是展示双面板
  360. onClose:true, //是否为选中日期后关闭弹层,为false时选中日期后关闭弹层
  361. range:false, //如果不为空且不为false,则会进行区域选择,例如 " 至 "," ~ "," To "
  362. trigger:"click", //是否为内部触发事件,默认为内部触发事件
  363. position:[], //自定义日期弹层的偏移位置,长度为0,弹层自动查找位置
  364. valiDate:[], //有效日期与非有效日期,例如 ["0[4-7]$,1[1-5]$,2[58]$",true]
  365. isinitVal:false, //是否初始化时间,默认不初始化时间
  366. initDate:{}, //初始化时间,加减 天 时 分
  367. isTime:true, //是否开启时间选择
  368. isClear:true, //是否显示清空按钮
  369. isToday:true, //是否显示今天或本月按钮
  370. isYes:true, //是否显示确定按钮
  371. festival:false, //是否显示农历节日
  372. fixed:true, //是否静止定位,为true时定位在输入框,为false时居中定位
  373. zIndex:2099, //弹出层的层级高度
  374. method:{}, //自定义方法
  375. theme:{}, //自定义主题色
  376. shortcut:[], //日期选择的快捷方式
  377. donefun:null, //选中日期完成的回调
  378. before:null, //在界面加载之前执行
  379. succeed:null //在界面加载之后执行
  380. };
  381. this.$opts = jet.extend(config,options||{});
  382. this.valCell = $Q(elem);
  383. this.format = this.$opts.format;
  384. this.valCell != null ? this.init() : alert(elem+" ID\u6216\u7C7B\u540D\u4E0D\u5B58\u5728!");
  385. jet.extend(this,this.$opts.method);
  386. delete this.$opts.method;
  387. }
  388. var searandom = function (){
  389. var str = "",arr = [1,2,3,4,5,6,7,8,9,0];
  390. for(var i=0; i<8; i++) str += arr[Math.round(Math.random() * (arr.length-1))];
  391. return str;
  392. };
  393. var jefix = "jefixed",ymdzArr = jet.reMatch(regymdzz),elx = "#jedate";
  394. jet.extend(jeDatePick.prototype,{
  395. init : function () {
  396. var that = this, opts = that.$opts, newDate = new Date(), shortArr = [],
  397. trigges = opts.trigger,ndate = opts.initDate || [], inVal, range = opts.range,
  398. zIndex = opts.zIndex == undefined ? 10000 : opts.zIndex,isShow = jet.isBool(opts.isShow),
  399. isinitVal = (opts.isinitVal == undefined || opts.isinitVal == false) ? false : true;
  400. that.setDatas();
  401. opts.before && opts.before(that.valCell);
  402. //为开启初始化的时间设置值
  403. if (isinitVal && trigges && isShow) {
  404. if (ndate[1]){
  405. var addval = jet.getDateTime(ndate[0]);
  406. inVal = [{
  407. YYYY:addval.YYYY, MM:jet.digit(addval.MM), DD:jet.digit(addval.DD) ,
  408. hh:jet.digit(addval.hh), mm:jet.digit(addval.mm), ss:jet.digit(addval.ss)
  409. }];
  410. }else {
  411. inVal = that.getValue(jet.isObj(ndate[0]) ? ndate[0] : {});
  412. }
  413. if(!range) that.setValue([inVal[0]],opts.format,true);
  414. }
  415. var getCurrValue = function () {
  416. var mats = jet.reMatch(that.format), isEmpty = that.getValue() != "",curVal = [],
  417. parmat = that.dlen == 7 ? "hh:mm:ss" : "YYYY-MM"+ (that.dlen <= 2 ? "":"-DD");
  418. that.selectValue = [jet.parse(jet.getDateTime({}), parmat)];
  419. if(isEmpty && isShow){
  420. var getVal = that.getValue().split(range);
  421. jet.each(new Array(range ? 2 : 1),function (a) {
  422. curVal[a] = {};
  423. jet.each(jet.reMatch(getVal[a]),function (i,val) {
  424. curVal[a][mats[i]] = parseInt(val);
  425. });
  426. });
  427. if(range) that.selectValue = getVal;
  428. }else{
  429. var parr = that.getValue({})[0], nmVal = jet.nextMonth(parr.YYYY,parr.MM||jet.getDateTime({}).MM),
  430. narr = (that.dlen>2 && that.dlen <=6) ? {YYYY:nmVal.y,MM:nmVal.m} : {};
  431. curVal = [parr];
  432. }
  433. that.selectDate = curVal;
  434. return curVal;
  435. },ymarr = [];
  436. that.minDate = ""; that.maxDate = "";
  437. if(!isShow || !trigges) ymarr = getCurrValue();
  438. if(!isShow || !trigges){
  439. that.minDate = jet.isType(opts.minDate,"function") ? opts.minDate(that) : opts.minDate;
  440. that.maxDate = jet.isType(opts.maxDate,"function") ? opts.maxDate(that) : opts.maxDate;
  441. that.storeData(ymarr[0],ymarr[1]);
  442. that.renderDate();
  443. opts.succeed && opts.succeed(that.dateCell);
  444. }else{
  445. if (trigges) {
  446. jet.on(that.valCell,trigges,function(){
  447. if (document.querySelectorAll(elx).length > 0) return;
  448. var gvarr = getCurrValue();
  449. that.minDate = jet.isType(opts.minDate,"function") ? opts.minDate(that) : opts.minDate;
  450. that.maxDate = jet.isType(opts.maxDate,"function") ? opts.maxDate(that) : opts.maxDate;
  451. that.storeData(gvarr[0],gvarr[1]);
  452. that.renderDate();
  453. });
  454. }
  455. }
  456. },
  457. setDatas : function(){
  458. var that = this, opts = that.$opts,range = opts.range,shortArr = [],isShow = jet.isBool(opts.isShow),multi = opts.multiPane;
  459. that.$data = jet.extend({year:false,month:false,day:true,time:false,timebtn:false},{
  460. shortcut:[],lang:opts.language,yaerlist:[],monthlist:[[],[]],ymlist:[[],[]], daylist:[[],[]],
  461. clear:opts.isClear,today:range ? false:opts.isToday,yes:opts.isYes,pane:multi ? 1:2
  462. });
  463. if(opts.shortcut.length>0){
  464. jet.each(opts.shortcut,function (i,short) {
  465. var tarr = [], shval = jet.isType(short.val,"function") ? short.val() : short.val;
  466. if(jet.isType(shval,"object")){
  467. for (var s in shval) tarr.push(s + ':' + shval[s]);
  468. shortArr.push(jet.extend({},{name:short.name,val:"{" + tarr.join('#') + "}"}));
  469. }
  470. });
  471. that.$data.shortcut = shortArr;
  472. }
  473. that.dlen = (function () {
  474. var mats = jet.reMatch(that.format),marr = [];
  475. jet.each(ymdzArr,function(i,val){
  476. jet.each(mats,function(m,mval){
  477. if(val == mval) marr.push(mval);
  478. });
  479. });
  480. var matlen = marr.length, lens = (marr[0] == "hh")&&matlen<=3 ? 7 : matlen;
  481. return lens;
  482. })();
  483. that.$data.dlen = that.dlen;
  484. that.timeInspect = false;
  485. if(that.dlen == 1){
  486. jet.extend(that.$data,{year:true,day:false});
  487. }else if(that.dlen == 2){
  488. jet.extend(that.$data,{month:true,day:false});
  489. }else if(that.dlen>3 && that.dlen <=6){
  490. that.$data.timebtn = true;
  491. }else if(that.dlen == 7){
  492. jet.extend(that.$data,{day:false,time:true});
  493. }
  494. if(!isShow){
  495. that.$data.clear = false;
  496. that.$data.yes = false;
  497. }
  498. },
  499. renderDate : function () {
  500. var that= this, opts = that.$opts,isShow = jet.isBool(opts.isShow),
  501. elxID = !isShow ? elx+searandom() : elx, setzin = {"zIndex": (opts.zIndex == undefined ? 10000 : opts.zIndex)};
  502. if(that.dateCell == undefined){
  503. that.dateCell = document.createElement("div");
  504. that.dateCell.id = elxID.replace(/\#/g,"");
  505. that.dateCell.className = elx.replace(/\#/g,"")+" "+(opts.shortcut.length>0?" leftmenu":"");
  506. that.dateCell.setAttribute("author","chen guojun");
  507. }
  508. jet.html(that.dateCell,jet.template(that.dateTemplate(),that.$data));
  509. //自定义主题色
  510. if(jet.isObj(opts.theme)){
  511. var styleDiv = document.createElement("style"),stCell = ".jedate"+searandom(), t = opts.theme,
  512. BG = "background-color:"+t.bgcolor, WC = "color:"+(t.color == undefined ? "#FFFFFF":t.color),
  513. OTH = (t.pnColor == undefined ? "":"color:"+t.pnColor+";");
  514. that.dateCell.className = that.dateCell.className+" "+stCell.replace(/^./g,""); styleDiv.setAttribute("type","text/css");
  515. styleDiv.innerHTML = stCell+" .jedate-menu p:hover{"+BG+";"+WC+";}"+stCell+" .jedate-header em{"+WC+";}"+
  516. stCell+" .jedate-content .yeartable td.action span,"+stCell+" .jedate-content .monthtable td.action span,"+
  517. stCell+" .jedate-content .yeartable td.action span:hover,"+stCell+" .jedate-content .monthtable td.action span:hover{"+BG+";border:1px "+t.bgcolor+" solid;"+WC+";}"+stCell+" .jedate-content .daystable td.action,"+stCell+" .jedate-content .daystable td.action:hover,"+
  518. stCell+" .jedate-content .daystable td.action .lunar,"+stCell+" .jedate-header,"+stCell+" .jedate-time .timeheader,"+
  519. stCell+" .jedate-time .hmslist ul li.action,"+stCell+" .jedate-time .hmslist ul li.action:hover,"+
  520. stCell+" .jedate-time .hmslist ul li.disabled.action,"+stCell+" .jedate-footbtn .timecon,"+stCell+" .jedate-footbtn .btnscon span{"+BG+";"+WC+";}"+
  521. stCell+" .jedate-content .daystable td.other,"+stCell+" .jedate-content .daystable td.other .nolunar,"+stCell+" .jedate-content .daystable td.other .lunar{"+OTH+"}"+stCell+" .jedate-content .daystable td.contain,"+stCell+" .jedate-content .daystable td.contain:hover{background-"+OTH+"}";
  522. that.dateCell.appendChild(styleDiv);
  523. }
  524. that.compileBindNode(that.dateCell);
  525. if (document.querySelectorAll(elxID).length > 0) document.body.removeChild($Q(elxID));
  526. !isShow ? that.valCell.appendChild(that.dateCell) : document.body.appendChild(that.dateCell);
  527. jet.setCss(that.dateCell,jet.extend({position:(!isShow ? "relative" : (opts.fixed == true ? "absolute" :"fixed"))},isShow ? setzin:{}));
  528. that.methodEventBind();
  529. if(that.dlen == 7 || (that.dlen>3 && that.dlen <=6)) that.locateScroll();
  530. if(opts.festival && opts.language.name == "cn") that.showFestival();
  531. if(isShow){
  532. that.dateOrien(that.dateCell,that.valCell);
  533. that.blankArea();
  534. }
  535. },
  536. //设置日期值
  537. setValue : function (fnStr,matStr,bool) {
  538. var that = this, valCell = that.valCell,strVal;
  539. matStr = matStr || that.format;
  540. if((typeof fnStr=='string')&&fnStr!=''){
  541. var sprange = fnStr.split(that.$opts.range), inArr=[];
  542. jet.each(sprange,function (i,sval) {
  543. var reVal = jet.reMatch(sval), inObj={};
  544. jet.each(jet.reMatch(matStr),function (r,val) {
  545. inObj[val] = reVal[r];
  546. });
  547. inArr.push(inObj);
  548. });
  549. strVal = inArr;
  550. }else {
  551. strVal = fnStr;
  552. }
  553. var vals = that.parseValue(strVal,matStr);
  554. if (bool != false) jet.valText(valCell,vals);
  555. return vals;
  556. },
  557. //获取日期值
  558. getValue : function (valobj) {
  559. var that = this, valCell = that.valCell,
  560. opts = that.$opts, reObj, result = new DateTime().reDate(),
  561. dateY = result.GetYear(),dateM = result.GetMonth(),dateD = result.GetDate(),
  562. timeh = result.GetHours(),timem = result.GetMinutes(),times = result.GetSeconds();
  563. if (valobj == undefined && jet.isBool(opts.isShow)){
  564. reObj = jet.valText(valCell);
  565. }else {
  566. var isValShow = jet.isBool(opts.isShow) ? (jet.valText(valCell) == "") : !jet.isBool(opts.isShow),
  567. objarr = jet.extend({YYYY:null,MM:null,DD:null},valobj||{}),
  568. ranMat = [],newArr = new Array(2),unObj = function (obj) {
  569. return [(objarr[obj] == undefined || objarr[obj] == null),objarr[obj]];
  570. }, defObj = [{ YYYY:dateY,MM:dateM,DD:dateD, hh:timeh,mm:timem,ss:times,zz:00},
  571. { YYYY:dateY,MM:dateM,DD:dateD, hh:timeh,mm:timem,ss:times,zz:00}];
  572. if (isValShow) {
  573. //目标为空值则获取当前日期时间
  574. jet.each(newArr,function (i) {
  575. var inObj = {};
  576. jet.each(ymdzArr, function (r, val) {
  577. inObj[val] = parseInt(unObj(val)[0] ? defObj[i][val] : unObj(val)[1]);
  578. });
  579. ranMat.push(jet.extend(defObj[i], inObj));
  580. });
  581. } else {
  582. var isunRange = opts.range != false, initVal = that.getValue(),
  583. spVal = initVal.split(opts.range), reMat = jet.reMatch(that.format);
  584. jet.each(newArr,function (i) {
  585. var inObj = {}, reVal = isunRange ? jet.reMatch(spVal[i]) : jet.reMatch(initVal);
  586. jet.each(reMat,function (r,val) {
  587. inObj[val] = reVal[r];
  588. });
  589. var exVal = jet.extend(inObj,valobj||{});
  590. ranMat.push(jet.extend(defObj[i],exVal));
  591. });
  592. }
  593. reObj = ranMat;
  594. }
  595. return reObj;
  596. },
  597. storeData:function (curr,next) {
  598. next = next || {};
  599. var that = this, opts = that.$opts,multi = opts.multiPane,valCell = that.valCell,
  600. days = new Date().getDate(), DTS = that.$data,isnext = jet.isObj(next),
  601. RES = {yearlist:[],monthlist:[[],[]],daylist:[],daytit:[],timelist:[]},seltime,
  602. cday = curr.DD == null ? days : curr.DD, nday = next.DD == null ? days : next.DD,
  603. timeA = {hh:curr.hh,mm:curr.mm,ss:curr.ss}, timeB = {hh:next.hh||0,mm:next.mm||0,ss:next.ss||0};
  604. //设置年的数据
  605. RES.yearlist.push(that.eachYear(parseInt(curr.YYYY),1));
  606. if(multi == false){
  607. var yearNext = isnext ? next.YYYY : curr.YYYY;
  608. RES.yearlist.push(that.eachYear(parseInt(yearNext),2));
  609. }
  610. //设置月的数据
  611. RES.monthlist[0] = that.eachMonth(curr.YYYY,0);
  612. if(multi == false){
  613. var monthNext = isnext ? next.YYYY : curr.YYYY+1;
  614. RES.monthlist[1] = that.eachMonth(curr.YYYY+1,1);
  615. }
  616. //设置天的数据
  617. RES.daylist.push(that.eachDays(curr.YYYY,curr.MM,cday,0));
  618. RES.daytit.push({YYYY:curr.YYYY,MM:curr.MM});
  619. if(multi == false){
  620. var dayNext = jet.nextMonth(curr.YYYY,curr.MM);
  621. RES.daylist.push(that.eachDays(dayNext.y,dayNext.m,nday,1));
  622. RES.daytit.push({YYYY:dayNext.y,MM:dayNext.m});
  623. }
  624. //设置时间数据
  625. that.selectTime = [timeA,timeB];
  626. RES.timelist.push(that.eachTime(timeA,1));
  627. if(multi == false){
  628. seltime = that.dlen == 7 && opts.range && !isnext ? timeA : timeB;
  629. if(that.dlen == 7 && opts.range && jet.valText(valCell) == ""){
  630. that.selectTime[1] = jet.extend(timeB,timeA);
  631. }
  632. RES.timelist.push(that.eachTime(seltime,2));
  633. }
  634. //最后将数据合并于总数据中
  635. jet.extend(that.$data,RES);
  636. },
  637. dateTemplate : function() {
  638. var that = this, opts = that.$opts, multi = opts.multiPane,YMDStr = "",hmsStr = "",lang = opts.language,
  639. ytxt = lang.name == "cn" ? "年":"", mtxt = lang.name == "cn" ? "月":"";
  640. var ymvals = multi ? '{%=ymlist[0].YYYY%}-{%=ymlist[0].MM%}':'{%=ymlist[0].YYYY%}-{%=ymlist[0].MM%}#{%=ymlist[ynidx].YYYY%}-{%=ymlist[ynidx].MM%}';
  641. var aowArr = (function () {
  642. var butArr = [], ismu = multi ? "11":"23";
  643. if(that.dlen == 1){
  644. butArr = ['{%=yearlist[i][0].y-'+ismu+'%}','{%=yearlist[i][yearlist[i].length-1].y%}'];
  645. }else if(that.dlen == 2){
  646. butArr = multi ? ['{%=yearlist[0][0].y-1%}','{%=yearlist[0][0].y+1%}']:['{%=yearlist[i][0].y-'+ismu+'%}','{%=yearlist[i][yearlist[i].length-1].y%}'];
  647. }else if(that.dlen>2 && that.dlen <=6){
  648. butArr = ['{%=yearlist[0][0].y-1%}','{%=yearlist[0][0].y+1%}'];
  649. }
  650. return butArr;
  651. })();
  652. var lyPrev = '<em class="yearprev yprev jedatefont" @on="yearBtn(lprev,'+aowArr[0]+')">&#xed6c2;</em>',
  653. lyNext = '<em class="yearnext ynext jedatefont" on="yearBtn(lnext,'+aowArr[2]+')">&#xed6c5;</em>',
  654. ryPrev = '<em class="yearprev yprev jedatefont" on="yearBtn(rprev,'+aowArr[3]+')">&#xed6c2;</em>',
  655. ryNext = '<em class="yearnext ynext jedatefont" @on="yearBtn(rnext,'+aowArr[1]+')">&#xed6c5;</em>',
  656. mPrev = '{% if(dlen>2){ %}<em class="monthprev mprev jedatefont" @on="monthBtn(mprev,{%=daytit[i].YYYY%}-{%=daytit[i].MM%})">&#xed602;</em>{% } %}',
  657. mNext = '{% if(dlen>2){ %}<em class="monthnext mnext jedatefont" @on="monthBtn(mnext,{%=daytit[i].YYYY%}-{%=daytit[i].MM%})">&#xed605;</em>{% } %}';
  658. //循环年的模板
  659. var yaerHtml = '<table class="yeartable year{%= i==0 ? "left":"right"%}" style="display:{%=year ? "block":"none"%};"><tbody><tr>'+
  660. '{% for(var y=0;y<=11;y++){ %}<td class="{%=yearlist[i][y].style%}" @on="yearClick({%=yearlist[i][y].y%})"><span>{%=yearlist[i][y].y%}'+ytxt+'</span></td>{% if((y+1)%3==0){ %} </tr>{% } %} {% } %} </tbody></table>';
  661. //循环月的模板
  662. var monthHtml = '<table class="monthtable month{%= i==0 ? "left":"right"%}" style="display:{%=month ? "block":"none"%};"><tbody><tr>'+
  663. '{% for(var m=0;m<=11;m++){ %}<td class="{%=monthlist[i][m].style%}" ym="{%=monthlist[i][m].y%}-{%=monthlist[i][m].m%}" @on="monthClick({%=monthlist[i][m].y%}-{%=monthlist[i][m].m%})"><span>{%=monthlist[i][m].m%}'+mtxt+'</span></td>{% if((m+1)%3==0){ %} </tr>{% } %} {% } %} </tbody></table>';
  664. //循环天的模板
  665. var daysHtml = '<table class="daystable days{%= i==0 ? "left":"right"%}" style="display:{%=day ? "block":"none"%};"><thead><tr>'+
  666. '{% for(var w=0;w<lang.weeks.length;w++){ %} <th>{%=lang.weeks[w]%}</th> {% } %}</tr></thead><tbody>'+
  667. '<tr>{% for(var d=0;d<=41;d++){ %}<td class="{%=daylist[i][d].style%}" ymd="{%=daylist[i][d].ymd%}" @on="daysClick({%=daylist[i][d].ymd%})">{%=daylist[i][d].day%}</td>{% if((d+1)%7==0){ %} </tr>{% } %} {% } %} </tbody></table>';
  668. //循环时间模板
  669. var hmsHtml = '<div class="jedate-time">{% for(var h=0;h<timelist.length;h++){ %}<div class="timepane"><div class="timeheader">{%= timelist.length == 1 ? lang.timetxt[0]:lang.timetxt[h+1]%}</div><div class="timecontent">'+
  670. '<div class="hmstitle"><p>{%=lang.times[0]%}</p><p>{%=lang.times[1]%}</p><p>{%=lang.times[2]%}</p></div>'+
  671. '<div class="hmslist">{% for(var t=0;t<3;t++){ %}<div class="hmsauto"><ul>{% for(var s=0;s<timelist[h][t].length;s++){ %}<li class="{%=timelist[h][t][s].style%}" @on="hmsClick({%= h %},{%= h>0?3+t:t %})">{%= timelist[h][t][s].hms < 10 ? "0" + timelist[h][t][s].hms :timelist[h][t][s].hms %}</li>{% } %}</ul></div>{% } %}</div></div>'+'</div>{% } %}</div>';
  672. //左边选择模板
  673. var shortHtml = opts.shortcut.length > 0 ? "{% for(var s=0;s<shortcut.length;s++){ %}<p @on=shortClick({%= shortcut[s].val %})>{%=shortcut[s].name%}</p>{% } %}":'';
  674. var ymtitHtml = (function () {
  675. var ymtitStr = "";
  676. if(that.dlen == 1){
  677. ymtitStr = '<span class="ymbtn">{%=yearlist[i][0].y%}'+ytxt+' ~ {%=yearlist[i][yearlist[i].length-1].y%}'+ytxt+'</span>';
  678. }else if(that.dlen == 2){
  679. ymtitStr = '<span class="ymbtn" @on="yearShow({%=yearlist[0][i].y%})">{%=yearlist[0][i].y%}'+ytxt+'</span>';
  680. }else if(that.dlen>2 && that.dlen <=6){
  681. ymtitStr = '<span class="ymbtn" @on="monthShow({%=daytit[i].MM%})">{%=daytit[i].MM%}'+mtxt+'</span>'+
  682. '<span class="ymbtn" @on="yearShow({%=daytit[i].YYYY%})">{%=daytit[i].YYYY%}'+ytxt+'</span>';
  683. }
  684. return ymtitStr;
  685. })();
  686. var ymButton = (function () {
  687. var titStrBut = "";
  688. if(that.dlen==1){
  689. titStrBut = multi ? [lyPrev+ryNext]:[lyPrev,ryNext];
  690. }else if(that.dlen==2){
  691. titStrBut = multi ? [lyPrev+ryNext] : [lyPrev,ryNext];
  692. }else if(that.dlen>2 && that.dlen <=6){
  693. titStrBut = multi ? [lyPrev+mPrev+mNext+ryNext] : [lyPrev+mPrev,mNext+ryNext];
  694. }else if(that.dlen==7){
  695. titStrBut = "";
  696. }
  697. return titStrBut;
  698. })();
  699. if(that.dlen == 1){
  700. YMDStr = yaerHtml;
  701. }else if(that.dlen == 2){
  702. YMDStr = yaerHtml + monthHtml;
  703. }else if(that.dlen == 3){
  704. YMDStr = yaerHtml + monthHtml + daysHtml;
  705. }else if(that.dlen > 3 && that.dlen <= 6){
  706. YMDStr = yaerHtml + monthHtml + daysHtml;
  707. hmsStr = hmsHtml;
  708. }else if(that.dlen == 7){
  709. hmsStr = hmsHtml;
  710. }
  711. var paneHtml = '{% for(var i=0;i<pane;i++){ %}<div class="jedate-pane">'+
  712. '<div class="jedate-header">{% if(i==0){ %}'+ymButton[0]+'{% }else{ %}'+ymButton[1]+'{% } %}'+ymtitHtml+'</div>'+
  713. '<div class="jedate-content{%= i==1?" bordge":"" %}">'+YMDStr+'</div>'+
  714. '</div>{% } %}';
  715. var btnStr = '{% if(timebtn){%}<div class="timecon" style="cursor: pointer;" @on="timeBtn">{%=lang.timetxt[0]%}</div>{% } %}<div class="btnscon">{% if(clear){ %}<span class="clear" @on="clearBtn">{%=lang.clear%}</span>{% } %}{% if(today){ %}<span class="today" @on="nowBtn">{%=lang.today%}</span>{% } %}{% if(yes){ %}<span class="setok" @on="sureBtn">{%=lang.yes%}</span>{% } %}</div>';
  716. return '<div class="jedate-menu" style="display:{%=shortcut.length>0 ? "block":"none"%};">'+shortHtml+'</div><div class="jedate-wrap">'+paneHtml+'</div>'+hmsStr+'<div class="jedate-footbtn">'+btnStr+'</div><div class="jedate-tips"></div>';
  717. },
  718. //递归绑定事件
  719. compileBindNode : function (dom) {
  720. var self = this, aton = "@on";
  721. var acquireAttr = function (atVal){
  722. var args=/\(.*\)/.exec(atVal);
  723. if(args) { //如果函数带参数,将参数字符串转换为参数数组
  724. args = args[0];
  725. atVal = atVal.replace(args,"");
  726. args = args.replace(/[\(\)\'\"]/g,'').split(",");
  727. }else args = [];
  728. return [atVal,args];
  729. };
  730. jet.each(dom.childNodes,function (i,node) {
  731. if (node.nodeType === 1) {
  732. if(!self.$opts.festival) node.removeAttribute("ymd");
  733. self.compileBindNode(node);
  734. var geton = node.getAttribute(aton);
  735. if(geton != null){
  736. var onarr = acquireAttr(geton);
  737. jet.on(node,"click",function () {
  738. self[onarr[0]] && self[onarr[0]].apply(node,onarr[1]);
  739. });
  740. node.removeAttribute(aton);
  741. }
  742. }
  743. });
  744. },
  745. methodEventBind : function() {
  746. var that = this, opts = that.$opts, multi = opts.multiPane, DTS = that.$data,
  747. result = new DateTime().reDate(),dateY = result.GetYear(),dateM = result.GetMonth(),dateD = result.GetDate(),
  748. range = opts.range,elCell = that.dateCell;
  749. jet.extend(that,{
  750. yearBtn:function (type,val) {
  751. var yarr = val.split("#"), pval = jet.reMatch(yarr[0]), tmval = that.selectTime;
  752. exarr = [jet.extend({YYYY:parseInt(val),MM:dateM,DD:dateD},tmval[0]),{}];
  753. var dateVal = that.parseValue([exarr[0]],that.format);
  754. that.storeData(exarr[0],exarr[1]);
  755. that.renderDate();
  756. opts.toggle && opts.toggle({elem:that.valCell,val:dateVal,date:exarr[0]});
  757. },
  758. yearShow:function (val) {
  759. DTS.year = DTS.year ? false : true;
  760. DTS.month = that.dlen < 3 ? true : false;
  761. if(that.dlen > 2 && that.dlen <= 6){
  762. var dayCell = $Q(".daystable",elCell);
  763. DTS.day = dayCell.style.display == "none" ? true : false;
  764. }
  765. that.renderDate();
  766. },
  767. monthBtn:function (type,val) {
  768. var ymarr = jet.reMatch(val),tmval = that.selectTime, exarr=[], PrevYM , NextYM,
  769. year = parseInt(ymarr[0]),month = parseInt(ymarr[1]);
  770. if(range){
  771. if(type == "mprev"){
  772. PrevYM = jet.prevMonth(year, month);
  773. NextYM = jet.nextMonth(PrevYM.y, PrevYM.m);
  774. }else{
  775. NextYM = jet.nextMonth(year, month);
  776. PrevYM = jet.prevMonth(NextYM.y, NextYM.m);
  777. }
  778. exarr = [jet.extend({YYYY:PrevYM.y,MM:PrevYM.m,DD:dateD},tmval[0]),{YYYY:NextYM.y,MM:NextYM.m,DD:dateD}];
  779. }else{
  780. var PNYM = (type == "mprev") ? jet.prevMonth(year, month) : jet.nextMonth(year, month);
  781. exarr = [jet.extend({YYYY:PNYM.y,MM:PNYM.m,DD:dateD},tmval[0]),{}];
  782. }
  783. var dateVal = that.parseValue([exarr[0]],that.format);
  784. that.storeData(exarr[0],exarr[1]);
  785. that.renderDate();
  786. opts.toggle && opts.toggle({elem:that.valCell,val:dateVal,date:exarr[0]});
  787. },
  788. monthShow:function (val) {
  789. DTS.year = false;
  790. DTS.month = DTS.month ? false : true;
  791. if(that.dlen > 2 && that.dlen <= 6){
  792. var dayCell = $Q(".daystable",elCell);
  793. DTS.day = dayCell.style.display == "none" ? true : false;
  794. }
  795. that.renderDate();
  796. },
  797. shortClick:function (val) {
  798. var reval = val.replace(/\#/g,','),evobj = eval("("+reval+")"),
  799. gval = jet.getDateTime(evobj),tmval = that.selectTime;
  800. that.selectValue = [jet.parse(gval,"YYYY-MM-DD")];
  801. that.selectDate = [{YYYY:gval.YYYY,MM:gval.MM,DD:gval.DD}];
  802. if(opts.onClose){
  803. var nYM = jet.nextMonth(gval.YYYY,gval.MM),
  804. ymarr = [{YYYY:gval.YYYY,MM:gval.MM,DD:gval.DD},{YYYY:nYM.y,MM:nYM.m,DD:null}];
  805. that.storeData(jet.extend(ymarr[0],tmval[0]),jet.extend(ymarr[1],tmval[1]));
  806. that.renderDate();
  807. }else{
  808. that.setValue(gval,that.format);
  809. that.closeDate();
  810. }
  811. },
  812. yearClick:function (val) {
  813. if(jet.hasClass(this,"disabled")) return;
  814. var yearVal = "",lens = that.dlen;
  815. if(range && lens == 1){
  816. var ylen = that.selectValue.length;
  817. that.selectDate = (ylen == 2) ? [{YYYY:parseInt(val),MM:dateM}] :
  818. [{YYYY:that.selectDate[0].YYYY,MM:that.selectDate[0].MM},{YYYY:parseInt(val),MM:dateM}];
  819. that.selectValue = (ylen == 2) ? [val+"-"+jet.digit(dateM)] : [that.selectValue[0],val+"-"+jet.digit(dateM)];
  820. if(that.selectValue.length == 2){
  821. var svalarr = [that.selectValue[0],that.selectValue[1]],newArr = [{},{}];
  822. svalarr.sort(function(a, b){ return a > b ? 1 : -1; });
  823. that.selectValue = svalarr;
  824. jet.each(svalarr,function(i,strval) {
  825. jet.each(jet.reMatch(strval),function(s,dval) {
  826. newArr[i][ymdzArr[s]] = dval;
  827. });
  828. });
  829. that.selectDate = newArr;
  830. }
  831. }else if(lens>1 && lens <=6){
  832. yearVal = parseInt(val);
  833. }else{
  834. that.selectValue = [val+"-"+jet.digit(dateM)];
  835. that.selectDate = [{YYYY:parseInt(val),MM:dateM}];
  836. }
  837. DTS.year = (lens == 1) ? true : false;
  838. DTS.month = (lens < 3) ? true : false;
  839. DTS.day = (lens > 2 && lens <= 6) ? true : false;
  840. var electVal = (lens>1 && lens <=6) ? yearVal : parseInt(that.selectDate[0].YYYY);
  841. that.storeData(jet.extend({YYYY:electVal,MM:dateM,DD:dateD},that.selectTime[0]),{});
  842. that.renderDate();
  843. },
  844. monthClick:function (val) {
  845. if(jet.hasClass(this,"disabled")) return;
  846. var ymval = jet.reMatch(val),newArr = [{},{}],mlen = that.selectValue.length ;
  847. if(range){
  848. that.selectDate = (mlen == 2) ? [{YYYY:ymval[0],MM:ymval[1]}] :
  849. [{YYYY:that.selectDate[0].YYYY,MM:that.selectDate[0].MM},{YYYY:parseInt(val),MM:ymval[1]}];
  850. that.selectValue = (mlen == 2) ? [val] : [that.selectValue[0],val];
  851. if(that.selectValue.length == 2){
  852. var svalarr = [that.selectValue[0],that.selectValue[1]];
  853. svalarr.sort(function(a, b){ return a > b ? 1 : -1; });
  854. that.selectValue = svalarr;
  855. jet.each(svalarr,function(i,strval) {
  856. jet.each(jet.reMatch(strval),function(s,dval) {
  857. newArr[i][ymdzArr[s]] = dval;
  858. });
  859. });
  860. that.selectDate = newArr;
  861. }
  862. }else{
  863. that.selectValue = [val];
  864. that.selectDate = [{YYYY:ymval[0],MM:ymval[1]}];
  865. }
  866. if(that.dlen > 2){
  867. DTS.year = false;
  868. DTS.month = false;
  869. }
  870. DTS.day = (that.dlen > 2 && that.dlen <= 6) ? true : false;
  871. that.storeData(jet.extend({
  872. YYYY:parseInt(that.selectDate[0].YYYY),
  873. MM:parseInt(that.selectDate[0].MM),
  874. DD:dateD
  875. },that.selectTime[0]),{});
  876. that.renderDate();
  877. },
  878. daysClick:function (val) {
  879. if(jet.hasClass(this,"disabled")) return;
  880. var tmval = that.selectTime, matVal = jet.reMatch(val),
  881. slen = that.selectValue.length,dateVal = "",
  882. newArr = [{},{}],sday,nYM,ymarr;
  883. if(range){
  884. if(slen == 1){
  885. var svalarr = [that.selectValue[0],val];
  886. svalarr.sort(function(a, b){ return a > b ? 1 : -1; });
  887. that.selectValue = svalarr;
  888. jet.each(svalarr,function(i,strval) {
  889. jet.each(jet.reMatch(strval),function(s,dval) {
  890. newArr[i][ymdzArr[s]] = dval;
  891. });
  892. });
  893. that.selectDate = newArr;
  894. }else{
  895. that.selectValue = [val];
  896. newArr = [{YYYY:matVal[0],MM:matVal[1],DD:matVal[2]}];
  897. that.selectDate = [{YYYY:matVal[0],MM:matVal[1],DD:matVal[2]},{}];
  898. }
  899. nYM = jet.nextMonth(newArr[0].YYYY,newArr[0].MM);
  900. ymarr = [{YYYY:newArr[0].YYYY,MM:newArr[0].MM,DD:newArr[0].DD},{YYYY:nYM.y,MM:nYM.m,DD:null}];
  901. that.storeData(jet.extend(ymarr[0],tmval[0]),jet.extend(ymarr[1],tmval[1]));
  902. that.renderDate();
  903. }else{
  904. that.selectValue = [val];
  905. that.selectDate = [{YYYY:matVal[0],MM:matVal[1],DD:matVal[2]},{YYYY:matVal[0],MM:matVal[1],DD:matVal[2]}];
  906. jet.each(new Array(range == false ? 1 : 2),function (a) {
  907. jet.each(matVal,function (i,val) {
  908. newArr[a][ymdzArr[i]] = val;
  909. });
  910. jet.extend(newArr[a],tmval[a]);
  911. });
  912. if(opts.onClose){
  913. that.storeData(jet.extend(newArr[0],tmval[0]),jet.extend(newArr[1],tmval[1]));
  914. that.renderDate();
  915. }else{
  916. dateVal = that.setValue(newArr,that.format);
  917. that.closeDate();
  918. opts.donefun && opts.donefun.call(that,{elem:that.valCell,val:dateVal,date:newArr});
  919. }
  920. }
  921. },
  922. hmsClick:function(idx,num) {
  923. var pidx = parseInt(num), vals = parseInt(jet.text(this)),
  924. paridx = parseInt(idx), act = "action",mhms = ["hh","mm","ss"],
  925. ulCell = $Q(".jedate-time",that.dateCell).querySelectorAll("ul")[pidx],
  926. tlen = that.$data.timelist[0].length;
  927. if(jet.hasClass(this,"disabled")) return;
  928. jet.each(ulCell.childNodes,function (i,node) {
  929. var reg = new RegExp("(^|\\s+)" + act + "(\\s+|$)", "g");
  930. node.className = reg.test(node.className) ? node.className.replace(reg, '') : node.className;
  931. });
  932. that.selectTime[paridx][paridx == 1 ? mhms[pidx-tlen]:mhms[pidx]] = vals;
  933. this.className = this.className + act;
  934. var hmsCls = ulCell.querySelector("."+act);
  935. ulCell.scrollTop = hmsCls ? (hmsCls.offsetTop-145):0;
  936. if(that.dlen == 7 && idx == 0 && range && !multi){
  937. var nVal = that.getValue({}), nYM = jet.nextMonth(nVal[0].YYYY,nVal[0].MM),st = that.selectTime;
  938. that.storeData(
  939. {YYYY:nVal[0].YYYY,MM:nVal[0].MM,DD:null,hh:st[0].hh,mm:st[0].mm,ss:st[0].ss},
  940. {YYYY:nYM.y,MM:nYM.m,DD:null,hh:st[1].hh,mm:st[1].mm,ss:st[1].ss}
  941. );
  942. that.renderDate();
  943. }
  944. },
  945. timeBtn:function() {
  946. var timeCell = $Q(".jedate-time",elCell), disNo = timeCell.style.display == "none";
  947. jet.text(this,disNo ? opts.language.backtxt:opts.language.timetxt[0]);
  948. jet.setCss(timeCell,{display: disNo ? "block":"none"});
  949. },
  950. //清空按钮函数
  951. clearBtn:function () {
  952. jet.valText(that.valCell,"");
  953. that.selectDate = [jet.parse(jet.getDateTime({}),"YYYY-MM-DD hh:mm:ss")];
  954. that.closeDate();
  955. opts.clearfun && opts.clearfun.call(that);
  956. },
  957. //现在按钮函数
  958. nowBtn:function () {
  959. var newArr = jet.getDateTime({}), nYM = jet.nextMonth(newArr.YYYY,newArr.MM), dateVal;
  960. that.selectDate = [newArr];
  961. dateVal = opts.isShow ? that.setValue([newArr],that.format,true) : jet.parse(newArr,that.format);
  962. if(opts.onClose && range || !opts.isShow){
  963. that.storeData(newArr,{YYYY:nYM.y,MM:nYM.m,DD:null,hh:0,mm:0,ss:0});
  964. that.renderDate();
  965. }else{
  966. that.closeDate();
  967. }
  968. opts.donefun && opts.donefun.call(that,{elem:that.valCell,val:dateVal,date:newArr});
  969. },
  970. //确认按钮函数
  971. sureBtn:function () {
  972. var newArr = that.selectValue.length > 1 ? [{},{}]: [{}], dateVal = "", tmval = that.selectTime;
  973. var equal = function (o) {
  974. var h = o.hh == undefined ? 0:o.hh, m = o.mm == undefined ? 0:o.mm, s = o.ss == undefined ? 0:o.ss;
  975. return parseInt(jet.digit(h)+""+jet.digit(m)+""+jet.digit(s));
  976. };
  977. if(range){
  978. if(that.selectValue.length > 1){
  979. var sortarr = that.selectValue;
  980. sortarr.sort(function(a, b){ return a > b ? 1 : -1; });
  981. jet.each(sortarr,function (i,arr) {
  982. jet.each(jet.reMatch(arr),function (a,val) {
  983. newArr[i][ymdzArr[a]] = val;
  984. });
  985. jet.extend(newArr[i],tmval[i]);
  986. });
  987. }else if(that.dlen == 7 && tmval.length>1){
  988. newArr = tmval;
  989. }
  990. var sameTime = equal(tmval[0]) >= equal(tmval[1]),selVal = that.selectValue, sameDate = "";
  991. if(selVal[1] != undefined) sameDate = selVal[0].replace(/\-/g,"") == selVal[1].replace(/\-/g,"");
  992. if(selVal.length == 1 && that.dlen < 7){
  993. that.tips(opts.language.name == "cn" ? "未选结束日期" : "Please select the end date"); return;
  994. }else if((that.dlen == 7 && sameTime) || (sameDate && sameTime)){
  995. that.tips(opts.language.name == "cn" ? "结束时间必须大于开始时间" : "The end time must be greater than the start time"); return;
  996. }
  997. }else{
  998. jet.each(new Array(range == false ? 1 : 2),function (i) {
  999. if(that.dlen != 7) jet.each(jet.reMatch(that.selectValue[0]),function (a,val) {
  1000. newArr[i][ymdzArr[a]] = val;
  1001. });
  1002. jet.extend(newArr[i],tmval[i]);
  1003. });
  1004. }
  1005. dateVal = that.setValue(newArr,that.format,opts.isShow ? true:false);
  1006. opts.isShow && that.closeDate();
  1007. opts.donefun && opts.donefun.call(that,{elem:that.valCell,val:dateVal,date:newArr});
  1008. },
  1009. blankArea:function () {
  1010. jet.on(document,"mouseup",function (ev) {
  1011. jet.stopPropagation(ev);
  1012. that.closeDate();
  1013. });
  1014. jet.on($Q(elx),"mouseup", function(ev) {
  1015. jet.stopPropagation(ev);
  1016. });
  1017. }
  1018. });
  1019. },
  1020. //循环生成年数据
  1021. eachYear : function (val,type) {
  1022. var that = this,opts = that.$opts, yNum = parseInt(val),yarr = [],seCls='', selYear = that.selectDate,i,
  1023. mins = jet.reMatch(that.minDate), maxs = jet.reMatch(that.maxDate);
  1024. i = type == 1 ? yNum : that.yindex;
  1025. that.yindex = type == 1 ? 12+yNum : 12+that.yindex;
  1026. var endDate = selYear[1] == undefined ? "":selYear[1].YYYY;
  1027. for(; i < that.yindex; i++){
  1028. if(i == selYear[0].YYYY || i == endDate){
  1029. seCls = "action";
  1030. }else if(i>selYear[0].YYYY && i<endDate){
  1031. seCls = "contain";
  1032. }else if(i < mins[0] || i > maxs[0]){
  1033. seCls = "disabled";
  1034. }else{
  1035. seCls = "";
  1036. }
  1037. yarr.push({style:seCls,y:i});
  1038. }
  1039. return yarr;
  1040. },
  1041. //循环生成月数据
  1042. eachMonth : function (val,type) {
  1043. var that = this,opts = that.$opts, range = opts.range, marr = [],
  1044. selMonth = that.selectDate, seCls='',monthArr = opts.language.month ,
  1045. mins = jet.reMatch(that.minDate), maxs = jet.reMatch(that.maxDate),
  1046. minym = parseInt(mins[0]+""+jet.digit(mins[1])),
  1047. maxym = parseInt(maxs[0]+""+jet.digit(maxs[1])),
  1048. currStart = parseInt(selMonth[0].YYYY+""+jet.digit(selMonth[0].MM)),
  1049. currEnd = selMonth[1] ? parseInt(selMonth[1].YYYY+""+jet.digit(selMonth[1].MM)) : 0;
  1050. jet.each(monthArr,function (i,months) {
  1051. var ival = parseInt(val+""+jet.digit(months));
  1052. if(ival == currStart || ival == currEnd){
  1053. seCls = "action";
  1054. }else if(ival > currStart && ival < currEnd){
  1055. seCls = "contain";
  1056. }else if(ival < minym || ival > maxym){
  1057. seCls = "disabled";
  1058. }else{
  1059. seCls = "";
  1060. }
  1061. marr.push({style:seCls ,y:val ,m:months});
  1062. });
  1063. return marr;
  1064. },
  1065. //循环生成天数据
  1066. eachDays : function (yd,md,ds,idx) {
  1067. var that = this, count = 0, daysArr = [],opts = that.$opts, multiPane = jet.isBool(opts.multiPane),
  1068. firstWeek = new Date(yd, md - 1, 1).getDay() || 7,valrange = opts.range != false,
  1069. daysNum = jet.getDaysNum(yd, md), didx = 0, sDate = that.selectDate,
  1070. prevM = jet.prevMonth(yd, md),isShow = jet.isBool(opts.isShow),
  1071. prevDaysNum = jet.getDaysNum(yd, prevM.m),nextM = jet.nextMonth(yd, md), objCell = that.valCell,
  1072. lang = opts.language, endval = opts.valiDate||[],
  1073. minArr = jet.reMatch(that.minDate), minNum = parseInt(minArr[0]+""+jet.digit(minArr[1])+""+jet.digit(minArr[2])),
  1074. maxArr = jet.reMatch(that.maxDate), maxNum = parseInt(maxArr[0]+""+jet.digit(maxArr[1])+""+jet.digit(maxArr[2]));
  1075. var startDate = sDate[0] ? parseInt(sDate[0].YYYY+""+jet.digit(sDate[0].MM)+""+jet.digit(sDate[0].DD)) : "";
  1076. var endDate = sDate[1] ? parseInt(sDate[1].YYYY+""+jet.digit(sDate[1].MM)+""+jet.digit(sDate[1].DD)) : "";
  1077. //设置时间标注
  1078. var setMark = function (my, mm, md) {
  1079. var Marks = opts.marks, contains = function(arr, obj) {
  1080. var clen = arr.length;
  1081. while (clen--) { if (arr[clen] === obj) return true; }
  1082. return false;
  1083. },isArr = jet.isType(Marks,"array");
  1084. return isArr && Marks.length > 0 && contains(Marks, my + "-" + jet.digit(mm) + "-" + jet.digit(md)) ? '<i class="marks"></i>' :"";
  1085. };
  1086. //是否显示节日
  1087. var isfestival = function(y, m ,d) {
  1088. var festivalStr = '';
  1089. if(opts.festival == true && lang.name == "cn"){
  1090. var lunar = jeLunar(y, m - 1, d), feslunar = (lunar.solarFestival || lunar.lunarFestival),
  1091. lunartext = (feslunar && lunar.jieqi) != "" ? feslunar : (lunar.jieqi || lunar.showInLunar);
  1092. festivalStr = '<p><span class="solar">' + d + '</span><span class="lunar">' + lunartext + '</span></p>';
  1093. }else{
  1094. festivalStr = '<p class="nolunar">' + d + '</p>';
  1095. }
  1096. return festivalStr;
  1097. };
  1098. //判断是否在限制的日期之中
  1099. var dateLimit = function(Y, M, D, isMonth){
  1100. var thatNum = parseInt(Y + "" + jet.digit(M) + "" + jet.digit(D));
  1101. if(isMonth){
  1102. if (thatNum >= minNum && thatNum <= maxNum) return true;
  1103. }else {
  1104. if (minNum > thatNum || maxNum < thatNum) return true;
  1105. }
  1106. };
  1107. var regExpDate = function (date,cls) {
  1108. var inArray = function (search,array){
  1109. for(var i in array) if(array[i]==search) return true;
  1110. return false;
  1111. };
  1112. if(endval.length > 0 && endval[0]!=""){
  1113. if(/\%/g.test(endval[0])){
  1114. var reval = endval[0].replace(/\%/g,"").split(","), enArr = [];
  1115. jet.each(reval,function (r,rel) {
  1116. enArr.push(jet.digit(parseInt(rel)));
  1117. });
  1118. var isfind = inArray(jet.digit(date), enArr) == false;
  1119. cls = jet.isBool(endval[1]) ? (isfind ? " disabled" :cls) : (isfind ? cls :" disabled");
  1120. }else {
  1121. var valreg = that.dateRegExp(endval[0]), regday = valreg.test(jet.digit(date));
  1122. cls = jet.isBool(endval[1]) ? (regday ? " disabled" : cls) : (regday ? cls : " disabled");
  1123. }
  1124. }
  1125. return cls;
  1126. };
  1127. //var ymds = ymdarr[1]
  1128. //上一月剩余天数
  1129. for (var p = prevDaysNum - firstWeek + 1; p <= prevDaysNum; p++, count++) {
  1130. var pmark = setMark(prevM.y,prevM.m,p), pcls = dateLimit(prevM.y, prevM.m, p, false) ? "disabled" : "other";
  1131. pcls = regExpDate(p,pcls);
  1132. daysArr.push({style:pcls,ymd:prevM.y+'-'+jet.digit(prevM.m)+'-'+jet.digit(p),day:(isfestival(prevM.y,prevM.m,p) + pmark)});
  1133. }
  1134. //本月的天数
  1135. for(var b = 1; b <= daysNum; b++, count++){
  1136. var bmark = setMark(yd,md,b), bcls = "";
  1137. var dateval = parseInt(yd+""+jet.digit(md)+""+jet.digit(b)),
  1138. parsdate = dateval > startDate, rangdate = dateval < endDate;
  1139. if(dateLimit(yd, md, b, true)){
  1140. if(dateval == startDate || dateval == endDate){
  1141. bcls = " action";
  1142. }else if(parsdate&&rangdate){
  1143. bcls = " contain";
  1144. }else {
  1145. bcls = "";
  1146. }
  1147. }else {
  1148. bcls = " disabled";
  1149. }
  1150. bcls = regExpDate(b,bcls);
  1151. daysArr.push({style:"normal"+bcls,ymd:yd+'-'+jet.digit(md)+'-'+jet.digit(b),day:(isfestival(yd,md,b) + bmark)});
  1152. }
  1153. //下一月开始天数
  1154. for(var n = 1, nlen = 42 - count; n <= nlen; n++){
  1155. var nmark = setMark(nextM.y,nextM.m,n);
  1156. var ncls = dateLimit(nextM.y, nextM.m, n, false) ? "disabled" : "other";
  1157. ncls = regExpDate(n,ncls);
  1158. daysArr.push({style:ncls,ymd:nextM.y+'-'+jet.digit(nextM.m)+'-'+jet.digit(n),day:(isfestival(nextM.y,nextM.m,n) + nmark)});
  1159. }
  1160. //将星期与日期拼接起来
  1161. return daysArr;
  1162. },
  1163. eachTime : function (hmsArr,type) {
  1164. var that = this,opts = that.$opts, range = opts.range,multi = opts.multiPane, minVal = [], maxVal = [],
  1165. mhms = ["hh","mm","ss"], timeArr = [],hmsCls = '',format = that.format,
  1166. ntVal = jet.trim(that.minDate).replace(/\s+/g," "),
  1167. xtVal = jet.trim(that.maxDate).replace(/\s+/g," "),
  1168. nVal = ntVal.split(" "), xVal = xtVal.split(" ");
  1169. if(that.dlen>3 && /\:/.test(nVal) && /\:/.test(xVal)){
  1170. minVal = jet.reMatch(/\s/.test(ntVal)&&that.dlen>3 ? nVal[1] : ntVal);
  1171. maxVal = jet.reMatch(/\s/.test(xtVal)&&that.dlen>3 ? xVal[1] : xtVal);
  1172. }
  1173. jet.each([24,60,60],function (s,lens) {
  1174. timeArr[s] = [];
  1175. var unhmsVal = minVal[s] == undefined || minVal[s] == 0 ? hmsArr[mhms[s]] : minVal[s],
  1176. currVal = that.getValue() == "" ? unhmsVal : hmsArr[mhms[s]];
  1177. if(that.dlen>3 && /\:/.test(nVal) && type==1){
  1178. that.selectTime[0][mhms[s]] = currVal;
  1179. }
  1180. for (var h = 0; h < lens; h++) {
  1181. var exists = new RegExp(mhms[s],"g").test(format);
  1182. if(h == currVal){
  1183. hmsCls = exists ? "action" : "disabled";
  1184. }else if(!exists || !range && multi &&(h<minVal[s] ||h>maxVal[s])){
  1185. hmsCls = "disabled";
  1186. }else if(!multi){
  1187. hmsCls = type == 1&&h<minVal[s] || type == 2&&h>maxVal[s] ? "disabled" : "";
  1188. }else{
  1189. hmsCls = "";
  1190. }
  1191. timeArr[s].push({style:hmsCls,hms:h});
  1192. }
  1193. });
  1194. return timeArr;
  1195. },
  1196. //关闭日期控件
  1197. closeDate : function () {
  1198. var elem = $Q(elx), tipelem = $Q("#jedatetipscon");
  1199. elem && document.body.removeChild(elem);
  1200. tipelem && document.body.removeChild(tipelem);
  1201. //再次初始化值
  1202. this.setDatas();
  1203. },
  1204. //转换日期值
  1205. parseValue : function (fnObj,matStr) {
  1206. var that = this, valArr=[],opts = that.$opts, range = opts.range;
  1207. jet.each(fnObj,function (i,val) {
  1208. valArr.push(jet.parse(val, matStr));
  1209. });
  1210. return range == false ? valArr[0] : valArr.join(range);
  1211. },
  1212. //初始验证正则
  1213. dateRegExp : function(valArr) {
  1214. var enval = valArr.split(",")||[], regs = "";
  1215. var doExp = function (val) {
  1216. var arr, tmpEval, regs = /#?\{(.*?)\}/;
  1217. val = val + "";
  1218. while ((arr = regs.exec(val)) != null) {
  1219. arr.lastIndex = arr.index + arr[1].length + arr[0].length - arr[1].length - 1;
  1220. tmpEval = parseInt(eval(arr[1]));
  1221. if (tmpEval < 0) tmpEval = "9700" + -tmpEval;
  1222. val = val.substring(0, arr.index) + tmpEval + val.substring(arr.lastIndex + 1);
  1223. }
  1224. return val;
  1225. };
  1226. if (enval && enval.length > 0) {
  1227. for (var i = 0; i < enval.length; i++) {
  1228. regs += doExp(enval[i]);
  1229. if (i != enval.length - 1) regs += "|";
  1230. }
  1231. regs = regs ? new RegExp("(?:" + regs + ")") : null;
  1232. } else {
  1233. regs = null;
  1234. }
  1235. //re = new RegExp((re + "").replace(/^\/\(\?:(.*)\)\/.*/, "$1"));
  1236. return regs;
  1237. },
  1238. //显示农历节日
  1239. showFestival:function () {
  1240. var that = this, opts = that.$opts;
  1241. jet.each(that.dateCell.querySelectorAll(".daystable td"),function (i,node) {
  1242. var tval = jet.reMatch(jet.attr(node,"ymd")),tipDiv = document.createElement("div");
  1243. node.removeAttribute("ymd");
  1244. //鼠标进入提示框出现
  1245. jet.on(node,"mouseover",function () {
  1246. var lunar = new jeLunar(tval[0], tval[1] - 1, tval[2]);
  1247. if($Q("#jedatetipscon")) return;
  1248. tipDiv.id = tipDiv.className = "jedatetipscon";
  1249. var tiphtml = '<p>' + lunar.solarYear + '\u5E74' + lunar.solarMonth + '\u6708' + lunar.solarDate + '\u65E5 ' + lunar.inWeekDays + '</p><p class="red">\u519C\u5386:' + lunar.shengxiao + '\u5E74 ' + lunar.lnongMonth + '\u6708' + lunar.lnongDate + '</p><p>' + lunar.ganzhiYear + '\u5E74 ' + lunar.ganzhiMonth + '\u6708 ' + lunar.ganzhiDate + '\u65E5</p>';
  1250. var Fesjieri = (lunar.solarFestival || lunar.lunarFestival) != "" ? '<p class="red">' + ("\u8282\u65E5:"+lunar.solarFestival + lunar.lunarFestival) + '</p>' : "";
  1251. var Fesjieqi = lunar.jieqi != "" ? '<p class="red">'+(lunar.jieqi != "" ? "\u8282\u6C14:"+lunar.jieqi : "") + '</p>': "";
  1252. var tiptext = (lunar.solarFestival || lunar.lunarFestival || lunar.jieqi) != "" ? (Fesjieri + Fesjieqi) : "";
  1253. jet.html(tipDiv,tiphtml + tiptext);
  1254. document.body.appendChild(tipDiv);
  1255. //获取并设置农历提示框出现的位置
  1256. var tipPos = that.lunarOrien(tipDiv, this);
  1257. jet.setCss(tipDiv,{"zIndex": (opts.zIndex == undefined ? 10000 + 5 : opts.zIndex + 5),top:tipPos.top,left:tipPos.left,position:"absolute",display:"block"});
  1258. });
  1259. //鼠标移除提示框消失
  1260. jet.on(node,"mouseout",function () {
  1261. document.body.removeChild($Q("#jedatetipscon"));
  1262. });
  1263. });
  1264. if (that.dateCell.nodeType === 1 && !jet.hasClass(that.dateCell,"grid")) that.dateCell.className = that.dateCell.className + " grid";
  1265. },
  1266. //农历方位辨别
  1267. lunarOrien : function(obj, self, pos) {
  1268. var tops, leris, ortop, orleri, rect =self.getBoundingClientRect(), boxW = obj.offsetWidth, boxH = obj.offsetHeight;
  1269. leris = rect.right + boxW / 1.5 >= jet.docArea(true) ? rect.right - boxW : rect.left + (pos ? 0 : jet.docScroll(true));
  1270. tops = rect.bottom + boxH / 1 <= jet.docArea() ? rect.bottom - 1 : rect.top > boxH / 1.5 ? rect.top - boxH - 1 : jet.docArea() - boxH;
  1271. if(leris + boxW > jet.docArea(true)) leris = rect.left - (boxW - rect.width);
  1272. ortop = Math.max(tops + (pos ? 0 :jet.docScroll()) + 1, 1) + "px", orleri = leris + "px";
  1273. return {top: ortop, left: orleri }
  1274. },
  1275. //辨别控件的方位
  1276. dateOrien : function(elbox, valCls, pos) {
  1277. var that = this, tops, leris, ortop, orleri,
  1278. rect = that.$opts.fixed ? valCls.getBoundingClientRect() : elbox.getBoundingClientRect(),
  1279. leris = rect.left, tops = rect.bottom;
  1280. if(that.$opts.fixed) {
  1281. var boxW = elbox.offsetWidth, boxH = elbox.offsetHeight;
  1282. //如果右侧超出边界
  1283. if(leris + boxW > jet.docArea(true)){
  1284. leris = leris - (boxW - rect.width);
  1285. }
  1286. //如果底部超出边界
  1287. if(tops + boxH > jet.docArea()){
  1288. tops = rect.top > boxH ? rect.top - boxH -2 : jet.docArea() - boxH -1;
  1289. }
  1290. //根据目标元素计算弹层位置
  1291. ortop = Math.max(tops + (pos ? 0 :jet.docScroll())+1, 1) + "px"; orleri = leris + "px";
  1292. }else{
  1293. //弹层位置位于页面上下左右居中
  1294. ortop = "50%"; orleri = "50%";
  1295. elbox.style.cssText = "marginTop:"+-(rect.height / 2)+";marginLeft:"+-(rect.width / 2);
  1296. }
  1297. jet.setCss(elbox,{top:ortop,left:orleri});
  1298. },
  1299. tips : function (text, time) {
  1300. var that = this, tipCls = $Q(".jedate-tips",that.dateCell),tipTime;
  1301. jet.html(tipCls,text||""); jet.setCss(tipCls,{display:"block"});
  1302. clearTimeout(tipTime);
  1303. tipTime = setTimeout(function(){
  1304. jet.html(tipCls,""); jet.setCss(tipCls,{display:"none"});
  1305. }, (time||2.5)*1000);
  1306. },
  1307. locateScroll : function () {
  1308. var that = this, ulCell = $Q(".jedate-time",that.dateCell).querySelectorAll("ul");
  1309. jet.each(ulCell, function(i,cell) {
  1310. var hmsCls = cell.querySelector(".action");
  1311. cell.scrollTop = hmsCls ? (hmsCls.offsetTop-145):0;
  1312. });
  1313. if(that.dlen != 7) jet.setCss($Q(".jedate-time",that.dateCell),{display:'none'});
  1314. }
  1315. });
  1316. //农历数据
  1317. function jeLunar(ly,lm,ld) {
  1318. var lunarInfo=[19416,19168,42352,21717,53856,55632,91476,22176,39632,21970,19168,42422,42192,53840,119381,46400,54944,44450,38320,84343,18800,42160,46261,27216,27968,109396,11104,38256,21234,18800,25958,54432,59984,28309,23248,11104,100067,37600,116951,51536,54432,120998,46416,22176,107956,9680,37584,53938,43344,46423,27808,46416,86869,19872,42448,83315,21200,43432,59728,27296,44710,43856,19296,43748,42352,21088,62051,55632,23383,22176,38608,19925,19152,42192,54484,53840,54616,46400,46496,103846,38320,18864,43380,42160,45690,27216,27968,44870,43872,38256,19189,18800,25776,29859,59984,27480,21952,43872,38613,37600,51552,55636,54432,55888,30034,22176,43959,9680,37584,51893,43344,46240,47780,44368,21977,19360,42416,86390,21168,43312,31060,27296,44368,23378,19296,42726,42208,53856,60005,54576,23200,30371,38608,19415,19152,42192,118966,53840,54560,56645,46496,22224,21938,18864,42359,42160,43600,111189,27936,44448],
  1319. sTermInfo = [ 0, 21208, 43467, 63836, 85337, 107014, 128867, 150921, 173149, 195551, 218072, 240693, 263343, 285989, 308563, 331033, 353350, 375494, 397447, 419210, 440795, 462224, 483532, 504758 ];
  1320. var Gan = "甲乙丙丁戊己庚辛壬癸", Zhi = "子丑寅卯辰巳午未申酉戌亥", Animals = "鼠牛虎兔龙蛇马羊猴鸡狗猪";
  1321. var solarTerm = [ "小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨", "立夏", "小满",
  1322. "芒种", "夏至", "小暑", "大暑", "立秋", "处暑", "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪", "冬至" ];
  1323. var nStr1 = "日一二三四五六七八九十", nStr2 = "初十廿卅", nStr3 = [ "正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "腊"],
  1324. sFtv1 = {
  1325. "0101" : "*1元旦节", "0202" : "湿地日",
  1326. "0214" : "情人节", "0308" : "妇女节",
  1327. "0312" : "植树节", "0315" : "消费者权益日",
  1328. "0401" : "愚人节", "0422" : "地球日",
  1329. "0501" : "*1劳动节", "0504" : "青年节",
  1330. "0512" : "护士节", "0518" : "博物馆日",
  1331. "0520" : "母亲节", "0601" : "儿童节",
  1332. "0623" : "奥林匹克日", "0630" : "父亲节",
  1333. "0701" : "建党节", "0801" : "建军节",
  1334. "0903" : "抗战胜利日", "0910" : "教师节",
  1335. "1001" : "*3国庆节", "1201" : "艾滋病日",
  1336. "1224" : "平安夜", "1225" : "圣诞节"
  1337. },
  1338. sFtv2 = {
  1339. "0100" : "除夕", "0101" : "*2春节",
  1340. "0115" : "元宵节", "0505" : "*1端午节",
  1341. "0707" : "七夕节", "0715" : "中元节",
  1342. "0815" : "*1中秋节", "0909" : "*1重阳节",
  1343. "1015" : "下元节", "1208" : "腊八节",
  1344. "1223" : "小年"
  1345. };
  1346. function flunar(Y) {
  1347. var sTerm = function (j, i) {
  1348. var h = new Date((31556925974.7 * (j - 1900) + sTermInfo[i] * 60000) + Date.UTC(1900, 0, 6, 2, 5));
  1349. return (h.getUTCDate());
  1350. },
  1351. d = function (k) {
  1352. var h, j = 348;
  1353. for (h = 32768; h > 8; h >>= 1) j += (lunarInfo[k - 1900] & h) ? 1 : 0;
  1354. return (j + b(k));
  1355. },
  1356. ymdCyl = function (h) {
  1357. return (Gan.charAt(h % 10) + Zhi.charAt(h % 12));
  1358. },
  1359. b = function (h) {
  1360. var islp = (g(h)) ? ((lunarInfo[h - 1900] & 65536) ? 30 : 29) : (0);
  1361. return islp;
  1362. },
  1363. g = function (h) {
  1364. return (lunarInfo[h - 1900] & 15)
  1365. },
  1366. e = function (i, h) {
  1367. return ((lunarInfo[i - 1900] & (65536 >> h)) ? 30 : 29);
  1368. },
  1369. newymd = function (m) {
  1370. var k, j = 0, h = 0, l = new Date(1900, 0, 31), n = (m - l) / 86400000;
  1371. this.dayCyl = n + 40;
  1372. this.monCyl = 14;
  1373. for (k = 1900; k < 2050 && n > 0; k++) {
  1374. h = d(k); n -= h;
  1375. this.monCyl += 12;
  1376. }
  1377. if (n < 0) {
  1378. n += h; k--;
  1379. this.monCyl -= 12;
  1380. }
  1381. this.year = k;
  1382. this.yearCyl = k - 1864;
  1383. j = g(k);
  1384. this.isLeap = false;
  1385. for (k = 1; k < 13 && n > 0; k++) {
  1386. if (j > 0 && k == (j + 1) && this.isLeap == false) {
  1387. --k;
  1388. this.isLeap = true;
  1389. h = b(this.year);
  1390. } else {
  1391. h = e(this.year, k);
  1392. }
  1393. if (this.isLeap == true && k == (j + 1)) {
  1394. this.isLeap = false;
  1395. }
  1396. n -= h;
  1397. if (this.isLeap == false) this.monCyl++;
  1398. }
  1399. if (n == 0 && j > 0 && k == j + 1) {
  1400. if (this.isLeap) {
  1401. this.isLeap = false;
  1402. } else {
  1403. this.isLeap = true;
  1404. --k;
  1405. --this.monCyl;
  1406. }
  1407. }
  1408. if (n < 0) {
  1409. n += h; --k;
  1410. --this.monCyl;
  1411. }
  1412. this.month = k;
  1413. this.day = n + 1;
  1414. },
  1415. digit = function (num) {
  1416. return num < 10 ? "0" + (num | 0) : num;
  1417. },
  1418. reymd = function (i, j) {
  1419. var h = i;
  1420. return j.replace(/dd?d?d?|MM?M?M?|yy?y?y?/g, function (k) {
  1421. switch (k) {
  1422. case "yyyy":
  1423. var l = "000" + h.getFullYear();
  1424. return l.substring(l.length - 4);
  1425. case "dd": return digit(h.getDate());
  1426. case "d": return h.getDate().toString();
  1427. case "MM": return digit((h.getMonth() + 1));
  1428. case "M": return h.getMonth() + 1;
  1429. }
  1430. });
  1431. },
  1432. lunarMD = function (i, h) {
  1433. var j;
  1434. switch (i, h) {
  1435. case 10: j = "初十"; break;
  1436. case 20: j = "二十"; break;
  1437. case 30: j = "三十"; break;
  1438. default:
  1439. j = nStr2.charAt(Math.floor(h / 10));
  1440. j += nStr1.charAt(h % 10);
  1441. }
  1442. return j;
  1443. };
  1444. this.isToday = false;
  1445. this.isRestDay = false;
  1446. this.solarYear = reymd(Y, "yyyy");
  1447. this.solarMonth = reymd(Y, "M");
  1448. this.solarDate = reymd(Y, "d");
  1449. this.solarWeekDay = Y.getDay();
  1450. this.inWeekDays = "星期" + nStr1.charAt(this.solarWeekDay);
  1451. var X = new newymd(Y);
  1452. this.lunarYear = X.year;
  1453. this.shengxiao = Animals.charAt((this.lunarYear - 4) % 12);
  1454. this.lunarMonth = X.month;
  1455. this.lunarIsLeapMonth = X.isLeap;
  1456. this.lnongMonth = this.lunarIsLeapMonth ? "闰" + nStr3[X.month - 1] : nStr3[X.month - 1];
  1457. this.lunarDate = X.day;
  1458. this.showInLunar = this.lnongDate = lunarMD(this.lunarMonth, this.lunarDate);
  1459. if (this.lunarDate == 1) {
  1460. this.showInLunar = this.lnongMonth + "月";
  1461. }
  1462. this.ganzhiYear = ymdCyl(X.yearCyl);
  1463. this.ganzhiMonth = ymdCyl(X.monCyl);
  1464. this.ganzhiDate = ymdCyl(X.dayCyl++);
  1465. this.jieqi = "";
  1466. this.restDays = 0;
  1467. if (sTerm(this.solarYear, (this.solarMonth - 1) * 2) == reymd(Y, "d")) {
  1468. this.showInLunar = this.jieqi = solarTerm[(this.solarMonth - 1) * 2];
  1469. }
  1470. if (sTerm(this.solarYear, (this.solarMonth - 1) * 2 + 1) == reymd(Y, "d")) {
  1471. this.showInLunar = this.jieqi = solarTerm[(this.solarMonth - 1) * 2 + 1];
  1472. }
  1473. if (this.showInLunar == "清明") {
  1474. this.showInLunar = "清明节";
  1475. this.restDays = 1;
  1476. }
  1477. this.solarFestival = sFtv1[reymd(Y, "MM") + reymd(Y, "dd")];
  1478. if (typeof this.solarFestival == "undefined") {
  1479. this.solarFestival = "";
  1480. } else {
  1481. if (/\*(\d)/.test(this.solarFestival)) {
  1482. this.restDays = parseInt(RegExp.$1);
  1483. this.solarFestival = this.solarFestival.replace(/\*\d/, "");
  1484. }
  1485. }
  1486. this.showInLunar = (this.solarFestival == "") ? this.showInLunar : this.solarFestival;
  1487. this.lunarFestival = sFtv2[this.lunarIsLeapMonth ? "00" : digit(this.lunarMonth) + digit(this.lunarDate)];
  1488. if (typeof this.lunarFestival == "undefined") {
  1489. this.lunarFestival = "";
  1490. } else {
  1491. if (/\*(\d)/.test(this.lunarFestival)) {
  1492. this.restDays = (this.restDays > parseInt(RegExp.$1)) ? this.restDays : parseInt(RegExp.$1);
  1493. this.lunarFestival = this.lunarFestival.replace(/\*\d/, "");
  1494. }
  1495. }
  1496. if (this.lunarMonth == 12 && this.lunarDate == e(this.lunarYear, 12)) {
  1497. this.lunarFestival = sFtv2["0100"];
  1498. this.restDays = 1;
  1499. }
  1500. this.showInLunar = (this.lunarFestival == "") ? this.showInLunar : this.lunarFestival;
  1501. }
  1502. return new flunar(new Date(ly, lm, ld));
  1503. }
  1504. return jeDate;
  1505. });