@@ -25,11 +25,6 @@ export class Dialog {
2525 closeLink : HTMLAnchorElement ;
2626 closeAction : Function ;
2727
28- mouseStartX : number ;
29- mouseStartY : number ;
30- dialogTop : number ;
31- dialogLeft : number ;
32-
3328 backdrop : HTMLDivElement ;
3429
3530 constructor ( width : number ) {
@@ -40,13 +35,12 @@ export class Dialog {
4035
4136 this . id = 'dia' + ( Math . random ( ) * 10000000 ) ;
4237 this . dialog = document . createElement ( 'div' ) ;
38+ this . dialog . id = this . id ;
4339 this . dialog . classList . add ( 'dialog' ) ;
4440 this . dialog . classList . add ( 'hidden' ) ;
4541 this . dialog . style . zIndex = ( 102 + ( 2 * RemoteTM . dialogCount ( ) ) ) + '' ;
4642 this . dialog . draggable = true ;
4743 this . dialog . addEventListener ( 'dragstart' , ( ev : DragEvent ) => { this . dragStart ( ev ) ; } ) ;
48- this . dialog . addEventListener ( 'drag' , ( ev : DragEvent ) => { this . drag ( ev ) ; } ) ;
49- this . dialog . addEventListener ( 'dragend' , ( ev : DragEvent ) => { this . dragEnd ( ev ) ; } )
5044 this . center ( width ) ;
5145 document . body . appendChild ( this . dialog ) ;
5246
@@ -139,30 +133,18 @@ export class Dialog {
139133 }
140134
141135 dragStart ( event : DragEvent ) {
142- this . mouseStartX = event . clientX ;
143- this . mouseStartY = event . clientY ;
144- this . dialogTop = this . dialog . offsetTop ;
145- this . dialogLeft = this . dialog . offsetLeft ;
146- if ( this . mouseStartY > this . dialogTop + this . titleArea . clientHeight ) {
136+ if ( event . clientY > this . dialog . offsetTop + this . titleArea . clientHeight ) {
147137 event . preventDefault ( ) ;
148138 event . stopPropagation ( ) ;
149139 }
150- }
151-
152- drag ( event : DragEvent ) {
153- event . preventDefault ( ) ;
154- event . stopPropagation ( ) ;
155- if ( event . clientX === 0 && event . clientY === 0 ) {
156- return ;
140+ if ( event . dataTransfer ) {
141+ event . dataTransfer . setData ( "id" , this . id ) ;
142+ const boundingRect = this . dialog . getBoundingClientRect ( ) ;
143+ const offset = {
144+ x : event . clientX - boundingRect . left ,
145+ y : event . clientY - boundingRect . top ,
146+ } ;
147+ event . dataTransfer . setData ( "offset" , JSON . stringify ( offset ) ) ;
157148 }
158- this . dialog . style . left = ( this . dialogLeft - this . mouseStartX + event . clientX ) + 'px' ;
159- this . dialog . style . top = ( this . dialogTop - this . mouseStartY + event . clientY ) + 'px' ;
160- }
161-
162- dragEnd ( event : DragEvent ) {
163- event . preventDefault ( ) ;
164- event . stopPropagation ( ) ;
165- this . dialog . style . left = ( this . dialogLeft - this . mouseStartX + event . clientX ) + 'px' ;
166- this . dialog . style . top = ( this . dialogTop - this . mouseStartY + event . clientY ) + 'px' ;
167149 }
168150}
0 commit comments