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);
24 this.alignment = Roo.bootstrap.Tooltip.alignment;
26 if(typeof(config) != 'undefined' && typeof(config.alignment) != 'undefined'){
27 this.alignment = config.alignment;
32 Roo.apply(Roo.bootstrap.Tooltip, {
34 * @function init initialize tooltip monitoring.
39 currentRegion : false,
45 Roo.get(document).on('mouseover', this.enter ,this);
46 Roo.get(document).on('mouseout', this.leave, this);
49 this.currentTip = new Roo.bootstrap.Tooltip();
54 var dom = ev.getTarget();
56 //Roo.log(['enter',dom]);
57 var el = Roo.fly(dom);
60 //Roo.log(this.currentEl);
61 //Roo.log(this.currentEl.contains(dom));
62 if (this.currentEl == el) {
65 if (dom != this.currentEl.dom && this.currentEl.contains(dom)) {
71 if (this.currentTip.el) {
72 this.currentTip.el.setVisibilityMode(Roo.Element.DISPLAY).hide(); // force hiding...
76 if(!el || el.dom == document){
82 // you can not look for children, as if el is the body.. then everythign is the child..
83 if (!el.attr('tooltip')) { //
84 if (!el.select("[tooltip]").elements.length) {
87 // is the mouse over this child...?
88 bindEl = el.select("[tooltip]").first();
90 if (!bindEl.getRegion().contains( { top : xy[1] ,right : xy[0] , bottom : xy[1], left : xy[0]})) {
91 //Roo.log("not in region.");
94 //Roo.log("child element over..");
97 this.currentEl = bindEl;
98 this.currentTip.bind(bindEl);
99 this.currentRegion = Roo.lib.Region.getRegion(dom);
100 this.currentTip.enter();
105 var dom = ev.getTarget();
106 //Roo.log(['leave',dom]);
107 if (!this.currentEl) {
112 if (dom != this.currentEl.dom) {
116 if (this.currentRegion.contains( new Roo.lib.Region( xy[1], xy[0] ,xy[1], xy[0] ))) {
119 // only activate leave if mouse cursor is outside... bounding box..
124 if (this.currentTip) {
125 this.currentTip.leave();
127 //Roo.log('clear currentEl');
128 this.currentEl = false;
133 'left' : ['r-l', [-2,0], 'right'],
134 'right' : ['l-r', [2,0], 'left'],
135 'bottom' : ['t-b', [0,2], 'top'],
136 'top' : [ 'b-t', [0,-2], 'bottom']
142 Roo.extend(Roo.bootstrap.Tooltip, Roo.bootstrap.Component, {
147 delay : null, // can be { show : 300 , hide: 500}
151 hoverState : null, //???
153 placement : 'bottom',
157 getAutoCreate : function(){
164 cls : 'tooltip-arrow'
167 cls : 'tooltip-inner'
180 enter : function () {
182 if (this.timeout != null) {
183 clearTimeout(this.timeout);
186 this.hoverState = 'in';
187 //Roo.log("enter - show");
188 if (!this.delay || !this.delay.show) {
193 this.timeout = setTimeout(function () {
194 if (_t.hoverState == 'in') {
201 clearTimeout(this.timeout);
203 this.hoverState = 'out';
204 if (!this.delay || !this.delay.hide) {
210 this.timeout = setTimeout(function () {
211 //Roo.log("leave - timeout");
213 if (_t.hoverState == 'out') {
215 Roo.bootstrap.Tooltip.currentEl = false;
220 show : function (msg)
223 this.render(document.body);
226 //Roo.log([this.bindEl, this.bindEl.attr('tooltip')]);
228 var tip = msg || this.bindEl.attr('tooltip') || this.bindEl.select("[tooltip]").first().attr('tooltip');
230 this.el.select('.tooltip-inner',true).first().dom.innerHTML = tip;
232 this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
234 var placement = typeof this.placement == 'function' ?
235 this.placement.call(this, this.el, on_el) :
238 var autoToken = /\s?auto?\s?/i;
239 var autoPlace = autoToken.test(placement);
241 placement = placement.replace(autoToken, '') || 'top';
245 //this.el.setXY([0,0]);
247 //this.el.dom.style.display='block';
249 //this.el.appendTo(on_el);
251 var p = this.getPosition();
252 var box = this.el.getBox();
258 var align = this.alignment[placement];
260 var xy = this.el.getAlignToXY(this.bindEl, align[0], align[1]);
262 if(placement == 'top' || placement == 'bottom'){
267 if(xy[0] + this.el.getWidth() > Roo.lib.Dom.getViewWidth()){
271 var scroll = Roo.select('body', true).first().getScroll();
273 if(xy[1] > Roo.lib.Dom.getViewHeight() + scroll.top - this.el.getHeight()){
277 align = this.alignment[placement];
280 this.el.alignTo(this.bindEl, align[0],align[1]);
281 //var arrow = this.el.select('.arrow',true).first();
282 //arrow.set(align[2],
284 this.el.addClass(placement);
286 this.el.addClass('in fade');
288 this.hoverState = null;
290 if (this.el.hasClass('fade')) {
301 //this.el.setXY([0,0]);
302 this.el.removeClass('in');