sidemenu

class webix.ui.sidemenu(data)
Arguments:
  • data (object) – A configuration object

Sidemenu view.

References

views
popup().
helpers
isSupported(), assert(), bind(), delay(), event(), eventRemove(), protoUI(), zIndex().

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
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
webix.protoUI({
    name:"sidemenu",
    defaults: {
        padding:0,
        animate: true,
        position: "left",
        width: 200,
        borderless: true
    },
    $init:function(){
        this.$view.className += " webix_sidemenu";
    },
    position_setter: function(value){
        var prevPosition = this._settings.position;
        if(prevPosition)
            webix.html.removeCss(this.$view," webix_sidemenu_"+prevPosition);
        webix.html.addCss(this.$view," webix_sidemenu_"+value);
        return value;
    },
    $getSize: function(){
        var sizes = webix.ui.window.prototype.$getSize.apply(this,arguments);
        this._desired_sizes = sizes;
        return sizes;
    },
    $setSize:function(x,y){
        webix.ui.view.prototype.$setSize.call(this,x,y);
        x = this._content_width-this._settings.padding*2;
        y = this._content_height-this._settings.padding*2;
        this._contentobj.style.padding = this._settings.padding+"px";
        this._headobj.style.display="none";
        this._bodyobj.style.height = y+"px";
        this._body_cell.$setSize(x,y);
    },
    show: function(){
        if(!this.callEvent("onBeforeShow",arguments))
            return false;

        this._settings.hidden = false;
        this._viewobj.style.zIndex = (this._settings.zIndex||webix.ui.zIndex());
        if (this._settings.modal || this._modal){
            this._modal_set(true);
            this._modal = null; // hidden_setter handling
        }
        this._viewobj.style.display = "block";
        this._render_hidden_views();
        if (this._settings.position)
            this._setPosition();

        this._hide_timer = 1;
        webix.delay(function(){ this._hide_timer = 0; }, this, [], (webix.env.touch ? 400 : 100 ));

        if (this.config.autofocus){
            this._prev_focus = webix.UIManager.getFocus();
            webix.UIManager.setFocus(this);
        }

        if (-1 == webix.ui._popups.find(this))
            webix.ui._popups.push(this);

        this.callEvent("onShow",[]);
    },
    _setPosition: function(x){
        var width, height, maxWidth, maxHeight,
            position,
            left = 0, top = 0,
            state = { };


        this.$view.style.position = "fixed";

        maxWidth = (window.innerWidth||document.documentElement.offsetWidth);
        maxHeight = (window.innerHeight||document.documentElement.offsetHeight);

        width = this._desired_sizes[0] || maxWidth;
        height = this._desired_sizes[2] ||maxHeight;

        webix.assert(width &&height, "Attempt to show not rendered window");

        position = this._settings.position;

        if(position == "top"){
            width = maxWidth;
        } else if(position == "right"){
            height = maxHeight;
            left = maxWidth - width;
        } else if(position == "bottom"){
            width = maxWidth;
            top = maxHeight - height;
        } else {
            height = maxHeight;
        }

        state = { left: left, top: top,
            width: width, height: height,
            maxWidth: maxWidth, maxHeight: maxHeight
        };

        if (typeof this._settings.state == "function")
            this._settings.state.call(this, state);

        this._state = state;

        this.$setSize(state.width, state.height);

        if (typeof x == "undefined" && this._isAnimationSupported()){
            webix.html.removeCss(this.$view,"webix_animate",true);
            // set initial state
            this._animate[this._settings.position].beforeShow.call(this, state);
            // set apply animation css
            webix.delay(function(){
                webix.html.addCss(this.$view,"webix_animate",true);
            },this, null,1);
            // animate popup
            webix.delay(function(){
                this._animate[this._settings.position].show.call(this, state);
            },this, null,10);

        }
        else{

            this.setPosition(state.left, state.top);
        }
    },
    _isAnimationSupported: function(){
        return webix.animate.isSupported() && this._settings.animate && !(webix.env.isIE && navigator.appVersion.indexOf("MSIE 9")!=-1);
    },
    hidden_setter:function(value){
        if(value)
            this.hide(true);
        else
            this.show();
        return !!value;
    },
    _animate:{
        left: {
            beforeShow: function(state){
                this.$view.style.left = -state.width+"px";
                this.$view.style.top = state.top+"px";
            },
            show: function(){
                this.$view.style.left = "0px";
            },
            hide: function(state){
                this.$view.style.left = -state.width+"px";
            }
        },
        right: {
            beforeShow: function(state){
                this.$view.style.left = "auto";
                this.$view.style.right = -state.width+"px";
                this.$view.style.top = state.top+"px";
            },
            show: function(){
                this.$view.style.right = 0 +"px";
            },
            hide: function(state){
                this.$view.style.right = -state.width+"px";
            }
        },
        top: {
            beforeShow: function(state){
                this.setPosition(state.left,state.top);
                this.$view.style.height ="0px";
                this._bodyobj.style.height ="0px";
            },
            show: function(state){
                this.$view.style.height = state.height +"px";
                this._bodyobj.style.height =state.height+"px";
            },
            hide: function(){
                this.$view.style.height = "0px";
                this._bodyobj.style.height = "0px";
            }
        },
        bottom: {
            beforeShow: function(state){
                this.$view.style.left = state.left + "px";
                this.$view.style.top = "auto";
                var bottom = (state.bottom != webix.undefined?state.bottom:(state.maxHeight-state.top  -state.height));
                this.$view.style.bottom = bottom +"px";
                this.$view.style.height ="0px";
            },
            show: function(state){
                this.$view.style.height = state.height +"px";
            },
            hide: function(){
                this.$view.style.height = "0px";
            }
        }
    },
    hide:function(force){

        if (this.$destructed) return;

        if (this._settings.modal)
            this._modal_set(false);

        var maxWidth = (window.innerWidth||document.documentElement.offsetWidth);
        var maxHeight = (window.innerHeight||document.documentElement.offsetHeight);

        if (!force && this._isAnimationSupported() && maxWidth == this._state.maxWidth && maxHeight == this._state.maxHeight){
            // call 'hide' animation handler
            this._animate[this._settings.position].hide.call(this, this._state);
            // hide popup
            var tid = webix.event(this.$view, webix.env.transitionEnd, webix.bind(function(ev){
                this._hide_callback();
                webix.eventRemove(tid);
            },this));
        }
        else{
            this._hide_callback();
        }

        if (this._settings.autofocus){
            var el = document.activeElement;
            if (el && this._viewobj && this._viewobj.contains(el)){
                webix.UIManager.setFocus(this._prev_focus);
                this._prev_focus = null;
            }
        }

        this._hide_sub_popups();

    }

}, webix.ui.popup);



(function(){