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);
117 var triggers = this.trigger ? this.trigger.split(' ') : [];
118 Roo.each(triggers, function(trigger) {
120 if (trigger == 'click') {
121 on_el.on('click', this.toggle, this);
122 } else if (trigger != 'manual') {
123 var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin';
124 var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout';
126 on_el.on(eventIn ,this.enter, this);
127 on_el.on(eventOut, this.leave, this);
138 toggle : function () {
140 Roo.log(this.hoverState);
141 this.hoverState == 'in' ? this.leave() : this.enter();
144 enter : function () {
146 clearTimeout(this.timeout);
149 Roo.log(this.hoverState);
150 this.hoverState = 'in';
152 Roo.log(this.hoverState);
153 if (!this.delay || !this.delay.show) {
158 this.timeout = setTimeout(function () {
159 if (_t.hoverState == 'in') {
165 clearTimeout(this.timeout);
167 this.hoverState = 'out';
169 if (!this.delay || !this.delay.hide) {
174 this.timeout = setTimeout(function () {
175 if (_t.hoverState == 'out') {
181 show : function (on_el)
184 on_el= (this.over == 'parent') ? this.parent().el : Roo.get(this.over);
187 this.el.select('.popover-title',true).first().dom.innerHtml = this.title;
188 if (this.html !== false) {
189 this.el.select('.popover-content',true).first().dom.innerHtml = this.title;
191 this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
192 if (!this.title.length) {
193 this.el.select('.popover-title',true).hide();
196 var placement = typeof this.placement == 'function' ?
197 this.placement.call(this, this.el, on_el) :
200 var autoToken = /\s?auto?\s?/i;
201 var autoPlace = autoToken.test(placement);
203 placement = placement.replace(autoToken, '') || 'top';
207 //this.el.setXY([0,0]);
209 this.el.dom.style.display='block';
210 this.el.addClass(placement);
212 //this.el.appendTo(on_el);
214 var p = this.getPosition();
215 var box = this.el.getBox();
220 var align = Roo.bootstrap.Popover.alignment[placement];
221 this.el.alignTo(on_el, align[0],align[1]);
222 //var arrow = this.el.select('.arrow',true).first();
223 //arrow.set(align[2],
225 this.el.addClass('in');
226 this.hoverState = null;
228 if (this.el.hasClass('fade')) {
235 this.el.setXY([0,0]);
236 this.el.removeClass('in');
243 Roo.bootstrap.Popover.alignment = {
244 'left' : ['r-l', [-10,0], 'right'],
245 'right' : ['l-r', [10,0], 'left'],
246 'bottom' : ['t-b', [0,10], 'top'],
247 'top' : [ 'b-t', [0,-10], 'bottom']