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()
79 getAutoCreate : function(){
82 cls : 'popover roo-dynamic shadow roo-popover' + (this.modal ? '-modal' : ''),
83 style: 'display:block',
89 cls : 'popover-inner ',
93 cls: 'popover-title popover-header',
94 html : this.title || ''
97 cls : 'popover-content popover-body' + this.cls,
98 html : this.html || ''
109 * @param {string} the title
111 setTitle: function(str)
115 this.headerEl.dom.innerHTML = str;
120 * @param {string} the body content
122 setContent: function(str)
125 if (this.contentEl) {
126 this.contentEl.dom.innerHTML = str;
130 // as it get's added to the bottom of the page.
131 onRender : function(ct, position)
133 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
135 var cfg = Roo.apply({}, this.getAutoCreate());
139 cfg.cls += ' ' + this.cls;
142 cfg.style = this.style;
144 //Roo.log("adding to ");
145 this.el = Roo.get(document.body).createChild(cfg, position);
150 if(typeof(this.items) != 'undefined'){
151 var items = this.items;
154 for(var i =0;i < items.length;i++) {
155 nitems.push(this.addxtype(Roo.apply({}, items[i])));
161 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
162 Roo.EventManager.onWindowResize(this.resizeMask, this, true);
165 this.contentEl = this.el.select('.popover-content',true).first();
166 this.headerEl = this.el.select('.popover-header',true).first();
171 resizeMask : function()
174 Roo.lib.Dom.getViewWidth(true),
175 Roo.lib.Dom.getViewHeight(true)
179 initEvents : function()
183 Roo.bootstrap.Popover.register(this);
187 this.headerEl.setVisibilityMode(Roo.Element.DISPLAY); // probably not needed as it's default in BS4
188 this.el.enableDisplayMode('block');
190 if (this.over === false && !this.parent()) {
193 if (this.triggers === false) {
198 var on_el = (this.over == 'parent' || this.over === false) ? this.parent().el : Roo.get(this.over);
199 var triggers = this.trigger ? this.trigger.split(' ') : [];
200 Roo.each(triggers, function(trigger) {
202 if (trigger == 'click') {
203 on_el.on('click', this.toggle, this);
204 } else if (trigger != 'manual') {
205 var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin';
206 var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout';
208 on_el.on(eventIn ,this.enter, this);
209 on_el.on(eventOut, this.leave, this);
220 toggle : function () {
221 this.hoverState == 'in' ? this.leave() : this.enter();
224 enter : function () {
226 clearTimeout(this.timeout);
228 this.hoverState = 'in';
230 if (!this.delay || !this.delay.show) {
235 this.timeout = setTimeout(function () {
236 if (_t.hoverState == 'in') {
243 clearTimeout(this.timeout);
245 this.hoverState = 'out';
247 if (!this.delay || !this.delay.hide) {
252 this.timeout = setTimeout(function () {
253 if (_t.hoverState == 'out') {
260 * @param {Roo.Element|string|false} - element to align and point to.
262 show : function (on_el)
265 on_el = on_el || false; // default to false
267 if (this.parent() && (this.over == 'parent' || (this.over === false))) {
268 on_el = this.parent().el;
269 } else if (this.over) {
276 this.render(document.body);
280 this.el.removeClass([
281 'fade','top','bottom', 'left', 'right','in',
282 'bs-popover-top','bs-popover-bottom', 'bs-popover-left', 'bs-popover-right'
285 if (!this.title.length) {
286 this.headerEl.hide();
290 var placement = typeof this.placement == 'function' ?
291 this.placement.call(this, this.el, on_el) :
295 var autoToken = /\s?auto?\s?/i; /// not sure how this was supposed to work? right auto ? what?
297 // I think 'auto right' - but
299 var autoPlace = autoToken.test(placement);
301 placement = placement.replace(autoToken, '') || 'top';
307 this.el.dom.style.display='block';
309 //this.el.appendTo(on_el);
311 var p = this.getPosition();
312 var box = this.el.getBox();
315 var align = Roo.bootstrap.Popover.alignment[placement];
316 this.el.addClass(align[2]);
321 this.el.alignTo(on_el, align[0],align[1]);
323 // this is usually just done by the builder = to show the popoup in the middle of the scren.
324 var es = this.el.getSize();
325 var x = Roo.lib.Dom.getViewWidth()/2;
326 var y = Roo.lib.Dom.getViewHeight()/2;
327 this.el.setXY([ x-(es.width/2), y-(es.height/2)] );
332 //var arrow = this.el.select('.arrow',true).first();
333 //arrow.set(align[2],
335 this.el.addClass('in');
338 if (this.el.hasClass('fade')) {
342 this.hoverState = 'in';
345 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
346 this.maskEl.setStyle('z-index', Roo.bootstrap.Popover.zIndex++);
347 this.maskEl.dom.style.display = 'block';
348 this.maskEl.addClass('show');
350 this.el.setStyle('z-index', Roo.bootstrap.Popover.zIndex++);
354 this.fireEvent('show', this);
359 this.el.setXY([0,0]);
360 this.el.removeClass('in');
362 this.hoverState = null;
363 this.maskEl.hide(); // always..
364 this.fireEvent('hide', this);
370 Roo.apply(Roo.bootstrap.Popover, {
373 'left' : ['r-l', [-10,0], 'left bs-popover-left'],
374 'right' : ['l-br', [10,0], 'right bs-popover-right'],
375 'bottom' : ['t-b', [0,10], 'top bs-popover-top'],
376 'top' : [ 'b-t', [0,-10], 'bottom bs-popover-bottom']
384 onMouseDown : function(e)
386 if (!e.getTarget(".roo-popover")) {
394 register : function(popup)
396 if (!Roo.bootstrap.Popover.clickHandler) {
397 Roo.bootstrap.Popover.clickHandler = Roo.get(document).on("mousedown", Roo.bootstrap.Popover.onMouseDown, Roo.bootstrap.Popover);
399 // hide other popups.
401 this.popups.push(popup);
405 this.popups.forEach(function(p) {