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);
52 Roo.debug && Roo.log(dom);
57 //Roo.log(this.currentEl);
58 //Roo.log(this.currentEl.contains(dom));
59 if (this.currentEl == el) {
62 if (dom != this.currentEl.dom && this.currentEl.contains(dom)) {
68 if (this.currentTip.el) {
69 this.currentTip.el.setVisibilityMode(Roo.Element.DISPLAY).hide(); // force hiding...
73 if(!el || el.dom == document){
79 // you can not look for children, as if el is the body.. then everythign is the child..
80 if (!el.attr('tooltip')) { //
81 if (!el.select("[tooltip]").elements.length) {
84 // is the mouse over this child...?
85 bindEl = el.select("[tooltip]").first();
87 if (!bindEl.getRegion().contains( { top : xy[1] ,right : xy[0] , bottom : xy[1], left : xy[0]})) {
88 //Roo.log("not in region.");
91 //Roo.log("child element over..");
94 this.currentEl = bindEl;
95 this.currentTip.bind(bindEl);
96 this.currentRegion = Roo.lib.Region.getRegion(dom);
97 this.currentTip.enter();
102 var dom = ev.getTarget();
103 //Roo.log(['leave',dom]);
104 if (!this.currentEl) {
109 if (dom != this.currentEl.dom) {
113 if (this.currentRegion.contains( new Roo.lib.Region( xy[1], xy[0] ,xy[1], xy[0] ))) {
116 // only activate leave if mouse cursor is outside... bounding box..
121 if (this.currentTip) {
122 this.currentTip.leave();
124 //Roo.log('clear currentEl');
125 this.currentEl = false;
130 'left' : ['r-l', [-2,0], 'right'],
131 'right' : ['l-r', [2,0], 'left'],
132 'bottom' : ['t-b', [0,2], 'top'],
133 'top' : [ 'b-t', [0,-2], 'bottom']
139 Roo.extend(Roo.bootstrap.Tooltip, Roo.bootstrap.Component, {
144 delay : null, // can be { show : 300 , hide: 500}
148 hoverState : null, //???
150 placement : 'bottom',
152 getAutoCreate : function(){
159 cls : 'tooltip-arrow'
162 cls : 'tooltip-inner'
175 enter : function () {
177 if (this.timeout != null) {
178 clearTimeout(this.timeout);
181 this.hoverState = 'in';
182 //Roo.log("enter - show");
183 if (!this.delay || !this.delay.show) {
188 this.timeout = setTimeout(function () {
189 if (_t.hoverState == 'in') {
196 clearTimeout(this.timeout);
198 this.hoverState = 'out';
199 if (!this.delay || !this.delay.hide) {
205 this.timeout = setTimeout(function () {
206 //Roo.log("leave - timeout");
208 if (_t.hoverState == 'out') {
210 Roo.bootstrap.Tooltip.currentEl = false;
218 this.render(document.body);
221 //Roo.log([this.bindEl, this.bindEl.attr('tooltip')]);
223 var tip = this.bindEl.attr('tooltip') || this.bindEl.select("[tooltip]").first().attr('tooltip');
225 this.el.select('.tooltip-inner',true).first().dom.innerHTML = tip;
227 this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
229 var placement = typeof this.placement == 'function' ?
230 this.placement.call(this, this.el, on_el) :
233 var autoToken = /\s?auto?\s?/i;
234 var autoPlace = autoToken.test(placement);
236 placement = placement.replace(autoToken, '') || 'top';
240 //this.el.setXY([0,0]);
242 //this.el.dom.style.display='block';
244 //this.el.appendTo(on_el);
246 var p = this.getPosition();
247 var box = this.el.getBox();
253 var align = Roo.bootstrap.Tooltip.alignment[placement];
255 var xy = this.el.getAlignToXY(this.bindEl, align[0], align[1]);
257 if(placement == 'top' || placement == 'bottom'){
262 if(xy[0] + this.el.getWidth() > Roo.lib.Dom.getViewWidth()){
266 var scroll = Roo.select('body', true).first().getScroll();
268 if(xy[1] > Roo.lib.Dom.getViewHeight() + scroll.top - this.el.getHeight()){
274 align = Roo.bootstrap.Tooltip.alignment[placement];
276 this.el.alignTo(this.bindEl, align[0],align[1]);
277 //var arrow = this.el.select('.arrow',true).first();
278 //arrow.set(align[2],
280 this.el.addClass(placement);
282 this.el.addClass('in fade');
284 this.hoverState = null;
286 if (this.el.hasClass('fade')) {
297 //this.el.setXY([0,0]);
298 this.el.removeClass('in');