1- // Movable View v1.2 EXPERIMENTAL JS PORT 02
2- // https://github.com/MustafaHi/Sciter-MovableView
1+ //| Movable View v1.3.0
2+ //| https://github.com/MustafaHi/Sciter-MovableView
33
4- // Call movableView('selector' [, screenBound:bool( false)] );
4+ // Call movableView('selector', true| false);
55
6- Number . prototype . limit = function ( min , max ) {
7- if ( this < min ) return min ;
8- if ( this > max ) return max ;
9- return this ;
6+ if ( ! Number . prototype . limit ) {
7+ Number . prototype . limit = function ( min , max ) {
8+ if ( this < min ) return min ;
9+ if ( this > max ) return max ;
10+ return this ;
11+ }
1012}
1113
1214function movableView ( s , screenBound = false )
@@ -26,46 +28,48 @@ function movableView(s, screenBound = false)
2628 }
2729 else
2830 {
29- maxX = Number . MAX_SAFE_INTEGER ;
30- maxY = Number . MAX_SAFE_INTEGER ;
31+ maxX = Number . MAX_SAFE_INTEGER ;
32+ maxY = Number . MAX_SAFE_INTEGER ;
3133 minXY = Number . MIN_SAFE_INTEGER ;
3234 }
3335 }
3436
3537 function onMouseDown ( e )
3638 {
3739 screenBounds ( ) ;
40+ e . target . state . capture ( true ) ;
41+
3842 var [ x , y ] = Window . this . box ( "position" , "border" , "screen" ) ;
3943 xoff = e . screenX - x ; yoff = e . screenY - y ;
40- dragging = true ;
4144
42- document . on ( "mouseup" , onMouseUp ) ;
43- document . on ( "mousemove" , onMouseMove ) ;
44- e . preventDefault ( ) ;
45- e . stopPropagation ( ) ;
45+ dragging = true ;
4646 }
4747
4848 function onMouseMove ( e )
4949 {
5050 if ( dragging )
5151 {
52- e . preventDefault ( ) ;
5352 Window . this . move ( ( e . screenX - xoff ) . limit ( minXY , maxX ) , ( e . screenY - yoff ) . limit ( minXY , maxY ) ) ;
5453 }
5554 }
5655
5756 function onMouseUp ( e )
5857 {
59- if ( dragging ) { dragging = false ; }
60- document . off ( "mouseup" ) ;
61- document . off ( "mousemove" ) ;
62- e . preventDefault ( ) ;
58+ if ( dragging )
59+ {
60+ dragging = false ;
61+ e . target . state . capture ( false ) ;
62+ }
6363 }
6464
6565 const elements = document . querySelectorAll ( s ) ;
6666 for ( var i = 0 ; i < elements . length ; ++ i ) {
6767 elements [ i ] . on ( "mousedown" , onMouseDown ) ;
68+ elements [ i ] . on ( "mousemove" , onMouseMove ) ;
69+ elements [ i ] . on ( "mouseup" , onMouseUp ) ;
6870 }
69- return true ;
71+ return elements . length ? true : false ;
7072}
7173
74+ //| Module export (uncomment bellow)
75+ // export { movableView as default };
0 commit comments