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.)
17 * @cfg {Number} delay - delay before showing
20 * Create a new Popover
21 * @param {Object} config The config object
24 Roo.bootstrap.Popover = function(config){
25 Roo.bootstrap.Popover.superclass.constructor.call(this, config);
28 Roo.extend(Roo.bootstrap.Popover, Roo.bootstrap.Component, {
30 title: 'Fill in a title',
34 trigger : 'hover', // hover
40 can_build_overlaid : false,
42 getChildContainer : function()
44 return this.el.select('.popover-content',true).first();
47 getAutoCreate : function(){
48 Roo.log('make popover?');
50 cls : 'popover roo-dynamic',
51 style: 'display:block',
57 cls : 'popover-inner',
65 cls : 'popover-content',
76 setTitle: function(str)
78 this.el.select('.popover-title',true).first().dom.innerHTML = str;
80 setContent: function(str)
82 this.el.select('.popover-content',true).first().dom.innerHTML = str;
84 // as it get's added to the bottom of the page.
85 onRender : function(ct, position)
87 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
89 var cfg = Roo.apply({}, this.getAutoCreate());
93 cfg.cls += ' ' + this.cls;
96 cfg.style = this.style;
99 this.el = Roo.get(document.body).createChild(cfg, position);
105 initEvents : function()
107 this.el.select('.popover-title',true).setVisibilityMode(Roo.Element.DISPLAY);
108 this.el.enableDisplayMode('block');
110 if (this.over === false) {
113 if (this.triggers === false) {
116 var on_el = (this.over == 'parent') ? this.parent().el : Roo.get(this.over);
118 var triggers = this.trigger ? this.trigger.split(' ') : [];
120 Roo.each(triggers, function(trigger) {
122 if (trigger == 'click') {
123 on_el.on('click', this.toggle, this);
124 } else if (trigger != 'manual') {
125 var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin';
126 var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout';
128 on_el.on(eventIn ,this.enter, this);
129 on_el.on(eventOut, this.leave, this);
140 toggle : function () {
141 Roo.log(this.hoverState);
142 this.hoverState == 'in' ? this.leave() : this.enter();
145 enter : function () {
148 clearTimeout(this.timeout);
150 this.hoverState = 'in';
152 if (!this.delay || !this.delay.show) {
157 this.timeout = setTimeout(function () {
158 if (_t.hoverState == 'in') {
164 clearTimeout(this.timeout);
166 this.hoverState = 'out';
168 if (!this.delay || !this.delay.hide) {
173 this.timeout = setTimeout(function () {
174 if (_t.hoverState == 'out') {
180 show : function (on_el)
183 on_el= (this.over == 'parent') ? this.parent().el : Roo.get(this.over);
186 this.el.select('.popover-title',true).first().dom.innerHtml = this.title;
187 if (this.html !== false) {
188 this.el.select('.popover-content',true).first().dom.innerHtml = this.title;
190 this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
191 if (!this.title.length) {
192 this.el.select('.popover-title',true).hide();
195 var placement = typeof this.placement == 'function' ?
196 this.placement.call(this, this.el, on_el) :
199 var autoToken = /\s?auto?\s?/i;
200 var autoPlace = autoToken.test(placement);
202 placement = placement.replace(autoToken, '') || 'top';
206 //this.el.setXY([0,0]);
208 this.el.dom.style.display='block';
209 this.el.addClass(placement);
211 //this.el.appendTo(on_el);
213 var p = this.getPosition();
214 var box = this.el.getBox();
219 var align = Roo.bootstrap.Popover.alignment[placement];
220 this.el.alignTo(on_el, align[0],align[1]);
221 //var arrow = this.el.select('.arrow',true).first();
222 //arrow.set(align[2],
224 this.el.addClass('in');
225 this.hoverState = null;
227 if (this.el.hasClass('fade')) {
234 this.el.setXY([0,0]);
235 this.el.removeClass('in');
242 Roo.bootstrap.Popover.alignment = {
243 'left' : ['r-l', [-10,0], 'right'],
244 'right' : ['l-r', [10,0], 'left'],
245 'bottom' : ['t-b', [0,10], 'top'],
246 'top' : [ 'b-t', [0,-10], 'bottom']