dphelper 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -1
- package/package.json +10 -1
- package/scripts/svgSupport.js +28 -28
package/README.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
1
|
# dpHelper
|
|
2
2
|
|
|
3
|
-
Many
|
|
3
|
+
Many utils for your projects
|
|
4
|
+
|
|
5
|
+
Use "npm i dphelper" to install
|
|
6
|
+
|
|
7
|
+
in the index:
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import "dphelper"
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
type 'dphelper' in your console to have a look about all available functions that you can use globaly!
|
package/package.json
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dphelper",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Many utils for your projects",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
8
|
},
|
|
9
|
+
"targets": {
|
|
10
|
+
"main": {
|
|
11
|
+
"includeNodeModules": {
|
|
12
|
+
"react": false,
|
|
13
|
+
"react-dom": false
|
|
14
|
+
},
|
|
15
|
+
"isLibrary": true
|
|
16
|
+
}
|
|
17
|
+
},
|
|
9
18
|
"deprecated": false,
|
|
10
19
|
"engines": {
|
|
11
20
|
"node": ">=0.10.0"
|
package/scripts/svgSupport.js
CHANGED
|
@@ -9,37 +9,37 @@
|
|
|
9
9
|
|
|
10
10
|
/***********************************************************************/
|
|
11
11
|
|
|
12
|
-
dphelper.
|
|
12
|
+
dphelper.svg_supportsVml = function () {
|
|
13
13
|
|
|
14
|
-
if ( typeof dphelper.
|
|
14
|
+
if ( typeof dphelper.svg_supportsVml.supported == "undefined" ) {
|
|
15
15
|
|
|
16
16
|
let a = document.body.appendChild( document.createElement( 'div' ) );
|
|
17
17
|
a.innerHTML = '<v:shape id="vml_flag1" adj="1" />';
|
|
18
18
|
|
|
19
19
|
let b = a.firstChild;
|
|
20
20
|
b.style.behavior = "url(#default#VML)";
|
|
21
|
-
dphelper.
|
|
21
|
+
dphelper.svg_supportsVml.supported = b ? typeof b.adj == "object" : true;
|
|
22
22
|
a.parentNode.removeChild( a );
|
|
23
23
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
return dphelper.
|
|
26
|
+
return dphelper.svg_supportsVml.supported;
|
|
27
27
|
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
dphelper.
|
|
30
|
+
dphelper.svg_supportsVml();
|
|
31
31
|
|
|
32
32
|
/**************************************************************************************************/
|
|
33
33
|
/**************************************************************************************************/
|
|
34
34
|
|
|
35
|
-
dphelper.
|
|
35
|
+
dphelper.svg_initConnection = function( container, source1, source2, cb ) {
|
|
36
36
|
|
|
37
37
|
if( $( container ).find( 'svg' ) ) {
|
|
38
|
-
|
|
38
|
+
dphelper.svg_removeConnection( container );
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
source1 =
|
|
42
|
-
source2 =
|
|
41
|
+
source1 = dphelper.svg_setConnector( source1[ 0 ], source1[ 1 ] );
|
|
42
|
+
source2 = dphelper.svg_setConnector( source2[ 0 ], source2[ 1 ] );
|
|
43
43
|
|
|
44
44
|
let parentCoords = container.getBoundingClientRect();
|
|
45
45
|
|
|
@@ -106,7 +106,7 @@ dphelper.initConnection = function( container, source1, source2, cb ) {
|
|
|
106
106
|
|
|
107
107
|
container.appendChild( svgElem );
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
dphelper.svg_updateConnection( $( rect1 )[0], $( rect2 )[0], $( '#connection' )[0]);
|
|
110
110
|
|
|
111
111
|
if( typeof cb == 'function' ) {
|
|
112
112
|
cb( source1, source2 );
|
|
@@ -116,7 +116,7 @@ dphelper.initConnection = function( container, source1, source2, cb ) {
|
|
|
116
116
|
|
|
117
117
|
/**************************************************************************************************/
|
|
118
118
|
|
|
119
|
-
dphelper.
|
|
119
|
+
dphelper.svg_updateConnection = function( rect1 , rect2 , cxn ) {
|
|
120
120
|
|
|
121
121
|
// Top left coordinates
|
|
122
122
|
let x1 = parseFloat( rect1.getAttribute( 'x' ) );
|
|
@@ -140,13 +140,13 @@ dphelper.updateConnection = function( rect1 , rect2 , cxn ) {
|
|
|
140
140
|
let dx = cx2 - cx1;
|
|
141
141
|
let dy = cy2 - cy1;
|
|
142
142
|
|
|
143
|
-
let p1 =
|
|
144
|
-
let p2 =
|
|
143
|
+
let p1 = dphelper.svg_getIntersection( dx , dy , cx1 , cy1 , w1 , h1 );
|
|
144
|
+
let p2 = dphelper.svg_getIntersection( -dx , -dy , cx2 , cy2 , w2 , h2 );
|
|
145
145
|
|
|
146
146
|
// Distance between edges
|
|
147
147
|
let dx1 = p2[ 0 ] - p1[ 0 ];
|
|
148
148
|
|
|
149
|
-
let d =
|
|
149
|
+
let d = dphelper.svg_getCurve( p1 , p2 , dx1 );
|
|
150
150
|
|
|
151
151
|
// Set a path connector
|
|
152
152
|
cxn.setAttributeNS( null , 'd' , "M" + cx1 + "," + cy1 + d + cx2 + "," + cy2 );
|
|
@@ -161,7 +161,7 @@ dphelper.updateConnection = function( rect1 , rect2 , cxn ) {
|
|
|
161
161
|
|
|
162
162
|
/**************************************************************************************************/
|
|
163
163
|
|
|
164
|
-
dphelper.
|
|
164
|
+
dphelper.svg_getCurve = function( p1 , p2 , dx ) {
|
|
165
165
|
|
|
166
166
|
let curve = dx / 2;
|
|
167
167
|
let d = " C" + ( curve + p1[0] ) + "," + p1[1] + " " + ( p2[0] - curve ) + "," + p2[1] + " ";
|
|
@@ -169,7 +169,7 @@ dphelper.getCurve = function( p1 , p2 , dx ) {
|
|
|
169
169
|
|
|
170
170
|
};
|
|
171
171
|
|
|
172
|
-
dphelper.
|
|
172
|
+
dphelper.svg_getIntersection = function( dx , dy , cx , cy , w , h ) {
|
|
173
173
|
|
|
174
174
|
if ( Math.abs( dy / dx ) < h / w )
|
|
175
175
|
return [ cx + ( dx > 0 ? w : -w ), cy + dy * w / Math.abs( dx ) ];
|
|
@@ -180,7 +180,7 @@ dphelper.getIntersection = function( dx , dy , cx , cy , w , h ) {
|
|
|
180
180
|
|
|
181
181
|
/**************************************************************************************************/
|
|
182
182
|
|
|
183
|
-
dphelper.
|
|
183
|
+
dphelper.svg_makeScrollable = function( svgContainer , scrollContainer , elm1 , elm2 , rect1 , rect2 ) {
|
|
184
184
|
|
|
185
185
|
//let scrollCoords = scrollContainer.getBoundingClientRect();
|
|
186
186
|
let svgCoords = svgContainer.getBoundingClientRect();
|
|
@@ -202,13 +202,13 @@ dphelper.makeScrollable = function( svgContainer , scrollContainer , elm1 , elm2
|
|
|
202
202
|
|
|
203
203
|
//***************************************************************
|
|
204
204
|
|
|
205
|
-
|
|
205
|
+
dphelper.svg_updateConnection( $( rect1 )[ 0 ], $( rect2 )[ 0 ], $( '#connection' )[ 0 ]);
|
|
206
206
|
|
|
207
207
|
};
|
|
208
208
|
|
|
209
209
|
/**************************************************************************************************/
|
|
210
210
|
|
|
211
|
-
dphelper.
|
|
211
|
+
dphelper.svg_makeDraggable = function( evt ) {
|
|
212
212
|
|
|
213
213
|
let svg = evt.target;
|
|
214
214
|
svg.addEventListener( 'mousedown' , startDrag );
|
|
@@ -242,7 +242,7 @@ dphelper.makeDraggable = function( evt ) {
|
|
|
242
242
|
let coord = getMousePosition( evt );
|
|
243
243
|
selectedElement.setAttributeNS( null, "x" , coord.x - offset.x );
|
|
244
244
|
selectedElement.setAttributeNS( null, "y" , coord.y - offset.y );
|
|
245
|
-
|
|
245
|
+
dphelper.svg_updateConnection();
|
|
246
246
|
}
|
|
247
247
|
|
|
248
248
|
}
|
|
@@ -255,7 +255,7 @@ dphelper.makeDraggable = function( evt ) {
|
|
|
255
255
|
|
|
256
256
|
/**************************************************************************************************/
|
|
257
257
|
|
|
258
|
-
dphelper.
|
|
258
|
+
dphelper.svg_setConnector = function( source , side ) {
|
|
259
259
|
|
|
260
260
|
let style;
|
|
261
261
|
let span = $( '<span class="connector"></span>' );
|
|
@@ -310,16 +310,16 @@ dphelper.setConnector = function( source , side ) {
|
|
|
310
310
|
|
|
311
311
|
/**************************************************************************************************/
|
|
312
312
|
|
|
313
|
-
dphelper.
|
|
313
|
+
dphelper.svg_handleSvgToggle = function( evt , container , source1 , source2 ) {
|
|
314
314
|
|
|
315
315
|
if( $( evt.target ).prop( 'checked' ) && $( source1 ).length && $( source2 ).length ) {
|
|
316
316
|
|
|
317
|
-
dphelper.
|
|
317
|
+
dphelper.cookie.set( $( evt.target ).attr( 'id' ), 1, 365 );
|
|
318
318
|
|
|
319
|
-
|
|
319
|
+
dphelper.svg_initConnection( container[0], [ $( source1 )[0], 'right' ], [ $( source2 )[0], 'left' ], function( source1 , source2 ) {
|
|
320
320
|
|
|
321
321
|
$( '#parts-left-body' ).on( 'scroll', function( evt ){
|
|
322
|
-
|
|
322
|
+
dphelper.svg_makeScrollable( $( container )[0], $( '#parts-left-body' )[0], $( source1 )[0],
|
|
323
323
|
$( source2 )[0], $( '#parts svg rect' )[0], $( '#parts svg rect' )[ 1 ] );
|
|
324
324
|
});
|
|
325
325
|
|
|
@@ -327,9 +327,9 @@ dphelper.handleSvgToggle = function( evt , container , source1 , source2 ) {
|
|
|
327
327
|
|
|
328
328
|
} else {
|
|
329
329
|
|
|
330
|
-
dphelper.
|
|
330
|
+
dphelper.svg_removeConnection( container );
|
|
331
331
|
$( '#parts-left-body' ).unbind( 'scroll' );
|
|
332
|
-
dphelper.
|
|
332
|
+
dphelper.cookie.set( $( evt.target ).attr( 'id' ), 0, 365 );
|
|
333
333
|
|
|
334
334
|
}
|
|
335
335
|
|
|
@@ -337,7 +337,7 @@ dphelper.handleSvgToggle = function( evt , container , source1 , source2 ) {
|
|
|
337
337
|
|
|
338
338
|
/**************************************************************************************************/
|
|
339
339
|
|
|
340
|
-
dphelper.
|
|
340
|
+
dphelper.svg_removeConnection = function( container ) {
|
|
341
341
|
|
|
342
342
|
$( container ).find( 'svg#pathConnection' ).each( function( i , elm ) {
|
|
343
343
|
$( elm ).remove();
|