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 getChildContainer : function()
65 return this.el.select('.popover-content',true).first();
68 getAutoCreate : function(){
71 cls : 'popover roo-dynamic shadow roo-popover',
72 style: 'display:block',
78 cls : 'popover-inner ',
82 cls: 'popover-title popover-header',
83 html : this.title || ''
86 cls : 'popover-content popover-body' + this.cls,
87 html : this.html || ''
98 * @param {string} the title
100 setTitle: function(str)
104 this.el.select('.popover-title',true).first().dom.innerHTML = str;
109 * @param {string} the body content
111 setContent: function(str)
115 this.el.select('.popover-content',true).first().dom.innerHTML = str;
119 // as it get's added to the bottom of the page.
120 onRender : function(ct, position)
122 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
124 var cfg = Roo.apply({}, this.getAutoCreate());
128 cfg.cls += ' ' + this.cls;
131 cfg.style = this.style;
133 //Roo.log("adding to ");
134 this.el = Roo.get(document.body).createChild(cfg, position);
139 if(typeof(this.items) != 'undefined'){
140 var items = this.items;
143 for(var i =0;i < items.length;i++) {
144 nitems.push(this.addxtype(Roo.apply({}, items[i])));
150 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
157 initEvents : function()
160 Roo.bootstrap.Popover.register(this);
161 this.el.select('.popover-title',true).setVisibilityMode(Roo.Element.DISPLAY);
162 this.el.enableDisplayMode('block');
164 if (this.over === false && !this.parent()) {
167 if (this.triggers === false) {
172 var on_el = (this.over == 'parent' || this.over === false) ? this.parent().el : Roo.get(this.over);
173 var triggers = this.trigger ? this.trigger.split(' ') : [];
174 Roo.each(triggers, function(trigger) {
176 if (trigger == 'click') {
177 on_el.on('click', this.toggle, this);
178 } else if (trigger != 'manual') {
179 var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin';
180 var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout';
182 on_el.on(eventIn ,this.enter, this);
183 on_el.on(eventOut, this.leave, this);
194 toggle : function () {
195 this.hoverState == 'in' ? this.leave() : this.enter();
198 enter : function () {
200 clearTimeout(this.timeout);
202 this.hoverState = 'in';
204 if (!this.delay || !this.delay.show) {
209 this.timeout = setTimeout(function () {
210 if (_t.hoverState == 'in') {
217 clearTimeout(this.timeout);
219 this.hoverState = 'out';
221 if (!this.delay || !this.delay.hide) {
226 this.timeout = setTimeout(function () {
227 if (_t.hoverState == 'out') {
234 * @param {Roo.Element|string|false} - element to align and point to.
236 show : function (on_el)
239 on_el = on_el || false; // default to false
241 if (this.parent() && (this.over == 'parent' || (this.over === false))) {
242 on_el = this.parent().el;
243 } else if (this.over) {
250 this.render(document.body);
254 this.el.removeClass([
255 'fade','top','bottom', 'left', 'right','in',
256 'bs-popover-top','bs-popover-bottom', 'bs-popover-left', 'bs-popover-right'
259 if (!this.title.length) {
260 this.el.select('.popover-title',true).hide();
264 var placement = typeof this.placement == 'function' ?
265 this.placement.call(this, this.el, on_el) :
269 var autoToken = /\s?auto?\s?/i; /// not sure how this was supposed to work? right auto ? what?
271 // I think 'auto right' - but
273 var autoPlace = autoToken.test(placement);
275 placement = placement.replace(autoToken, '') || 'top';
281 this.el.dom.style.display='block';
283 //this.el.appendTo(on_el);
285 var p = this.getPosition();
286 var box = this.el.getBox();
289 var align = Roo.bootstrap.Popover.alignment[placement];
290 this.el.addClass(align[2]);
295 this.el.alignTo(on_el, align[0],align[1]);
297 // this is usually just done by the builder = to show the popoup in the middle of the scren.
298 var es = this.el.getSize();
299 var x = Roo.lib.Dom.getViewWidth()/2;
300 var y = Roo.lib.Dom.getViewHeight()/2;
301 this.el.setXY([ x-(es.width/2), y-(es.height/2)] );
306 //var arrow = this.el.select('.arrow',true).first();
307 //arrow.set(align[2],
309 this.el.addClass('in');
312 if (this.el.hasClass('fade')) {
316 this.hoverState = 'in';
318 this.fireEvent('show', this);
323 this.el.setXY([0,0]);
324 this.el.removeClass('in');
326 this.hoverState = null;
328 this.fireEvent('hide', this);
334 Roo.apply(Roo.bootstrap.Popover, {
337 'left' : ['r-l', [-10,0], 'left bs-popover-left'],
338 'right' : ['l-br', [10,0], 'right bs-popover-right'],
339 'bottom' : ['t-b', [0,10], 'top bs-popover-top'],
340 'top' : [ 'b-t', [0,-10], 'bottom bs-popover-bottom']
346 onMouseDown : function(e)
348 if (!e.getTarget(".roo-popover")) {
356 register : function(popup)
358 if (!Roo.bootstrap.Popover.clickHandler) {
359 Roo.bootstrap.Popover.clickHandler = Roo.get(document).on("mousedown", Roo.bootstrap.Popover.onMouseDown, Roo.bootstrap.Popover);
361 // hide other popups.
363 this.popups.push(popup);
367 this.popups.forEach(function(p) {