maskEl : false, // the mask element
headerEl : false,
contentEl : false,
-
+ alignEl : false, // when show is called with an element - this get's stored.
getChildContainer : function()
{
* @param {Roo.Element|string|Boolean} - element to align and point to. (set align to [ pos, offset ])
* @param {string} (left|right|top|bottom) position
*/
- show : function (on_el)
+ show : function (on_el, placement)
{
-
+ this.placement = typeof(placement) == 'undefined' ? this.placement : placement;
on_el = on_el || false; // default to false
- var align = on_el && typeof(on_el._align) != 'undefined' ? on_el._align : false;
-
+
if (!on_el) {
if (this.parent() && (this.over == 'parent' || (this.over === false))) {
on_el = this.parent().el;
}
+ this.alignEl = on_el;
+
if (!this.el) {
this.render(document.body);
}
- this.el.removeClass([
- 'fade','top','bottom', 'left', 'right','in',
- 'bs-popover-top','bs-popover-bottom', 'bs-popover-left', 'bs-popover-right'
- ]);
+
if (this.title === false) {
this.headerEl.hide();
}
-
- var placement = typeof this.placement == 'function' ?
- this.placement.call(this, this.el, on_el) :
- this.placement;
-
- /*
- var autoToken = /\s?auto?\s?/i; /// not sure how this was supposed to work? right auto ? what?
-
- // I think 'auto right' - but
-
- var autoPlace = autoToken.test(placement);
- if (autoPlace) {
- placement = placement.replace(autoToken, '') || 'top';
- }
- */
-
-
+
this.el.show();
- this.el.dom.style.display='block';
-
- //this.el.appendTo(on_el);
-
- var p = this.getPosition();
- var box = this.el.getBox();
-
-
- this.alignment = align || Roo.bootstrap.Popover.alignment[placement];
- this.el.addClass(this.alignment[2]);
-
-// Roo.log(align);
-
- if (on_el) {
- this.alignEl = on_el;
- this.updatePosition();
+ this.el.dom.style.display = 'block';
+
+
+ if (this.alignEl) {
+ this.updatePosition(this.placement, true);
} else {
// this is usually just done by the builder = to show the popoup in the middle of the scren.
},
/**
* fire this manually after loading a grid in the table for example
- *
+ * @param {string} (left|right|top|bottom) where to try and put it (use false to use the last one)
+ * @param {Boolean} try and move it if we cant get right position.
*/
- updatePosition : function()
+ updatePosition : function(placement, try_move)
{
- if (!this.alignEl || !this.alignment) {
- return;
+ placement = placement === false ? this.placement : placement;
+
+ this.el.removeClass([
+ 'fade','top','bottom', 'left', 'right','in',
+ 'bs-popover-top','bs-popover-bottom', 'bs-popover-left', 'bs-popover-right'
+ ]);
+ this.el.addClass(placement + ' roo-popover-' + placement);
+
+ if (!this.alignEl ) {
+ return false;
+ }
+
+ switch (placement) {
+ case 'right':
+ var exact = this.el.getAlignToXY(this.alignEl, 'tl-tr', [10,0]);
+ var offset = this.el.getAlignToXY(this.alignEl, 'tl-tr?',[10,0]);
+ if (!try_move || exact.equals(offset) || exact[0] == offset[0] ) {
+ //normal display... or moved up/down.
+ this.el.setXY(offset);
+ var xy = this.alignEl.getAnchorXY('tr', false);
+ xy[0]+=2;xy[1]+=5;
+ this.arrowEl.setXY(xy);
+ return true;
+ }
+ // continue through...
+ try_move = false;
+
+
+ case 'left':
+ var exact = this.el.getAlignToXY(this.alignEl, 'tr-tl', [-10,0]);
+ var offset = this.el.getAlignToXY(this.alignEl, 'tr-tl?',[-10,0]);
+ if (!try_move || exact.equals(offset) || exact[0] == offset[0] ) {
+ //normal display... or moved up/down.
+ this.el.setXY(offset);
+ var xy = this.alignEl.getAnchorXY('tl', false);
+ xy[0]+=2;xy[1]+=5; // << fix me
+ this.arrowEl.setXY(xy);
+ return true;
+ }
+ // call self...
+ return this.updatePosition('right', false);
+
+ case 'top':
+ var exact = this.el.getAlignToXY(this.alignEl, 't-b', [0,-10]);
+ var offset = this.el.getAlignToXY(this.alignEl, 't-b?',[0,-10]);
+ if (!try_move || exact.equals(offset) || exact[1] == offset[1] ) {
+ //normal display... or moved up/down.
+ this.el.setXY(offset);
+ var xy = this.alignEl.getAnchorXY('b', false);
+ xy[0]+=2;xy[1]+=5; // << fix me
+ this.arrowEl.setXY(xy);
+ return true;
+ }
+ // fall through
+ try_move = false;
+
+ case 'bottom':
+ var exact = this.el.getAlignToXY(this.alignEl, 'b-t', [0,10]);
+ var offset = this.el.getAlignToXY(this.alignEl, 'b-t?',[0,10]);
+ if (!try_move || exact.equals(offset) || exact[1] == offset[1] ) {
+ //normal display... or moved up/down.
+ this.el.setXY(offset);
+ var xy = this.alignEl.getAnchorXY('t', false);
+ xy[0]+=2;xy[1]+=5; // << fix me
+ this.arrowEl.setXY(xy);
+ return true;
+ }
+ // fall through
+ return this.updatePosition('top', false);
+
+
}
- this.el.alignTo(this.alignEl , this.alignment[0],this.alignment[1]);
- // work out the pointy position.
- var p1 = this.alignment[0].split('-').pop().replace('?','');
- var xy = this.alignEl.getAnchorXY(p1, false);
- xy[0]+=2;xy[1]+=5;
- this.arrowEl.setXY(xy);
+ return false;
},
hide : function()