AutoTooltip

class webix.AutoTooltip()

Autotooltip mixin

References

helpers
bind(), event(), eventRemove(), template().
views
tooltip().

Referenced by

views
chart(), datatable(), property(), proto(), tree().

External references

Official documentation page.

Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
webix.AutoTooltip = {
    tooltip_setter:function(value){
        if (value){
            if (typeof value == "function")
                value = { template:value };

            var col_mode = !value.template;
            var t = new webix.ui.tooltip(value);
            this._enable_mouse_move();
            var showEvent = this.attachEvent("onMouseMove",function(id,e){    //show tooltip on mousemove
                this._mouseEventX = e.clientX;
                this._mouseEventY = e.clientY;
                if (this.getColumnConfig){
                    var config = t.type.column = this.getColumnConfig(id.column);
                    if (col_mode){
                        //empty tooltip - ignoring
                        if (!config.tooltip && config.tooltip != webix.undefined)
                            return;
                        var trg = e.target || e.srcElements;

                        if(trg.getAttribute("webix_area") && config.tooltip){
                            var area = trg.getAttribute("webix_area");
                            t.type.template = function(obj,common){
                                var values = obj[common.column.id];
                                return webix.template(config.tooltip).call(this,obj,common,values[area],area);
                            };
                        }
                        else{
                            if (config.tooltip)
                                t.type.template = config.tooltip = webix.template(config.tooltip);
                            else {
                                var text = this.getText(id.row, id.column);
                                t.type.template = function(){ return text; };
                            }
                        }
                    }
                }

                if (!webix.DragControl.active)
                    t.show(this.getItem(id),webix.html.pos(e));
            });
            // [[IMPROVE]]  As we can can have only one instance of tooltip per page
            //                this handler can be attached once per page, not once per component
            var hideEvent = webix.event(document.body, "mousemove", webix.bind(function(e){
                e = e||event;
                if(this._mouseEventX != e.clientX || this._mouseEventY != e.clientY)
                    t.hide();
            },this));
            this.attachEvent("onDestruct",function(){
                if(this.config.tooltip)
                    this.config.tooltip.destructor();
            });
            this.attachEvent("onAfterScroll", function(){
                t.hide();
            });
            t.attachEvent("onDestruct",webix.bind(function(){
                this.detachEvent(showEvent);
                webix.eventRemove(hideEvent);
            },this));
            return t;
        }
    }
};