Browse Source

Changed Range into an emitter

css_transitions
josdejong 10 years ago
parent
commit
ae95765c18
2 changed files with 17 additions and 14 deletions
  1. +15
    -10
      src/timeline/Range.js
  2. +2
    -4
      src/timeline/Timeline.js

+ 15
- 10
src/timeline/Range.js View File

@ -16,6 +16,8 @@ function Range(parent, emitter, options) {
this.emitter = emitter; this.emitter = emitter;
this.options = options || {}; this.options = options || {};
// TODO: not so nice having to specify an emitter (different from parent) where to subscribe for events
// drag start listener // drag start listener
var me = this; var me = this;
emitter.on('dragstart', function (event) { emitter.on('dragstart', function (event) {
@ -55,6 +57,9 @@ function Range(parent, emitter, options) {
this.setOptions(options); this.setOptions(options);
} }
Emitter(Range.prototype);
/** /**
* Set options for the range controller * Set options for the range controller
* @param {Object} options Available options: * @param {Object} options Available options:
@ -94,11 +99,11 @@ Range.prototype.setRange = function(start, end) {
var changed = this._applyRange(start, end); var changed = this._applyRange(start, end);
if (changed) { if (changed) {
var params = { var params = {
start: this.start,
end: this.end
start: new Date(this.start),
end: new Date(this.end)
}; };
this.emitter.emit('rangechange', params);
this.emitter.emit('rangechanged', params);
this.emit('rangechange', params);
this.emit('rangechanged', params);
} }
}; };
@ -304,9 +309,9 @@ Range.prototype._onDrag = function (event) {
this._applyRange(touchParams.start + diffRange, touchParams.end + diffRange); this._applyRange(touchParams.start + diffRange, touchParams.end + diffRange);
this.emitter.emit('rangechange', {
start: this.start,
end: this.end
this.emit('rangechange', {
start: new Date(this.start),
end: new Date(this.end)
}); });
}; };
@ -327,9 +332,9 @@ Range.prototype._onDragEnd = function (event) {
} }
// fire a rangechanged event // fire a rangechanged event
this.emitter.emit('rangechanged', {
start: this.start,
end: this.end
this.emit('rangechanged', {
start: new Date(this.start),
end: new Date(this.end)
}); });
}; };

+ 2
- 4
src/timeline/Timeline.js View File

@ -130,14 +130,12 @@ function Timeline (container, items, options) {
now.clone().add('days', -3).valueOf(), now.clone().add('days', -3).valueOf(),
now.clone().add('days', 4).valueOf() now.clone().add('days', 4).valueOf()
); );
/* TODO
this.range.on('rangechange', function (properties) { this.range.on('rangechange', function (properties) {
me.controller.emit('rangechange', properties);
me.emitter.emit('rangechange', properties);
}); });
this.range.on('rangechanged', function (properties) { this.range.on('rangechanged', function (properties) {
me.controller.emit('rangechanged', properties);
me.emitter.emit('rangechanged', properties);
}); });
*/
// panel with time axis // panel with time axis
var timeAxisOptions = Object.create(rootOptions); var timeAxisOptions = Object.create(rootOptions);

Loading…
Cancel
Save