@@ -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 } ;
1521new 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