9 * @class Roo.bootstrap.Popover
10 * @extends Roo.bootstrap.Component
11 * Bootstrap Element 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 this.el.select('.popover-title',true).setVisibilityMode(Roo.Element.DISPLAY);
95 this.el.enableDisplayMode('block');
97 if (this.over === false) {
100 if (this.triggers === false) {
103 var on_el = (this.over == 'parent') ? this.parent().el : Roo.get(this.over);
104 var triggers = this.trigger.split(' ');
105 Roo.each(triggers, function(trigger) {
107 if (trigger == 'click') {
108 on_el.on('click', this.toggle, this);
109 } else if (trigger != 'manual') {
110 var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin'
111 var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout'
113 on_el.on(eventIn ,this.enter, this);
114 on_el.on(eventOut, this.leave, this);
125 toggle : function () {
126 this.hoverState == 'in' ? this.leave() : this.enter();
129 enter : function () {
132 clearTimeout(this.timeout);
134 this.hoverState = 'in'
136 if (!this.delay || !this.delay.show) {
141 this.timeout = setTimeout(function () {
142 if (_t.hoverState == 'in') {
148 clearTimeout(this.timeout);
150 this.hoverState = 'out'
152 if (!this.delay || !this.delay.hide) {
157 this.timeout = setTimeout(function () {
158 if (_t.hoverState == 'out') {
164 show : function (on_el)
167 on_el= (this.over == 'parent') ? this.parent().el : Roo.get(this.over);
170 this.el.select('.popover-title',true).first().dom.innerHtml = this.title;
171 if (this.html !== false) {
172 this.el.select('.popover-content',true).first().dom.innerHtml = this.title;
174 this.el.removeClass('fade top bottom left right in');
175 if (!this.title.length) {
176 this.el.select('.popover-title',true).hide();
179 var placement = typeof this.placement == 'function' ?
180 this.placement.call(this, this.el, on_el) :
183 var autoToken = /\s?auto?\s?/i;
184 var autoPlace = autoToken.test(placement);
186 placement = placement.replace(autoToken, '') || 'top';
190 //this.el.setXY([0,0]);
192 this.el.dom.style.display='block';
193 this.el.addClass(placement);
195 //this.el.appendTo(on_el);
197 var p = this.getPosition();
198 var box = this.el.getBox();
203 var align = Roo.bootstrap.Popover.alignment[placement]
204 this.el.alignTo(on_el, align[0],align[1]);
205 var arrow = this.el.select('.arrow').first();
206 //arrow.set(align[2],
208 this.el.addClass('in');
209 this.hoverState = null;
211 if (this.el.hasClass('fade')) {
218 this.el.setXY([0,0]);
219 this.el.removeClass('in');
225 Roo.bootstrap.Popover.alignment = {
226 'left' : ['r-l', [-10,0], 'right'],
227 'right' : ['l-r', [10,0], 'left'],
228 'bottom' : ['t-b', [0,10], 'top'],
229 'top' : [ 'b-t', [0,-10], 'bottom']