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} placement how it is placed
15 * @cfg {String} trigger click || hover (or false to trigger manually)
16 * @cfg {String} over what (parent or false to trigger manually.)
19 * Create a new Popover
20 * @param {Object} config The config object
23 Roo.bootstrap.Popover = function(config){
24 Roo.bootstrap.Popover.superclass.constructor.call(this, config);
27 Roo.extend(Roo.bootstrap.Popover, Roo.bootstrap.Component, {
29 title: 'Fill in a title',
33 trigger : 'hover', // hover
37 can_build_overlaid : false,
39 getChildContainer : function()
41 return this.el.select('.popover-content',true).first();
44 getAutoCreate : function(){
45 Roo.log('make popover?');
47 cls : 'popover roo-dynamic',
48 style: 'display:block',
54 cls : 'popover-inner',
62 cls : 'popover-content',
73 setTitle: function(str)
75 this.el.select('.popover-title',true).first().dom.innerHTML = str;
77 setContent: function(str)
79 this.el.select('.popover-content',true).first().dom.innerHTML = str;
81 // as it get's added to the bottom of the page.
82 onRender : function(ct, position)
84 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
86 var cfg = Roo.apply({}, this.getAutoCreate());
90 cfg.cls += ' ' + this.cls;
93 cfg.style = this.style;
96 this.el = Roo.get(document.body).createChild(cfg, position);
102 initEvents : function()
104 this.el.select('.popover-title',true).setVisibilityMode(Roo.Element.DISPLAY);
105 this.el.enableDisplayMode('block');
107 if (this.over === false) {
110 if (this.triggers === false) {
113 var on_el = (this.over == 'parent') ? this.parent().el : Roo.get(this.over);
114 var triggers = this.trigger ? this.trigger.split(' ') : [];
115 Roo.each(triggers, function(trigger) {
117 if (trigger == 'click') {
118 on_el.on('click', this.toggle, this);
119 } else if (trigger != 'manual') {
120 var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin'
121 var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout'
123 on_el.on(eventIn ,this.enter, this);
124 on_el.on(eventOut, this.leave, this);
135 toggle : function () {
136 this.hoverState == 'in' ? this.leave() : this.enter();
139 enter : function () {
142 clearTimeout(this.timeout);
144 this.hoverState = 'in'
146 if (!this.delay || !this.delay.show) {
151 this.timeout = setTimeout(function () {
152 if (_t.hoverState == 'in') {
158 clearTimeout(this.timeout);
160 this.hoverState = 'out'
162 if (!this.delay || !this.delay.hide) {
167 this.timeout = setTimeout(function () {
168 if (_t.hoverState == 'out') {
174 show : function (on_el)
177 on_el= (this.over == 'parent') ? this.parent().el : Roo.get(this.over);
180 this.el.select('.popover-title',true).first().dom.innerHtml = this.title;
181 if (this.html !== false) {
182 this.el.select('.popover-content',true).first().dom.innerHtml = this.title;
184 this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
185 if (!this.title.length) {
186 this.el.select('.popover-title',true).hide();
189 var placement = typeof this.placement == 'function' ?
190 this.placement.call(this, this.el, on_el) :
193 var autoToken = /\s?auto?\s?/i;
194 var autoPlace = autoToken.test(placement);
196 placement = placement.replace(autoToken, '') || 'top';
200 //this.el.setXY([0,0]);
202 this.el.dom.style.display='block';
203 this.el.addClass(placement);
205 //this.el.appendTo(on_el);
207 var p = this.getPosition();
208 var box = this.el.getBox();
213 var align = Roo.bootstrap.Popover.alignment[placement]
214 this.el.alignTo(on_el, align[0],align[1]);
215 //var arrow = this.el.select('.arrow',true).first();
216 //arrow.set(align[2],
218 this.el.addClass('in');
219 this.hoverState = null;
221 if (this.el.hasClass('fade')) {
228 this.el.setXY([0,0]);
229 this.el.removeClass('in');
236 Roo.bootstrap.Popover.alignment = {
237 'left' : ['r-l', [-10,0], 'right'],
238 'right' : ['l-r', [10,0], 'left'],
239 'bottom' : ['t-b', [0,10], 'top'],
240 'top' : [ 'b-t', [0,-10], 'bottom']