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();
48 //Roo.log(['enter',dom]);
49 var el = Roo.fly(dom);
52 //Roo.log(this.currentEl);
53 //Roo.log(this.currentEl.contains(dom));
54 if (this.currentEl == el) {
57 if (dom != this.currentEl.dom && this.currentEl.contains(dom)) {
65 if (this.currentTip.el) {
66 this.currentTip.el.hide(); // force hiding...
69 if (!el.attr('tooltip')) { // parents who have tip?
73 this.currentTip.bind(el);
74 this.currentRegion = Roo.lib.Region.getRegion(dom);
75 this.currentTip.enter();
80 var dom = ev.getTarget();
81 //Roo.log(['leave',dom]);
82 if (!this.currentEl) {
87 if (dom != this.currentEl.dom) {
91 if (this.currentRegion.contains( new Roo.lib.Region( xy[1], xy[0] ,xy[1], xy[0] ))) {
94 // only activate leave if mouse cursor is outside... bounding box..
99 if (this.currentTip) {
100 this.currentTip.leave();
102 //Roo.log('clear currentEl');
103 this.currentEl = false;
108 'left' : ['r-l', [-2,0], 'right'],
109 'right' : ['l-r', [2,0], 'left'],
110 'bottom' : ['t-b', [0,2], 'top'],
111 'top' : [ 'b-t', [0,-2], 'bottom']
117 Roo.extend(Roo.bootstrap.Tooltip, Roo.bootstrap.Component, {
122 delay : null, // can be { show : 300 , hide: 500}
126 hoverState : null, //???
128 placement : 'bottom',
130 getAutoCreate : function(){
137 cls : 'tooltip-arrow'
140 cls : 'tooltip-inner'
153 enter : function () {
155 if (this.timeout != null) {
156 clearTimeout(this.timeout);
159 this.hoverState = 'in';
160 //Roo.log("enter - show");
161 if (!this.delay || !this.delay.show) {
166 this.timeout = setTimeout(function () {
167 if (_t.hoverState == 'in') {
174 clearTimeout(this.timeout);
176 this.hoverState = 'out';
177 if (!this.delay || !this.delay.hide) {
183 this.timeout = setTimeout(function () {
184 //Roo.log("leave - timeout");
186 if (_t.hoverState == 'out') {
188 Roo.bootstrap.Tooltip.currentEl = false;
196 this.render(document.body);
199 //Roo.log([this.bindEl, this.bindEl.attr('tooltip')]);
200 this.el.select('.tooltip-inner',true).first().dom.innerHTML = this.bindEl.attr('tooltip');
202 this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
204 var placement = typeof this.placement == 'function' ?
205 this.placement.call(this, this.el, on_el) :
208 var autoToken = /\s?auto?\s?/i;
209 var autoPlace = autoToken.test(placement);
211 placement = placement.replace(autoToken, '') || 'top';
215 //this.el.setXY([0,0]);
217 //this.el.dom.style.display='block';
218 this.el.addClass(placement);
220 //this.el.appendTo(on_el);
222 var p = this.getPosition();
223 var box = this.el.getBox();
228 var align = Roo.bootstrap.Tooltip.alignment[placement];
229 this.el.alignTo(this.bindEl, align[0],align[1]);
230 //var arrow = this.el.select('.arrow',true).first();
231 //arrow.set(align[2],
233 this.el.addClass('in fade');
234 this.hoverState = null;
236 if (this.el.hasClass('fade')) {
247 //this.el.setXY([0,0]);
248 this.el.removeClass('in');