diff --git a/API.md b/API.md index a2df723..b6feec1 100644 --- a/API.md +++ b/API.md @@ -2,4 +2,6 @@ > calendar ## setConfig() -`setConfig([options])` \ No newline at end of file +`setConfig([options])` + +**Easy Way - without setConfig** \ No newline at end of file diff --git a/README.md b/README.md index 9aadec3..2268d38 100755 --- a/README.md +++ b/README.md @@ -32,10 +32,12 @@ exactly the path. ```html - + - + .... @@ -45,8 +47,7 @@ exactly the path. ### Basic Usages ```js -var myCalendar = new ax5.ui.calendar(); -myCalendar.setConfig({ +var myCalendar = new ax5.ui.calendar({ target: document.getElementById("calendar-target"), displayDate: (new Date()), onClick: function () { diff --git a/bower.json b/bower.json index ddf568e..134a518 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "bootstrap-ax5calendar", - "version": "0.2.0", + "version": "0.3.0", "authors": [ "ThomasJ " ], diff --git a/dist/ax5calendar.js b/dist/ax5calendar.js index 0dc3a65..8901f9a 100755 --- a/dist/ax5calendar.js +++ b/dist/ax5calendar.js @@ -16,46 +16,42 @@ //== UI Class var axClass = function () { + if (_SUPER_) _SUPER_.call(this); // 부모호출 + var self = this, cfg, aDay = 1000 * 60 * 60 * 24, selectableCount = 1 ; - - // 클래스 생성자 - this.main = (function () { - if (_SUPER_) _SUPER_.call(this); // 부모호출 - this.config = { - clickEventName: "click", - theme: 'default', - mode: 'day', // day|month|year, - 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", - year: "%s", - month: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], - day: "%s" - }, - multipleSelect: false - }; - }).apply(this, arguments); - + this.target = null; this.selection = []; - cfg = this.config; - this.printedDay = { start: "", end: "" }; + this.config = { + clickEventName: "click", + theme: 'default', + mode: 'day', // day|month|year, + 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", + year: "%s", + month: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], + day: "%s" + }, + multipleSelect: false + }; + cfg = this.config; /** * Preferences of calendar UI @@ -74,8 +70,7 @@ //== class body start this.init = function () { // after setConfig(); - if (!cfg.target) - { + if (!cfg.target) { console.log(ax5.info.getError("ax5calendar", "401", "setConfig")); } this.target = jQuery(cfg.target); @@ -624,7 +619,7 @@ selectableCount = (cfg.multipleSelect) ? (U.isNumber(cfg.multipleSelect)) ? cfg.multipleSelect : 2 : 1; this.selection = selection.splice(0, selectableCount); this.selection.forEach(function (d) { - self.$["body"].find('[data-calendar-item-date="' + U.date(d, {"return": cfg.dateFormat}) + '"]').addClass("selected"); + self.$["body"].find('[data-calendar-item-date="' + U.date(d, {"return": cfg.dateFormat}) + '"]').addClass("selected-day"); }); return this; @@ -636,12 +631,20 @@ this.getSelection = function () { return this.selection; }; + + // 클래스 생성자 + this.main = (function () { + if(arguments && U.isObject(arguments[0])) { + this.setConfig(arguments[0]); + } + }).apply(this, arguments); }; //== UI Class - + + //== ui class 공통 처리 구문 if (U.isFunction(_SUPER_)) axClass.prototype = new _SUPER_(); // 상속 root.calendar = axClass; // ax5.ui에 연결 //== ui class 공통 처리 구문 - + })(ax5.ui, ax5.ui.root); \ No newline at end of file diff --git a/dist/ax5calendar.min.js b/dist/ax5calendar.min.js index 2b5d651..30266fd 100755 --- a/dist/ax5calendar.min.js +++ b/dist/ax5calendar.min.js @@ -1 +1 @@ -!function(t,e){var a=ax5.util,n=function(){var t,n=this,i=1;this.main=function(){e&&e.call(this),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",year:"%s",month:["January","February","March","April","May","June","July","August","September","October","November","December"],day:"%s"},multipleSelect:!1}}.apply(this,arguments),this.target=null,this.selection=[],t=this.config,this.printedDay={start:"",end:""},this.init=function(){t.target||console.log(ax5.info.getError("ax5calendar","401","setConfig")),this.target=jQuery(t.target),t.displayDate=a.date(t.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"]')},t.control&&this.$.control.find("[data-calendar-move]").on(t.clickEventName,function(t){this.move(t||window.event)}.bind(this)),"day"===t.mode||"d"===t.mode?this.printDay(t.displayDate):"month"===t.mode||"m"===t.mode?this.printMonth(t.displayDate):("year"===t.mode||"y"===t.mode)&&this.printYear(t.displayDate)},this.getFrame=function(){var e=[];if(e.push('
'),t.control){var n={},i={};i.height=n.height=a.cssNumber(t.dimensions.controlHeight),i["line-height"]=n["line-height"]=a.cssNumber(t.dimensions.controlHeight),i.width=a.cssNumber(t.dimensions.controlHeight),e.push('
'),e.push(''+t.control.left+""),e.push('
'),e.push(''+t.control.right+""),e.push("
")}return e.push('
'),e.push("
"),e.join("")},this.setDisplay=function(){if(t.control){var e=a.date(t.displayDate),n="",i="";if("day"==t.mode||"d"==t.mode)t.control.yearTmpl&&(n=t.control.yearTmpl.replace("%s",e.getFullYear())),t.control.monthTmpl&&(i=t.control.monthTmpl.replace("%s",t.lang.month[e.getMonth()])),this.$["control-display"].html(function(){return t.control.yearFirst?''+n+''+i+"":''+i+''+n+""}());else if("month"==t.mode||"m"==t.mode)t.control.yearTmpl&&(n=t.control.yearTmpl.replace("%s",e.getFullYear())),this.$["control-display"].html(''+n+"");else if("year"==t.mode||"y"==t.mode){var d=t.control.yearTmpl.replace("%s",e.getFullYear()-10),s=t.control.yearTmpl.replace("%s",Number(e.getFullYear())+9);this.$["control-display"].html(d+" ~ "+s)}this.$["control-display"].find("[data-calendar-display]").on(t.clickEventName,function(t){if(target=a.findParentNode(t.target,function(t){return t.getAttribute("data-calendar-display")?!0:void 0}),target){var e=target.getAttribute("data-calendar-display");this.changeMode(e)}}.bind(this))}},this.printDay=function(e){var i,d,s,l=a.date(e),r=[],o=new Date(l.getFullYear(),l.getMonth(),1,12),h=t.displayDate,c=function(){var t=o.getDay();return 0==t&&(t=7),a.date(o,{add:{d:-t}})}(),p=l.getMonth(),u=(l.getDate(),{}),m=this.$.body.width(),y=Math.floor(m*(6/7));for(t.dimensions.height&&(y=a.number(t.dimensions.height)),u.height=Math.floor(y/6)-2*a.number(t.dimensions.itemPadding)+"px",u["line-height"]=u.height,u.padding=a.cssNumber(t.dimensions.itemPadding),r.push(''),r.push(""),r.push(""),s=0;7>s;)r.push('"),s++;for(r.push(""),r.push(""),r.push(""),i=c,d=0;6>d;){for(r.push(""),s=0;7>s;)r.push('"),s++,i=a.date(i,{add:{d:1}});r.push(""),d++}if(r.push(""),r.push("
'),r.push(ax5.info.weekNames[s].label),r.push("
'),r.push(''+t.lang.day.replace("%s",i.getDate())+''),r.push("
"),this.$.body.html(r.join("")),this.$.body.find("[data-calendar-item-date]").on(t.clickEventName,function(t){t=t||window.event,n.onclick(t);try{t.preventDefault&&t.preventDefault(),t.stopPropagation&&t.stopPropagation(),t.cancelBubble=!0}catch(t){}return!1}),this.printedDay={start:c,end:i},t.onStateChanged){var g={action:"printDay",printedDay:this.printedDay};t.onStateChanged.call(g,g)}this.setDisplay()},this.printMonth=function(e){var i,d,s,l=a.date(e),r=l.getMonth(),o=[],h={},c=this.$.body.width(),p=Math.floor(c*(6/7));for(t.dimensions.height&&(p=a.number(t.dimensions.height)),h.height=Math.floor(p/4)-2*a.number(t.dimensions.itemPadding)+"px",h["line-height"]=h.height,h.padding=a.cssNumber(t.dimensions.itemPadding),o.push(''),o.push(""),o.push(""),o.push('"),o.push(""),o.push(""),o.push(""),s=0,i=0;4>i;){for(o.push(""),d=0;3>d;)o.push('"),s++,d++;o.push(""),i++}o.push(""),o.push("
'+t.lang.monthHeading+"
'),o.push(''+t.lang.month[s]+""),o.push("
"),this.$.body.html(o.join("")),this.$.body.find("[data-calendar-item-month]").on(t.clickEventName,function(t){if(t=t||window.event,target=a.findParentNode(t.target,function(t){return t.getAttribute("data-calendar-item-month")?!0:void 0}),target){value=target.getAttribute("data-calendar-item-month"),n.changeMode("day",value);try{t.preventDefault&&t.preventDefault(),t.stopPropagation&&t.stopPropagation(),t.cancelBubble=!0}catch(t){}return!1}}),this.setDisplay()},this.printYear=function(e){var i,d,s=a.date(e),l=s.getFullYear(),r=[],o={},h=this.$.body.width(),c=Math.floor(h*(6/7));for(t.dimensions.height&&(c=a.number(t.dimensions.height)),o.height=Math.floor(c/5)-2*a.number(t.dimensions.itemPadding)+"px",o["line-height"]=o.height,o.padding=a.cssNumber(t.dimensions.itemPadding),r.push(''),r.push(""),r.push(""),r.push('"),r.push(""),r.push(""),r.push(""),y=l-10,i=0;5>i;){for(r.push(""),d=0;4>d;)r.push('"),y++,d++;r.push(""),i++}r.push(""),r.push("
'+t.lang.yearHeading+"
'),r.push(''+t.lang.year.replace("%s",y)+""),r.push("
"),this.$.body.html(r.join("")),this.$.body.find("[data-calendar-item-year]").on(t.clickEventName,function(t){if(t=t||window.event,target=a.findParentNode(t.target,function(t){return t.getAttribute("data-calendar-item-year")?!0:void 0}),target){value=target.getAttribute("data-calendar-item-year"),n.changeMode("month",value);try{t.preventDefault&&t.preventDefault(),t.stopPropagation&&t.stopPropagation(),t.cancelBubble=!0}catch(t){}return!1}}),this.setDisplay()},this.onclick=function(e,d,s){if(d=a.findParentNode(e.target,function(t){return t.getAttribute("data-calendar-item-date")?!0:void 0})){s=d.getAttribute("data-calendar-item-date");var l=a.date(s,{"return":t.dateFormat}),r=!0;if(t.selectable&&(t.selectable[l]||(r=!1)),r){if(i=t.multipleSelect?a.isNumber(t.multipleSelect)?t.multipleSelect:2:1,console.log(i),n.selection.length>=i){var o=n.selection.splice(0,n.selection.length-(i-1));o.forEach(function(e){n.$.body.find('[data-calendar-item-date="'+a.date(e,{"return":t.dateFormat})+'"]').removeClass("selected-day")})}jQuery(d).addClass("selected-day"),n.selection.push(s),t.onClick&&t.onClick.call({date:s,target:this.target,dateElement:d})}}},this.move=function(e,n,i){n=a.findParentNode(e.target,function(t){return t.getAttribute("data-calendar-move")?!0:void 0}),n&&(i=n.getAttribute("data-calendar-move"),"day"==t.mode?("left"==i?t.displayDate=a.date(t.displayDate,{add:{m:-1}}):t.displayDate=a.date(t.displayDate,{add:{m:1}}),this.printDay(t.displayDate)):"month"==t.mode?("left"==i?t.displayDate=a.date(t.displayDate,{add:{y:-1}}):t.displayDate=a.date(t.displayDate,{add:{y:1}}),this.printMonth(t.displayDate)):"year"==t.mode&&("left"==i?t.displayDate=a.date(t.displayDate,{add:{y:-10}}):t.displayDate=a.date(t.displayDate,{add:{y:10}}),this.printYear(t.displayDate)))},this.changeMode=function(e,a){"undefined"!=typeof a&&(t.displayDate=a),t.mode=e,this.$.body.removeClass("fadein").addClass("fadeout"),setTimeout(function(){"day"==t.mode?this.printDay(t.displayDate):"month"==t.mode?this.printMonth(t.displayDate):"year"==t.mode&&this.printYear(t.displayDate),this.$.body.removeClass("fadeout").addClass("fadein")}.bind(this),t.animateTime)},this.setDisplayDate=function(e){t.displayDate=a.date(e),this.$.body.removeClass("fadein").addClass("fadeout"),setTimeout(function(){"day"==t.mode?this.printDay(t.displayDate):"month"==t.mode?this.printMonth(t.displayDate):"year"==t.mode&&this.printYear(t.displayDate),this.$.body.removeClass("fadeout").addClass("fadein")}.bind(this),t.animateTime)},this.setSelection=function(e){return a.isArray(e)?(i=t.multipleSelect?a.isNumber(t.multipleSelect)?t.multipleSelect:2:1,this.selection=e.splice(0,i),this.selection.forEach(function(e){n.$.body.find('[data-calendar-item-date="'+a.date(e,{"return":t.dateFormat})+'"]').addClass("selected")}),this):this},this.getSelection=function(){return this.selection}};a.isFunction(e)&&(n.prototype=new e),t.calendar=n}(ax5.ui,ax5.ui.root); \ No newline at end of file +!function(t,e){var a=ax5.util,n=function(){e&&e.call(this);var t,n=this,i=1;this.target=null,this.selection=[],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",year:"%s",month:["January","February","March","April","May","June","July","August","September","October","November","December"],day:"%s"},multipleSelect:!1},t=this.config,this.init=function(){t.target||console.log(ax5.info.getError("ax5calendar","401","setConfig")),this.target=jQuery(t.target),t.displayDate=a.date(t.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"]')},t.control&&this.$.control.find("[data-calendar-move]").on(t.clickEventName,function(t){this.move(t||window.event)}.bind(this)),"day"===t.mode||"d"===t.mode?this.printDay(t.displayDate):"month"===t.mode||"m"===t.mode?this.printMonth(t.displayDate):("year"===t.mode||"y"===t.mode)&&this.printYear(t.displayDate)},this.getFrame=function(){var e=[];if(e.push('
'),t.control){var n={},i={};i.height=n.height=a.cssNumber(t.dimensions.controlHeight),i["line-height"]=n["line-height"]=a.cssNumber(t.dimensions.controlHeight),i.width=a.cssNumber(t.dimensions.controlHeight),e.push('
'),e.push(''+t.control.left+""),e.push('
'),e.push(''+t.control.right+""),e.push("
")}return e.push('
'),e.push("
"),e.join("")},this.setDisplay=function(){if(t.control){var e=a.date(t.displayDate),n="",i="";if("day"==t.mode||"d"==t.mode)t.control.yearTmpl&&(n=t.control.yearTmpl.replace("%s",e.getFullYear())),t.control.monthTmpl&&(i=t.control.monthTmpl.replace("%s",t.lang.month[e.getMonth()])),this.$["control-display"].html(function(){return t.control.yearFirst?''+n+''+i+"":''+i+''+n+""}());else if("month"==t.mode||"m"==t.mode)t.control.yearTmpl&&(n=t.control.yearTmpl.replace("%s",e.getFullYear())),this.$["control-display"].html(''+n+"");else if("year"==t.mode||"y"==t.mode){var d=t.control.yearTmpl.replace("%s",e.getFullYear()-10),s=t.control.yearTmpl.replace("%s",Number(e.getFullYear())+9);this.$["control-display"].html(d+" ~ "+s)}this.$["control-display"].find("[data-calendar-display]").on(t.clickEventName,function(t){if(target=a.findParentNode(t.target,function(t){return t.getAttribute("data-calendar-display")?!0:void 0}),target){var e=target.getAttribute("data-calendar-display");this.changeMode(e)}}.bind(this))}},this.printDay=function(e){var i,d,s,l=a.date(e),r=[],o=new Date(l.getFullYear(),l.getMonth(),1,12),h=t.displayDate,c=function(){var t=o.getDay();return 0==t&&(t=7),a.date(o,{add:{d:-t}})}(),p=l.getMonth(),u=(l.getDate(),{}),m=this.$.body.width(),y=Math.floor(m*(6/7));for(t.dimensions.height&&(y=a.number(t.dimensions.height)),u.height=Math.floor(y/6)-2*a.number(t.dimensions.itemPadding)+"px",u["line-height"]=u.height,u.padding=a.cssNumber(t.dimensions.itemPadding),r.push(''),r.push(""),r.push(""),s=0;7>s;)r.push('"),s++;for(r.push(""),r.push(""),r.push(""),i=c,d=0;6>d;){for(r.push(""),s=0;7>s;)r.push('"),s++,i=a.date(i,{add:{d:1}});r.push(""),d++}if(r.push(""),r.push("
'),r.push(ax5.info.weekNames[s].label),r.push("
'),r.push(''+t.lang.day.replace("%s",i.getDate())+''),r.push("
"),this.$.body.html(r.join("")),this.$.body.find("[data-calendar-item-date]").on(t.clickEventName,function(t){t=t||window.event,n.onclick(t);try{t.preventDefault&&t.preventDefault(),t.stopPropagation&&t.stopPropagation(),t.cancelBubble=!0}catch(t){}return!1}),this.printedDay={start:c,end:i},t.onStateChanged){var g={action:"printDay",printedDay:this.printedDay};t.onStateChanged.call(g,g)}this.setDisplay()},this.printMonth=function(e){var i,d,s,l=a.date(e),r=l.getMonth(),o=[],h={},c=this.$.body.width(),p=Math.floor(c*(6/7));for(t.dimensions.height&&(p=a.number(t.dimensions.height)),h.height=Math.floor(p/4)-2*a.number(t.dimensions.itemPadding)+"px",h["line-height"]=h.height,h.padding=a.cssNumber(t.dimensions.itemPadding),o.push(''),o.push(""),o.push(""),o.push('"),o.push(""),o.push(""),o.push(""),s=0,i=0;4>i;){for(o.push(""),d=0;3>d;)o.push('"),s++,d++;o.push(""),i++}o.push(""),o.push("
'+t.lang.monthHeading+"
'),o.push(''+t.lang.month[s]+""),o.push("
"),this.$.body.html(o.join("")),this.$.body.find("[data-calendar-item-month]").on(t.clickEventName,function(t){if(t=t||window.event,target=a.findParentNode(t.target,function(t){return t.getAttribute("data-calendar-item-month")?!0:void 0}),target){value=target.getAttribute("data-calendar-item-month"),n.changeMode("day",value);try{t.preventDefault&&t.preventDefault(),t.stopPropagation&&t.stopPropagation(),t.cancelBubble=!0}catch(t){}return!1}}),this.setDisplay()},this.printYear=function(e){var i,d,s=a.date(e),l=s.getFullYear(),r=[],o={},h=this.$.body.width(),c=Math.floor(h*(6/7));for(t.dimensions.height&&(c=a.number(t.dimensions.height)),o.height=Math.floor(c/5)-2*a.number(t.dimensions.itemPadding)+"px",o["line-height"]=o.height,o.padding=a.cssNumber(t.dimensions.itemPadding),r.push(''),r.push(""),r.push(""),r.push('"),r.push(""),r.push(""),r.push(""),y=l-10,i=0;5>i;){for(r.push(""),d=0;4>d;)r.push('"),y++,d++;r.push(""),i++}r.push(""),r.push("
'+t.lang.yearHeading+"
'),r.push(''+t.lang.year.replace("%s",y)+""),r.push("
"),this.$.body.html(r.join("")),this.$.body.find("[data-calendar-item-year]").on(t.clickEventName,function(t){if(t=t||window.event,target=a.findParentNode(t.target,function(t){return t.getAttribute("data-calendar-item-year")?!0:void 0}),target){value=target.getAttribute("data-calendar-item-year"),n.changeMode("month",value);try{t.preventDefault&&t.preventDefault(),t.stopPropagation&&t.stopPropagation(),t.cancelBubble=!0}catch(t){}return!1}}),this.setDisplay()},this.onclick=function(e,d,s){if(d=a.findParentNode(e.target,function(t){return t.getAttribute("data-calendar-item-date")?!0:void 0})){s=d.getAttribute("data-calendar-item-date");var l=a.date(s,{"return":t.dateFormat}),r=!0;if(t.selectable&&(t.selectable[l]||(r=!1)),r){if(i=t.multipleSelect?a.isNumber(t.multipleSelect)?t.multipleSelect:2:1,console.log(i),n.selection.length>=i){var o=n.selection.splice(0,n.selection.length-(i-1));o.forEach(function(e){n.$.body.find('[data-calendar-item-date="'+a.date(e,{"return":t.dateFormat})+'"]').removeClass("selected-day")})}jQuery(d).addClass("selected-day"),n.selection.push(s),t.onClick&&t.onClick.call({date:s,target:this.target,dateElement:d})}}},this.move=function(e,n,i){n=a.findParentNode(e.target,function(t){return t.getAttribute("data-calendar-move")?!0:void 0}),n&&(i=n.getAttribute("data-calendar-move"),"day"==t.mode?("left"==i?t.displayDate=a.date(t.displayDate,{add:{m:-1}}):t.displayDate=a.date(t.displayDate,{add:{m:1}}),this.printDay(t.displayDate)):"month"==t.mode?("left"==i?t.displayDate=a.date(t.displayDate,{add:{y:-1}}):t.displayDate=a.date(t.displayDate,{add:{y:1}}),this.printMonth(t.displayDate)):"year"==t.mode&&("left"==i?t.displayDate=a.date(t.displayDate,{add:{y:-10}}):t.displayDate=a.date(t.displayDate,{add:{y:10}}),this.printYear(t.displayDate)))},this.changeMode=function(e,a){"undefined"!=typeof a&&(t.displayDate=a),t.mode=e,this.$.body.removeClass("fadein").addClass("fadeout"),setTimeout(function(){"day"==t.mode?this.printDay(t.displayDate):"month"==t.mode?this.printMonth(t.displayDate):"year"==t.mode&&this.printYear(t.displayDate),this.$.body.removeClass("fadeout").addClass("fadein")}.bind(this),t.animateTime)},this.setDisplayDate=function(e){t.displayDate=a.date(e),this.$.body.removeClass("fadein").addClass("fadeout"),setTimeout(function(){"day"==t.mode?this.printDay(t.displayDate):"month"==t.mode?this.printMonth(t.displayDate):"year"==t.mode&&this.printYear(t.displayDate),this.$.body.removeClass("fadeout").addClass("fadein")}.bind(this),t.animateTime)},this.setSelection=function(e){return a.isArray(e)?(i=t.multipleSelect?a.isNumber(t.multipleSelect)?t.multipleSelect:2:1,this.selection=e.splice(0,i),this.selection.forEach(function(e){n.$.body.find('[data-calendar-item-date="'+a.date(e,{"return":t.dateFormat})+'"]').addClass("selected-day")}),this):this},this.getSelection=function(){return this.selection},this.main=function(){arguments&&a.isObject(arguments[0])&&this.setConfig(arguments[0])}.apply(this,arguments)};a.isFunction(e)&&(n.prototype=new e),t.calendar=n}(ax5.ui,ax5.ui.root); \ No newline at end of file diff --git a/package.json b/package.json index be1cf2f..1faa764 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bootstrap-ax5calendar", - "version": "0.2.0", + "version": "0.3.0", "description": "A calendar plugin that works with Bootstrap & jQuery", "license": "MIT", "repository": { diff --git a/src/ax5calendar.js b/src/ax5calendar.js index 0dc3a65..8901f9a 100755 --- a/src/ax5calendar.js +++ b/src/ax5calendar.js @@ -16,46 +16,42 @@ //== UI Class var axClass = function () { + if (_SUPER_) _SUPER_.call(this); // 부모호출 + var self = this, cfg, aDay = 1000 * 60 * 60 * 24, selectableCount = 1 ; - - // 클래스 생성자 - this.main = (function () { - if (_SUPER_) _SUPER_.call(this); // 부모호출 - this.config = { - clickEventName: "click", - theme: 'default', - mode: 'day', // day|month|year, - 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", - year: "%s", - month: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], - day: "%s" - }, - multipleSelect: false - }; - }).apply(this, arguments); - + this.target = null; this.selection = []; - cfg = this.config; - this.printedDay = { start: "", end: "" }; + this.config = { + clickEventName: "click", + theme: 'default', + mode: 'day', // day|month|year, + 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", + year: "%s", + month: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], + day: "%s" + }, + multipleSelect: false + }; + cfg = this.config; /** * Preferences of calendar UI @@ -74,8 +70,7 @@ //== class body start this.init = function () { // after setConfig(); - if (!cfg.target) - { + if (!cfg.target) { console.log(ax5.info.getError("ax5calendar", "401", "setConfig")); } this.target = jQuery(cfg.target); @@ -624,7 +619,7 @@ selectableCount = (cfg.multipleSelect) ? (U.isNumber(cfg.multipleSelect)) ? cfg.multipleSelect : 2 : 1; this.selection = selection.splice(0, selectableCount); this.selection.forEach(function (d) { - self.$["body"].find('[data-calendar-item-date="' + U.date(d, {"return": cfg.dateFormat}) + '"]').addClass("selected"); + self.$["body"].find('[data-calendar-item-date="' + U.date(d, {"return": cfg.dateFormat}) + '"]').addClass("selected-day"); }); return this; @@ -636,12 +631,20 @@ this.getSelection = function () { return this.selection; }; + + // 클래스 생성자 + this.main = (function () { + if(arguments && U.isObject(arguments[0])) { + this.setConfig(arguments[0]); + } + }).apply(this, arguments); }; //== UI Class - + + //== ui class 공통 처리 구문 if (U.isFunction(_SUPER_)) axClass.prototype = new _SUPER_(); // 상속 root.calendar = axClass; // ax5.ui에 연결 //== ui class 공통 처리 구문 - + })(ax5.ui, ax5.ui.root); \ No newline at end of file diff --git a/test/index.html b/test/index.html index 8bc2f01..bc88d9a 100644 --- a/test/index.html +++ b/test/index.html @@ -1,6 +1,6 @@ -ㅔ목 + Title @@ -35,8 +35,7 @@ {label: "토"} ]; - var myCalendar = new ax5.ui.calendar(); - myCalendar.setConfig({ + var myCalendar = new ax5.ui.calendar({ control: { left: 'P', yearTmpl: '%s', @@ -47,15 +46,15 @@ /* dimensions: { - itemPadding: 2, - height: 250 + itemPadding: 2, + height: 250 }, */ /* lang: { - year: "%s", - month: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], - day: "%s" + year: "%s", + month: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], + day: "%s" }, */