Sha256: da758c36f57e8037103ee480a100a3c9753aef91fa98761610ad889d4333f7d2

Contents?: true

Size: 1.8 KB

Versions: 27

Compression:

Stored size: 1.8 KB

Contents

// Simple view for centering a view.
// The rect's left position is used as the minimum left position, the rects
// top and width are used as-is and the HCenterView itself is geometrically
// centered inside its parent by adjusting its "left" style property.
// Designed to be used as a root-level view, listens to the resize event and
// re-calculates the center position accordingly. Likely to evolve a lot still.
var//RSence.Views
HCenterView = HControl.extend({
  defaultEvents: {
    resize: true
  },
  controlDefaults: HControlDefaults.extend({
    centerX: true,
    centerY: false
  }),
  drawRect: function(_selfCalled){
    this.base();
    if(!_selfCalled){
      this.resize();
    }
  },
  minLeft: false,
  minTop: false,
  resize: function(){
    if(this.minLeft === false){
      this.minLeft = this.rect.left;
    }
    if(this.minTop === false){
      this.minTop = this.rect.top;
    }
    var
    _rect = this.rect,
    _winSize = ELEM.windowSize(),
    _winWidth = _winSize[0],
    _winHeight = _winSize[1],
    _rectWidth = _rect.width,
    _rectWidthHalf = Math.floor(_rectWidth/2),
    _winWidthHalf = Math.floor(_winWidth/2),
    _left = _winWidthHalf - _rectWidthHalf,
    _rectHeight = _rect.height,
    _rectHeightHalf = Math.floor(_rectHeight/2),
    _winHeightHalf = Math.floor(_winHeight/2),
    _top = _winHeightHalf - _rectHeightHalf;
    if (!this.options.centerX){
      _left = _rect.left;
    }
    else if( _left < this.minLeft ){
      _left = this.minLeft;
    }
    if (!this.options.centerY){
      _top = _rect.top;
    }
    else if( _top < this.minTop ){
      _top = this.minTop;
    }
    _rect.offsetTo( _left, _top );
    this.drawRect(true);
  }
});

var//RSence.Views
HMiddleView = HCenterView.extend({
  controlDefaults: HControlDefaults.extend({
    centerX: false,
    centerY: true
  })
});

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
rsence-pre-3.0.0.16 client/js/views/centerview/centerview.js
rsence-pre-3.0.0.15 client/js/views/centerview/centerview.js
rsence-pre-3.0.0.14 client/js/views/centerview/centerview.js
rsence-pre-3.0.0.12 client/js/views/centerview/centerview.js
rsence-pre-3.0.0.11 client/js/views/centerview/centerview.js
rsence-pre-3.0.0.10 client/js/views/centerview/centerview.js
rsence-pre-3.0.0.9 client/js/views/centerview/centerview.js
rsence-pre-3.0.0.8 client/js/views/centerview/centerview.js
rsence-pre-3.0.0.7 client/js/views/centerview/centerview.js
rsence-pre-3.0.0.6 client/js/views/centerview/centerview.js
rsence-pre-3.0.0.5 client/js/views/centerview/centerview.js
rsence-pre-3.0.0.4 client/js/views/centerview/centerview.js
rsence-pre-3.0.0.3 client/js/views/centerview/centerview.js
rsence-pre-3.0.0.2 client/js/views/centerview/centerview.js
rsence-pre-3.0.0.1 client/js/views/centerview/centerview.js
rsence-pre-3.0.0.0 client/js/views/centerview/centerview.js
rsence-pre-2.3.0.26 js/views/centerview/centerview.js
rsence-pre-2.3.0.25 js/views/centerview/centerview.js
rsence-pre-2.3.0.24 js/views/centerview/centerview.js
rsence-pre-2.3.0.23 js/views/centerview/centerview.js