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 getChildContainer : function()
39 return this.el.select('.popover-content',true).first();
42 getAutoCreate : function(){
43 Roo.log('make popover?');
46 style: 'display:block',
52 cls : 'popover-inner',
60 cls : 'popover-content',
71 // as it get's added to the bottom of the page.
72 onRender : function(ct, position)
74 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
76 var cfg = Roo.apply({}, this.getAutoCreate());
80 cfg.cls += ' ' + this.cls;
83 cfg.style = this.style;
86 this.el = Roo.get(document.body).createChild(cfg, position);
92 initEvents : function()
94 Roo.log('init Popover');
95 this.el.select('.popover-title',true).setVisibilityMode(Roo.Element.DISPLAY);
96 this.el.enableDisplayMode('block');
98 if (this.over === false) {
101 if (this.triggers === false) {
104 var on_el = (this.over == 'parent') ? this.parent().el : Roo.get(this.over);
105 var triggers = this.trigger ? this.trigger.split(' ') : [];
106 Roo.each(triggers, function(trigger) {
108 if (trigger == 'click') {
109 on_el.on('click', this.toggle, this);
110 } else if (trigger != 'manual') {
111 var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin'
112 var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout'
114 on_el.on(eventIn ,this.enter, this);
115 on_el.on(eventOut, this.leave, this);
126 toggle : function () {
127 this.hoverState == 'in' ? this.leave() : this.enter();
130 enter : function () {
133 clearTimeout(this.timeout);
135 this.hoverState = 'in'
137 if (!this.delay || !this.delay.show) {
142 this.timeout = setTimeout(function () {
143 if (_t.hoverState == 'in') {
149 clearTimeout(this.timeout);
151 this.hoverState = 'out'
153 if (!this.delay || !this.delay.hide) {
158 this.timeout = setTimeout(function () {
159 if (_t.hoverState == 'out') {
165 show : function (on_el)
167 Roo.log('Popover show');
169 on_el= (this.over == 'parent') ? this.parent().el : Roo.get(this.over);
172 this.el.select('.popover-title',true).first().dom.innerHtml = this.title;
173 if (this.html !== false) {
174 this.el.select('.popover-content',true).first().dom.innerHtml = this.title;
176 this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
177 if (!this.title.length) {
178 this.el.select('.popover-title',true).hide();
181 var placement = typeof this.placement == 'function' ?
182 this.placement.call(this, this.el, on_el) :
185 var autoToken = /\s?auto?\s?/i;
186 var autoPlace = autoToken.test(placement);
188 placement = placement.replace(autoToken, '') || 'top';
192 //this.el.setXY([0,0]);
194 this.el.dom.style.display='block';
195 this.el.addClass(placement);
197 //this.el.appendTo(on_el);
199 var p = this.getPosition();
200 var box = this.el.getBox();
205 var align = Roo.bootstrap.Popover.alignment[placement]
206 this.el.alignTo(on_el, align[0],align[1]);
207 //var arrow = this.el.select('.arrow',true).first();
208 //arrow.set(align[2],
210 this.el.addClass('in');
211 this.hoverState = null;
213 if (this.el.hasClass('fade')) {
220 this.el.setXY([0,0]);
221 this.el.removeClass('in');
228 Roo.bootstrap.Popover.alignment = {
229 'left' : ['r-l', [-10,0], 'right'],
230 'right' : ['l-r', [10,0], 'left'],
231 'bottom' : ['t-b', [0,10], 'top'],
232 'top' : [ 'b-t', [0,-10], 'bottom']