Browse Source

Fixed option autoResize

css_transitions
josdejong 10 years ago
parent
commit
aa810f6502
2 changed files with 25 additions and 14 deletions
  1. +3
    -2
      src/timeline/component/ItemSet.js
  2. +22
    -12
      src/timeline/component/RootPanel.js

+ 3
- 2
src/timeline/component/ItemSet.js View File

@ -219,8 +219,9 @@ ItemSet.prototype.repaint = function repaint() {
// check whether zoomed (in that case we need to re-stack everything)
var visibleInterval = this.range.end - this.range.start;
var zoomed = (this.visibleInterval != visibleInterval);
this.visibleInterval = visibleInterval;
var zoomed = (visibleInterval != this.lastVisibleInterval) || (this.width != this.lastWidth);
this.lastVisibleInterval = visibleInterval;
this.lastWidth = this.width;
/* TODO: implement+fix smarter way to update visible items
// find the first visible item

+ 22
- 12
src/timeline/component/RootPanel.js View File

@ -14,6 +14,8 @@ function RootPanel(container, options) {
this.defaultOptions = {
autoResize: true
};
this._initWatch();
}
RootPanel.prototype = new Panel();
@ -28,26 +30,20 @@ RootPanel.prototype = new Panel();
* {String | Number | function} [height]
* {Boolean | function} [autoResize]
*/
RootPanel.prototype.setOptions = function (options) {
RootPanel.prototype.setOptions = function setOptions(options) {
if (options) {
util.extend(this.options, options);
this.repaint();
var autoResize = this.getOption('autoResize');
if (autoResize) {
this._watch();
}
else {
this._unwatch();
}
this._initWatch();
}
};
/**
* Repaint the root panel
*/
RootPanel.prototype.repaint = function () {
RootPanel.prototype.repaint = function repaint() {
// create frame
if (!this.frame) {
if (!this.container) throw new Error('Cannot repaint root panel: no container attached');
@ -98,17 +94,31 @@ RootPanel.prototype.repaint = function () {
}
};
/**
* Initialize watching when option autoResize is true
* @private
*/
RootPanel.prototype._initWatch = function _initWatch() {
var autoResize = this.getOption('autoResize');
if (autoResize) {
this._watch();
}
else {
this._unwatch();
}
};
/**
* Watch for changes in the size of the frame. On resize, the Panel will
* automatically redraw itself.
* @private
*/
RootPanel.prototype._watch = function () {
RootPanel.prototype._watch = function _watch() {
var me = this;
this._unwatch();
var checkSize = function () {
var checkSize = function checkSize() {
var autoResize = me.getOption('autoResize');
if (!autoResize) {
// stop watching when the option autoResize is changed to false
@ -138,7 +148,7 @@ RootPanel.prototype._watch = function () {
* Stop watching for a resize of the frame.
* @private
*/
RootPanel.prototype._unwatch = function () {
RootPanel.prototype._unwatch = function _unwatch() {
if (this.watchTimer) {
clearInterval(this.watchTimer);
this.watchTimer = undefined;

Loading…
Cancel
Save