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.el.select('.popover-content',true).first();
70 getAutoCreate : function(){
73 cls : 'popover roo-dynamic shadow roo-popover',
74 style: 'display:block',
80 cls : 'popover-inner ',
84 cls: 'popover-title popover-header',
85 html : this.title || ''
88 cls : 'popover-content popover-body' + this.cls,
89 html : this.html || ''
100 * @param {string} the title
102 setTitle: function(str)
106 this.el.select('.popover-title',true).first().dom.innerHTML = str;
111 * @param {string} the body content
113 setContent: function(str)
117 this.el.select('.popover-content',true).first().dom.innerHTML = str;
121 // as it get's added to the bottom of the page.
122 onRender : function(ct, position)
124 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
126 var cfg = Roo.apply({}, this.getAutoCreate());
130 cfg.cls += ' ' + this.cls;
133 cfg.style = this.style;
135 //Roo.log("adding to ");
136 this.el = Roo.get(document.body).createChild(cfg, position);
141 if(typeof(this.items) != 'undefined'){
142 var items = this.items;
145 for(var i =0;i < items.length;i++) {
146 nitems.push(this.addxtype(Roo.apply({}, items[i])));
152 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
159 initEvents : function()
162 Roo.bootstrap.Popover.register(this);
163 this.el.select('.popover-title',true).setVisibilityMode(Roo.Element.DISPLAY);
164 this.el.enableDisplayMode('block');
166 if (this.over === false && !this.parent()) {
169 if (this.triggers === false) {
174 var on_el = (this.over == 'parent' || this.over === false) ? this.parent().el : Roo.get(this.over);
175 var triggers = this.trigger ? this.trigger.split(' ') : [];
176 Roo.each(triggers, function(trigger) {
178 if (trigger == 'click') {
179 on_el.on('click', this.toggle, this);
180 } else if (trigger != 'manual') {
181 var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin';
182 var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout';
184 on_el.on(eventIn ,this.enter, this);
185 on_el.on(eventOut, this.leave, this);
196 toggle : function () {
197 this.hoverState == 'in' ? this.leave() : this.enter();
200 enter : function () {
202 clearTimeout(this.timeout);
204 this.hoverState = 'in';
206 if (!this.delay || !this.delay.show) {
211 this.timeout = setTimeout(function () {
212 if (_t.hoverState == 'in') {
219 clearTimeout(this.timeout);
221 this.hoverState = 'out';
223 if (!this.delay || !this.delay.hide) {
228 this.timeout = setTimeout(function () {
229 if (_t.hoverState == 'out') {
236 * @param {Roo.Element|string|false} - element to align and point to.
238 show : function (on_el)
241 on_el = on_el || false; // default to false
243 if (this.parent() && (this.over == 'parent' || (this.over === false))) {
244 on_el = this.parent().el;
245 } else if (this.over) {
252 this.render(document.body);
256 this.el.removeClass([
257 'fade','top','bottom', 'left', 'right','in',
258 'bs-popover-top','bs-popover-bottom', 'bs-popover-left', 'bs-popover-right'
261 if (!this.title.length) {
262 this.el.select('.popover-title',true).hide();
266 var placement = typeof this.placement == 'function' ?
267 this.placement.call(this, this.el, on_el) :
271 var autoToken = /\s?auto?\s?/i; /// not sure how this was supposed to work? right auto ? what?
273 // I think 'auto right' - but
275 var autoPlace = autoToken.test(placement);
277 placement = placement.replace(autoToken, '') || 'top';
283 this.el.dom.style.display='block';
285 //this.el.appendTo(on_el);
287 var p = this.getPosition();
288 var box = this.el.getBox();
291 var align = Roo.bootstrap.Popover.alignment[placement];
292 this.el.addClass(align[2]);
297 this.el.alignTo(on_el, align[0],align[1]);
299 // this is usually just done by the builder = to show the popoup in the middle of the scren.
300 var es = this.el.getSize();
301 var x = Roo.lib.Dom.getViewWidth()/2;
302 var y = Roo.lib.Dom.getViewHeight()/2;
303 this.el.setXY([ x-(es.width/2), y-(es.height/2)] );
308 //var arrow = this.el.select('.arrow',true).first();
309 //arrow.set(align[2],
311 this.el.addClass('in');
314 if (this.el.hasClass('fade')) {
318 this.hoverState = 'in';
320 this.fireEvent('show', this);
325 this.el.setXY([0,0]);
326 this.el.removeClass('in');
328 this.hoverState = null;
330 this.fireEvent('hide', this);
336 Roo.apply(Roo.bootstrap.Popover, {
339 'left' : ['r-l', [-10,0], 'left bs-popover-left'],
340 'right' : ['l-br', [10,0], 'right bs-popover-right'],
341 'bottom' : ['t-b', [0,10], 'top bs-popover-top'],
342 'top' : [ 'b-t', [0,-10], 'bottom bs-popover-bottom']
348 onMouseDown : function(e)
350 if (!e.getTarget(".roo-popover")) {
358 register : function(popup)
360 if (!Roo.bootstrap.Popover.clickHandler) {
361 Roo.bootstrap.Popover.clickHandler = Roo.get(document).on("mousedown", Roo.bootstrap.Popover.onMouseDown, Roo.bootstrap.Popover);
363 // hide other popups.
365 this.popups.push(popup);
369 this.popups.forEach(function(p) {