ContextHelper

class webix.ContextHelper()

Contexthelper mixin

References

helpers
assert(), bind(), event(), eventRemove(), toNode().

Referenced by

views
context(), contextmenu().

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
webix.ContextHelper = {
    defaults:{
        padding:"4",
        hidden:true
    },
    body_setter:function(value){
        value = webix.ui.window.prototype.body_setter.call(this, value);
        this._body_cell._viewobj.style.borderWidth = "0px";
        return value;
    },
    attachTo:function(obj){
        webix.assert(obj, "Invalid target for Context::attach");
        var id;
        if (obj.on_context)
            id = obj.attachEvent("onAfterContextMenu", webix.bind(this._show_at_ui, this));
        else
            id = webix.event(obj, "contextmenu", this._show_at_node, {bind:this});

        this.attachEvent("onDestruct", function(){
            if (obj.detachEvent)
                obj.detachEvent(id);
            else
                webix.eventRemove(id);
            obj = null;
        });
    },
    getContext:function(){
        return this._area;
    },
    setContext:function(area){
        this._area = area;
    },
    _show_at_node:function(e){
        this._area = webix.toNode(e||event);
        return this._show_at(e);
    },
    _show_at_ui:function(id, e, trg){
        this._area = { obj:webix.$$(e), id:id };
        return this._show_at(e);
    },
    _show_at:function(e){
        var result = this.show(e, null, true);
        if (result === false) return result;

        //event forced to close other popups|context menus
        webix.callEvent("onClick", []);
        return webix.html.preventEvent(e);
    },
    _show_on_mouse_out:true,
    master_setter:function(value){
        this.attachTo(value);
        return null;
    }
};