From 817b644ba619e8e8e046834f90ce1df376f96f51 Mon Sep 17 00:00:00 2001 From: ThomasJ Date: Fri, 5 Feb 2016 00:41:51 +0900 Subject: [PATCH] ax5calendar 0.7.0 --- API.md | 26 ++++++++++++++++++++++++++ bower.json | 2 +- dist/ax5calendar.js | 13 +++++++++++-- dist/ax5calendar.min.js | 2 +- package.json | 2 +- src/ax5calendar.js | 13 +++++++++++-- test/index.html | 12 ++++++++++-- 7 files changed, 61 insertions(+), 9 deletions(-) diff --git a/API.md b/API.md index 3515366..f7cce11 100644 --- a/API.md +++ b/API.md @@ -34,6 +34,7 @@ myCalendar.setConfig({ dayTmpl: 'String' // %s }, selectable: 'Array|Object', + marker: 'Object', multipleSelect: 'false|Number', // false onClick: "Function", // null onStateChanged: "Function" // null @@ -168,6 +169,18 @@ selectable: { range: [{from: new Date(2016, 0, 1), to: new Date(2016, 0, 2)}] } selectable: { '2016-01-01': true, '2016-01-02': true } ``` +### marker + +Type: `Object` + +```js +marker: { + '2016-02-07': {theme: 'holiday', label: '설날'}, + '2016-02-08': {theme: 'holiday', label: '설날'}, + '2016-02-09': {theme: 'holiday', label: '설날'}, + '2016-02-10': {theme: 'holiday', label: '대체휴일'} +} +``` ### multipleSelect @@ -237,3 +250,16 @@ myCalendar.setSelectable({ range: [{from: new Date(), to: new Date()}] }); myCalendar.setSelectable({ '2016-01-01': true, '2016-01-02': true }); ``` +- - - + +## setMarker() +`setMarker(marker[, isApply])` + +```js +myCalendar.setMarker({ + '2016-02-07': {theme: 'holiday', label: '설날'}, + '2016-02-08': {theme: 'holiday', label: '설날'}, + '2016-02-09': {theme: 'holiday', label: '설날'}, + '2016-02-10': {theme: 'holiday', label: '대체휴일'} +}); +``` \ No newline at end of file diff --git a/bower.json b/bower.json index f7ac5a5..7e28de3 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "bootstrap-ax5calendar", - "version": "0.6.0", + "version": "0.7.0", "authors": [ "ThomasJ " ], diff --git a/dist/ax5calendar.js b/dist/ax5calendar.js index 4aafbba..ddd63fc 100755 --- a/dist/ax5calendar.js +++ b/dist/ax5calendar.js @@ -875,7 +875,7 @@ } }; - return function (marker, isPrint) { + return function (marker, isApply) { var key, @@ -896,10 +896,19 @@ this.markerMap = result; // 변경내용 적용하여 출력 - if (isPrint !== false) this.changeMode(); + if (isApply !== false) this.applyMarkerMap(); }; })(); + this.applyMarkerMap = function(){ + if (cfg.mode === "day" || cfg.mode === "d") + { + for(var k in this.markerMap){ + this.$["body"].find('[data-calendar-item-date="'+k+'"]').addClass(this.markerMap[k].theme); + } + } + }; + // 클래스 생성자 this.main = (function () { if (arguments && U.isObject(arguments[0])) { diff --git a/dist/ax5calendar.min.js b/dist/ax5calendar.min.js index f0a7f50..c99f9c3 100755 --- a/dist/ax5calendar.min.js +++ b/dist/ax5calendar.min.js @@ -1 +1 @@ -!function(e,t){var a=ax5.util,n=function(){t&&t.call(this);var e,n=this,i=1;this.target=null,this.selection=[],this.selectableMap={},this.markerMap={},this.printedDay={start:"",end:""},this.config={clickEventName:"click",theme:"default",mode:"day",dateFormat:"yyyy-mm-dd",displayDate:new Date,animateTime:250,dimensions:{controlHeight:"40px",controlButtonWidth:"40px",itemPadding:2},lang:{yearHeading:"Choose the year",monthHeading:"Choose the month",yearTmpl:"%s",months:["January","February","March","April","May","June","July","August","September","October","November","December"],dayTmpl:"%s"},multipleSelect:!1,selectMode:"day"},e=this.config,this.init=function(){e.target||console.log(ax5.info.getError("ax5calendar","401","setConfig")),this.target=jQuery(e.target),e.displayDate=a.date(e.displayDate),this.target.html(this.getFrame()),this.$={root:this.target.find('[data-calendar-els="root"]'),control:this.target.find('[data-calendar-els="control"]'),"control-display":this.target.find('[data-calendar-els="control-display"]'),body:this.target.find('[data-calendar-els="body"]')},e.control&&this.$.control.find("[data-calendar-move]").on(e.clickEventName,function(e){this.move(e||window.event)}.bind(this)),e.selectable&&this.setSelectable(e.selectable,!1),e.marker&&this.setMarker(e.marker,!1),"day"===e.mode||"d"===e.mode?this.printDay(e.displayDate):"month"===e.mode||"m"===e.mode?this.printMonth(e.displayDate):("year"===e.mode||"y"===e.mode)&&this.printYear(e.displayDate)},this.getFrame=function(){var t=[];if(t.push('
'),e.control){var n={},i={};i.height=n.height=a.cssNumber(e.dimensions.controlHeight),i["line-height"]=n["line-height"]=a.cssNumber(e.dimensions.controlHeight),i.width=a.cssNumber(e.dimensions.controlHeight),t.push('
'),t.push(''+e.control.left+""),t.push('
'),t.push(''+e.control.right+""),t.push("
")}return t.push('
'),t.push("
"),t.join("")},this.setDisplay=function(){if(e.control){var t=a.date(e.displayDate),n="",i="";if("day"==e.mode||"d"==e.mode)n=e.control.yearTmpl?e.control.yearTmpl.replace("%s",t.getFullYear()):t.getFullYear(),i=e.control.monthTmpl?e.control.monthTmpl.replace("%s",e.lang.months[t.getMonth()]):e.lang.months[t.getMonth()],this.$["control-display"].html(function(){return e.control.yearFirst?''+n+''+i+"":''+i+''+n+""}());else if("month"==e.mode||"m"==e.mode)n=e.control.yearTmpl?e.control.yearTmpl.replace("%s",t.getFullYear()):t.getFullYear(),this.$["control-display"].html(''+n+"");else if("year"==e.mode||"y"==e.mode){var r=e.control.yearTmpl?e.control.yearTmpl.replace("%s",t.getFullYear()-10):t.getFullYear()-10,s=e.control.yearTmpl?e.control.yearTmpl.replace("%s",Number(t.getFullYear())+9):Number(t.getFullYear())+9;this.$["control-display"].html(r+" ~ "+s)}this.$["control-display"].find("[data-calendar-display]").on(e.clickEventName,function(e){if(target=a.findParentNode(e.target,function(e){return e.getAttribute("data-calendar-display")?!0:void 0}),target){var t=target.getAttribute("data-calendar-display");this.changeMode(t)}}.bind(this))}return this},this.printDay=function(t){var i,r,s,l,d=a.date(t),o=[],c=new Date(d.getFullYear(),d.getMonth(),1,12),h=e.displayDate,u=function(){var e=c.getDay();return 0==e&&(e=7),a.date(c,{add:{d:-e}})}(),p=d.getMonth(),m={},y=this.$.body.width(),f=Math.floor(y*(6/7));for(e.dimensions.height&&(f=a.number(e.dimensions.height)),m.height=Math.floor(f/6)-2*a.number(e.dimensions.itemPadding)+"px",m["line-height"]=m.height,m.padding=a.cssNumber(e.dimensions.itemPadding),o.push(''),o.push(""),o.push(""),l=0;7>l;)o.push('"),l++;for(o.push(""),o.push(""),o.push(""),i=u,s=0;6>s;){for(o.push(""),l=0;7>l;)r=""+a.date(i,{"return":e.dateFormat}),o.push('"),l++,i=a.date(i,{add:{d:1}});o.push(""),s++}if(o.push(""),o.push("
'),o.push(ax5.info.weekNames[l].label),o.push("
'),o.push(''+e.lang.dayTmpl.replace("%s",i.getDate())+''),o.push("
"),this.$.body.html(o.join("")),this.$.body.find("[data-calendar-item-date]").on(e.clickEventName,function(e){e=e||window.event,n.onclick(e,"date");try{e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),e.cancelBubble=!0}catch(e){}return!1}),this.printedDay={start:u,end:i},e.onStateChanged){var g={action:"printDay",printedDay:this.printedDay};e.onStateChanged.call(g,g)}this.setDisplay()},this.printMonth=function(t){var i,r,s,l,d=a.date(t),o=d.getMonth(),c=[],h={},u=this.$.body.width(),p=Math.floor(u*(6/7));for(e.dimensions.height&&(p=a.number(e.dimensions.height)),h.height=Math.floor(p/4)-2*a.number(e.dimensions.itemPadding)+"px",h["line-height"]=h.height,h.padding=a.cssNumber(e.dimensions.itemPadding),c.push(''),c.push(""),c.push(""),c.push('"),c.push(""),c.push(""),c.push(""),l=0,s=0,i=0;4>i;){for(c.push(""),r=0;3>r;)c.push('"),s++,r++;c.push(""),i++}if(c.push(""),c.push("
'+e.lang.monthHeading+"
'),c.push(''+e.lang.months[s]+""),c.push("
"),this.$.body.html(c.join("")),this.$.body.find("[data-calendar-item-month]").on(e.clickEventName,function(e){e=e||window.event,n.onclick(e,"month");try{e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),e.cancelBubble=!0}catch(e){}return!1}),this.printedDay={start:d.getFullYear()+"-"+a.setDigit(l+1,2),end:d.getFullYear()+"-"+a.setDigit(s,2)},e.onStateChanged){var m={action:"printMonth",printedDay:this.printedDay};e.onStateChanged.call(m,m)}return this.setDisplay(),this},this.printYear=function(t){var i,r,s,l,d=a.date(t),o=d.getFullYear(),c=[],h={},u=this.$.body.width(),p=Math.floor(u*(6/7));for(e.dimensions.height&&(p=a.number(e.dimensions.height)),h.height=Math.floor(p/5)-2*a.number(e.dimensions.itemPadding)+"px",h["line-height"]=h.height,h.padding=a.cssNumber(e.dimensions.itemPadding),c.push(''),c.push(""),c.push(""),c.push('"),c.push(""),c.push(""),c.push(""),l=o-10,s=o-10,i=0;5>i;){for(c.push(""),r=0;4>r;)c.push('"),s++,r++;c.push(""),i++}if(c.push(""),c.push("
'+e.lang.yearHeading+"
'),c.push(''+e.lang.yearTmpl.replace("%s",s)+""),c.push("
"),this.$.body.html(c.join("")),this.$.body.find("[data-calendar-item-year]").on(e.clickEventName,function(e){e=e||window.event,n.onclick(e,"year");try{e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),e.cancelBubble=!0}catch(e){}return!1}),this.printedDay={start:l,end:s-1},e.onStateChanged){var m={action:"printYear",printedDay:this.printedDay};e.onStateChanged.call(m,m)}return this.setDisplay(),this},this.onclick=function(t,r,s,l){if(r=r||"date",s=a.findParentNode(t.target,function(e){return e.getAttribute("data-calendar-item-"+r)?!0:void 0})){l=s.getAttribute("data-calendar-item-"+r);var d=a.date(l,{"return":e.dateFormat}),o=!0;if(i=e.multipleSelect?a.isNumber(e.multipleSelect)?e.multipleSelect:2:1,e.selectable&&(n.selectableMap[d]||(o=!1)),"date"==r){if(o){if(n.selection.length>=i){var c=n.selection.splice(0,n.selection.length-(i-1));c.forEach(function(t){n.$.body.find('[data-calendar-item-date="'+a.date(t,{"return":e.dateFormat})+'"]').removeClass("selected-day")})}jQuery(s).addClass("selected-day"),n.selection.push(l),e.onClick&&e.onClick.call({date:l,target:this.target,dateElement:s})}}else if("month"==r)if("month"==e.selectMode){if(o){if(n.selection.length>=i){var c=n.selection.splice(0,n.selection.length-(i-1));c.forEach(function(e){n.$.body.find('[data-calendar-item-month="'+a.date(e,{"return":"yyyy-mm-dd"})+'"]').removeClass("selected-month")})}jQuery(s).addClass("selected-month"),n.selection.push(l),e.onClick&&e.onClick.call({date:l,target:this.target,dateElement:s})}}else n.changeMode("day",l);else if("year"==r)if("year"==e.selectMode){if(o){if(n.selection.length>=i){var c=n.selection.splice(0,n.selection.length-(i-1));c.forEach(function(e){n.$.body.find('[data-calendar-item-year="'+a.date(e,{"return":"yyyy-mm-dd"})+'"]').removeClass("selected-year")})}jQuery(s).addClass("selected-year"),n.selection.push(l),e.onClick&&e.onClick.call({date:l,target:this.target,dateElement:s})}}else n.changeMode("month",l)}},this.move=function(t,n,i){return n=a.findParentNode(t.target,function(e){return e.getAttribute("data-calendar-move")?!0:void 0}),n&&(i=n.getAttribute("data-calendar-move"),"day"==e.mode?("left"==i?e.displayDate=a.date(e.displayDate,{add:{m:-1}}):e.displayDate=a.date(e.displayDate,{add:{m:1}}),this.printDay(e.displayDate)):"month"==e.mode?("left"==i?e.displayDate=a.date(e.displayDate,{add:{y:-1}}):e.displayDate=a.date(e.displayDate,{add:{y:1}}),this.printMonth(e.displayDate)):"year"==e.mode&&("left"==i?e.displayDate=a.date(e.displayDate,{add:{y:-10}}):e.displayDate=a.date(e.displayDate,{add:{y:10}}),this.printYear(e.displayDate))),this},this.changeMode=function(t,a){return"undefined"!=typeof a&&(e.displayDate=a),t&&(e.mode=t),this.$.body.removeClass("fadein").addClass("fadeout"),setTimeout(function(){"day"==e.mode||"d"==e.mode?this.printDay(e.displayDate):"month"==e.mode||"m"==e.mode?this.printMonth(e.displayDate):("year"==e.mode||"y"==e.mode)&&this.printYear(e.displayDate),this.$.body.removeClass("fadeout").addClass("fadein")}.bind(this),e.animateTime),this},this.setDisplayDate=function(t){return e.displayDate=a.date(t),this.$.body.removeClass("fadein").addClass("fadeout"),setTimeout(function(){"day"==e.mode||"d"==e.mode?this.printDay(e.displayDate):"month"==e.mode||"m"==e.mode?this.printMonth(e.displayDate):("year"==e.mode||"y"==e.mode)&&this.printYear(e.displayDate),this.$.body.removeClass("fadeout").addClass("fadein")}.bind(this),e.animateTime),this},this.setSelection=function(t){return a.isArray(t)?(i=e.multipleSelect?a.isNumber(e.multipleSelect)?e.multipleSelect:2:1,this.selection=t.splice(0,i),this.selection.forEach(function(t){n.$.body.find('[data-calendar-item-date="'+a.date(t,{"return":e.dateFormat})+'"]').addClass("selected-day")}),this):this},this.getSelection=function(){return this.selection},this.setSelectable=function(){this.selectableMap={};var t={arr:function(t,n){return n={},a.isArray(t)?(t.forEach(function(t){a.isDate(t)&&(t=a.date(t,{"return":e.dateFormat})),n[t]=!0}),n):n},obj:function(e,t){if(t={},a.isArray(e))return t;if(e.range)return t;for(var n in e)t[n]=e[n];return t},range:function(t,n){return n={},a.isArray(t)?n:t.range?(t.range.forEach(function(t){if(a.isDateFormat(t.from)&&a.isDateFormat(t.to))for(var i=a.date(t.from);i<=a.date(t.to);i.setDate(i.getDate()+1))n[a.date(i,{"return":e.dateFormat})]=!0;else for(var r=t.from;r<=t.to;r++)n[r]=!0}),n):n}};return function(n,i){var r,s={};if(e.selectable=n)if(a.isArray(n))s=t.arr(n);else{for(r in t)if(n[r]){s=t[r](n);break}0===Object.keys(s).length&&(s=t.obj(n))}this.selectableMap=s,i!==!1&&this.changeMode()}}(),this.setMarker=function(){this.markerMap={};var t={obj:function(e,t){if(t={},a.isArray(e))return t;if(e.range)return t;for(var n in e)t[n]=e[n];return t},range:function(t,n){return n={},a.isArray(t)?n:t.range?(t.range.forEach(function(t){if(a.isDateFormat(t.from)&&a.isDateFormat(t.to))for(var i=a.date(t.from);i<=a.date(t.to);i.setDate(i.getDate()+1))n[a.date(i,{"return":e.dateFormat})]={theme:t.theme,label:t.label};else for(var r=t.from;r<=t.to;r++)n[r]={theme:t.theme,label:t.label}}),n):n}};return function(a,n){var i,r={};if(e.marker=a){for(i in t)if(a[i]){r=t[i](a);break}0===Object.keys(r).length&&(r=t.obj(a))}this.markerMap=r,n!==!1&&this.changeMode()}}(),this.main=function(){arguments&&a.isObject(arguments[0])&&this.setConfig(arguments[0])}.apply(this,arguments)};e.calendar=function(){return a.isFunction(t)&&(n.prototype=new t),n}()}(ax5.ui,ax5.ui.root); \ No newline at end of file +!function(e,t){var a=ax5.util,n=function(){t&&t.call(this);var e,n=this,i=1;this.target=null,this.selection=[],this.selectableMap={},this.markerMap={},this.printedDay={start:"",end:""},this.config={clickEventName:"click",theme:"default",mode:"day",dateFormat:"yyyy-mm-dd",displayDate:new Date,animateTime:250,dimensions:{controlHeight:"40px",controlButtonWidth:"40px",itemPadding:2},lang:{yearHeading:"Choose the year",monthHeading:"Choose the month",yearTmpl:"%s",months:["January","February","March","April","May","June","July","August","September","October","November","December"],dayTmpl:"%s"},multipleSelect:!1,selectMode:"day"},e=this.config,this.init=function(){e.target||console.log(ax5.info.getError("ax5calendar","401","setConfig")),this.target=jQuery(e.target),e.displayDate=a.date(e.displayDate),this.target.html(this.getFrame()),this.$={root:this.target.find('[data-calendar-els="root"]'),control:this.target.find('[data-calendar-els="control"]'),"control-display":this.target.find('[data-calendar-els="control-display"]'),body:this.target.find('[data-calendar-els="body"]')},e.control&&this.$.control.find("[data-calendar-move]").on(e.clickEventName,function(e){this.move(e||window.event)}.bind(this)),e.selectable&&this.setSelectable(e.selectable,!1),e.marker&&this.setMarker(e.marker,!1),"day"===e.mode||"d"===e.mode?this.printDay(e.displayDate):"month"===e.mode||"m"===e.mode?this.printMonth(e.displayDate):("year"===e.mode||"y"===e.mode)&&this.printYear(e.displayDate)},this.getFrame=function(){var t=[];if(t.push('
'),e.control){var n={},i={};i.height=n.height=a.cssNumber(e.dimensions.controlHeight),i["line-height"]=n["line-height"]=a.cssNumber(e.dimensions.controlHeight),i.width=a.cssNumber(e.dimensions.controlHeight),t.push('
'),t.push(''+e.control.left+""),t.push('
'),t.push(''+e.control.right+""),t.push("
")}return t.push('
'),t.push("
"),t.join("")},this.setDisplay=function(){if(e.control){var t=a.date(e.displayDate),n="",i="";if("day"==e.mode||"d"==e.mode)n=e.control.yearTmpl?e.control.yearTmpl.replace("%s",t.getFullYear()):t.getFullYear(),i=e.control.monthTmpl?e.control.monthTmpl.replace("%s",e.lang.months[t.getMonth()]):e.lang.months[t.getMonth()],this.$["control-display"].html(function(){return e.control.yearFirst?''+n+''+i+"":''+i+''+n+""}());else if("month"==e.mode||"m"==e.mode)n=e.control.yearTmpl?e.control.yearTmpl.replace("%s",t.getFullYear()):t.getFullYear(),this.$["control-display"].html(''+n+"");else if("year"==e.mode||"y"==e.mode){var r=e.control.yearTmpl?e.control.yearTmpl.replace("%s",t.getFullYear()-10):t.getFullYear()-10,s=e.control.yearTmpl?e.control.yearTmpl.replace("%s",Number(t.getFullYear())+9):Number(t.getFullYear())+9;this.$["control-display"].html(r+" ~ "+s)}this.$["control-display"].find("[data-calendar-display]").on(e.clickEventName,function(e){if(target=a.findParentNode(e.target,function(e){return e.getAttribute("data-calendar-display")?!0:void 0}),target){var t=target.getAttribute("data-calendar-display");this.changeMode(t)}}.bind(this))}return this},this.printDay=function(t){var i,r,s,l,d=a.date(t),o=[],c=new Date(d.getFullYear(),d.getMonth(),1,12),h=e.displayDate,p=function(){var e=c.getDay();return 0==e&&(e=7),a.date(c,{add:{d:-e}})}(),u=d.getMonth(),m={},y=this.$.body.width(),f=Math.floor(y*(6/7));for(e.dimensions.height&&(f=a.number(e.dimensions.height)),m.height=Math.floor(f/6)-2*a.number(e.dimensions.itemPadding)+"px",m["line-height"]=m.height,m.padding=a.cssNumber(e.dimensions.itemPadding),o.push(''),o.push(""),o.push(""),l=0;7>l;)o.push('"),l++;for(o.push(""),o.push(""),o.push(""),i=p,s=0;6>s;){for(o.push(""),l=0;7>l;)r=""+a.date(i,{"return":e.dateFormat}),o.push('"),l++,i=a.date(i,{add:{d:1}});o.push(""),s++}if(o.push(""),o.push("
'),o.push(ax5.info.weekNames[l].label),o.push("
'),o.push(''+e.lang.dayTmpl.replace("%s",i.getDate())+''),o.push("
"),this.$.body.html(o.join("")),this.$.body.find("[data-calendar-item-date]").on(e.clickEventName,function(e){e=e||window.event,n.onclick(e,"date");try{e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),e.cancelBubble=!0}catch(e){}return!1}),this.printedDay={start:p,end:i},e.onStateChanged){var g={action:"printDay",printedDay:this.printedDay};e.onStateChanged.call(g,g)}this.setDisplay()},this.printMonth=function(t){var i,r,s,l,d=a.date(t),o=d.getMonth(),c=[],h={},p=this.$.body.width(),u=Math.floor(p*(6/7));for(e.dimensions.height&&(u=a.number(e.dimensions.height)),h.height=Math.floor(u/4)-2*a.number(e.dimensions.itemPadding)+"px",h["line-height"]=h.height,h.padding=a.cssNumber(e.dimensions.itemPadding),c.push(''),c.push(""),c.push(""),c.push('"),c.push(""),c.push(""),c.push(""),l=0,s=0,i=0;4>i;){for(c.push(""),r=0;3>r;)c.push('"),s++,r++;c.push(""),i++}if(c.push(""),c.push("
'+e.lang.monthHeading+"
'),c.push(''+e.lang.months[s]+""),c.push("
"),this.$.body.html(c.join("")),this.$.body.find("[data-calendar-item-month]").on(e.clickEventName,function(e){e=e||window.event,n.onclick(e,"month");try{e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),e.cancelBubble=!0}catch(e){}return!1}),this.printedDay={start:d.getFullYear()+"-"+a.setDigit(l+1,2),end:d.getFullYear()+"-"+a.setDigit(s,2)},e.onStateChanged){var m={action:"printMonth",printedDay:this.printedDay};e.onStateChanged.call(m,m)}return this.setDisplay(),this},this.printYear=function(t){var i,r,s,l,d=a.date(t),o=d.getFullYear(),c=[],h={},p=this.$.body.width(),u=Math.floor(p*(6/7));for(e.dimensions.height&&(u=a.number(e.dimensions.height)),h.height=Math.floor(u/5)-2*a.number(e.dimensions.itemPadding)+"px",h["line-height"]=h.height,h.padding=a.cssNumber(e.dimensions.itemPadding),c.push(''),c.push(""),c.push(""),c.push('"),c.push(""),c.push(""),c.push(""),l=o-10,s=o-10,i=0;5>i;){for(c.push(""),r=0;4>r;)c.push('"),s++,r++;c.push(""),i++}if(c.push(""),c.push("
'+e.lang.yearHeading+"
'),c.push(''+e.lang.yearTmpl.replace("%s",s)+""),c.push("
"),this.$.body.html(c.join("")),this.$.body.find("[data-calendar-item-year]").on(e.clickEventName,function(e){e=e||window.event,n.onclick(e,"year");try{e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),e.cancelBubble=!0}catch(e){}return!1}),this.printedDay={start:l,end:s-1},e.onStateChanged){var m={action:"printYear",printedDay:this.printedDay};e.onStateChanged.call(m,m)}return this.setDisplay(),this},this.onclick=function(t,r,s,l){if(r=r||"date",s=a.findParentNode(t.target,function(e){return e.getAttribute("data-calendar-item-"+r)?!0:void 0})){l=s.getAttribute("data-calendar-item-"+r);var d=a.date(l,{"return":e.dateFormat}),o=!0;if(i=e.multipleSelect?a.isNumber(e.multipleSelect)?e.multipleSelect:2:1,e.selectable&&(n.selectableMap[d]||(o=!1)),"date"==r){if(o){if(n.selection.length>=i){var c=n.selection.splice(0,n.selection.length-(i-1));c.forEach(function(t){n.$.body.find('[data-calendar-item-date="'+a.date(t,{"return":e.dateFormat})+'"]').removeClass("selected-day")})}jQuery(s).addClass("selected-day"),n.selection.push(l),e.onClick&&e.onClick.call({date:l,target:this.target,dateElement:s})}}else if("month"==r)if("month"==e.selectMode){if(o){if(n.selection.length>=i){var c=n.selection.splice(0,n.selection.length-(i-1));c.forEach(function(e){n.$.body.find('[data-calendar-item-month="'+a.date(e,{"return":"yyyy-mm-dd"})+'"]').removeClass("selected-month")})}jQuery(s).addClass("selected-month"),n.selection.push(l),e.onClick&&e.onClick.call({date:l,target:this.target,dateElement:s})}}else n.changeMode("day",l);else if("year"==r)if("year"==e.selectMode){if(o){if(n.selection.length>=i){var c=n.selection.splice(0,n.selection.length-(i-1));c.forEach(function(e){n.$.body.find('[data-calendar-item-year="'+a.date(e,{"return":"yyyy-mm-dd"})+'"]').removeClass("selected-year")})}jQuery(s).addClass("selected-year"),n.selection.push(l),e.onClick&&e.onClick.call({date:l,target:this.target,dateElement:s})}}else n.changeMode("month",l)}},this.move=function(t,n,i){return n=a.findParentNode(t.target,function(e){return e.getAttribute("data-calendar-move")?!0:void 0}),n&&(i=n.getAttribute("data-calendar-move"),"day"==e.mode?("left"==i?e.displayDate=a.date(e.displayDate,{add:{m:-1}}):e.displayDate=a.date(e.displayDate,{add:{m:1}}),this.printDay(e.displayDate)):"month"==e.mode?("left"==i?e.displayDate=a.date(e.displayDate,{add:{y:-1}}):e.displayDate=a.date(e.displayDate,{add:{y:1}}),this.printMonth(e.displayDate)):"year"==e.mode&&("left"==i?e.displayDate=a.date(e.displayDate,{add:{y:-10}}):e.displayDate=a.date(e.displayDate,{add:{y:10}}),this.printYear(e.displayDate))),this},this.changeMode=function(t,a){return"undefined"!=typeof a&&(e.displayDate=a),t&&(e.mode=t),this.$.body.removeClass("fadein").addClass("fadeout"),setTimeout(function(){"day"==e.mode||"d"==e.mode?this.printDay(e.displayDate):"month"==e.mode||"m"==e.mode?this.printMonth(e.displayDate):("year"==e.mode||"y"==e.mode)&&this.printYear(e.displayDate),this.$.body.removeClass("fadeout").addClass("fadein")}.bind(this),e.animateTime),this},this.setDisplayDate=function(t){return e.displayDate=a.date(t),this.$.body.removeClass("fadein").addClass("fadeout"),setTimeout(function(){"day"==e.mode||"d"==e.mode?this.printDay(e.displayDate):"month"==e.mode||"m"==e.mode?this.printMonth(e.displayDate):("year"==e.mode||"y"==e.mode)&&this.printYear(e.displayDate),this.$.body.removeClass("fadeout").addClass("fadein")}.bind(this),e.animateTime),this},this.setSelection=function(t){return a.isArray(t)?(i=e.multipleSelect?a.isNumber(e.multipleSelect)?e.multipleSelect:2:1,this.selection=t.splice(0,i),this.selection.forEach(function(t){n.$.body.find('[data-calendar-item-date="'+a.date(t,{"return":e.dateFormat})+'"]').addClass("selected-day")}),this):this},this.getSelection=function(){return this.selection},this.setSelectable=function(){this.selectableMap={};var t={arr:function(t,n){return n={},a.isArray(t)?(t.forEach(function(t){a.isDate(t)&&(t=a.date(t,{"return":e.dateFormat})),n[t]=!0}),n):n},obj:function(e,t){if(t={},a.isArray(e))return t;if(e.range)return t;for(var n in e)t[n]=e[n];return t},range:function(t,n){return n={},a.isArray(t)?n:t.range?(t.range.forEach(function(t){if(a.isDateFormat(t.from)&&a.isDateFormat(t.to))for(var i=a.date(t.from);i<=a.date(t.to);i.setDate(i.getDate()+1))n[a.date(i,{"return":e.dateFormat})]=!0;else for(var r=t.from;r<=t.to;r++)n[r]=!0}),n):n}};return function(n,i){var r,s={};if(e.selectable=n)if(a.isArray(n))s=t.arr(n);else{for(r in t)if(n[r]){s=t[r](n);break}0===Object.keys(s).length&&(s=t.obj(n))}this.selectableMap=s,i!==!1&&this.changeMode()}}(),this.setMarker=function(){this.markerMap={};var t={obj:function(e,t){if(t={},a.isArray(e))return t;if(e.range)return t;for(var n in e)t[n]=e[n];return t},range:function(t,n){return n={},a.isArray(t)?n:t.range?(t.range.forEach(function(t){if(a.isDateFormat(t.from)&&a.isDateFormat(t.to))for(var i=a.date(t.from);i<=a.date(t.to);i.setDate(i.getDate()+1))n[a.date(i,{"return":e.dateFormat})]={theme:t.theme,label:t.label};else for(var r=t.from;r<=t.to;r++)n[r]={theme:t.theme,label:t.label}}),n):n}};return function(a,n){var i,r={};if(e.marker=a){for(i in t)if(a[i]){r=t[i](a);break}0===Object.keys(r).length&&(r=t.obj(a))}this.markerMap=r,n!==!1&&this.applyMarkerMap()}}(),this.applyMarkerMap=function(){if("day"===e.mode||"d"===e.mode)for(var t in this.markerMap)this.$.body.find('[data-calendar-item-date="'+t+'"]').addClass(this.markerMap[t].theme)},this.main=function(){arguments&&a.isObject(arguments[0])&&this.setConfig(arguments[0])}.apply(this,arguments)};e.calendar=function(){return a.isFunction(t)&&(n.prototype=new t),n}()}(ax5.ui,ax5.ui.root); \ No newline at end of file diff --git a/package.json b/package.json index fa7f670..c07684f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bootstrap-ax5calendar", - "version": "0.6.0", + "version": "0.7.0", "description": "A calendar plugin that works with Bootstrap & jQuery", "license": "MIT", "repository": { diff --git a/src/ax5calendar.js b/src/ax5calendar.js index 4aafbba..ddd63fc 100755 --- a/src/ax5calendar.js +++ b/src/ax5calendar.js @@ -875,7 +875,7 @@ } }; - return function (marker, isPrint) { + return function (marker, isApply) { var key, @@ -896,10 +896,19 @@ this.markerMap = result; // 변경내용 적용하여 출력 - if (isPrint !== false) this.changeMode(); + if (isApply !== false) this.applyMarkerMap(); }; })(); + this.applyMarkerMap = function(){ + if (cfg.mode === "day" || cfg.mode === "d") + { + for(var k in this.markerMap){ + this.$["body"].find('[data-calendar-item-date="'+k+'"]').addClass(this.markerMap[k].theme); + } + } + }; + // 클래스 생성자 this.main = (function () { if (arguments && U.isObject(arguments[0])) { diff --git a/test/index.html b/test/index.html index 2ceba79..c8fd95f 100644 --- a/test/index.html +++ b/test/index.html @@ -64,13 +64,14 @@ selectMode: "day", // selectable: {range:[{from: '2016-02-01', to: '2016-02-20'}]}, - + /* marker: { '2016-02-07': {theme: 'holiday', label: '설날'}, '2016-02-08': {theme: 'holiday', label: '설날'}, '2016-02-09': {theme: 'holiday', label: '설날'}, '2016-02-10': {theme: 'holiday', label: '대체휴일'} }, + */ onClick: function () { console.log(myCalendar.getSelection()); }, @@ -81,7 +82,14 @@ }); /// todo : 공휴일 표시에 대한 대안 필요. - myCalendar.setSelection(['2016-02-11', '2016-02-12', '2016-02-13']); + // myCalendar.setSelection(['2016-02-11', '2016-02-12', '2016-02-13']); + + myCalendar.setMarker({ + '2016-02-07': {theme: 'holiday', label: '설날'}, + '2016-02-08': {theme: 'holiday', label: '설날'}, + '2016-02-09': {theme: 'holiday', label: '설날'}, + '2016-02-10': {theme: 'holiday', label: '대체휴일'} + }); });