9 * @class Roo.bootstrap.Popover
10 * @extends Roo.bootstrap.Component
11 * Bootstrap Popover class
12 * @cfg {String} html contents of the popover (or false to use children..)
13 * @cfg {String} title of popover (or false to hide)
14 * @cfg {String|function} (right|top|bottom|left|auto) placement how it is placed
15 * @cfg {String} trigger click || hover (or false to trigger manually)
16 * @cfg {Boolean} modal - popovers that are modal will mask the screen, and must be closed with another event.
17 * @cfg {String|Boolean|Roo.Element} add click hander to trigger show over what element
18 * - if false and it has a 'parent' then it will be automatically added to that element
19 * - if string - Roo.get will be called
20 * @cfg {Number} delay - delay before showing
23 * Create a new Popover
24 * @param {Object} config The config object
27 Roo.bootstrap.Popover = function(config){
28 Roo.bootstrap.Popover.superclass.constructor.call(this, config);
34 * After the popover show
36 * @param {Roo.bootstrap.Popover} this
41 * After the popover hide
43 * @param {Roo.bootstrap.Popover} this
49 Roo.extend(Roo.bootstrap.Popover, Roo.bootstrap.Component, {
55 trigger : 'hover', // hover
61 can_build_overlaid : false,
63 maskEl : false, // the mask element
65 getChildContainer : function()
67 return this.contentEl;
68 return this.el.select('.popover-content',true).first();
70 getPopoverHeader : function()
76 getAutoCreate : function(){
79 cls : 'popover roo-dynamic shadow roo-popover' + (this.modal ? '-modal' : ''),
80 style: 'display:block',
86 cls : 'popover-inner ',
90 cls: 'popover-title popover-header',
91 html : this.title || ''
94 cls : 'popover-content popover-body' + this.cls,
95 html : this.html || ''
106 * @param {string} the title
108 setTitle: function(str)
112 this.el.select('.popover-title',true).first().dom.innerHTML = str;
117 * @param {string} the body content
119 setContent: function(str)
122 if (this.contentEl) {
123 this.contentEl.dom.innerHTML = str;
127 // as it get's added to the bottom of the page.
128 onRender : function(ct, position)
130 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
132 var cfg = Roo.apply({}, this.getAutoCreate());
136 cfg.cls += ' ' + this.cls;
139 cfg.style = this.style;
141 //Roo.log("adding to ");
142 this.el = Roo.get(document.body).createChild(cfg, position);
147 if(typeof(this.items) != 'undefined'){
148 var items = this.items;
151 for(var i =0;i < items.length;i++) {
152 nitems.push(this.addxtype(Roo.apply({}, items[i])));
158 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
159 Roo.EventManager.onWindowResize(this.resizeMask, this, true);
162 this.contentEl = this.el.select('.popover-content',true).first();
163 this.headerEl = this.el.select('.popover-header',true).first();
168 resizeMask : function()
171 Roo.lib.Dom.getViewWidth(true),
172 Roo.lib.Dom.getViewHeight(true)
176 initEvents : function()
180 Roo.bootstrap.Popover.register(this);
184 this.el.select('.popover-title',true).setVisibilityMode(Roo.Element.DISPLAY);
185 this.el.enableDisplayMode('block');
187 if (this.over === false && !this.parent()) {
190 if (this.triggers === false) {
195 var on_el = (this.over == 'parent' || this.over === false) ? this.parent().el : Roo.get(this.over);
196 var triggers = this.trigger ? this.trigger.split(' ') : [];
197 Roo.each(triggers, function(trigger) {
199 if (trigger == 'click') {
200 on_el.on('click', this.toggle, this);
201 } else if (trigger != 'manual') {
202 var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin';
203 var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout';
205 on_el.on(eventIn ,this.enter, this);
206 on_el.on(eventOut, this.leave, this);
217 toggle : function () {
218 this.hoverState == 'in' ? this.leave() : this.enter();
221 enter : function () {
223 clearTimeout(this.timeout);
225 this.hoverState = 'in';
227 if (!this.delay || !this.delay.show) {
232 this.timeout = setTimeout(function () {
233 if (_t.hoverState == 'in') {
240 clearTimeout(this.timeout);
242 this.hoverState = 'out';
244 if (!this.delay || !this.delay.hide) {
249 this.timeout = setTimeout(function () {
250 if (_t.hoverState == 'out') {
257 * @param {Roo.Element|string|false} - element to align and point to.
259 show : function (on_el)
262 on_el = on_el || false; // default to false
264 if (this.parent() && (this.over == 'parent' || (this.over === false))) {
265 on_el = this.parent().el;
266 } else if (this.over) {
273 this.render(document.body);
277 this.el.removeClass([
278 'fade','top','bottom', 'left', 'right','in',
279 'bs-popover-top','bs-popover-bottom', 'bs-popover-left', 'bs-popover-right'
282 if (!this.title.length) {
283 this.el.select('.popover-title',true).hide();
287 var placement = typeof this.placement == 'function' ?
288 this.placement.call(this, this.el, on_el) :
292 var autoToken = /\s?auto?\s?/i; /// not sure how this was supposed to work? right auto ? what?
294 // I think 'auto right' - but
296 var autoPlace = autoToken.test(placement);
298 placement = placement.replace(autoToken, '') || 'top';
304 this.el.dom.style.display='block';
306 //this.el.appendTo(on_el);
308 var p = this.getPosition();
309 var box = this.el.getBox();
312 var align = Roo.bootstrap.Popover.alignment[placement];
313 this.el.addClass(align[2]);
318 this.el.alignTo(on_el, align[0],align[1]);
320 // this is usually just done by the builder = to show the popoup in the middle of the scren.
321 var es = this.el.getSize();
322 var x = Roo.lib.Dom.getViewWidth()/2;
323 var y = Roo.lib.Dom.getViewHeight()/2;
324 this.el.setXY([ x-(es.width/2), y-(es.height/2)] );
329 //var arrow = this.el.select('.arrow',true).first();
330 //arrow.set(align[2],
332 this.el.addClass('in');
335 if (this.el.hasClass('fade')) {
339 this.hoverState = 'in';
342 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
343 this.maskEl.setStyle('z-index', Roo.bootstrap.Popover.zIndex++);
344 this.maskEl.dom.style.display = 'block';
345 this.maskEl.addClass('show');
347 this.el.setStyle('z-index', Roo.bootstrap.Popover.zIndex++);
351 this.fireEvent('show', this);
356 this.el.setXY([0,0]);
357 this.el.removeClass('in');
359 this.hoverState = null;
360 this.maskEl.hide(); // always..
361 this.fireEvent('hide', this);
367 Roo.apply(Roo.bootstrap.Popover, {
370 'left' : ['r-l', [-10,0], 'left bs-popover-left'],
371 'right' : ['l-br', [10,0], 'right bs-popover-right'],
372 'bottom' : ['t-b', [0,10], 'top bs-popover-top'],
373 'top' : [ 'b-t', [0,-10], 'bottom bs-popover-bottom']
381 onMouseDown : function(e)
383 if (!e.getTarget(".roo-popover")) {
391 register : function(popup)
393 if (!Roo.bootstrap.Popover.clickHandler) {
394 Roo.bootstrap.Popover.clickHandler = Roo.get(document).on("mousedown", Roo.bootstrap.Popover.onMouseDown, Roo.bootstrap.Popover);
396 // hide other popups.
398 this.popups.push(popup);
402 this.popups.forEach(function(p) {