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...
72 // you can not look for children, as if el is the body.. then everythign is the child..
73 if (!el.attr('tooltip')) { //
74 if (!el.select("[tooltip]").elements.length) {
77 // is the mouse over this child...?
78 bindEl = el.select("[tooltip]").first();
80 if (!bindEl.getRegion().contains( { top : xy[1] ,right : xy[0] , bottom : xy[1], left : xy[0]})) {
81 //Roo.log("not in region.");
84 //Roo.log("child element over..");
87 this.currentEl = bindEl;
88 this.currentTip.bind(bindEl);
89 this.currentRegion = Roo.lib.Region.getRegion(dom);
90 this.currentTip.enter();
95 var dom = ev.getTarget();
96 //Roo.log(['leave',dom]);
97 if (!this.currentEl) {
102 if (dom != this.currentEl.dom) {
106 if (this.currentRegion.contains( new Roo.lib.Region( xy[1], xy[0] ,xy[1], xy[0] ))) {
109 // only activate leave if mouse cursor is outside... bounding box..
114 if (this.currentTip) {
115 this.currentTip.leave();
117 //Roo.log('clear currentEl');
118 this.currentEl = false;
123 'left' : ['r-l', [-2,0], 'right'],
124 'right' : ['l-r', [2,0], 'left'],
125 'bottom' : ['t-b', [0,2], 'top'],
126 'top' : [ 'b-t', [0,-2], 'bottom']
132 Roo.extend(Roo.bootstrap.Tooltip, Roo.bootstrap.Component, {
137 delay : null, // can be { show : 300 , hide: 500}
141 hoverState : null, //???
143 placement : 'bottom',
145 getAutoCreate : function(){
152 cls : 'tooltip-arrow'
155 cls : 'tooltip-inner'
168 enter : function () {
170 if (this.timeout != null) {
171 clearTimeout(this.timeout);
174 this.hoverState = 'in';
175 //Roo.log("enter - show");
176 if (!this.delay || !this.delay.show) {
181 this.timeout = setTimeout(function () {
182 if (_t.hoverState == 'in') {
189 clearTimeout(this.timeout);
191 this.hoverState = 'out';
192 if (!this.delay || !this.delay.hide) {
198 this.timeout = setTimeout(function () {
199 //Roo.log("leave - timeout");
201 if (_t.hoverState == 'out') {
203 Roo.bootstrap.Tooltip.currentEl = false;
211 this.render(document.body);
214 //Roo.log([this.bindEl, this.bindEl.attr('tooltip')]);
216 var tip = this.bindEl.attr('tooltip') || this.bindEl.select("[tooltip]").first().attr('tooltip');
218 this.el.select('.tooltip-inner',true).first().dom.innerHTML = tip;
220 this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
222 var placement = typeof this.placement == 'function' ?
223 this.placement.call(this, this.el, on_el) :
226 var autoToken = /\s?auto?\s?/i;
227 var autoPlace = autoToken.test(placement);
229 placement = placement.replace(autoToken, '') || 'top';
233 //this.el.setXY([0,0]);
235 //this.el.dom.style.display='block';
236 this.el.addClass(placement);
238 //this.el.appendTo(on_el);
240 var p = this.getPosition();
241 var box = this.el.getBox();
247 var align = Roo.bootstrap.Tooltip.alignment[placement];
249 var xy = this.el.getAlignToXY(this.bindEl, align[0], align[1]);
251 if(placement == 'top' || placement == 'bottom'){
257 align = Roo.bootstrap.Tooltip.alignment[placement];
262 this.el.alignTo(this.bindEl, align[0],align[1]);
263 //var arrow = this.el.select('.arrow',true).first();
264 //arrow.set(align[2],
266 this.el.addClass('in fade');
267 this.hoverState = null;
269 if (this.el.hasClass('fade')) {
280 //this.el.setXY([0,0]);
281 this.el.removeClass('in');