Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
ditto
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Oct 26, 2015
1 parent e314128 commit da5552e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
35 changes: 20 additions & 15 deletions src/Selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ function isOverContainer(container, x, y){
return !container || contains(container, document.elementFromPoint(x, y))
}

const clickTolerance = 5;

class Selection {

constructor(node, global = false){
Expand Down Expand Up @@ -120,15 +122,9 @@ class Selection {

if (!this._mouseDownData) return;

let clickTolerance = 5;

var { x, y } = this._mouseDownData;
var inRoot = !this.container || contains(this.container(), e.target);
var bounds = this._selectRect;
var click = (
Math.abs(e.pageX - x) <= clickTolerance &&
Math.abs(e.pageY - y) <= clickTolerance
);
var click = this.isClick(e.pageX, e.pageY);

this._mouseDownData = null

Expand Down Expand Up @@ -161,19 +157,28 @@ class Selection {
this.emit('selectStart', this._mouseDownData)
}

this.emit('selecting', this._selectRect = {
top,
left,
x: e.pageX,
y: e.pageY,
right: left + w,
bottom: top + h
});
if (!this.isClick(e.pageX, e.pageY))
this.emit('selecting', this._selectRect = {
top,
left,
x: e.pageX,
y: e.pageY,
right: left + w,
bottom: top + h
});
}

_keyListener(e) {
this.ctrl = (e.metaKey || e.ctrlKey)
}

isClick(pageX, pageY){
var { x, y } = this._mouseDownData;
return (
Math.abs(pageX - x) <= clickTolerance &&
Math.abs(pageY - y) <= clickTolerance
);
}
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/utils/dates.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ let dates = Object.assign(dateMath, {
return days
},

ceil(date, unit){
let floor = dates.startOf(date, unit)

return dates.eq(floor, date) ? floor : dates.add(floor, 1, unit)
},

move(date, min, max, unit, direction){
let isUpOrDown = direction === directions.UP || direction === directions.DOWN
, addUnit = isUpOrDown ? 'week' : 'day'
Expand Down
2 changes: 1 addition & 1 deletion src/utils/eventLevels.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { accessor as get } from './accessors';
export function eventSegments(event, first, last, { startAccessor, endAccessor, culture }){
let slots = dates.diff(first, last, 'day')
let start = dates.max(get(event, startAccessor), first);
let end = dates.min(get(event, endAccessor), dates.add(last, 1, 'day'))
let end = dates.min(dates.ceil(get(event, endAccessor), 'day'), dates.add(last, 1, 'day'))

let span = dates.diff(start, end, 'day');

Expand Down

0 comments on commit da5552e

Please sign in to comment.