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
68 getChildContainer : function()
70 return this.contentEl;
73 getPopoverHeader : function()
75 this.title = true; // flag not to hide it..
80 getAutoCreate : function(){
83 cls : 'popover roo-dynamic shadow roo-popover' + (this.modal ? '-modal' : ''),
84 style: 'display:block',
90 cls : 'popover-inner ',
94 cls: 'popover-title popover-header',
95 html : this.title === false ? '' : this.title
98 cls : 'popover-content popover-body ' + (this.cls || ''),
99 html : this.html || ''
110 * @param {string} the title
112 setTitle: function(str)
116 this.headerEl.dom.innerHTML = str;
121 * @param {string} the body content
123 setContent: function(str)
126 if (this.contentEl) {
127 this.contentEl.dom.innerHTML = str;
131 // as it get's added to the bottom of the page.
132 onRender : function(ct, position)
134 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
139 var cfg = Roo.apply({}, this.getAutoCreate());
143 cfg.cls += ' ' + this.cls;
146 cfg.style = this.style;
148 //Roo.log("adding to ");
149 this.el = Roo.get(document.body).createChild(cfg, position);
153 this.contentEl = this.el.select('.popover-content',true).first();
154 this.headerEl = this.el.select('.popover-title',true).first();
157 if(typeof(this.items) != 'undefined'){
158 var items = this.items;
161 for(var i =0;i < items.length;i++) {
162 nitems.push(this.addxtype(Roo.apply({}, items[i])));
168 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
169 Roo.EventManager.onWindowResize(this.resizeMask, this, true);
176 resizeMask : function()
179 Roo.lib.Dom.getViewWidth(true),
180 Roo.lib.Dom.getViewHeight(true)
184 initEvents : function()
188 Roo.bootstrap.Popover.register(this);
192 this.headerEl.setVisibilityMode(Roo.Element.DISPLAY); // probably not needed as it's default in BS4
193 this.el.enableDisplayMode('block');
195 if (this.over === false && !this.parent()) {
198 if (this.triggers === false) {
203 var on_el = (this.over == 'parent' || this.over === false) ? this.parent().el : Roo.get(this.over);
204 var triggers = this.trigger ? this.trigger.split(' ') : [];
205 Roo.each(triggers, function(trigger) {
207 if (trigger == 'click') {
208 on_el.on('click', this.toggle, this);
209 } else if (trigger != 'manual') {
210 var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin';
211 var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout';
213 on_el.on(eventIn ,this.enter, this);
214 on_el.on(eventOut, this.leave, this);
225 toggle : function () {
226 this.hoverState == 'in' ? this.leave() : this.enter();
229 enter : function () {
231 clearTimeout(this.timeout);
233 this.hoverState = 'in';
235 if (!this.delay || !this.delay.show) {
240 this.timeout = setTimeout(function () {
241 if (_t.hoverState == 'in') {
248 clearTimeout(this.timeout);
250 this.hoverState = 'out';
252 if (!this.delay || !this.delay.hide) {
257 this.timeout = setTimeout(function () {
258 if (_t.hoverState == 'out') {
265 * @param {Roo.Element|string|false} - element to align and point to.
267 show : function (on_el)
270 on_el = on_el || false; // default to false
272 if (this.parent() && (this.over == 'parent' || (this.over === false))) {
273 on_el = this.parent().el;
274 } else if (this.over) {
281 this.render(document.body);
285 this.el.removeClass([
286 'fade','top','bottom', 'left', 'right','in',
287 'bs-popover-top','bs-popover-bottom', 'bs-popover-left', 'bs-popover-right'
290 if (this.title === false) {
291 this.headerEl.hide();
295 var placement = typeof this.placement == 'function' ?
296 this.placement.call(this, this.el, on_el) :
300 var autoToken = /\s?auto?\s?/i; /// not sure how this was supposed to work? right auto ? what?
302 // I think 'auto right' - but
304 var autoPlace = autoToken.test(placement);
306 placement = placement.replace(autoToken, '') || 'top';
312 this.el.dom.style.display='block';
314 //this.el.appendTo(on_el);
316 var p = this.getPosition();
317 var box = this.el.getBox();
320 var align = Roo.bootstrap.Popover.alignment[placement];
321 this.el.addClass(align[2]);
326 this.el.alignTo(on_el, align[0],align[1]);
328 // this is usually just done by the builder = to show the popoup in the middle of the scren.
329 var es = this.el.getSize();
330 var x = Roo.lib.Dom.getViewWidth()/2;
331 var y = Roo.lib.Dom.getViewHeight()/2;
332 this.el.setXY([ x-(es.width/2), y-(es.height/2)] );
337 //var arrow = this.el.select('.arrow',true).first();
338 //arrow.set(align[2],
340 this.el.addClass('in');
343 if (this.el.hasClass('fade')) {
347 this.hoverState = 'in';
350 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
351 this.maskEl.setStyle('z-index', Roo.bootstrap.Popover.zIndex++);
352 this.maskEl.dom.style.display = 'block';
353 this.maskEl.addClass('show');
355 this.el.setStyle('z-index', Roo.bootstrap.Popover.zIndex++);
359 this.fireEvent('show', this);
364 this.el.setXY([0,0]);
365 this.el.removeClass('in');
367 this.hoverState = null;
368 this.maskEl.hide(); // always..
369 this.fireEvent('hide', this);
375 Roo.apply(Roo.bootstrap.Popover, {
378 'left' : ['r-l', [-10,0], 'left bs-popover-left'],
379 'right' : ['l-br', [10,0], 'right bs-popover-right'],
380 'bottom' : ['t-b', [0,10], 'top bs-popover-top'],
381 'top' : [ 'b-t', [0,-10], 'bottom bs-popover-bottom']
389 onMouseDown : function(e)
391 if (!e.getTarget(".roo-popover")) {
399 register : function(popup)
401 if (!Roo.bootstrap.Popover.clickHandler) {
402 Roo.bootstrap.Popover.clickHandler = Roo.get(document).on("mousedown", Roo.bootstrap.Popover.onMouseDown, Roo.bootstrap.Popover);
404 // hide other popups.
406 this.popups.push(popup);
410 this.popups.forEach(function(p) {