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)) {
64 if (this.currentTip.el) {
65 this.currentTip.el.setVisibilityMode(Roo.Element.DISPLAY).hide(); // force hiding...
76 // you can not look for children, as if el is the body.. then everythign is the child..
77 if (!el.attr('tooltip')) { //
78 if (!el.select("[tooltip]").elements.length) {
81 // is the mouse over this child...?
82 bindEl = el.select("[tooltip]").first();
84 if (!bindEl.getRegion().contains( { top : xy[1] ,right : xy[0] , bottom : xy[1], left : xy[0]})) {
85 //Roo.log("not in region.");
88 //Roo.log("child element over..");
91 this.currentEl = bindEl;
92 this.currentTip.bind(bindEl);
93 this.currentRegion = Roo.lib.Region.getRegion(dom);
94 this.currentTip.enter();
99 var dom = ev.getTarget();
100 //Roo.log(['leave',dom]);
101 if (!this.currentEl) {
106 if (dom != this.currentEl.dom) {
110 if (this.currentRegion.contains( new Roo.lib.Region( xy[1], xy[0] ,xy[1], xy[0] ))) {
113 // only activate leave if mouse cursor is outside... bounding box..
118 if (this.currentTip) {
119 this.currentTip.leave();
121 //Roo.log('clear currentEl');
122 this.currentEl = false;
127 'left' : ['r-l', [-2,0], 'right'],
128 'right' : ['l-r', [2,0], 'left'],
129 'bottom' : ['t-b', [0,2], 'top'],
130 'top' : [ 'b-t', [0,-2], 'bottom']
136 Roo.extend(Roo.bootstrap.Tooltip, Roo.bootstrap.Component, {
141 delay : null, // can be { show : 300 , hide: 500}
145 hoverState : null, //???
147 placement : 'bottom',
149 getAutoCreate : function(){
156 cls : 'tooltip-arrow'
159 cls : 'tooltip-inner'
172 enter : function () {
174 if (this.timeout != null) {
175 clearTimeout(this.timeout);
178 this.hoverState = 'in';
179 //Roo.log("enter - show");
180 if (!this.delay || !this.delay.show) {
185 this.timeout = setTimeout(function () {
186 if (_t.hoverState == 'in') {
193 clearTimeout(this.timeout);
195 this.hoverState = 'out';
196 if (!this.delay || !this.delay.hide) {
202 this.timeout = setTimeout(function () {
203 //Roo.log("leave - timeout");
205 if (_t.hoverState == 'out') {
207 Roo.bootstrap.Tooltip.currentEl = false;
215 this.render(document.body);
218 //Roo.log([this.bindEl, this.bindEl.attr('tooltip')]);
220 var tip = this.bindEl.attr('tooltip') || this.bindEl.select("[tooltip]").first().attr('tooltip');
222 this.el.select('.tooltip-inner',true).first().dom.innerHTML = tip;
224 this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
226 var placement = typeof this.placement == 'function' ?
227 this.placement.call(this, this.el, on_el) :
230 var autoToken = /\s?auto?\s?/i;
231 var autoPlace = autoToken.test(placement);
233 placement = placement.replace(autoToken, '') || 'top';
237 //this.el.setXY([0,0]);
239 //this.el.dom.style.display='block';
241 //this.el.appendTo(on_el);
243 var p = this.getPosition();
244 var box = this.el.getBox();
250 var align = Roo.bootstrap.Tooltip.alignment[placement];
252 var xy = this.el.getAlignToXY(this.bindEl, align[0], align[1]);
254 if(placement == 'top' || placement == 'bottom'){
259 if(xy[0] + this.el.getWidth() > Roo.lib.Dom.getViewWidth()){
263 var scroll = Roo.select('body', true).first().getScroll();
265 if(xy[1] > Roo.lib.Dom.getViewHeight() + scroll.top - this.el.getHeight()){
271 align = Roo.bootstrap.Tooltip.alignment[placement];
273 this.el.alignTo(this.bindEl, align[0],align[1]);
274 //var arrow = this.el.select('.arrow',true).first();
275 //arrow.set(align[2],
277 this.el.addClass(placement);
279 this.el.addClass('in fade');
281 this.hoverState = null;
283 if (this.el.hasClass('fade')) {
294 //this.el.setXY([0,0]);
295 this.el.removeClass('in');