9 * @class Roo.bootstrap.Tooltip
10 * Bootstrap Tooltip class
11 * This is basic at present - all componets support it by default, however they should add tooltipEl() method
12 * to determine which dom element triggers the tooltip.
14 * It needs to add support for additional attributes like tooltip-position
18 * @param {Object} config The config object
21 Roo.bootstrap.Tooltip = function(config){
22 Roo.bootstrap.Tooltip.superclass.constructor.call(this, config);
25 Roo.apply(Roo.bootstrap.Tooltip, {
27 * @function init initialize tooltip monitoring.
32 currentRegion : false,
38 Roo.get(document).on('mouseover', this.enter ,this);
39 Roo.get(document).on('mouseout', this.leave, this);
42 this.currentTip = new Roo.bootstrap.Tooltip();
47 var dom = ev.getTarget();
49 //Roo.log(['enter',dom]);
50 var el = Roo.fly(dom);
53 //Roo.log(this.currentEl);
54 //Roo.log(this.currentEl.contains(dom));
55 if (this.currentEl == el) {
58 if (dom != this.currentEl.dom && this.currentEl.contains(dom)) {
66 if (this.currentTip.el) {
67 this.currentTip.el.hide(); // force hiding...
70 if (!el.attr('tooltip') && !el.select("[tooltip]").elements.length) { // parents who have tip?
74 this.currentTip.bind(el);
75 this.currentRegion = Roo.lib.Region.getRegion(dom);
76 this.currentTip.enter();
81 var dom = ev.getTarget();
82 //Roo.log(['leave',dom]);
83 if (!this.currentEl) {
88 if (dom != this.currentEl.dom) {
92 if (this.currentRegion.contains( new Roo.lib.Region( xy[1], xy[0] ,xy[1], xy[0] ))) {
95 // only activate leave if mouse cursor is outside... bounding box..
100 if (this.currentTip) {
101 this.currentTip.leave();
103 //Roo.log('clear currentEl');
104 this.currentEl = false;
109 'left' : ['r-l', [-2,0], 'right'],
110 'right' : ['l-r', [2,0], 'left'],
111 'bottom' : ['t-b', [0,2], 'top'],
112 'top' : [ 'b-t', [0,-2], 'bottom']
118 Roo.extend(Roo.bootstrap.Tooltip, Roo.bootstrap.Component, {
123 delay : null, // can be { show : 300 , hide: 500}
127 hoverState : null, //???
129 placement : 'bottom',
131 getAutoCreate : function(){
138 cls : 'tooltip-arrow'
141 cls : 'tooltip-inner'
154 enter : function () {
156 if (this.timeout != null) {
157 clearTimeout(this.timeout);
160 this.hoverState = 'in';
161 //Roo.log("enter - show");
162 if (!this.delay || !this.delay.show) {
167 this.timeout = setTimeout(function () {
168 if (_t.hoverState == 'in') {
175 clearTimeout(this.timeout);
177 this.hoverState = 'out';
178 if (!this.delay || !this.delay.hide) {
184 this.timeout = setTimeout(function () {
185 //Roo.log("leave - timeout");
187 if (_t.hoverState == 'out') {
189 Roo.bootstrap.Tooltip.currentEl = false;
197 this.render(document.body);
200 //Roo.log([this.bindEl, this.bindEl.attr('tooltip')]);
202 var tip = el.attr('tooltip') || el.select("[tooltip]").first().attr('tooltip');
204 this.el.select('.tooltip-inner',true).first().dom.innerHTML = tip
206 this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
208 var placement = typeof this.placement == 'function' ?
209 this.placement.call(this, this.el, on_el) :
212 var autoToken = /\s?auto?\s?/i;
213 var autoPlace = autoToken.test(placement);
215 placement = placement.replace(autoToken, '') || 'top';
219 //this.el.setXY([0,0]);
221 //this.el.dom.style.display='block';
222 this.el.addClass(placement);
224 //this.el.appendTo(on_el);
226 var p = this.getPosition();
227 var box = this.el.getBox();
232 var align = Roo.bootstrap.Tooltip.alignment[placement];
233 this.el.alignTo(this.bindEl, align[0],align[1]);
234 //var arrow = this.el.select('.arrow',true).first();
235 //arrow.set(align[2],
237 this.el.addClass('in fade');
238 this.hoverState = null;
240 if (this.el.hasClass('fade')) {
251 //this.el.setXY([0,0]);
252 this.el.removeClass('in');