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);
55 //Roo.log(this.currentEl);
56 //Roo.log(this.currentEl.contains(dom));
57 if (this.currentEl == el) {
60 if (dom != this.currentEl.dom && this.currentEl.contains(dom)) {
68 if (this.currentTip.el) {
69 this.currentTip.el.hide(); // force hiding...
74 // you can not look for children, as if el is the body.. then everythign is the child..
75 if (!el.attr('tooltip')) { //
76 if (!el.select("[tooltip]").elements.length) {
79 // is the mouse over this child...?
80 bindEl = el.select("[tooltip]").first();
82 if (!bindEl.getRegion().contains( { top : xy[1] ,right : xy[0] , bottom : xy[1], left : xy[0]})) {
83 //Roo.log("not in region.");
86 //Roo.log("child element over..");
89 this.currentEl = bindEl;
90 this.currentTip.bind(bindEl);
91 this.currentRegion = Roo.lib.Region.getRegion(dom);
92 this.currentTip.enter();
97 var dom = ev.getTarget();
98 //Roo.log(['leave',dom]);
99 if (!this.currentEl) {
104 if (dom != this.currentEl.dom) {
108 if (this.currentRegion.contains( new Roo.lib.Region( xy[1], xy[0] ,xy[1], xy[0] ))) {
111 // only activate leave if mouse cursor is outside... bounding box..
116 if (this.currentTip) {
117 this.currentTip.leave();
119 //Roo.log('clear currentEl');
120 this.currentEl = false;
125 'left' : ['r-l', [-2,0], 'right'],
126 'right' : ['l-r', [2,0], 'left'],
127 'bottom' : ['t-b', [0,2], 'top'],
128 'top' : [ 'b-t', [0,-2], 'bottom']
134 Roo.extend(Roo.bootstrap.Tooltip, Roo.bootstrap.Component, {
139 delay : null, // can be { show : 300 , hide: 500}
143 hoverState : null, //???
145 placement : 'bottom',
147 getAutoCreate : function(){
154 cls : 'tooltip-arrow'
157 cls : 'tooltip-inner'
170 enter : function () {
172 if (this.timeout != null) {
173 clearTimeout(this.timeout);
176 this.hoverState = 'in';
177 //Roo.log("enter - show");
178 if (!this.delay || !this.delay.show) {
183 this.timeout = setTimeout(function () {
184 if (_t.hoverState == 'in') {
191 clearTimeout(this.timeout);
193 this.hoverState = 'out';
194 if (!this.delay || !this.delay.hide) {
200 this.timeout = setTimeout(function () {
201 //Roo.log("leave - timeout");
203 if (_t.hoverState == 'out') {
205 Roo.bootstrap.Tooltip.currentEl = false;
213 this.render(document.body);
216 //Roo.log([this.bindEl, this.bindEl.attr('tooltip')]);
218 var tip = this.bindEl.attr('tooltip') || this.bindEl.select("[tooltip]").first().attr('tooltip');
220 this.el.select('.tooltip-inner',true).first().dom.innerHTML = tip;
222 this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
224 var placement = typeof this.placement == 'function' ?
225 this.placement.call(this, this.el, on_el) :
228 var autoToken = /\s?auto?\s?/i;
229 var autoPlace = autoToken.test(placement);
231 placement = placement.replace(autoToken, '') || 'top';
235 //this.el.setXY([0,0]);
237 //this.el.dom.style.display='block';
239 //this.el.appendTo(on_el);
241 var p = this.getPosition();
242 var box = this.el.getBox();
248 var align = Roo.bootstrap.Tooltip.alignment[placement];
250 var xy = this.el.getAlignToXY(this.bindEl, align[0], align[1]);
252 if(placement == 'top' || placement == 'bottom'){
257 if(xy[0] + this.el.getWidth() > Roo.lib.Dom.getViewWidth()){
262 align = Roo.bootstrap.Tooltip.alignment[placement];
264 this.el.alignTo(this.bindEl, align[0],align[1]);
265 //var arrow = this.el.select('.arrow',true).first();
266 //arrow.set(align[2],
268 this.el.addClass(placement);
270 this.el.addClass('in fade');
272 this.hoverState = null;
274 if (this.el.hasClass('fade')) {
285 //this.el.setXY([0,0]);
286 this.el.removeClass('in');