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...
70 // you can not look for children, as if el is the body.. then everythign is the child..
71 if (!el.attr('tooltip')) { //
72 if (!el.select("[tooltip]").elements.length) {
75 // is the mouse over this child...?
76 bindEl = el.select("[tooltip]").first();
78 if (!bindEl.getRegion().contains( { top : xy[1] ,right : xy[0] , bottom : xy[1], left : xy[0]})) {
79 //Roo.log("not in region.");
82 //Roo.log("child element over..");
86 this.currenTip.replacement = el.attr('xxxx');
88 this.currentEl = bindEl;
89 this.currentTip.bind(bindEl);
90 this.currentRegion = Roo.lib.Region.getRegion(dom);
91 this.currentTip.enter();
96 var dom = ev.getTarget();
97 //Roo.log(['leave',dom]);
98 if (!this.currentEl) {
103 if (dom != this.currentEl.dom) {
107 if (this.currentRegion.contains( new Roo.lib.Region( xy[1], xy[0] ,xy[1], xy[0] ))) {
110 // only activate leave if mouse cursor is outside... bounding box..
115 if (this.currentTip) {
116 this.currentTip.leave();
118 //Roo.log('clear currentEl');
119 this.currentEl = false;
124 'left' : ['r-l', [-2,0], 'right'],
125 'right' : ['l-r', [2,0], 'left'],
126 'bottom' : ['t-b', [0,2], 'top'],
127 'top' : [ 'b-t', [0,-2], 'bottom']
133 Roo.extend(Roo.bootstrap.Tooltip, Roo.bootstrap.Component, {
138 delay : null, // can be { show : 300 , hide: 500}
142 hoverState : null, //???
144 placement : 'bottom',
146 getAutoCreate : function(){
153 cls : 'tooltip-arrow'
156 cls : 'tooltip-inner'
169 enter : function () {
171 if (this.timeout != null) {
172 clearTimeout(this.timeout);
175 this.hoverState = 'in';
176 //Roo.log("enter - show");
177 if (!this.delay || !this.delay.show) {
182 this.timeout = setTimeout(function () {
183 if (_t.hoverState == 'in') {
190 clearTimeout(this.timeout);
192 this.hoverState = 'out';
193 if (!this.delay || !this.delay.hide) {
199 this.timeout = setTimeout(function () {
200 //Roo.log("leave - timeout");
202 if (_t.hoverState == 'out') {
204 Roo.bootstrap.Tooltip.currentEl = false;
212 this.render(document.body);
215 //Roo.log([this.bindEl, this.bindEl.attr('tooltip')]);
217 var tip = this.bindEl.attr('tooltip') || this.bindEl.select("[tooltip]").first().attr('tooltip');
219 this.el.select('.tooltip-inner',true).first().dom.innerHTML = tip;
221 this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
223 var placement = typeof this.placement == 'function' ?
224 this.placement.call(this, this.el, on_el) :
227 var autoToken = /\s?auto?\s?/i;
228 var autoPlace = autoToken.test(placement);
230 placement = placement.replace(autoToken, '') || 'top';
234 //this.el.setXY([0,0]);
236 //this.el.dom.style.display='block';
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'){
256 if(xy[0] + this.el.getWidth() > Roo.lib.Dom.getViewWidth()){
261 align = Roo.bootstrap.Tooltip.alignment[placement];
263 this.el.alignTo(this.bindEl, align[0],align[1]);
264 //var arrow = this.el.select('.arrow',true).first();
265 //arrow.set(align[2],
267 this.el.addClass(placement);
269 this.el.addClass('in fade');
271 this.hoverState = null;
273 if (this.el.hasClass('fade')) {
284 //this.el.setXY([0,0]);
285 this.el.removeClass('in');