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);
136 var cfg = Roo.apply({}, this.getAutoCreate());
140 cfg.cls += ' ' + this.cls;
143 cfg.style = this.style;
145 //Roo.log("adding to ");
146 this.el = Roo.get(document.body).createChild(cfg, position);
151 if(typeof(this.items) != 'undefined'){
152 var items = this.items;
155 for(var i =0;i < items.length;i++) {
156 nitems.push(this.addxtype(Roo.apply({}, items[i])));
162 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
163 Roo.EventManager.onWindowResize(this.resizeMask, this, true);
166 this.contentEl = this.el.select('.popover-content',true).first();
167 this.headerEl = this.el.select('.popover-title',true).first();
172 resizeMask : function()
175 Roo.lib.Dom.getViewWidth(true),
176 Roo.lib.Dom.getViewHeight(true)
180 initEvents : function()
184 Roo.bootstrap.Popover.register(this);
188 this.headerEl.setVisibilityMode(Roo.Element.DISPLAY); // probably not needed as it's default in BS4
189 this.el.enableDisplayMode('block');
191 if (this.over === false && !this.parent()) {
194 if (this.triggers === false) {
199 var on_el = (this.over == 'parent' || this.over === false) ? this.parent().el : Roo.get(this.over);
200 var triggers = this.trigger ? this.trigger.split(' ') : [];
201 Roo.each(triggers, function(trigger) {
203 if (trigger == 'click') {
204 on_el.on('click', this.toggle, this);
205 } else if (trigger != 'manual') {
206 var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin';
207 var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout';
209 on_el.on(eventIn ,this.enter, this);
210 on_el.on(eventOut, this.leave, this);
221 toggle : function () {
222 this.hoverState == 'in' ? this.leave() : this.enter();
225 enter : function () {
227 clearTimeout(this.timeout);
229 this.hoverState = 'in';
231 if (!this.delay || !this.delay.show) {
236 this.timeout = setTimeout(function () {
237 if (_t.hoverState == 'in') {
244 clearTimeout(this.timeout);
246 this.hoverState = 'out';
248 if (!this.delay || !this.delay.hide) {
253 this.timeout = setTimeout(function () {
254 if (_t.hoverState == 'out') {
261 * @param {Roo.Element|string|false} - element to align and point to.
263 show : function (on_el)
266 on_el = on_el || false; // default to false
268 if (this.parent() && (this.over == 'parent' || (this.over === false))) {
269 on_el = this.parent().el;
270 } else if (this.over) {
277 this.render(document.body);
281 this.el.removeClass([
282 'fade','top','bottom', 'left', 'right','in',
283 'bs-popover-top','bs-popover-bottom', 'bs-popover-left', 'bs-popover-right'
286 if (this.title === false) {
287 this.headerEl.hide();
291 var placement = typeof this.placement == 'function' ?
292 this.placement.call(this, this.el, on_el) :
296 var autoToken = /\s?auto?\s?/i; /// not sure how this was supposed to work? right auto ? what?
298 // I think 'auto right' - but
300 var autoPlace = autoToken.test(placement);
302 placement = placement.replace(autoToken, '') || 'top';
308 this.el.dom.style.display='block';
310 //this.el.appendTo(on_el);
312 var p = this.getPosition();
313 var box = this.el.getBox();
316 var align = Roo.bootstrap.Popover.alignment[placement];
317 this.el.addClass(align[2]);
322 this.el.alignTo(on_el, align[0],align[1]);
324 // this is usually just done by the builder = to show the popoup in the middle of the scren.
325 var es = this.el.getSize();
326 var x = Roo.lib.Dom.getViewWidth()/2;
327 var y = Roo.lib.Dom.getViewHeight()/2;
328 this.el.setXY([ x-(es.width/2), y-(es.height/2)] );
333 //var arrow = this.el.select('.arrow',true).first();
334 //arrow.set(align[2],
336 this.el.addClass('in');
339 if (this.el.hasClass('fade')) {
343 this.hoverState = 'in';
346 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
347 this.maskEl.setStyle('z-index', Roo.bootstrap.Popover.zIndex++);
348 this.maskEl.dom.style.display = 'block';
349 this.maskEl.addClass('show');
351 this.el.setStyle('z-index', Roo.bootstrap.Popover.zIndex++);
355 this.fireEvent('show', this);
360 this.el.setXY([0,0]);
361 this.el.removeClass('in');
363 this.hoverState = null;
364 this.maskEl.hide(); // always..
365 this.fireEvent('hide', this);
371 Roo.apply(Roo.bootstrap.Popover, {
374 'left' : ['r-l', [-10,0], 'left bs-popover-left'],
375 'right' : ['l-br', [10,0], 'right bs-popover-right'],
376 'bottom' : ['t-b', [0,10], 'top bs-popover-top'],
377 'top' : [ 'b-t', [0,-10], 'bottom bs-popover-bottom']
385 onMouseDown : function(e)
387 if (!e.getTarget(".roo-popover")) {
395 register : function(popup)
397 if (!Roo.bootstrap.Popover.clickHandler) {
398 Roo.bootstrap.Popover.clickHandler = Roo.get(document).on("mousedown", Roo.bootstrap.Popover.onMouseDown, Roo.bootstrap.Popover);
400 // hide other popups.
402 this.popups.push(popup);
406 this.popups.forEach(function(p) {