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);
153 Roo.EventManager.onWindowResize(this.resizeMask, this, true);
159 resizeMask : function()
162 Roo.lib.Dom.getViewWidth(true),
163 Roo.lib.Dom.getViewHeight(true)
167 initEvents : function()
170 Roo.bootstrap.Popover.register(this);
171 this.el.select('.popover-title',true).setVisibilityMode(Roo.Element.DISPLAY);
172 this.el.enableDisplayMode('block');
174 if (this.over === false && !this.parent()) {
177 if (this.triggers === false) {
182 var on_el = (this.over == 'parent' || this.over === false) ? this.parent().el : Roo.get(this.over);
183 var triggers = this.trigger ? this.trigger.split(' ') : [];
184 Roo.each(triggers, function(trigger) {
186 if (trigger == 'click') {
187 on_el.on('click', this.toggle, this);
188 } else if (trigger != 'manual') {
189 var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin';
190 var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout';
192 on_el.on(eventIn ,this.enter, this);
193 on_el.on(eventOut, this.leave, this);
204 toggle : function () {
205 this.hoverState == 'in' ? this.leave() : this.enter();
208 enter : function () {
210 clearTimeout(this.timeout);
212 this.hoverState = 'in';
214 if (!this.delay || !this.delay.show) {
219 this.timeout = setTimeout(function () {
220 if (_t.hoverState == 'in') {
227 clearTimeout(this.timeout);
229 this.hoverState = 'out';
231 if (!this.delay || !this.delay.hide) {
236 this.timeout = setTimeout(function () {
237 if (_t.hoverState == 'out') {
244 * @param {Roo.Element|string|false} - element to align and point to.
246 show : function (on_el)
249 on_el = on_el || false; // default to false
251 if (this.parent() && (this.over == 'parent' || (this.over === false))) {
252 on_el = this.parent().el;
253 } else if (this.over) {
260 this.render(document.body);
264 this.el.removeClass([
265 'fade','top','bottom', 'left', 'right','in',
266 'bs-popover-top','bs-popover-bottom', 'bs-popover-left', 'bs-popover-right'
269 if (!this.title.length) {
270 this.el.select('.popover-title',true).hide();
274 var placement = typeof this.placement == 'function' ?
275 this.placement.call(this, this.el, on_el) :
279 var autoToken = /\s?auto?\s?/i; /// not sure how this was supposed to work? right auto ? what?
281 // I think 'auto right' - but
283 var autoPlace = autoToken.test(placement);
285 placement = placement.replace(autoToken, '') || 'top';
291 this.el.dom.style.display='block';
293 //this.el.appendTo(on_el);
295 var p = this.getPosition();
296 var box = this.el.getBox();
299 var align = Roo.bootstrap.Popover.alignment[placement];
300 this.el.addClass(align[2]);
305 this.el.alignTo(on_el, align[0],align[1]);
307 // this is usually just done by the builder = to show the popoup in the middle of the scren.
308 var es = this.el.getSize();
309 var x = Roo.lib.Dom.getViewWidth()/2;
310 var y = Roo.lib.Dom.getViewHeight()/2;
311 this.el.setXY([ x-(es.width/2), y-(es.height/2)] );
316 //var arrow = this.el.select('.arrow',true).first();
317 //arrow.set(align[2],
319 this.el.addClass('in');
322 if (this.el.hasClass('fade')) {
326 this.hoverState = 'in';
329 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
330 this.maskEl.setStyle('z-index', Roo.bootstrap.Popover.zIndex++);
331 this.maskEl.dom.style.display = 'block';
332 this.maskEl.addClass('show');
337 this.fireEvent('show', this);
342 this.el.setXY([0,0]);
343 this.el.removeClass('in');
345 this.hoverState = null;
347 this.fireEvent('hide', this);
353 Roo.apply(Roo.bootstrap.Popover, {
356 'left' : ['r-l', [-10,0], 'left bs-popover-left'],
357 'right' : ['l-br', [10,0], 'right bs-popover-right'],
358 'bottom' : ['t-b', [0,10], 'top bs-popover-top'],
359 'top' : [ 'b-t', [0,-10], 'bottom bs-popover-bottom']
367 onMouseDown : function(e)
369 if (!e.getTarget(".roo-popover")) {
377 register : function(popup)
379 if (!Roo.bootstrap.Popover.clickHandler) {
380 Roo.bootstrap.Popover.clickHandler = Roo.get(document).on("mousedown", Roo.bootstrap.Popover.onMouseDown, Roo.bootstrap.Popover);
382 // hide other popups.
384 this.popups.push(popup);
388 this.popups.forEach(function(p) {