Skip to content
This repository has been archived by the owner on Jul 29, 2019. It is now read-only.

Commit

Permalink
Added validation for callback functions. Some css fixes for range
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Feb 18, 2014
1 parent dbd68d7 commit 819f130
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
11 changes: 11 additions & 0 deletions src/timeline/Range.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ Range.prototype._onDragStart = function(event, component) {
// when releasing the fingers in opposite order from the touch screen
if (touchParams.ignore) return;

// TODO: reckon with option movable

touchParams.start = this.start;
touchParams.end = this.end;

Expand All @@ -307,6 +309,9 @@ Range.prototype._onDragStart = function(event, component) {
Range.prototype._onDrag = function (event, component, direction) {
validateDirection(direction);

// TODO: reckon with option movable


// refuse to drag when we where pinching to prevent the timeline make a jump
// when releasing the fingers in opposite order from the touch screen
if (touchParams.ignore) return;
Expand Down Expand Up @@ -335,6 +340,8 @@ Range.prototype._onDragEnd = function (event, component) {
// when releasing the fingers in opposite order from the touch screen
if (touchParams.ignore) return;

// TODO: reckon with option movable

if (component.frame) {
component.frame.style.cursor = 'auto';
}
Expand All @@ -357,6 +364,8 @@ Range.prototype._onDragEnd = function (event, component) {
Range.prototype._onMouseWheel = function(event, component, direction) {
validateDirection(direction);

// TODO: reckon with option zoomable

// retrieve delta
var delta = 0;
if (event.wheelDelta) { /* IE/Opera. */
Expand Down Expand Up @@ -432,6 +441,8 @@ Range.prototype._onHold = function () {
Range.prototype._onPinch = function (event, component, direction) {
touchParams.ignore = true;

// TODO: reckon with option zoomable

if (event.gesture.touches.length > 1) {
if (!touchParams.center) {
touchParams.center = getPointer(event.gesture.center, component.frame);
Expand Down
24 changes: 16 additions & 8 deletions src/timeline/Timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ function Timeline (container, items, options) {
now.clone().add('days', 4).valueOf()
);

// TODO: reckon with options moveable and zoomable
// TODO: put the listeners in setOptions, be able to dynamically change with options moveable and zoomable
// TODO: enable moving again
this.range.subscribe(this.controller, this.rootPanel, 'move', 'horizontal');
this.range.subscribe(this.controller, this.rootPanel, 'zoom', 'horizontal');
this.range.on('rangechange', function (properties) {
Expand Down Expand Up @@ -194,9 +191,24 @@ Timeline.prototype.setOptions = function (options) {
this.range.setRange(options.start, options.end);

if ('editable' in options || 'selectable' in options) {
// TODO: update current selection according to changed options
if (this.options.selectable) {
// force update of selection
this.setSelection(this.getSelection());
}
else {
// remove selection
this.setSelection([]);
}
}

// validate the callback functions
var validateCallback = (function (fn) {
if (!(this.options[fn] instanceof Function) || this.options[fn].length != 2) {
throw new Error('option ' + fn + ' must be a function ' + fn + '(item, callback)');
}
}).bind(this);
['onAdd', 'onUpdate', 'onRemove', 'onMove'].forEach(validateCallback);

this.controller.reflow();
this.controller.repaint();
};
Expand Down Expand Up @@ -532,10 +544,6 @@ Timeline.prototype._onMultiSelectItem = function (event) {

event.stopPropagation();
}
else {
// create a new item
this._onAddItem(event);
}
};

/**
Expand Down
9 changes: 5 additions & 4 deletions src/timeline/component/css/item.css
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,17 @@
box-sizing: border-box;
}

.vis.timeline .item.range {
overflow: hidden;
}

.vis.timeline .item.range .content,
.vis.timeline .item.rangeoverflow .content {
position: relative;
display: inline-block;
}

.vis.timeline .item.range .content {
overflow: hidden;
max-width: 100%;
}

.vis.timeline .item.line {
padding: 0;
position: absolute;
Expand Down

0 comments on commit 819f130

Please sign in to comment.