Skip to content

Commit 83b0902

Browse files
authored
Add files via upload
1 parent bcb6cb9 commit 83b0902

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

examples/09-drag-from-outside.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</style>
1919

2020
</head>
21-
<body>
21+
<body @dragover="dragover">
2222
<h1>Vue Grid Layout Example 09 - Drag From Outside</h1>
2323

2424
<a href="https://github.com/jbaysolutions/vue-grid-layout">View project on Github</a>
@@ -48,9 +48,9 @@ <h1>Vue Grid Layout Example 09 - Drag From Outside</h1>
4848
</div>
4949
</div>
5050
<br/>
51-
<div @dragstart="dragstart" @drag="drag" @dragend="dragend" class="droppable-element" draggable="true" unselectable="on">Droppable Element (Drag me!)</div>
51+
<div @drag="drag" @dragend="dragend" class="droppable-element" draggable="true" unselectable="on">Droppable Element (Drag me!)</div>
5252
<div id="content">
53-
<grid-layout ref="gridLayout" :layout.sync="layout"
53+
<grid-layout ref="gridLayout" :layout.sync="layout"
5454
:col-num="12"
5555
:row-height="30"
5656
:is-draggable="true"

examples/09-drag-from-outside.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,24 @@ var testLayout = [
1010
{"x":4,"y":5,"w":2,"h":5,"i":"8"},
1111
{"x":5,"y":10,"w":4,"h":3,"i":"9"},
1212
];
13+
var mouseXY={"x":null,"y":null};
14+
var DragPos = {"x":null,"y":null,"w":1,"h":1,"i":null};
15+
16+
document.addEventListener("dragover", function(e) {
17+
mouseXY.x=e.clientX;
18+
mouseXY.y=e.clientY;
19+
}, false);
1320

14-
let DragPos = {"x":null,"y":null,"w":1,"h":1,"i":null};
1521
new Vue({
1622
el: '#app',
1723
data: {
1824
layout: testLayout,
1925
},
2026
methods: {
21-
dragstart:function(e){
22-
},
2327
drag:function(e){
24-
2528
let parentRect = document.getElementById('content').getBoundingClientRect();
2629
let mouseInGrid=false;
27-
if (((e.x>parentRect.left) && (e.x<parentRect.right)) && ((e.y>parentRect.top) && (e.y<parentRect.bottom))){
30+
if (((mouseXY.x>parentRect.left) && (mouseXY.x<parentRect.right)) && ((mouseXY.y>parentRect.top) && (mouseXY.y<parentRect.bottom))){
2831
mouseInGrid=true;
2932
}
3033
if (mouseInGrid==true && (this.layout.findIndex(item => item.i === 'drop')) == -1){
@@ -43,8 +46,8 @@ new Vue({
4346
} catch {
4447
}
4548
let el=this.$refs.gridLayout.$children[index];
46-
el.dragging={"top":e.y-parentRect.top,"left":e.x-parentRect.left};
47-
let new_pos=el.calcXY(e.y-parentRect.top, e.x-parentRect.left);
49+
el.dragging={"top":mouseXY.y-parentRect.top,"left":mouseXY.x-parentRect.left};
50+
let new_pos=el.calcXY(mouseXY.y-parentRect.top, mouseXY.x-parentRect.left);
4851

4952
if (mouseInGrid==true){
5053
this.$refs.gridLayout.dragEvent('dragstart', 'drop', new_pos.x,new_pos.y,1,1);
@@ -58,15 +61,18 @@ new Vue({
5861

5962
},
6063
dragend:function(e){
64+
6165
let parentRect = document.getElementById('content').getBoundingClientRect();
6266
let mouseInGrid=false;
63-
if (((e.x>parentRect.left) && (e.x<parentRect.right)) && ((e.y>parentRect.top) && (e.y<parentRect.bottom))){
67+
if (((mouseXY.x>parentRect.left) && (mouseXY.x<parentRect.right)) && ((mouseXY.y>parentRect.top) && (mouseXY.y<parentRect.bottom))){
6468
mouseInGrid=true;
6569
}
6670
if (mouseInGrid==true){
6771
alert(`Dropped element props:\n${JSON.stringify(DragPos, ['x', 'y', 'w', 'h'], 2)}`);
72+
this.$refs.gridLayout.dragEvent('dragend', 'drop', DragPos.x,DragPos.y,1,1);
73+
this.layout = this.layout.filter(obj => obj.i !=='drop');
6874

69-
// UNCOMMENT below if you want to add a GridLayout item
75+
// UNCOMMENT below if you want to add a grid-item
7076
/*
7177
this.layout.push({
7278
x: DragPos.x,
@@ -81,8 +87,9 @@ new Vue({
8187
} catch {
8288
}
8389
*/
90+
8491
}
85-
},
92+
},
8693
},
8794
});
8895

0 commit comments

Comments
 (0)