Skip to content

Commit

Permalink
fix: all-day block width is wrong when resizing it (close #43)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dongsik Yoo committed Mar 26, 2018
1 parent a267e16 commit a345dba
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
4 changes: 4 additions & 0 deletions src/js/handler/allday/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ function getX(grids, left) {
var i = 0;
var length = grids.length;
var grid;
if (left < 0) {
left = 0;
}

for (; i < length; i += 1) {
grid = grids[i];
if (grid.left <= left && left <= (grid.left + grid.width)) {
Expand Down
37 changes: 16 additions & 21 deletions src/js/handler/allday/resizeGuide.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,29 +88,24 @@ AlldayResizeGuide.prototype.refreshGuideElement = function(newWidth) {
AlldayResizeGuide.prototype.getGuideElementWidthFunc = function(dragStartEventData) {
var model = dragStartEventData.model,
viewOptions = this.alldayResize.alldayView.options,
startDate = datetime.start(
new TZDate(Math.max(
model.start.getTime(),
datetime.parse(viewOptions.renderStartDate).getTime()
))
),
endDate = datetime.end(
new TZDate(Math.min(
model.end.getTime(),
datetime.parse(viewOptions.renderEndDate).getTime()
))
),
originLength = datetime.range(startDate, endDate, datetime.MILLISECONDS_PER_DAY).length,
baseWidthPercent = 100 / dragStartEventData.datesInRange,
dragStartIndex = dragStartEventData.xIndex;
fromLeft = (new TZDate(
model.start.getTime() - datetime.parse(viewOptions.renderStartDate)
)) / datetime.MILLISECONDS_PER_DAY | 0,
grids = dragStartEventData.grids;

return function(xIndex) {
var offset = xIndex - dragStartIndex,
newLength = originLength + offset;

newLength = Math.max(1, newLength);

return newLength * baseWidthPercent;
var width = 0;
var i = 0;
var length = grids.length;
width += grids[fromLeft] ? grids[fromLeft].width : 0;

for (; i < length; i += 1) {
if (i > fromLeft && i <= xIndex) {
width += grids[i] ? grids[i].width : 0;
}
}

return width;
};
};

Expand Down
3 changes: 2 additions & 1 deletion test/app/handler/allday/resizeGuide.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ describe('handler:AlldayResizeGuide', function() {
model: {
start: new Date('2015-05-04T00:00:00+09:00'),
end: new Date('2015-05-04T23:59:59+09:00')
}
},
grids: [{width: 20}, {width: 20}, {width: 20}, {width: 20}, {width: 20}]
};

var func = inst.getGuideElementWidthFunc.call(mockAlldayResize, mockDragStartEventData);
Expand Down

0 comments on commit a345dba

Please sign in to comment.