jquery.jedate.js 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076
  1. /**
  2. @Name : jeDate v3.6 日期控件
  3. @Author: chen guojun
  4. @Date: 2016-18-8
  5. @QQ群:516754269
  6. @官网:http://www.jayui.com/jedate/ 或 https://github.com/singod/jeDate
  7. */
  8. window.console && (console = console || {log : function(){return;}});
  9. ;(function(root, factory) {
  10. //amd
  11. if (typeof define === 'function' && define.amd) {
  12. define(['$'], factory);
  13. } else if (typeof exports === 'object') { //umd
  14. module.exports = factory();
  15. } else {
  16. root.jeDate = factory(window.jQuery || $);
  17. }
  18. })(this, function($) {
  19. var jet = {}, doc = document, ymdMacth = /\w+|d+/g, parseInt = function (n) { return window.parseInt(n, 10);},
  20. config = {
  21. skinCell:"jedateblue",
  22. format:"YYYY-MM-DD hh:mm:ss", //日期格式
  23. minDate:"1900-01-01 00:00:00", //最小日期
  24. maxDate:"2099-12-31 23:59:59" //最大日期
  25. };
  26. $.fn.jeDate = function(options){
  27. return this.each(function(){
  28. return new jeDate($(this),options||{});
  29. });
  30. };
  31. $.extend({
  32. jeDate:function(elem, options){
  33. return $(elem).each(function(){
  34. return new jeDate($(this),options||{});
  35. });
  36. }
  37. });
  38. jet.docScroll = function(type) {
  39. type = type ? "scrollLeft" :"scrollTop";
  40. return doc.body[type] | doc.documentElement[type];
  41. };
  42. jet.winarea = function(type) {
  43. return doc.documentElement[type ? "clientWidth" :"clientHeight"];
  44. };
  45. jet.isShow = function(elem, bool) {
  46. elem.css({display: bool != true ? "none" :"block"});
  47. };
  48. //判断是否闰年
  49. jet.isLeap = function(y) {
  50. return (y % 100 !== 0 && y % 4 === 0) || (y % 400 === 0);
  51. }
  52. //获取本月的总天数
  53. jet.getDaysNum = function(y, m) {
  54. var num = 31;
  55. switch (parseInt(m)) {
  56. case 2:
  57. num = jet.isLeap(y) ? 29 : 28; break;
  58. case 4: case 6: case 9: case 11:
  59. num = 30; break;
  60. }
  61. return num;
  62. }
  63. //获取月与年
  64. jet.getYM = function(y, m, n) {
  65. var nd = new Date(y, m - 1);
  66. nd.setMonth(m - 1 + n);
  67. return {
  68. y: nd.getFullYear(),
  69. m: nd.getMonth() + 1
  70. };
  71. }
  72. //获取上个月
  73. jet.getPrevMonth = function(y, m, n) {
  74. return jet.getYM(y, m, 0 - (n || 1));
  75. }
  76. //获取下个月
  77. jet.getNextMonth = function(y, m, n) {
  78. return jet.getYM(y, m, n || 1);
  79. }
  80. //补齐数位
  81. jet.digit = function(num) {
  82. return num < 10 ? "0" + (num | 0) :num;
  83. };
  84. //判断是否为数字
  85. jet.IsNum = function(str){
  86. return (str!=null && str!="") ? !isNaN(str) : false;
  87. }
  88. //转换日期格式
  89. jet.parse = function(ymd, hms, format) {
  90. ymd = ymd.concat(hms);
  91. var hmsCheck = jet.parseCheck(format, false).substring(0, 5) == "hh:mm", num = 2;
  92. return format.replace(/YYYY|MM|DD|hh|mm|ss/g, function(str, index) {
  93. var idx = hmsCheck ? ++num :ymd.index = ++ymd.index | 0;
  94. return jet.digit(ymd[idx]);
  95. });
  96. };
  97. jet.parseCheck = function(format, bool) {
  98. var ymdhms = [];
  99. format.replace(/YYYY|MM|DD|hh|mm|ss/g, function(str, index) {
  100. ymdhms.push(str);
  101. });
  102. return ymdhms.join(bool == true ? "-" :":");
  103. };
  104. jet.checkFormat = function(format) {
  105. var ymdhms = [];
  106. format.replace(/YYYY|MM|DD|hh|mm|ss/g, function(str, index) {
  107. ymdhms.push(str);
  108. });
  109. return ymdhms.join("-");
  110. };
  111. jet.parseMatch = function(str) {
  112. var timeArr = str.split(" ");
  113. return timeArr[0].match(ymdMacth);
  114. };
  115. //验证日期
  116. jet.checkDate = function (date) {
  117. var dateArr = date.match(ymdMacth);
  118. if (isNaN(dateArr[0]) || isNaN(dateArr[1]) || isNaN(dateArr[2])) return false;
  119. if (dateArr[1] > 12 || dateArr[1] < 1) return false;
  120. if (dateArr[2] < 1 || dateArr[2] > 31) return false;
  121. if ((dateArr[1] == 4 || dateArr[1] == 6 || dateArr[1] == 9 || dateArr[1] == 11) && dateArr[2] > 30) return false;
  122. if (dateArr[1] == 2) {
  123. if (dateArr[2] > 29) return false;
  124. if ((dateArr[0] % 100 == 0 && dateArr[0] % 400 != 0 || dateArr[0] % 4 != 0) && dateArr[2] > 28) return false;
  125. }
  126. return true;
  127. }
  128. //初始化日期
  129. jet.initDates = function(num, format) {
  130. format = format || 'YYYY-MM-DD hh:mm:ss';
  131. if(typeof num === "string"){
  132. var newDate = new Date(parseInt(num.substring(0,10)) * 1e3);
  133. }else{
  134. num = num | 0;
  135. var newDate = new Date(), todayTime = newDate.getTime() + 1000*60*60*24*num;
  136. newDate.setTime(todayTime);
  137. }
  138. var years = newDate.getFullYear(), months = newDate.getMonth() + 1, days = newDate.getDate(), hh = newDate.getHours(), mm = newDate.getMinutes(), ss = newDate.getSeconds();
  139. return jet.parse([ years, jet.digit(months), jet.digit(days) ], [ jet.digit(hh), jet.digit(mm), jet.digit(ss) ], format);
  140. };
  141. jet.montharr = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ];
  142. jet.weeks = [ "一", "二", "三", "四", "五", "六", "日"];
  143. //判断元素类型
  144. jet.isValHtml = function(that) {
  145. return /textarea|input/.test(that[0].tagName.toLocaleLowerCase());
  146. };
  147. jet.isBool = function(obj){ return (obj == undefined || obj == true ? true : false); };
  148. jet.addDateTime = function(time,num,type,format){
  149. var ishhmm = jet.checkFormat(format).substring(0, 5) == "hh-mm" ? true :false;
  150. var nocharDate = ishhmm ? time.replace(/^(\d{2})(?=\d)/g,"$1,") : time.substr(0,4).replace(/^(\d{4})/g,"$1,") + time.substr(4).replace(/^(\d{2})(?=\d)/g,"$1,");
  151. var tarr = jet.IsNum(time) ? nocharDate.match(ymdMacth) : time.match(ymdMacth), date = new Date(),
  152. tm0 = parseInt(tarr[0]), tm1 = tarr[1] == undefined ? date.getMonth() + 1 : parseInt(tarr[1]), tm2 = tarr[2] == undefined ? date.getDate() : parseInt(tarr[2]),
  153. tm3 = tarr[3] == undefined ? date.getHours() : parseInt(tarr[3]), tm4 = tarr[4] == undefined ? date.getMinutes() : parseInt(tarr[4]), tm5 = tarr[5] == undefined ? date.getMinutes() : parseInt(tarr[5]);
  154. var newDate = new Date(tm0,jet.digit(tm1)-1,(type == "DD" ? tm2 + num : tm2),(type == "hh" ? tm3 + num : tm3),(type == "mm" ? tm4 + num : tm4),jet.digit(tm5));
  155. return jet.parse([ newDate.getFullYear(), newDate.getMonth()+1, newDate.getDate() ], [ newDate.getHours(), newDate.getMinutes(), newDate.getSeconds() ], format);
  156. }
  157. jet.boxCell = "#jedatebox";
  158. function jeDate(elem, opts){
  159. this.opts = opts;
  160. this.valCell = elem;
  161. this.init();
  162. }
  163. var jedfn = jeDate.prototype;
  164. jedfn.init = function(){
  165. //console.log(this)
  166. var that = this, opts = that.opts, zIndex = opts.zIndex == undefined ? 2099 : opts.zIndex,
  167. isinitVal = (opts.isinitVal == undefined || opts.isinitVal == false) ? false : true,
  168. createDiv = $("<div id="+jet.boxCell.replace(/\#/g,"")+" class='jedatebox "+(opts.skinCell || config.skinCell)+"'></div");
  169. jet.fixed = jet.isBool(opts.fixed);
  170. createDiv.attr("author","chen guojun--www.jayui.com--version:3.5");
  171. createDiv.css({"z-index": zIndex ,"position":(jet.fixed == true ? "absolute" :"fixed"),"display":"block"});
  172. var initVals = function(elem) {
  173. var jeformat = opts.format || config.format, inaddVal = opts.initAddVal || [0], num, type;
  174. if(inaddVal.length == 1){
  175. num = inaddVal[0], type = "DD";
  176. }else{
  177. num = inaddVal[0], type = inaddVal[1];
  178. }
  179. var nowDateVal = jet.initDates(0, jeformat), jeaddDate = jet.addDateTime(nowDateVal, num, type, jeformat);
  180. (elem.val() || elem.text()) == "" ? jet.isValHtml(elem) ? elem.val(jeaddDate) :elem.text(jeaddDate) :jet.isValHtml(elem) ? elem.val() : elem.text();
  181. };
  182. //为开启初始化的时间设置值
  183. if (isinitVal && jet.isBool(opts.insTrigger)) {
  184. that.valCell.each(function() {
  185. initVals($(this));
  186. });
  187. }
  188. if (jet.isBool(opts.insTrigger)) {
  189. that.valCell.on("click", function (ev) {
  190. ev.stopPropagation();
  191. if ($(jet.boxCell).size() > 0) return;
  192. jet.format = that.opts.format || config.format;
  193. jet.minDate = that.opts.minDate || config.minDate;
  194. jet.maxDate = that.opts.maxDate || config.maxDate;
  195. $("body").append(createDiv);
  196. that.setHtml(that.opts);
  197. });
  198. }else {
  199. jet.format = that.opts.format || config.format;
  200. jet.minDate = that.opts.minDate || config.minDate;
  201. jet.maxDate = that.opts.maxDate || config.maxDate;
  202. $("body").append(createDiv);
  203. that.setHtml(that.opts);
  204. }
  205. };
  206. //方位辨别
  207. jedfn.orien = function(obj, self, pos) {
  208. var tops, leris, ortop, orleri, rect = jet.fixed ? self[0].getBoundingClientRect() : obj[0].getBoundingClientRect();
  209. if(jet.fixed) {
  210. leris = rect.right + obj.outerWidth() / 1.5 >= jet.winarea(1) ? rect.right - obj.outerWidth() : rect.left + (pos ? 0 : jet.docScroll(1));
  211. tops = rect.bottom + obj.outerHeight() / 1 <= jet.winarea() ? rect.bottom - 1 : rect.top > obj.outerHeight() / 1.5 ? rect.top - obj.outerHeight() - 1 : jet.winarea() - obj.outerHeight();
  212. ortop = Math.max(tops + (pos ? 0 :jet.docScroll()) + 1, 1) + "px", orleri = leris + "px";
  213. }else{
  214. ortop = "50%", orleri = "50%";
  215. obj.css({"margin-top":-(rect.height / 2),"margin-left":-(rect.width / 2)});
  216. }
  217. obj.css({"top":ortop,"left":orleri});
  218. };
  219. //关闭层
  220. jedfn.dateClose = function() {
  221. $(jet.boxCell).remove();
  222. };
  223. //布局控件骨架
  224. jedfn.setHtml = function(opts){
  225. var that = this, elemCell = that.valCell, boxCell = $(jet.boxCell);
  226. var weekHtml = "", tmsArr = "", date = new Date(), dateFormat = jet.checkFormat(jet.format),
  227. isYYMM = (dateFormat == "YYYY-MM" || dateFormat == "YYYY") ? true :false, ishhmm = dateFormat.substring(0, 5) == "hh-mm" ? true :false;
  228. if ((elemCell.val() || elemCell.text()) == "") {
  229. tmsArr = [ date.getFullYear(), date.getMonth() + 1, date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds() ];
  230. jet.currDate = new Date(tmsArr[0], parseInt(tmsArr[1])-1, tmsArr[2], tmsArr[3], tmsArr[4], tmsArr[5]);
  231. jet.ymdDate = tmsArr[0] + "-" + jet.digit(tmsArr[1]) + "-" + jet.digit(tmsArr[2]);
  232. } else {
  233. var initVal = jet.isValHtml(elemCell) ? elemCell.val() : elemCell.text();
  234. //对获取到日期的进行替换
  235. var nocharDate = ishhmm ? initVal.replace(/^(\d{2})(?=\d)/g,"$1,") : initVal.substr(0,4).replace(/^(\d{4})/g,"$1,") + initVal.substr(4).replace(/^(\d{2})(?=\d)/g,"$1,");
  236. //判断是否为数字类型,并分割
  237. var inVals = jet.IsNum(initVal) ? nocharDate.match(ymdMacth) : initVal.match(ymdMacth);
  238. if(ishhmm){
  239. tmsArr = dateFormat == "hh-mm" ? [ inVals[0], inVals[1], date.getSeconds() ] :[ inVals[0], inVals[1], inVals[2] ];
  240. jet.currDate = new Date(date.getFullYear(), date.getMonth()-1, date.getDate());
  241. }else{
  242. tmsArr = [ inVals[0], inVals[1], inVals[2], inVals[3] == undefined ? date.getHours() : inVals[3], inVals[4] == undefined ? date.getMinutes() : inVals[4], inVals[5] == undefined ? date.getSeconds() :inVals[5] ];
  243. jet.currDate = new Date(tmsArr[0], parseInt(tmsArr[1])-1, tmsArr[2], tmsArr[3], tmsArr[4], tmsArr[5]);
  244. jet.ymdDate = tmsArr[0] + "-" + jet.digit(tmsArr[1]) + "-" + jet.digit(tmsArr[2]);
  245. }
  246. }
  247. jet.currMonth = tmsArr[1], jet.currDays = tmsArr[2];
  248. //控件HMTL模板
  249. var datetopStr = '<div class="jedatetop">' + (!isYYMM ? '<div class="jedateym" style="width:50%;"><i class="prev triangle yearprev"></i><span class="jedateyy" ym="24"><em class="jedateyear"></em><em class="pndrop"></em></span><i class="next triangle yearnext"></i></div>' + '<div class="jedateym" style="width:50%;"><i class="prev triangle monthprev"></i><span class="jedatemm" ym="12"><em class="jedatemonth"></em><em class="pndrop"></em></span><i class="next triangle monthnext"></i></div>' :'<div class="jedateym" style="width:100%;"><i class="prev triangle ymprev"></i><span class="jedateyy"><em class="jedateyearmonth"></em></span><i class="next triangle ymnext"></i></div>') + "</div>";
  250. var dateymList = !isYYMM ? '<div class="jedatetopym" style="display: none;">' + '<ul class="ymdropul"></ul><p><span class="jedateymchle">&lt;&lt;</span><span class="jedateymchri">&gt;&gt;</span><span class="jedateymchok">关闭</span></p>' + "</div>" :(dateFormat == "YYYY" ? '<ul class="jedayy"></ul>' : '<ul class="jedaym"></ul>');
  251. var dateriList = '<ol class="jedaol"></ol><ul class="jedaul"></ul>';
  252. var bothmsStr = !isYYMM ? '<div class="botflex jedatehmsshde"><ul class="jedatehms"><li><input type="text" /></li><i>:</i><li><input type="text" /></li><i>:</i><li><input type="text" /></li></ul></div>' + '<div class="botflex jedatebtn"><span class="dataSelectAdd" >添加时间</span><span class="jedateok">确认</span><span class="jedateclear">清空</span></div>' :(dateFormat == "YYYY" ? '<div class="botflex jedatebtn"><span class="jedateok" style="width:47.8%">确认</span><span class="jedateclear" style="width:47.8%">清空</span></div>' : '<div class="botflex jedatebtn"><span class="jedateok">确认</span><span class="jedatetodaymonth">本月</span><span class="jedateclear">清空</span></div>');
  253. var datebotStr = '<div class="jedatebot">' + bothmsStr + "</div>";
  254. var datehmschoose = '<div class="jedateprophms ' + (ishhmm ? "jedatepropfix" :"jedateproppos") + '"><div class="jedatepropcon"><div class="jedatehmstitle">时间选择<div class="jedatehmsclose">&times;</div></div><div class="jedateproptext">小时</div><div class="jedateproptext">分钟</div><div class="jedateproptext">秒数</div><div class="jedatehmscon jedateprophours"></div><div class="jedatehmscon jedatepropminutes"></div><div class="jedatehmscon jedatepropseconds"></div></div></div>';
  255. var dateHtmStr = isYYMM ? datetopStr + dateymList + datebotStr :ishhmm ? datetopStr + datehmschoose + datebotStr :datetopStr + dateymList + dateriList + datehmschoose + datebotStr;
  256. boxCell.html(dateHtmStr);
  257. if(that.opts.isTime){
  258. boxCell.find(".dataSelectAdd").text("取消")
  259. }else{
  260. boxCell.find(".dataSelectAdd").text("时间")
  261. }
  262. //是否显示清除按钮
  263. jet.isBool(opts.isClear) ? "" : jet.isShow(boxCell.find(".jedatebot .jedateclear"), false);
  264. //是否显示今天按钮
  265. if(!isYYMM){
  266. jet.isBool(opts.isToday) ? "" : jet.isShow(boxCell.find(".jedatebot .jedatetodaymonth"), false);
  267. };
  268. //判断是否有时分秒
  269. if(/\hh-mm/.test(dateFormat)){
  270. var isTimehms = function(bool) {
  271. if(elemCell.val() != "" || elemCell.text() != "") {
  272. var hmsArrs = bool ? [ tmsArr[0], tmsArr[1], tmsArr[2] ] : [ tmsArr[3], tmsArr[4], tmsArr[5] ];
  273. }else{
  274. var hmsArrs = [ jet.currDate.getHours(), jet.currDate.getMinutes(), jet.currDate.getSeconds() ];
  275. }
  276. boxCell.find(".jedatebot .jedatehms input").each(function(i) {
  277. $(this).val(jet.digit(hmsArrs[i]));
  278. jet.isBool(opts.ishmsVal) ? "" : $(this).attr("readOnly",'true');
  279. });
  280. };
  281. console.log(ishhmm);
  282. if(ishhmm){
  283. isTimehms(true);
  284. boxCell.find(".jedateyear").text(jet.currDate.getFullYear() + '年');
  285. boxCell.find(".jedatemonth").text(jet.digit(jet.currDate.getMonth() + 1) + '月');
  286. }else{
  287. if(jet.isBool(opts.isTime)){
  288. isTimehms(false);
  289. }else{
  290. jet.isShow(boxCell.find(".jedatebot .jedatehmsshde"), false);
  291. boxCell.find(".jedatebot .jedatebtn").css("width" , "100%");
  292. }
  293. }
  294. }else{
  295. if (!isYYMM) jet.isShow(boxCell.find(".jedatebot .jedatehmsshde"), false);
  296. boxCell.find(".jedatebot .jedatebtn").css("width" , "100%");
  297. };
  298. //判断是否为年月类型
  299. if(/\YYYY-MM-DD/.test(dateFormat)){
  300. $.each(jet.weeks, function(i, week) {
  301. weekHtml += '<li class="weeks" data-week="' + week + '">' + week + "</li>";
  302. });
  303. boxCell.find(".jedaol").html(weekHtml);
  304. that.createDaysHtml(jet.currDate.getFullYear(), jet.currDate.getMonth()+1, opts);
  305. that.chooseYM(opts);
  306. };
  307. if(isYYMM){
  308. var monthCls = boxCell.find(".jedateym .jedateyearmonth");
  309. if(dateFormat == "YYYY"){
  310. monthCls.attr("data-onyy",tmsArr[0]).text(tmsArr[0] + "年");
  311. boxCell.find(".jedayy").html(that.onlyYear(tmsArr[0]));
  312. }else{
  313. monthCls.attr("data-onym",tmsArr[0]+"-"+jet.digit(tmsArr[1])).text(tmsArr[0] + "年" + parseInt(tmsArr[1]) + "月");
  314. boxCell.find(".jedaym").html(that.onlyYMStr(tmsArr[0], parseInt(tmsArr[1])));
  315. }
  316. that.onlyYMevents(tmsArr,opts);
  317. }
  318. that.orien(boxCell, elemCell);
  319. setTimeout(function () {
  320. opts.success && opts.success(elemCell);
  321. }, 2);
  322. that.events(tmsArr, opts);
  323. };
  324. //循环生成日历
  325. jedfn.createDaysHtml = function(ys, ms, opts){
  326. var that = this, elemCell = that.valCell, boxCell = $(jet.boxCell);
  327. var year = parseInt(ys), month = parseInt(ms), dateHtml = "",count = 0;
  328. var minArr = jet.minDate.match(ymdMacth), minNum = minArr[0] + minArr[1] + minArr[2],
  329. maxArr = jet.maxDate.match(ymdMacth), maxNum = maxArr[0] + maxArr[1] + maxArr[2];
  330. boxCell.find(".jedaul").html(""); //切忌一定要把这个内容去掉,要不然会点一次翻页都在日历下面依次显示出来
  331. var firstWeek = new Date(year, month - 1, 1).getDay() || 7,
  332. daysNum = jet.getDaysNum(year, month), prevM = jet.getPrevMonth(year, month),
  333. prevDaysNum = jet.getDaysNum(year, prevM.m), nextM = jet.getNextMonth(year, month),
  334. currOne = jet.currDate.getFullYear() + "-" + jet.digit(jet.currDate.getMonth() + 1) + "-" + jet.digit(1),
  335. thisOne = year + "-" + jet.digit(month) + "-" + jet.digit(1);
  336. boxCell.find(".jedateyear").attr("year", year).text(year + '年');
  337. boxCell.find(".jedatemonth").attr("month", month).text(month + '月');
  338. //设置时间标注
  339. var mark = function (my, mm, md) {
  340. var Marks = opts.marks, contains = function(arr, obj) {
  341. var len = arr.length;
  342. while (len--) {
  343. if (arr[len] === obj) return true;
  344. }
  345. return false;
  346. };
  347. return $.isArray(Marks) && Marks.length > 0 && contains(Marks, my + "-" + jet.digit(mm) + "-" + jet.digit(md)) ? '<i class="marks"></i>' :"";
  348. }
  349. //是否显示节日
  350. var isfestival = function(y, m ,d) {
  351. var festivalStr;
  352. if(opts.festival == true){
  353. var lunar = jeLunar(y, m - 1, d), feslunar = (lunar.solarFestival || lunar.lunarFestival),
  354. lunartext = (feslunar && lunar.jieqi) != "" ? feslunar : (lunar.jieqi || lunar.showInLunar);
  355. festivalStr = '<p><span class="solar">' + d + '</span><span class="lunar">' + lunartext + '</span></p>';
  356. }else{
  357. festivalStr = '<p class="nolunar">' + d + '</p>';
  358. }
  359. return festivalStr;
  360. };
  361. //判断是否在限制的日期之中
  362. var dateOfLimit = function(Y, M, D, isMonth){
  363. var thatNum = (Y + "-" + jet.digit(M) + "-" + jet.digit(D)).replace(/\-/g, '');
  364. if(isMonth){
  365. if (parseInt(thatNum) >= parseInt(minNum) && parseInt(thatNum) <= parseInt(maxNum)) return true;
  366. }else {
  367. if (parseInt(minNum) > parseInt(thatNum) || parseInt(maxNum) < parseInt(thatNum)) return true;
  368. }
  369. }
  370. //上一月剩余天数
  371. for (var p = prevDaysNum - firstWeek + 2; p <= prevDaysNum; p++, count++) {
  372. var pmark = mark(prevM.y,prevM.m,p), pCls = dateOfLimit(prevM.y, prevM.m, p, false) ? "disabled" : "other";
  373. dateHtml += '<li year="'+prevM.y+'" month="'+prevM.m+'" day="'+p+'" class='+pCls+'>'+(isfestival(prevM.y,prevM.m,p) + pmark)+'</li>';
  374. }
  375. //本月的天数
  376. for(var b = 1; b <= daysNum; b++, count++){
  377. var bCls = "", bmark = mark(year,month,b),
  378. thisDate = (year + "-" + jet.digit(month) + "-" + jet.digit(b)); //本月当前日期
  379. if(dateOfLimit(year, month, b, true)){
  380. bCls = jet.ymdDate == thisDate ? "action" : (currOne != thisOne && thisOne == thisDate ? "action" : "");
  381. }else{
  382. bCls = "disabled";
  383. }
  384. dateHtml += '<li year="'+year+'" month="'+month+'" day="'+b+'" '+(bCls != "" ? "class="+bCls+"" : "")+'>'+(isfestival(year,month,b) + bmark)+'</li>';
  385. }
  386. //下一月开始天数
  387. for(var n = 1, nlen = 42 - count; n <= nlen; n++){
  388. var nmark = mark(nextM.y,nextM.m,n), nCls = dateOfLimit(nextM.y, nextM.m, n, false) ? "disabled" : "other";
  389. dateHtml += '<li year="'+nextM.y+'" month="'+nextM.m+'" day="'+n+'" class='+nCls+'>'+(isfestival(nextM.y,nextM.m,n) + nmark)+'</li>';
  390. }
  391. //把日期拼接起来并插入
  392. boxCell.find(".jedaul").html(dateHtml);
  393. that.chooseDays(opts);
  394. };
  395. //循环生成年月(YYYY-MM)
  396. jedfn.onlyYMStr = function(y, m) {
  397. var onlyYM = "";
  398. $.each(jet.montharr, function(i, val) {
  399. var minArr = jet.parseMatch(jet.minDate), maxArr = jet.parseMatch(jet.maxDate),
  400. thisDate = new Date(y, jet.digit(val), "01"), minTime = new Date(minArr[0], minArr[1], minArr[2]), maxTime = new Date(maxArr[0], maxArr[1], maxArr[2]);
  401. if (thisDate < minTime || thisDate > maxTime) {
  402. onlyYM += "<li class='disabled' ym='" + y + "-" + jet.digit(val) + "'>" + y + "年" + jet.digit(val) + "月</li>";
  403. } else {
  404. onlyYM += "<li " + (m == val ? 'class="action"' :"") + ' ym="' + y + "-" + jet.digit(val) + '">' + y + "年" + jet.digit(val) + "月</li>";
  405. }
  406. });
  407. return onlyYM;
  408. };
  409. //循环生成年(YYYY)
  410. jedfn.onlyYear = function(YY) {
  411. var onlyStr = "";
  412. jet.yearArr = new Array(15);
  413. $.each(jet.yearArr, function(i) {
  414. var minArr = jet.parseMatch(jet.minDate), maxArr = jet.parseMatch(jet.maxDate),
  415. minY = minArr[0], maxY = maxArr[0], yyi = YY - 7 + i,
  416. getyear = $(jet.boxCell).find(".jedateym .jedateyearmonth").attr("data-onyy");
  417. if (yyi < minY || yyi > maxY) {
  418. onlyStr += "<li class='disabled' yy='" + yyi + "'>" + yyi + "年</li>";
  419. } else {
  420. onlyStr += "<li "+(getyear == yyi ? 'class="action"' : "")+" yy='" + yyi + "'>" + yyi + "年</li>";
  421. }
  422. });
  423. return onlyStr;
  424. };
  425. //生成定位时分秒
  426. jedfn.setStrhms = function(opts) {
  427. var that = this, boxCell = $(jet.boxCell);
  428. var parseFormat = jet.format, hmsArr = [], hmsliCls = boxCell.find(".jedatehms li"),
  429. proptextCls = boxCell.find(".jedatepropcon .jedateproptext"), propconCls = boxCell.find(".jedatepropcon .jedatehmscon");
  430. var parsehms = function(str) {
  431. var ymdstr = str.match(ymdMacth).join("-"), timeArr = ymdstr == "YYYY-MM-DD-hh-mm" ? str.split(" ") : ymdstr,
  432. isHMtime = ymdstr == "YYYY-MM-DD-hh-mm" ? timeArr[1] :timeArr;
  433. return isHMtime.match(ymdMacth).join("-");
  434. };
  435. var parmathm = parsehms(parseFormat) == "hh-mm";
  436. if(parmathm){
  437. var hmsliWidth = hmsliCls.css('width').replace(/\px|em|rem/g,''), hmsiW = boxCell.find(".jedatehms i").css('width').replace(/\px|em|rem/g,''),
  438. hmschoseW = proptextCls.css('width').replace(/\px|em|rem/g,''), hmslival = Math.round(parseInt(hmsliWidth) + parseInt(hmsliWidth)/2 + parseInt(hmsiW)/2);
  439. hmsliCls[0].style.width = hmsliCls[1].style.width = hmslival + "px";
  440. proptextCls[0].style.width = proptextCls[1].style.width = propconCls[0].style.width = propconCls[1].style.width = Math.round(parseInt(hmschoseW) + parseInt(hmschoseW)/2 + 2) + "px";
  441. }
  442. //生成时分秒
  443. $.each([ 24, 60, 60 ], function(i, len) {
  444. var hmsStr = "", hmsCls = "", inputCls = boxCell.find(".jedatehms input"), textem = inputCls.eq(i).val();
  445. inputCls.eq(i).attr("maxlength",2).attr("numval",len-1).attr("item",i);
  446. for (var h = 0; h < len; h++) {
  447. h = jet.digit(h);
  448. if (opts.ishmsLimit) {
  449. hmsCls = h < textem ? "disabled" :h == textem ? "action" :"";
  450. } else {
  451. hmsCls = parmathm && i == 2 ? textem == h ? "disabled action" :"disabled" :textem == h ? "action" :"";
  452. if(parmathm && i == 2){
  453. var readCls = hmsliCls.eq(2);
  454. readCls.css({"display":"none"}).prev().css({"display":"none"});
  455. proptextCls.eq(i).css({"display":"none"});
  456. propconCls.eq(i).css({"display":"none"});
  457. }
  458. }
  459. hmsStr += '<p class="' + hmsCls + '">' + h + "</p>";
  460. }
  461. hmsArr.push(hmsStr);
  462. });
  463. return hmsArr;
  464. };
  465. //仅年月情况下的点击
  466. jedfn.onlyYMevents = function(tmsArr, opts) {
  467. var that = this, boxCell = $(jet.boxCell);
  468. var ymVal, ymPre = boxCell.find(".jedateym .ymprev"), ymNext = boxCell.find(".jedateym .ymnext"), ony = parseInt(tmsArr[0]), onm = parseFloat(tmsArr[1]);
  469. $.each([ ymPre, ymNext ], function(i, cls) {
  470. cls.on("click", function(ev) {
  471. ev.stopPropagation();
  472. if(jet.checkFormat(jet.format) == "YYYY"){
  473. ymVal = cls == ymPre ? boxCell.find(".jedayy li").attr("yy") : boxCell.find(".jedayy li").eq(jet.yearArr.length-1).attr("yy");
  474. boxCell.find(".jedayy").html(that.onlyYear(parseInt(ymVal)));
  475. }else{
  476. ymVal = cls == ymPre ? ony -= 1 :ony += 1;
  477. boxCell.find(".jedaym").html(that.onlyYMStr(ymVal, onm));
  478. }
  479. that.ymPremNextEvents(opts);
  480. });
  481. });
  482. };
  483. jedfn.nongliorien = function(obj, self, pos) {
  484. var tops, leris, ortop, orleri, rect =self[0].getBoundingClientRect();
  485. leris = rect.right + obj[0].offsetWidth / 1.5 >= jet.winarea(1) ? rect.right - obj[0].offsetWidth : rect.left + (pos ? 0 : jet.docScroll(1));
  486. tops = rect.bottom + obj[0].offsetHeight / 1 <= jet.winarea() ? rect.bottom - 1 : rect.top > obj[0].offsetHeight / 1.5 ? rect.top - obj[0].offsetHeight - 1 : jet.winarea() - obj[0].offsetHeight;
  487. ortop = Math.max(tops + (pos ? 0 :jet.docScroll()) + 1, 1) + "px", orleri = leris + "px";
  488. return {top: ortop, left: orleri }
  489. };
  490. //选择日期
  491. jedfn.chooseDays = function(opts) {
  492. var that = this, elemCell = that.valCell, boxCell = $(jet.boxCell);
  493. boxCell.find(".jedaul li").on("click", function(ev) {
  494. var _that = $(this), liTms = [];
  495. if (_that.hasClass("disabled")) return;
  496. ev.stopPropagation();
  497. //获取时分秒的集合
  498. boxCell.find(".jedatehms input").each(function() {
  499. liTms.push($(this).val());
  500. });
  501. var aty = parseInt(_that.attr("year")), atm = parseFloat(_that.attr("month")), atd = parseFloat(_that.attr("day")),
  502. getDateVal = jet.parse([ aty, atm, atd ], [ liTms[0], liTms[1], liTms[2] ], jet.format);
  503. jet.isValHtml(elemCell) ? elemCell.val(getDateVal) :elemCell.text(getDateVal);
  504. // elemCell.css({borderColor:"#838383"});
  505. that.dateClose();
  506. opts.festival && $("#jedatetipscon").remove();
  507. if ($.isFunction(opts.choosefun) || opts.choosefun != null) opts.choosefun && opts.choosefun(elemCell,getDateVal);
  508. if ($.isFunction(opts.okfun) || opts.okfun != null) opts.okfun && opts.okfun(elemCell,getDateVal);
  509. });
  510. if(opts.festival) {
  511. //鼠标进入提示框出现
  512. boxCell.find(".jedaul li").on("mouseover", function () {
  513. var _this = $(this), aty = parseInt(_this.attr("year")), atm = parseFloat(_this.attr("month")), atd = parseFloat(_this.attr("day")),
  514. tipDiv = $("<div/>",{"id":"jedatetipscon","class":"jedatetipscon"}), lunar = jeLunar(aty, atm - 1, atd);
  515. var tiphtml = '<p>' + lunar.solarYear + '年' + lunar.solarMonth + '月' + lunar.solarDate + '日 ' + lunar.inWeekDays + '</p><p class="red">农历:' + lunar.shengxiao + '年 ' + lunar.lnongMonth + '月' + lunar.lnongDate + '</p><p>' + lunar.ganzhiYear + '年 ' + lunar.ganzhiMonth + '月 ' + lunar.ganzhiDate + '日</p>';
  516. var Fesjieri = (lunar.solarFestival || lunar.lunarFestival) != "" ? '<p class="red">' + ("节日:"+lunar.solarFestival + lunar.lunarFestival) + '</p>' : "";
  517. var Fesjieqi = lunar.jieqi != "" ? '<p class="red">'+(lunar.jieqi != "" ? "节气:"+lunar.jieqi : "") + '</p>': "";
  518. var tiptext = (lunar.solarFestival || lunar.lunarFestival || lunar.jieqi) != "" ? (Fesjieri + Fesjieqi) : "";
  519. //生成提示框到文档中
  520. $("body").append(tipDiv);
  521. tipDiv.html(tiphtml + tiptext);
  522. //获取并设置农历提示框出现的位置
  523. var tipPos = jedfn.nongliorien(tipDiv, _this);
  524. tipDiv.css({"z-index": (opts.zIndex == undefined ? 2099 + 5 : opts.zIndex + 5),top:tipPos.top,left:tipPos.left,position:"absolute",display:"block"});
  525. }).on( "mouseout", function () { //鼠标移除提示框消失
  526. if($("#jedatetipscon").size() > 0) $("#jedatetipscon").remove();
  527. });
  528. }
  529. };
  530. //下拉选择年和月
  531. jedfn.chooseYM = function(opts) {
  532. var that = this, boxCell = $(jet.boxCell);
  533. var jetopym = boxCell.find(".jedatetopym"), jedateyy = boxCell.find(".jedateyy"), jedatemm = boxCell.find(".jedatemm"), jedateyear = boxCell.find(".jedateyy .jedateyear"),
  534. jedatemonth = boxCell.find(".jedatemm .jedatemonth"), mchri = boxCell.find(".jedateymchri"), mchle = boxCell.find(".jedateymchle"),
  535. ishhmmss = jet.checkFormat(jet.format).substring(0, 5) == "hh-mm" ? true :false;
  536. var minArr = jet.minDate.match(ymdMacth), minNum = minArr[0] + minArr[1],
  537. maxArr = jet.maxDate.match(ymdMacth), maxNum = maxArr[0] + maxArr[1];
  538. //循环生成年
  539. function eachYears(YY) {
  540. var eachStr = "", ycls;
  541. $.each(new Array(15), function(i,v) {
  542. if (i === 7) {
  543. var getyear = jedateyear.attr("year");
  544. ycls = (parseInt(YY) >= parseInt(minArr[0]) && parseInt(YY) <= parseInt(maxArr[0])) ? (getyear == YY ? 'class="action"' :"") : 'class="disabled"';
  545. eachStr += "<li " + ycls + ' yy="' + YY + '">' + YY + "年</li>";
  546. } else {
  547. ycls = (parseInt(YY - 7 + i) >= parseInt(minArr[0]) && parseInt(YY - 7 + i) <= parseInt(maxArr[0])) ? "" : 'class="disabled"';
  548. eachStr += '<li ' + ycls + ' yy="' + (YY - 7 + i) + '">' + (YY - 7 + i) + "年</li>";
  549. }
  550. });
  551. return eachStr;
  552. }
  553. //循环生成月
  554. function eachYearMonth(YY, ymlen) {
  555. var ymStr = "";
  556. if (ymlen == 12) {
  557. $.each(jet.montharr, function(i, val) {
  558. var getmonth = jedatemonth.attr("month"), val = jet.digit(val);
  559. var mcls = (parseInt(jedateyear.attr("year") + val) >= parseInt(minNum) && parseInt(jedateyear.attr("year") + val) <= parseInt(maxNum)) ?
  560. (jet.digit(getmonth) == val ? 'class="action"' :"") : 'class="disabled"';
  561. ymStr += "<li " + mcls + ' mm="' + val + '">' + val + "月</li>";
  562. });
  563. $.each([ mchri, mchle ], function(c, cls) {
  564. jet.isShow(cls,false);
  565. });
  566. } else {
  567. ymStr = eachYears(YY);
  568. $.each([ mchri, mchle ], function(c, cls) {
  569. jet.isShow(cls,true);
  570. });
  571. }
  572. jetopym.removeClass( ymlen == 12 ? "jedatesety" :"jedatesetm").addClass(ymlen == 12 ? "jedatesetm" :"jedatesety");
  573. boxCell.find(".jedatetopym .ymdropul").html(ymStr);
  574. jet.isShow(jetopym,true);
  575. }
  576. function clickLiYears(year) {
  577. boxCell.find(".ymdropul li").on("click", function(ev) {
  578. var _this = $(this), Years = _this.attr("yy"), Months = parseInt(jedatemonth.attr("month"));
  579. if (_this.hasClass("disabled")) return;
  580. ev.stopPropagation();
  581. year.attr("year", Years).html(Years + '年');
  582. jet.isShow(jetopym,false);
  583. that.createDaysHtml(Years, Months, opts);
  584. });
  585. }
  586. //下拉选择年
  587. !ishhmmss && jedateyy.on("click", function() {
  588. var yythat = $(this), YMlen = parseInt(yythat.attr("ym")), yearAttr = parseInt(jedateyear.attr("year"));
  589. eachYearMonth(yearAttr, YMlen);
  590. clickLiYears(jedateyear);
  591. });
  592. //下拉选择月
  593. !ishhmmss && jedatemm.on("click", function() {
  594. var mmthis = $(this), YMlen = parseInt(mmthis.attr("ym")), yearAttr = parseInt(jedateyear.attr("year"));
  595. eachYearMonth(yearAttr, YMlen);
  596. boxCell.find(".ymdropul li").on("click", function(ev) {
  597. if ($(this).hasClass("disabled")) return;
  598. ev.stopPropagation();
  599. var lithat = $(this), Years = jedateyear.attr("year"), Months = parseInt(lithat.attr("mm"));
  600. jedatemonth.attr("month", Months).html(Months + '月');
  601. jet.isShow(jetopym,false);
  602. that.createDaysHtml(Years, Months, opts);
  603. });
  604. });
  605. //关闭下拉选择
  606. boxCell.find(".jedateymchok").on("click", function(ev) {
  607. ev.stopPropagation();
  608. jet.isShow(jetopym,false);
  609. });
  610. var yearMch = parseInt(jedateyear.attr("year"));
  611. $.each([ mchle, mchri ], function(d, cls) {
  612. cls.on("click", function(ev) {
  613. ev.stopPropagation();
  614. d == 0 ? yearMch -= 15 :yearMch += 15;
  615. var mchStr = eachYears(yearMch);
  616. boxCell.find(".jedatetopym .ymdropul").html(mchStr);
  617. clickLiYears(jedateyear);
  618. });
  619. });
  620. };
  621. //年月情况下的事件绑定
  622. jedfn.ymPremNextEvents = function(opts){
  623. var that = this, elemCell = that.valCell, boxCell = $(jet.boxCell);
  624. var newDate = new Date(), isYY = (jet.checkFormat(jet.format) == "YYYY"), ymCls = isYY ? boxCell.find(".jedayy li") : boxCell.find(".jedaym li");
  625. //选择年月
  626. ymCls.on("click", function (ev) {
  627. if ($(this).hasClass("disabled")) return; //判断是否为禁选状态
  628. ev.stopPropagation();
  629. var atYM = isYY ? $(this).attr("yy").match(ymdMacth) : $(this).attr("ym").match(ymdMacth),
  630. getYMDate = isYY ? jet.parse([atYM[0], newDate.getMonth() + 1, 1], [0, 0, 0], jet.format) : jet.parse([atYM[0], atYM[1], 1], [0, 0, 0], jet.format);
  631. jet.isValHtml(elemCell) ? elemCell.val(getYMDate) : elemCell.text(getYMDate);
  632. // elemCell.css({borderColor:"#838383"});
  633. that.dateClose();
  634. if ($.isFunction(opts.choosefun) || opts.choosefun != null) opts.choosefun(elemCell, getYMDate);
  635. });
  636. };
  637. jedfn.events = function(tmsArr,opts){
  638. var that = this, elemCell = that.valCell, boxCell = $(jet.boxCell);
  639. var newDate = new Date(), yPre = boxCell.find(".yearprev"), yNext = boxCell.find(".yearnext"),
  640. mPre = boxCell.find(".monthprev"), mNext = boxCell.find(".monthnext"),
  641. jedateyear = boxCell.find(".jedateyear"), jedatemonth = boxCell.find(".jedatemonth"),
  642. isYYMM = (jet.checkFormat(jet.format) == "YYYY-MM" || jet.checkFormat(jet.format) == "YYYY") ? true :false,
  643. ishhmmss = jet.checkFormat(jet.format).substring(0, 5) == "hh-mm" ? true :false;
  644. if (!isYYMM) {
  645. //切换年
  646. !ishhmmss && $.each([ yPre, yNext ], function(i, cls) {
  647. cls.on("click", function(ev) {
  648. if(boxCell.find(".jedatetopym").css("display") == "block") return;
  649. ev.stopPropagation();
  650. var year = parseInt(jedateyear.attr("year")),
  651. month = parseInt(jedatemonth.attr("month")),
  652. pnYear = cls == yPre ? --year : ++year,
  653. PrevYM = jet.getPrevMonth(pnYear, month);
  654. if(month == 12){
  655. var NextYM = jet.getNextMonth(pnYear-1, month);
  656. }else{
  657. NextYM = jet.getNextMonth(pnYear, month);
  658. }
  659. cls == yPre ? that.createDaysHtml(PrevYM.y, month, opts) : that.createDaysHtml(NextYM.y, month, opts);
  660. });
  661. });
  662. //切换月
  663. !ishhmmss && $.each([ mPre, mNext ], function(i, cls) {
  664. cls.on("click", function(ev) {
  665. if(boxCell.find(".jedatetopym").css("display") == "block") return;
  666. ev.stopPropagation();
  667. var year = parseInt(jedateyear.attr("year")), month = parseInt(jedatemonth.attr("month")),
  668. PrevYM = jet.getPrevMonth(year, month), NextYM = jet.getNextMonth(year, month);
  669. cls == mPre ? that.createDaysHtml(PrevYM.y, PrevYM.m, opts) : that.createDaysHtml(NextYM.y, NextYM.m, opts);
  670. });
  671. });
  672. //时分秒事件绑定
  673. var hmsStr = that.setStrhms(opts), hmsevents = function(hmsArr) {
  674. $.each(hmsArr, function(i, hmsCls) {
  675. if (hmsCls.html() == "") hmsCls.html(hmsStr[i]);
  676. });
  677. if (ishhmmss) {
  678. jet.isShow(boxCell.find(".jedatehmsclose"), false);
  679. jet.isShow(boxCell.find(".jedatetodaymonth"), false);
  680. } else {
  681. jet.isShow(boxCell.find(".jedateprophms"), true);
  682. }
  683. //计算当前时分秒的位置
  684. $.each([ "hours", "minutes", "seconds" ], function(i, hms) {
  685. var hmsCls = boxCell.find(".jedateprop" + hms), achmsCls = boxCell.find(".jedateprop"+hms+" .action");
  686. hmsCls[0].scrollTop = achmsCls[0].offsetTop - 146;
  687. var onhmsPCls = boxCell.find(".jedateprop" + hms + " p");
  688. onhmsPCls.on("click", function() {
  689. var _this = $(this);
  690. if (_this.hasClass("disabled")) return;
  691. onhmsPCls.each(function() {
  692. $(this).removeClass("action");
  693. });
  694. _this.addClass("action");
  695. boxCell.find(".jedatebot .jedatehms input").eq(i).val(jet.digit(_this.text()));
  696. if (!ishhmmss) jet.isShow(boxCell.find(".jedateprophms"), false);
  697. });
  698. });
  699. };
  700. var hs = boxCell.find(".jedateprophours"), ms = boxCell.find(".jedatepropminutes"), ss = boxCell.find(".jedatepropseconds");
  701. if (ishhmmss) {
  702. hmsevents([ hs, ms, ss ]);
  703. } else {
  704. boxCell.find(".jedatehms").on("click", function() {
  705. if (boxCell.find(".jedateprophms").css("display") !== "block") hmsevents([ hs, ms, ss ]);
  706. //关闭时分秒层
  707. boxCell.find(".jedateprophms .jedatehmsclose").on("click", function() {
  708. jet.isShow(boxCell.find(".jedateprophms"), false);
  709. });
  710. });
  711. }
  712. // 添加时间
  713. boxCell.find(".jedatebot .dataSelectAdd").on("click",function(){
  714. var box = $(jet.boxCell);
  715. if (box && box.css("display") !== "none") box.remove();
  716. var optionDate = {};
  717. if(that.opts.isTime){
  718. optionDate = {
  719. format:"YYYY-MM-DD",
  720. isTime:false
  721. };
  722. }else{
  723. optionDate = {
  724. format:"YYYY-MM-DD hh:mm:ss",
  725. isTime:true
  726. };
  727. }
  728. jeDate.call(that,that.valCell,optionDate);
  729. that.valCell.trigger("click");
  730. });
  731. //今天按钮设置日期时间
  732. //boxCell.find(".jedatebot .jedatetodaymonth").on("click", function() {
  733. // var toTime = [ newDate.getFullYear(), newDate.getMonth() + 1, newDate.getDate(), newDate.getHours(), newDate.getMinutes(), newDate.getSeconds() ],
  734. // gettoDate = jet.parse([ toTime[0], toTime[1], toTime[2] ], [ toTime[3], toTime[4], toTime[5] ], jet.format);
  735. // that.createDaysHtml(toTime[0], toTime[1], opts);
  736. // jet.isValHtml(elemCell) ? elemCell.val(gettoDate) :jet.text(gettoDate);
  737. // elemCell.css({borderColor:"#838383"});
  738. // that.dateClose();
  739. // if ($.isFunction(opts.choosefun) || opts.choosefun != null) opts.choosefun(elemCell,gettoDate);
  740. // if (!isYYMM) that.chooseDays(opts);
  741. //});
  742. }else{
  743. that.ymPremNextEvents(opts);
  744. //本月按钮设置日期时间
  745. //boxCell.find(".jedatebot .jedatetodaymonth").on("click", function(ev) {
  746. // ev.stopPropagation();
  747. // var ymTime = [ newDate.getFullYear(), newDate.getMonth() + 1, newDate.getDate() ],
  748. // YMDate = jet.parse([ ymTime[0], ymTime[1], 0 ], [ 0, 0, 0 ], jet.format);
  749. // jet.isValHtml(elemCell) ? elemCell.val(YMDate) :elemCell.text(YMDate);
  750. // elemCell.css({borderColor:"#838383"});
  751. // that.dateClose();
  752. // if ($.isFunction(opts.choosefun) || opts.choosefun != null) opts.choosefun(elemCell,YMDate);
  753. //});
  754. }
  755. //检查时间输入值,并对应到相应位置
  756. boxCell.find(".jedatehms input").on("keyup", function() {
  757. if(isNaN($(this).val())) return;
  758. var _this = $(this), thatval = _this.val(), hmsVal = parseInt(_this.attr("numval")), thatitem = parseInt(_this.attr("item"));
  759. _this.val(thatval.replace(/\D/g,""));
  760. //判断输入值是否大于所设值
  761. if(thatval > hmsVal){
  762. _this.val(hmsVal);
  763. alert("输入值不能大于"+hmsVal);
  764. }
  765. if(thatval == "") _this.val("00");
  766. boxCell.find(".jedatehmscon").eq(thatitem).children().each(function(){
  767. $(this).removeClass("action");
  768. })
  769. boxCell.find(".jedatehmscon").eq(thatitem).children().eq(parseInt(_this.val().replace(/^0/g,''))).addClass("action");
  770. $.each([ "hours", "minutes", "seconds" ], function(i, hms) {
  771. var hmsCls = boxCell.find(".jedateprop" + hms), achmsCls = boxCell.find(".jedateprop" + hms + " .action");
  772. hmsCls[0].scrollTop = achmsCls[0].offsetTop - 118;
  773. });
  774. });
  775. //清空按钮清空日期时间
  776. boxCell.find(".jedatebot .jedateclear").on("click", function(ev) {
  777. ev.stopPropagation();
  778. var clearVal = jet.isValHtml(elemCell) ? elemCell.val() :elemCell.text();
  779. jet.isValHtml(elemCell) ? elemCell.val("") :elemCell.text("");
  780. // elemCell.css({borderColor:"red"});
  781. that.dateClose();
  782. if (clearVal != "") {
  783. if (jet.isBool(opts.clearRestore)){
  784. jet.minDate = opts.startMin || jet.minDate;
  785. jet.maxDate = opts.startMax || jet.maxDate;
  786. }
  787. if ($.isFunction(opts.clearfun) || opts.clearfun != null) opts.clearfun(elemCell,clearVal);
  788. }
  789. });
  790. //确认按钮设置日期时间
  791. boxCell.find(".jedatebot .jedateok").on("click", function(ev) {
  792. ev.stopPropagation();
  793. var isValtext = (elemCell.val() || elemCell.text()) != "", isYYYY = jet.checkFormat(jet.format) == "YYYY", okVal = "",
  794. //获取时分秒的数组
  795. eachhmsem = function() {
  796. var hmsArr = [];
  797. boxCell.find(".jedatehms input").each(function() {
  798. hmsArr.push($(this).val());
  799. });
  800. return hmsArr;
  801. };
  802. var minArr = jet.minDate.match(ymdMacth), minNum = minArr[0] + minArr[1] + minArr[2],
  803. maxArr = jet.maxDate.match(ymdMacth), maxNum = maxArr[0] + maxArr[1] + maxArr[2];
  804. if (isValtext) {
  805. var btnokVal = jet.isValHtml(elemCell) ? elemCell.val() :elemCell.text(), oktms = btnokVal.match(ymdMacth);
  806. if (!isYYMM) {
  807. var okTimeArr = eachhmsem(), okTime = [ parseInt(jedateyear.attr("year")), parseInt(jedatemonth.attr("month")), oktms[2]],
  808. okTimeNum = okTime[0] + okTime[1] + okTime[2];
  809. //判断获取到的日期是否在有效期内
  810. var isokTime = (parseInt(okTimeNum) >= parseInt(minNum) && parseInt(okTimeNum) <= parseInt(maxNum)) ? true : false;
  811. okVal = isValtext && isokTime ? jet.parse([ okTime[0], okTime[1], okTime[2] ], [ okTimeArr[0], okTimeArr[1], okTimeArr[2] ], jet.format) :
  812. jet.parse([ oktms[0], oktms[1], oktms[2] ], [ okTimeArr[0], okTimeArr[1], okTimeArr[2] ], jet.format);
  813. if(!ishhmmss) that.createDaysHtml(okTime[0], okTime[1], opts); console.log(okVal)
  814. that.chooseDays(opts);
  815. } else {
  816. var ymactCls = isYYYY ? boxCell.find(".jedayy .action") : boxCell.find(".jedaym .action");
  817. //判断是否为(YYYY或YYYY-MM)类型
  818. if(isYYYY){
  819. var okDate = ymactCls ? ymactCls.attr("yy").match(ymdMacth) : oktms;
  820. okVal = jet.parse([parseInt(okDate[0]), newDate.getMonth() + 1, 1], [0, 0, 0], jet.format);
  821. }else {
  822. var jedYM = ymactCls ? ymactCls.attr("ym").match(ymdMacth) : oktms;
  823. okVal = jet.parse([parseInt(jedYM[0]), parseInt(jedYM[1]), 1], [0, 0, 0], jet.format);
  824. }
  825. }
  826. } else {
  827. var okArr = eachhmsem(), monthCls = boxCell.find(".jedateyearmonth")[0], okDate = "";
  828. //判断是否为时分秒(hh:mm:ss)类型
  829. if (ishhmmss) {
  830. okVal = jet.parse([ tmsArr[0], tmsArr[1], tmsArr[2] ], [ okArr[0], okArr[1], okArr[2] ], jet.format);
  831. } else {
  832. //判断是否为年月(YYYY或YYYY-MM)类型
  833. if(isYYMM){
  834. okDate = jet.checkFormat(jet.format) == "YYYY" ? monthCls.attr("data-onyy").match(ymdMacth) : monthCls.attr("data-onym").match(ymdMacth);
  835. }else{
  836. okDate = [ newDate.getFullYear(), newDate.getMonth() + 1, newDate.getDate()];
  837. }
  838. okVal = isYYYY ? jet.parse([parseInt(okDate[0]), newDate.getMonth(), 1], [0, 0, 0], jet.format) :
  839. jet.parse([parseInt(okDate[0]), parseInt(okDate[1]), newDate.getDate()], [okArr[0], okArr[1], okArr[2]], jet.format);
  840. }
  841. }
  842. jet.isValHtml(elemCell) ? elemCell.val(okVal) :elemCell.text(okVal);
  843. // elemCell.css({borderColor:"#838383"});
  844. that.dateClose();
  845. if ($.isFunction(opts.okfun) || opts.okfun != null) opts.okfun(jet.elemCell,okVal);
  846. });
  847. //点击空白处隐藏
  848. $(document).on("mouseup", function(ev) {
  849. ev.stopPropagation();
  850. var box = $(jet.boxCell);
  851. if (box && box.css("display") !== "none") box.remove();
  852. });
  853. $(jet.boxCell).on("mouseup", function(ev) {
  854. ev.stopPropagation();
  855. });
  856. };
  857. //日期控件版本
  858. $.dateVer = "3.6";
  859. //返回指定日期
  860. $.nowDate = function(num) {
  861. return jet.initDates(num);
  862. };
  863. //为当前获取到的日期加减天数,这里只能控制到天数,不能控制时分秒加减
  864. $.addDate = function(time,num,type) {
  865. num = num | 0; type = type || "DD";
  866. return jet.addDateTime(time,num,type,jet.format);
  867. };
  868. return jeDate;
  869. });
  870. //农历数据
  871. ;(function(root, factory) {
  872. root.jeLunar = factory(root.jeLunar);
  873. })(this, function(jeLunar) {
  874. 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],
  875. 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 ];
  876. var Gan = "甲乙丙丁戊己庚辛壬癸", Zhi = "子丑寅卯辰巳午未申酉戌亥", Animals = "鼠牛虎兔龙蛇马羊猴鸡狗猪";
  877. var solarTerm = [ "小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨", "立夏", "小满",
  878. "芒种", "夏至", "小暑", "大暑", "立秋", "处暑", "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪", "冬至" ];
  879. var nStr1 = "日一二三四五六七八九十", nStr2 = "初十廿卅", nStr3 = [ "正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "腊"],
  880. sFtv1 = {
  881. "0101" : "*1元旦节", "0202" : "湿地日",
  882. "0214" : "情人节", "0308" : "妇女节",
  883. "0312" : "植树节", "0315" : "消费者权益日",
  884. "0401" : "愚人节", "0422" : "地球日",
  885. "0501" : "*1劳动节", "0504" : "青年节",
  886. "0512" : "护士节", "0518" : "博物馆日",
  887. "0520" : "母亲节", "0601" : "儿童节",
  888. "0623" : "奥林匹克日", "0630" : "父亲节",
  889. "0701" : "建党节", "0801" : "建军节",
  890. "0903" : "抗战胜利日", "0910" : "教师节",
  891. "1001" : "*3国庆节", "1201" : "艾滋病日",
  892. "1224" : "平安夜", "1225" : "圣诞节"
  893. },
  894. sFtv2 = {
  895. "0100" : "除夕", "0101" : "*2春节",
  896. "0115" : "元宵节", "0505" : "*1端午节",
  897. "0707" : "七夕节", "0715" : "中元节",
  898. "0815" : "*1中秋节", "0909" : "*1重阳节",
  899. "1015" : "下元节", "1208" : "腊八节",
  900. "1223" : "小年"
  901. };
  902. function flunar(Y) {
  903. var sTerm = function (j, i) {
  904. var h = new Date((31556925974.7 * (j - 1900) + sTermInfo[i] * 60000) + Date.UTC(1900, 0, 6, 2, 5));
  905. return (h.getUTCDate())
  906. },
  907. d = function (k) {
  908. var h, j = 348;
  909. for (h = 32768; h > 8; h >>= 1) {
  910. j += (lunarInfo[k - 1900] & h) ? 1 : 0;
  911. }
  912. return (j + b(k))
  913. },
  914. ymdCyl = function (h) {
  915. return (Gan.charAt(h % 10) + Zhi.charAt(h % 12))
  916. },
  917. b =function (h) {
  918. var islp = (g(h)) ? ((lunarInfo[h - 1900] & 65536) ? 30 : 29) : (0);
  919. return islp
  920. },
  921. g = function (h) {
  922. return (lunarInfo[h - 1900] & 15)
  923. },
  924. e = function (i, h) {
  925. return ((lunarInfo[i - 1900] & (65536 >> h)) ? 30 : 29)
  926. },
  927. newymd = function (m) {
  928. var k, j = 0, h = 0, l = new Date(1900, 0, 31), n = (m - l) / 86400000;
  929. this.dayCyl = n + 40;
  930. this.monCyl = 14;
  931. for (k = 1900; k<2050&&n>0; k++) {
  932. h = d(k); n -= h;
  933. this.monCyl += 12;
  934. }
  935. if (n < 0) {
  936. n += h; k--;
  937. this.monCyl -= 12;
  938. }
  939. this.year = k;
  940. this.yearCyl = k - 1864;
  941. j = g(k);
  942. this.isLeap = false;
  943. for (k = 1; k<13&&n>0; k++) {
  944. if (j > 0 && k == (j + 1) && this.isLeap == false) {
  945. --k;
  946. this.isLeap = true;
  947. h = b(this.year);
  948. } else {
  949. h = e(this.year, k);
  950. }
  951. if (this.isLeap == true && k == (j + 1)) {
  952. this.isLeap = false;
  953. }
  954. n -= h;
  955. if (this.isLeap == false) this.monCyl++;
  956. }
  957. if (n == 0 && j > 0 && k == j + 1) {
  958. if (this.isLeap) {
  959. this.isLeap = false;
  960. } else {
  961. this.isLeap = true;
  962. --k;
  963. --this.monCyl;
  964. }
  965. }
  966. if (n < 0) {
  967. n += h; --k;
  968. --this.monCyl
  969. }
  970. this.month = k;
  971. this.day = n + 1;
  972. },
  973. digit = function (num) {
  974. return num < 10 ? "0" + (num | 0) :num;
  975. },
  976. reymd = function (i, j) {
  977. var h = i;
  978. return j.replace(/dd?d?d?|MM?M?M?|yy?y?y?/g, function(k) {
  979. switch (k) {
  980. case "yyyy":
  981. var l = "000" + h.getFullYear();
  982. return l.substring(l.length - 4);
  983. case "dd": return digit(h.getDate());
  984. case "d": return h.getDate().toString();
  985. case "MM": return digit((h.getMonth() + 1));
  986. case "M": return h.getMonth() + 1;
  987. }
  988. })
  989. },
  990. lunarMD = function (i, h) {
  991. var j;
  992. switch (i, h) {
  993. case 10: j = "初十"; break;
  994. case 20: j = "二十"; break;
  995. case 30: j = "三十"; break;
  996. default:
  997. j = nStr2.charAt(Math.floor(h / 10));
  998. j += nStr1.charAt(h % 10);
  999. }
  1000. return (j)
  1001. };
  1002. this.isToday = false;
  1003. this.isRestDay = false;
  1004. this.solarYear = reymd(Y, "yyyy");
  1005. this.solarMonth = reymd(Y, "M");
  1006. this.solarDate = reymd(Y, "d");
  1007. this.solarWeekDay = Y.getDay();
  1008. this.inWeekDays = "星期" + nStr1.charAt(this.solarWeekDay);
  1009. var X = new newymd(Y);
  1010. this.lunarYear = X.year;
  1011. this.shengxiao = Animals.charAt((this.lunarYear - 4) % 12);
  1012. this.lunarMonth = X.month;
  1013. this.lunarIsLeapMonth = X.isLeap;
  1014. this.lnongMonth = this.lunarIsLeapMonth ? "闰" + nStr3[X.month - 1] : nStr3[X.month - 1];
  1015. this.lunarDate = X.day;
  1016. this.showInLunar = this.lnongDate = lunarMD(this.lunarMonth, this.lunarDate);
  1017. if (this.lunarDate == 1) {
  1018. this.showInLunar = this.lnongMonth + "月";
  1019. }
  1020. this.ganzhiYear = ymdCyl(X.yearCyl);
  1021. this.ganzhiMonth = ymdCyl(X.monCyl);
  1022. this.ganzhiDate = ymdCyl(X.dayCyl++);
  1023. this.jieqi = "";
  1024. this.restDays = 0;
  1025. if (sTerm(this.solarYear, (this.solarMonth - 1) * 2) == reymd(Y, "d")) {
  1026. this.showInLunar = this.jieqi = solarTerm[(this.solarMonth - 1) * 2];
  1027. }
  1028. if (sTerm(this.solarYear, (this.solarMonth - 1) * 2 + 1) == reymd(Y, "d")) {
  1029. this.showInLunar = this.jieqi = solarTerm[(this.solarMonth - 1) * 2 + 1];
  1030. }
  1031. if (this.showInLunar == "清明") {
  1032. this.showInLunar = "清明节";
  1033. this.restDays = 1;
  1034. }
  1035. this.solarFestival = sFtv1[reymd(Y, "MM") + reymd(Y, "dd")];
  1036. if (typeof this.solarFestival == "undefined") {
  1037. this.solarFestival = "";
  1038. } else {
  1039. if (/\*(\d)/.test(this.solarFestival)) {
  1040. this.restDays = parseInt(RegExp.$1);
  1041. this.solarFestival = this.solarFestival.replace(/\*\d/, "");
  1042. }
  1043. }
  1044. this.showInLunar = (this.solarFestival == "") ? this.showInLunar : this.solarFestival;
  1045. this.lunarFestival = sFtv2[this.lunarIsLeapMonth ? "00" : digit(this.lunarMonth) + digit(this.lunarDate)];
  1046. if (typeof this.lunarFestival == "undefined") {
  1047. this.lunarFestival = "";
  1048. } else {
  1049. if (/\*(\d)/.test(this.lunarFestival)) {
  1050. this.restDays = (this.restDays > parseInt(RegExp.$1)) ? this.restDays : parseInt(RegExp.$1);
  1051. this.lunarFestival = this.lunarFestival.replace(/\*\d/, "");
  1052. }
  1053. }
  1054. if (this.lunarMonth == 12 && this.lunarDate == e(this.lunarYear, 12)) {
  1055. this.lunarFestival = sFtv2["0100"];
  1056. this.restDays = 1;
  1057. }
  1058. this.showInLunar = (this.lunarFestival == "") ? this.showInLunar : this.lunarFestival;
  1059. }
  1060. var jeLunar = function(y,m,d) {
  1061. return new flunar(new Date(y,m,d));
  1062. };
  1063. return jeLunar;
  1064. });