//日历PC命名空间 Namespace.register("U.Boom.A.P.Calen"); //日历PC 田海涛 陈裕豪 陈卓锐 //调用函数:U.Boom.A.P.Calen.A() //返回参数:divs 日历整体 U.Boom.A.P.Calen.A = function (input) { var DateJson = ['一', '二', '三', '四', '五', '六', '日']; //外框 //var divs = $('
')[0]; //var input = $$('div', { 'class': 'U_BP_Cal-input' }, divs); divs = input.parentNode; var div = $$('div', { 'class': 'U_BP_Cal-div', 'tabindex': '0' }, divs); div.style.left = input.offsetLeft + "px"; div.style.top = (input.offsetTop + input.offsetHeight) + "px"; div.input = input; //input.onfocus = function () { U.Boom.A.P.Calen.A.click(div); } div.onblur = function () { $(div).remove(); /**/ } div.focus(); //日历头部 var divTop = $$('div', { 'class': 'U_BP_Cal-Top' }, div); var TopTitle = $$('div', { 'class': 'U_BP_Cal-Top-Title' }, divTop); var tYear = $$('div', { 'class': 'U_BP_Cal-Top-tYear' }, TopTitle); tYear.onclick = function () { U.Boom.A.P.Calen.A.Close(conetY, this, conet, yearText, monthText, conetDB); } var yearText = $$('a', { 'class': 'U_BP_Cal-Top-yearText', 'innerHTML': '年份' }, tYear); var yearTitle = $$('a', { 'class': 'U_BP_Cal-Top-yearText', 'innerHTML': '年' }, tYear); var tMonths = $$('div', { 'class': 'U_BP_Cal-Top-tMonths' }, TopTitle); var tMonth = $$('div', { 'class': 'U_BP_Cal-Top-tMonth' }, tMonths); tMonth.onclick = function () { U.Boom.A.P.Calen.A.Close(conetM, this, conet, yearText, monthText, conetDB); } var monthText = $$('a', { 'class': 'U_BP_Cal-Top-monthText', 'innerHTML': '月份' }, tMonth); var monthTitle = $$('a', { 'class': 'U_BP_Cal-Top-monthText', 'innerHTML': '月' }, tMonth); //日历内容 var conet = $$('div', { 'class': 'U_BP_Cal-conet', 'i': 'U_BP_Cal-conetD' }, div); var conetY = $$('div', { 'class': 'U_BP_Cal-conetY', 'style': { 'cssText': 'display:none;'} }, conet); var conetM = $$('div', { 'style': { 'cssText': 'display:none' }, 'class': 'U_BP_Cal-conetM' }, conet); var conetD = $$('div', { 'class': 'U_BP_Cal-conetD', 'style': { 'cssText': 'display:block'} }, conet); var conetDT = $$('div', { 'class': 'U_BP_Cal-conetDT' }, conetD); var conetDB = $$('div', { 'class': 'U_BP_Cal-conetDB' }, conetD); //月份左右切换 var tMonthLeft = $$('div', { 'class': 'U_BP_Cal-triangleLeft', 'onclick': [U.Boom.A.P.Calen.A.Ontop, [yearText, monthText, conetDB]] }, tMonths); //'U.Boom.A.P.Calen.A.Ontop()' var tMonthRight = $$('div', { 'class': 'U_BP_Cal-triangleRight', 'onclick': [U.Boom.A.P.Calen.A.Onbottom, [yearText, monthText, conetDB]] }, tMonths); //'U.Boom.A.P.Calen.A.Onbottom()' //获取今天的信息 var mydate = U.Boom.A.P.Calen.Date(); //年份 把元素放在conetY 起始年今年 U.Boom.A.P.Calen.A.couldY(conetY, mydate['year'] - 5, conetM, conet, yearText); //月份 for (i = 1; i < 13; i++) { blockM = $$('div', { 'class': 'U_BP_Cal-blockM', 'innerHTML': i + "月" }, conetM); blockM.onclick = function () { U.Boom.A.P.Calen.A.Open(conetD, this, conet, yearText, monthText, conetDB); } } //日历的星期 for (i = 0; i < 7; i++) { $$('div', { 'class': 'U_BP_Cal-conetDTT', 'innerHTML': DateJson[i] }, conetDT); } yearText.innerHTML = mydate['year']; //今天的年 monthText.innerHTML = mydate['month']; //今天的月 //生成本月的日历 U.Boom.A.P.Calen.A.nowMonth(U.Boom.A.P.Calen.Mouth(mydate['year'], mydate['month'], mydate['date'], 7, 5), conetDB, monthText.innerHTML, yearText.innerHTML); return div; } U.Boom.A.P.Calen.A.Default = function (div, html) { div.innerHTML = html; } //点击日历隐藏显示 U.Boom.A.P.Calen.A.click = function (div) { (div.style.display != "block") ? div.style.display = "block" : div.style.display = "none"; div.focus(); // div.style.left = input.offsetLeft + "px"; // div.style.top = (input.offsetTop + input.offsetHeight) + "px"; } //通用 返回:年-月-日 星期 时-分-秒 U.Boom.A.P.Calen.Date = function () { var myDate = new Date()//获取日期时间 //年月日 var year = myDate.getFullYear(); var month = myDate.getMonth() + 1; var date = myDate.getDate(); var day = myDate.getDay(); //时分秒 var hours = myDate.getHours(); var minutes = myDate.getMinutes(); var seconds = myDate.getSeconds(); //时与分小于9前面加上0 if (minutes <= 9) minutes = "0" + minutes; if (seconds <= 9) seconds = "0" + seconds; //数字转文字 var days = { 0: "日", 1: "一", 2: "二", 3: "三", 4: "四", 5: "五", 6: "六" } return { "year": year, "month": month, "date": date, "day": days[day], "hours": hours, "minutes": minutes, "seconds": seconds } } //生成年(年份整体id,哪一年) U.Boom.A.P.Calen.A.couldY = function (conetY, nowYear, conetM, conet, yearText) { //blocks(年月横向)i j定义for循环 var blocks, i, j; //div清空年月的div conetY.innerHTML = ""; //for循环生产年份的div for (i = 0; i < 4; i++) {//竖向四个 blocks = $$('div', { 'class': 'U_BP_Cal-blocks' }, conetY); for (j = 0; j < 3; j++) {//横向三个 block = $$('div', { 'class': 'U_BP_Cal-block', 'innerHTML': nowYear++ }, blocks); block.onclick = function () { U.Boom.A.P.Calen.A.Open(conetM, this, conet, yearText); } } } //在年份添加鼠标滑动事件 传入DOM的event var last, year, blocks, block; //定义年 conetY.onmousewheel = function (event) { event = event || window.event; if (event.wheelDeltaY == -120) {//向下滚动 last = conetY.firstChild; //年份第一个数 year = parseInt(conetY.lastChild.lastChild.innerHTML); //获取年最后一个数-->转成数字形式 last.parentNode.removeChild(last); //删除年第一个 blocks = $$('div', { 'class': 'U_BP_Cal-blocks' }, conetY); //创建一个年 for (i = 0; i < 3; i++) {//循环出一行连续的年份 year = year + 1; //连续所以++ $$('div', { 'onclick': 'U.Boom.A.P.Calen.conetM,this)', 'class': 'U_BP_Cal-block', 'innerHTML': year }, blocks); } } if (event.wheelDeltaY == 120) {//向上滚动 last = conetY.lastChild; //获取年份最后一个数 year = parseInt(conetY.firstChild.firstChild.innerHTML); //获取年第一个数-->转成数字形式 last.parentNode.removeChild(last); //删除最后一个数 blocks = $('')[0]; //创建一个年 conetY.insertBefore(blocks, conetY.childNodes[0]); //插入第一行第一个 for (i = 0; i < 3; i++) { year = year - 1; //连续所以-- block = $('