Skip to content

Commit

Permalink
ax5calendar 70%
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasJang committed Jan 25, 2016
1 parent b261b8d commit ed6fc2f
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 31 deletions.
2 changes: 1 addition & 1 deletion dist/ax5calendar.css

Large diffs are not rendered by default.

58 changes: 50 additions & 8 deletions dist/ax5calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
var
self = this,
cfg,
aDay = 1000 * 60 * 60 * 24;
aDay = 1000 * 60 * 60 * 24,
selectableCount = 1
;

// 클래스 생성자
this.main = (function () {
Expand All @@ -42,13 +44,15 @@
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: ""
};
Expand Down Expand Up @@ -488,9 +492,17 @@
}

if (selectable) {
this.$["body"].find('[data-calendar-item-date="' + U.date(cfg.displayDate, {"return": cfg.dateFormat}) + '"]').removeClass("hover");
jQuery(target).addClass("hover");
cfg.displayDate = value;
selectableCount = (cfg.multipleSelect) ? (U.isNumber(cfg.multipleSelect)) ? cfg.multipleSelect : 2 : 1;
if (self.selection.length >= selectableCount) {
var removed = self.selection.splice(0, self.selection.length - (selectableCount - 1));
removed.forEach(function (d) {
self.$["body"].find('[data-calendar-item-date="' + U.date(d, {"return": cfg.dateFormat}) + '"]').removeClass("selected");
});
}

jQuery(target).addClass("selected");
self.selection.push(value);
// cfg.displayDate = value;

if (cfg.onClick)
{
Expand Down Expand Up @@ -570,7 +582,10 @@
this.$["body"].removeClass("fadeout").addClass("fadein");
}).bind(this), cfg.animateTime);
};


/**
* @method ax5.ui.calendar.setDisplayDate
*/
this.setDisplayDate = function (d) {
cfg.displayDate = U.date(d);

Expand All @@ -591,7 +606,34 @@
this.$["body"].removeClass("fadeout").addClass("fadein");
}).bind(this), cfg.animateTime);
};


/**
* @method ax5.ui.calendar.setSelection
* @param {Array} selection
* @returns {ax5.ui.calendar}
* @example
* ```
*
* ```
*/
this.setSelection = function (selection) {
if(!U.isArray(selection)) return this;

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");
});

return this;
};

/**
* @method ax5.ui.calendar.getSelection
*/
this.getSelection = function () {
return this.selection;
};
};
//== UI Class

Expand Down
2 changes: 1 addition & 1 deletion dist/ax5calendar.min.js

Large diffs are not rendered by default.

58 changes: 50 additions & 8 deletions src/ax5calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
var
self = this,
cfg,
aDay = 1000 * 60 * 60 * 24;
aDay = 1000 * 60 * 60 * 24,
selectableCount = 1
;

// 클래스 생성자
this.main = (function () {
Expand All @@ -42,13 +44,15 @@
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: ""
};
Expand Down Expand Up @@ -488,9 +492,17 @@
}

if (selectable) {
this.$["body"].find('[data-calendar-item-date="' + U.date(cfg.displayDate, {"return": cfg.dateFormat}) + '"]').removeClass("hover");
jQuery(target).addClass("hover");
cfg.displayDate = value;
selectableCount = (cfg.multipleSelect) ? (U.isNumber(cfg.multipleSelect)) ? cfg.multipleSelect : 2 : 1;
if (self.selection.length >= selectableCount) {
var removed = self.selection.splice(0, self.selection.length - (selectableCount - 1));
removed.forEach(function (d) {
self.$["body"].find('[data-calendar-item-date="' + U.date(d, {"return": cfg.dateFormat}) + '"]').removeClass("selected");
});
}

jQuery(target).addClass("selected");
self.selection.push(value);
// cfg.displayDate = value;

if (cfg.onClick)
{
Expand Down Expand Up @@ -570,7 +582,10 @@
this.$["body"].removeClass("fadeout").addClass("fadein");
}).bind(this), cfg.animateTime);
};


/**
* @method ax5.ui.calendar.setDisplayDate
*/
this.setDisplayDate = function (d) {
cfg.displayDate = U.date(d);

Expand All @@ -591,7 +606,34 @@
this.$["body"].removeClass("fadeout").addClass("fadein");
}).bind(this), cfg.animateTime);
};


/**
* @method ax5.ui.calendar.setSelection
* @param {Array} selection
* @returns {ax5.ui.calendar}
* @example
* ```
*
* ```
*/
this.setSelection = function (selection) {
if(!U.isArray(selection)) return this;

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");
});

return this;
};

/**
* @method ax5.ui.calendar.getSelection
*/
this.getSelection = function () {
return this.selection;
};
};
//== UI Class

Expand Down
2 changes: 1 addition & 1 deletion src/scss/_ax5calendar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
}
}
}
&.hover {
&.selected {
@include ax-background($ax5calendar-hover-bg);
color: $ax5calendar-hover-text-color !important;
span.addon {
Expand Down
36 changes: 24 additions & 12 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,36 @@
right: 'N',
yearFirst: true
},
dimensions: {
itemRatio: 1,
itemPadding: 2,
height: 250
},
lang: {
year: "%s",
month: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
day: "%s"
},

/*
dimensions: {
itemPadding: 2,
height: 250
},
*/
/*
lang: {
year: "%s",
month: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
day: "%s"
},
*/

target: document.getElementById("calendar-target"),
displayDate: "2016-01-01",
mode: "day",
displayDate: (new Date()),
// mode: "day",

onClick: function () {
console.log(myCalendar.getSelection());
},
onStateChanged: function () {
console.log(this);
}
//multipleSelect: 1
});

myCalendar.setSelection(['2016-01-11', '2016-01-12', '2016-01-13']);

});
</script>

Expand Down

0 comments on commit ed6fc2f

Please sign in to comment.