resizearea

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

Resizearea view.

Referenced by

views
resizer().

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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
webix.protoUI({
    name:"resizearea",
    defaults:{
        dir:"x"
    },
    $init:function(config){
        var dir = config.dir||"x";
        var node = webix.toNode(config.container);
        var size = (dir=="x"?"width":"height");
        var margin = (config.margin? config.margin+"px":0);

        this._key_property = (dir == "x"?"left":"top");

        this._viewobj = webix.html.create("DIV",{
            "class"    : "webix_resize_area webix_dir_"+dir
        });
        //[[COMPAT]] FF12 can produce 2 move events
        webix._event(this._viewobj, webix.env.mouse.down, webix.html.stopEvent);

        if(margin){
            if(dir=="x")
                margin = margin+" 0 "+margin;
            else
                margin = "0 "+margin+" 0 "+margin;
        }
        this._dragobj = webix.html.create("DIV",{
            "class"    : "webix_resize_handle_"+dir,
             "style" : (margin?"padding:"+margin:"")
        },"<div class='webix_handle_content'></div>");

        this._originobj = webix.html.create("DIV",{
            "class"    : "webix_resize_origin_"+dir
        });

        if(config[size]){
            this._originobj.style[size] = config[size]+(config.border?1:0)+"px";
            this._dragobj.style[size] = config[size]+"px";
        }
        if (config.cursor)
            this._dragobj.style.cursor = this._originobj.style.cursor = this._viewobj.style.cursor = config.cursor;
        this._moveev =    webix.event(node, webix.env.mouse.move, this._onmove, {bind:this});
        this._upev =    webix.event(document.body, webix.env.mouse.up, this._onup, {bind:this});

        this._dragobj.style[this._key_property] = this._originobj.style[this._key_property] = config.start+"px";

        node.appendChild(this._viewobj);
        node.appendChild(this._dragobj);
        node.appendChild(this._originobj);
    },
    _onup:function(){

        this.callEvent("onResizeEnd", [this._last_result]);

        webix.eventRemove(this._moveev);
        webix.eventRemove(this._upev);

        webix.html.remove(this._viewobj);
        webix.html.remove(this._dragobj);
        webix.html.remove(this._originobj);
        this._viewobj = this._dragobj = this._originobj = null;
    },
    _onmove:function(e){
        var pos = webix.html.pos(e);
        this._last_result = (this._settings.dir == "x" ? pos.x : pos.y)+this._settings.start-this._settings.eventPos;
        this._dragobj.style[this._key_property] = this._last_result+"px";
        this.callEvent("onResize", [this._last_result]);
    }
}, webix.EventSystem, webix.Settings);
webix.extend(webix.ui.datatable, {

    resizeRow_setter:function(value){
        this._settings.scrollAlignY = false;
        this._settings.fixedRowHeight = false;
        return this.resizeColumn_setter(value);
    },
    resizeColumn_setter:function(value){
        if (value && this._rs_init_flag){
            webix._event(this._viewobj, "mousemove", this._rs_move, {bind:this});
            webix._event(this._viewobj, "mousedown", this._rs_down, {bind:this});
            webix._event(this._viewobj, "mouseup", this._rs_up, {bind:this});
            this._rs_init_flag = false;
        }
        return value;
    },
    _rs_init_flag:true,
    _rs_down:function(e){
        // do not listen to mousedown of subview on master
        if (this._settings.subview && this != webix.$$(e.target||e.srcElement)) return;
        //if mouse was near border
        if (!this._rs_ready) return;
        this._rs_process = [webix.html.pos(e),this._rs_ready[2]];
        webix.html.addCss(document.body,"webix_noselect");
        webix.html.denySelect();
    },
    _rs_up:function(){
        this._rs_process = false;
        webix.html.removeCss(document.body,"webix_noselect");
        webix.html.allowSelect();
    },
    _rs_start:function(e){
        e = e||event;
        if(this._rs_progress)
            return;
        var dir  = this._rs_ready[0];
        var node = this._rs_process[1];
        var obj  = this._locate(node);
        if (!obj) return;

        var eventPos = this._rs_process[0];
        var start;

        if (dir == "x"){
            start = webix.html.offset(node).x+this._rs_ready[1] - webix.html.offset(this._body).x;
            eventPos = eventPos.x;
            if (!this._rs_ready[1]) obj.cind-=(node.parentNode.colSpan||1);
        } else {
            start = webix.html.offset(node).y+this._rs_ready[1] - webix.html.offset(this._body).y+this._header_height;
            eventPos = eventPos.y;
            if (!this._rs_ready[1]) obj.rind--;
        }
        if (obj.cind>=0 && obj.rind>=0){
            this._rs_progress = [dir, obj, start];

            var resize = new webix.ui.resizearea({
                container:this._viewobj,
                dir:dir,
                eventPos:eventPos,
                start:start,
                cursor:(dir == "x"?"e":"n")+"-resize"
            });
            resize.attachEvent("onResizeEnd", webix.bind(this._rs_end, this));
        }
        this._rs_down = this._rs_ready = false;
    },
    _rs_end:function(result){
        if (this._rs_progress){
            var dir = this._rs_progress[0];
            var obj = this._rs_progress[1];
            var newsize = result-this._rs_progress[2];
            if (dir == "x"){

                //in case of right split - different sizing logic applied
                if (this._settings.rightSplit && obj.cind+1>=this._rightSplit &&
                    obj.cind !== this._columns.length - 1)
                {
                    obj.cind++;
                    newsize *= -1;
                }

                var column = this._columns[obj.cind];
                var oldwidth = column.width;
                delete column.fillspace;
                this._setColumnWidth(obj.cind, oldwidth + newsize, true, true);
                this._updateColsSizeSettings();
            }
            else {
                var rid = this.getIdByIndex(obj.rind);
                var oldheight = this._getRowHeight(this.getItem(rid));
                this.setRowHeight(rid, oldheight + newsize);
            }
            this._rs_up();
        }
        this._rs_progress = null;
    },
    _rs_move:function(e){
        var cell= null,
            config = this._settings;
        if (this._rs_ready && this._rs_process)
            return this._rs_start(e);

        e = e||event;
        var node = e.target||e.srcElement;
        var mode = false; //resize ready flag

        if (node.tagName == "TD" || node.tagName == "TABLE") return ;
        var element_class = node.className||"";
        var in_body = typeof element_class === "string" && element_class.indexOf("webix_cell")!=-1;
        //ignore resize in case of drag-n-drop enabled
        if (in_body && config.drag) return;
        var in_header = typeof element_class === "string" && element_class.indexOf("webix_hcell")!=-1;
        this._rs_ready = false;

        if (in_body || in_header){
            var dx = node.offsetWidth;
            var dy = node.offsetHeight;
            var pos = webix.html.posRelative(e);

            var resizeRow = config.resizeRow;
            // if resize is only within the first column
            if(typeof resizeRow == "object" && resizeRow.headerOnly){
                cell = this._locate(node);
                if(cell.cind >0)
                    resizeRow = false;
            }

            if (in_body && resizeRow){
                resizeRow = (typeof resizeRow == "object" && resizeRow.size?resizeRow.size:3);
                if (pos.y<resizeRow){
                    if(!cell)
                        cell = this._locate(node);
                    // avoid resize header border
                    if(cell.rind){
                        this._rs_ready = ["y", 0, node];
                        mode = "n-resize";
                    }
                } else if (dy-pos.y<resizeRow+1){
                    this._rs_ready = ["y", dy, node];
                    mode = "n-resize";
                }
            }

            var resizeColumn = config.resizeColumn;
            // if resize is only within the header
            if(typeof resizeColumn == "object" && resizeColumn.headerOnly && in_body)
                resizeColumn = false;

            if (resizeColumn){
                resizeColumn = (typeof resizeColumn == "object" && resizeColumn.size?resizeColumn.size:3);

                if (pos.x<resizeColumn){
                    this._rs_ready = ["x", 0, node];
                    mode = "e-resize";
                } else if (dx-pos.x<resizeColumn+1){
                    this._rs_ready = ["x", dx, node];
                    mode = "e-resize";
                }
            }
        }

        //mark or unmark resizing ready state
        if (this._cursor_timer) window.clearTimeout(this._cursor_timer);
        this._cursor_timer = webix.delay(this._mark_resize_ready, this, [mode], mode?100:0);
    },

    _mark_resize_ready:function(mode){
        if (this._last_cursor_mode != mode){
            this._last_cursor_mode = mode;
            this._viewobj.style.cursor=mode||"default";
        }
    }
});


webix.extend(webix.ui.datatable,webix.PagingAbility);