dphelper 0.0.1 → 0.0.2

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.
Files changed (53) hide show
  1. package/.editorconfig +12 -0
  2. package/3party/shortcut.js +224 -0
  3. package/init.js +71 -4
  4. package/package.json +6 -5
  5. package/scripts/anchorToOnClick.js +36 -0
  6. package/scripts/arrayItemFinder.js +22 -0
  7. package/scripts/arrayMerge.js +20 -0
  8. package/scripts/currency.js +21 -0
  9. package/scripts/date2Iso.js +20 -0
  10. package/scripts/date2MMDDYYYY.js +16 -0
  11. package/scripts/dateConvert.js +20 -0
  12. package/scripts/dateIso2Epoch.js +17 -0
  13. package/scripts/dateLocal-ISOTime.js +17 -0
  14. package/scripts/dateUTC.js +14 -0
  15. package/scripts/disableSelect.js +41 -0
  16. package/scripts/disableSpellCheck.js +21 -0
  17. package/scripts/epoch.js +14 -0
  18. package/scripts/fullScreen.js +40 -0
  19. package/scripts/handleEvent.js +59 -0
  20. package/scripts/isPromise.js +14 -0
  21. package/scripts/jsonCounter.js +21 -0
  22. package/scripts/loadAsset.js +26 -0
  23. package/scripts/loadFile.js +17 -0
  24. package/scripts/loadJson.js +15 -0
  25. package/scripts/loadJsonExternal.js +32 -0
  26. package/scripts/nl2br.js +14 -0
  27. package/scripts/noCache.js +14 -0
  28. package/scripts/object2array.js +18 -0
  29. package/scripts/onBeforeUnLoad.js +108 -0
  30. package/scripts/parseBool.js +15 -0
  31. package/scripts/parseDate.js +19 -0
  32. package/scripts/pathHash.js +20 -0
  33. package/scripts/pathQuery.js +24 -0
  34. package/scripts/pathRail.js +26 -0
  35. package/scripts/printInfo.js +16 -0
  36. package/scripts/purge.js +41 -0
  37. package/scripts/pushState.js +14 -0
  38. package/scripts/randomNum.js +14 -0
  39. package/scripts/randomNumTmr.js +14 -0
  40. package/scripts/scrollCustom.js +41 -0
  41. package/scripts/scrollIndicator.js +67 -0
  42. package/scripts/scrollMemory.js +26 -0
  43. package/scripts/scrollSmooth.js +74 -0
  44. package/scripts/scrollToElement.js +25 -0
  45. package/scripts/serializeForm.js +92 -0
  46. package/scripts/serializeObj.js +47 -0
  47. package/scripts/sleep.js +14 -0
  48. package/scripts/stopConsole.js +49 -0
  49. package/scripts/svgSupport.js +346 -0
  50. package/scripts/textChanger.js +24 -0
  51. package/scripts/triggerClick.js +16 -0
  52. package/scripts/uuid.js +14 -0
  53. package/scripts/window.js +38 -0
@@ -0,0 +1,26 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * setScrollPos, getScrollPos
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /*****************************************************************************************/
11
+ // SAVE OLD SCROLL POSITION
12
+
13
+ dphelper.setScrollPos = ( el ) => {
14
+ let ar = [ $( el ).scrollTop() , $( el ).scrollLeft() ];
15
+ if( ar[0] != null && ar[1] != null ){ dphelper.storage.set( el , ar ); }
16
+ };
17
+
18
+ /*****************************************************************************************/
19
+ // LOAD OLD SCROLL POSITION
20
+
21
+ dphelper.getScrollPos = ( el ) => {
22
+ if( !dphelper.storage.get( el ) ) return;
23
+ let ar = dphelper.storage.get( el ).trim().split(',');
24
+ $( el ).scrollTop( ar[0] );
25
+ $( el ).scrollLeft( ar[1] );
26
+ };
@@ -0,0 +1,74 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * scrollSmooth
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /***********************************************************************/
11
+
12
+ // function init(){
13
+ // new scrollSmooth(document,120,12);
14
+ // }
15
+
16
+ dphelper.scrollSmooth = (target, speed, smooth) => {
17
+ if (target === document)
18
+ target = (document.scrollingElement || document.documentElement || document.body.parentNode || document.body); // cross browser support for document scrolling
19
+
20
+ let moving = false;
21
+ let pos = target.scrollTop;
22
+ let frame = target === document.body && document.documentElement ? document.documentElement : target; // safari is the new IE
23
+
24
+ target.addEventListener('mousewheel', scrolled, { passive: false });
25
+ target.addEventListener('DOMMouseScroll', scrolled, { passive: false });
26
+
27
+ function scrolled( e ) {
28
+ e.preventDefault(); // disable default scrolling
29
+
30
+ let delta = normalizeWheelDelta( e );
31
+
32
+ pos += -delta * speed;
33
+ pos = Math.max(0, Math.min(pos, target.scrollHeight - frame.clientHeight)); // limit scrolling
34
+
35
+ if (!moving) update();
36
+ }
37
+
38
+ function normalizeWheelDelta( e ){
39
+ if(e.detail){
40
+ if(e.wheelDelta)
41
+ return e.wheelDelta/e.detail/40 * (e.detail>0 ? 1 : -1); // Opera
42
+ else
43
+ return -e.detail/3; // Firefox
44
+ }else
45
+ return e.wheelDelta/120; // IE,Safari,Chrome
46
+ }
47
+
48
+ function update() {
49
+ moving = true;
50
+
51
+ let delta = (pos - target.scrollTop) / smooth;
52
+
53
+ target.scrollTop += delta;
54
+
55
+ if (Math.abs(delta) > 0.5)
56
+ requestFrame(update);
57
+ else
58
+ moving = false;
59
+ }
60
+
61
+ let requestFrame = function() { // requestAnimationFrame cross browser
62
+ return (
63
+ window.requestAnimationFrame ||
64
+ window.webkitRequestAnimationFrame ||
65
+ window.mozRequestAnimationFrame ||
66
+ window.oRequestAnimationFrame ||
67
+ window.msRequestAnimationFrame ||
68
+ function(func) {
69
+ window.setTimeout(func, 1000 / 50);
70
+ }
71
+ );
72
+ }();
73
+
74
+ };
@@ -0,0 +1,25 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * scrollToElement
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /***********************************************************************/
11
+
12
+ dphelper.scrollToElement = function( container, element, gap = 0 ) {
13
+
14
+ let el1 = document.querySelector( container );
15
+ let el2 = document.querySelector( element );
16
+ let el3 = gap; // DIVERGENCE
17
+
18
+ if( !el1 || !el2 || !el3 ) return;
19
+
20
+ el1.scrollTo({
21
+ top: el2.offsetTop,
22
+ behavior: "smooth"
23
+ });
24
+
25
+ };
@@ -0,0 +1,92 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * serializeForm
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /***********************************************************************/
11
+
12
+ dphelper.serializeForm = function( form ) {
13
+
14
+ const $ = require("jquery");
15
+ const el = this;
16
+ //const el = $( form );
17
+
18
+ var self = el,
19
+
20
+ json = {},
21
+ push_counters = {},
22
+ patterns = {
23
+ "validate": /^[a-zA-Z][a-zA-Z0-9_]*(?:\[(?:\d*|[a-zA-Z0-9_]+)\])*$/,
24
+ "key": /[a-zA-Z0-9_]+|(?=\[\])/g,
25
+ "push": /^$/,
26
+ "fixed": /^\d+$/,
27
+ "named": /^[a-zA-Z0-9_]+$/
28
+ };
29
+
30
+ //console.log( el )
31
+
32
+ el.build = function(base, key, value) {
33
+ base[key] = isNaN(value) || Array.isArray(value) ? value : Number(value);
34
+ return base;
35
+ };
36
+
37
+ el.push_counter = function(key) {
38
+ if (push_counters[key] === undefined) {
39
+ push_counters[key] = 0;
40
+ }
41
+ return push_counters[key]++;
42
+ };
43
+
44
+ $.each( $(el).serializeArray(), function() {
45
+
46
+ // skip invalid keys
47
+ if (!patterns.validate.test(el.name)) {
48
+ return;
49
+ }
50
+
51
+ var k,
52
+ keys = el.name.match(patterns.key),
53
+ merge = el.value,
54
+ reverse_key = el.name;
55
+
56
+ if( merge === 'false' ) merge = Boolean(false);
57
+ if( merge === 'true' ) merge = Boolean(true);
58
+ if( merge === 'off' ) merge = Boolean(false);
59
+ if( merge === 'on' ) merge = Boolean(true);
60
+ if( merge === '[]' ) merge = [];
61
+ if( merge === '{}' ) merge = {};
62
+ if( merge === 'undefined' ) merge = undefined;
63
+ if( merge === 'null' ) merge = null;
64
+ if( merge === '' ) merge = '';
65
+
66
+ while ((k = keys.pop()) !== undefined) {
67
+
68
+ // adjust reverse_key
69
+ reverse_key = reverse_key.replace(new RegExp("\\[" + k + "\\]$"), '');
70
+
71
+ // push
72
+ if (k.match(patterns.push)) {
73
+ merge = self.build([], self.push_counter(reverse_key), merge);
74
+ }
75
+
76
+ // fixed
77
+ else if (k.match(patterns.fixed)) {
78
+ merge = self.build([], k, merge);
79
+ }
80
+
81
+ // named
82
+ else if (k.match(patterns.named)) {
83
+ merge = self.build({}, k, merge);
84
+ }
85
+
86
+ }
87
+
88
+ json = $.extend(true, json, merge);
89
+ });
90
+
91
+ return json;
92
+ };
@@ -0,0 +1,47 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * objSerialize, objDeSerialize
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /***********************************************************************/
11
+
12
+ dphelper.objSerialize = (value) => {
13
+
14
+ if (typeof value === 'function') {
15
+ return value.toString();
16
+ }
17
+
18
+ if (typeof value === 'object') {
19
+ let serializeObject = {};
20
+ for (const [objectKey, objectValue] of Object.entries(value)) {
21
+ console.info( `objectKey=${objectKey} value=${objectValue}` );
22
+ serializeObject[objectKey] = wng.objSerialize(objectValue);
23
+ }
24
+ return serializeObject;
25
+ }
26
+
27
+ return value;
28
+ };
29
+
30
+
31
+ dphelper.objDeSerialize = (valueNew) => {
32
+
33
+ if (valueNew.toLowerCase().startsWith( 'function(' ) ) {
34
+ return Function('"use strict";return ' + valueNew);
35
+ }
36
+
37
+ if (typeof valueNew === 'object') {
38
+ let deserializeObject = {};
39
+ for (const [objectKey, objectValue] of Object.entries(valueNew)) {
40
+ console.info( `objectKey=${objectKey} value=${objectValue}` );
41
+ deserializeObject[objectKey] = wng.objDeSerialize(objectValue);
42
+ }
43
+ return deserializeObject;
44
+ }
45
+
46
+ return value;
47
+ };
@@ -0,0 +1,14 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * sleep
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /***********************************************************************/
11
+
12
+ dphelper.sleep = (ms) => {
13
+ return new Promise( resolve => setTimeout( resolve, ms) );
14
+ };
@@ -0,0 +1,49 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * stopConsole
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /***********************************************************************/
11
+
12
+ dphelper.stopConsole = () => {
13
+
14
+ let console = {};
15
+ console.log = function(){};
16
+ window.console = console;
17
+ if(!window.console) window.console = {};
18
+
19
+ const noop = () => {}
20
+ [
21
+ 'assert',
22
+ 'clear',
23
+ 'count',
24
+ 'debug',
25
+ 'dir',
26
+ 'dirxml',
27
+ 'error',
28
+ 'exception',
29
+ 'group',
30
+ 'groupCollapsed',
31
+ 'groupEnd',
32
+ 'info',
33
+ 'log',
34
+ 'markTimeline',
35
+ 'profile',
36
+ 'profileEnd',
37
+ 'table',
38
+ 'time',
39
+ 'timeEnd',
40
+ 'timeline',
41
+ 'timelineEnd',
42
+ 'timeStamp',
43
+ 'trace',
44
+ 'warn'
45
+ ].forEach((method) => {
46
+ window.console[method] = noop;
47
+ });
48
+
49
+ };
@@ -0,0 +1,346 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * svgSupport
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /***********************************************************************/
11
+
12
+ dphelper.supportsVml = function () {
13
+
14
+ if ( typeof supportsVml.supported == "undefined" ) {
15
+
16
+ let a = document.body.appendChild( document.createElement( 'div' ) );
17
+ a.innerHTML = '<v:shape id="vml_flag1" adj="1" />';
18
+
19
+ let b = a.firstChild;
20
+ b.style.behavior = "url(#default#VML)";
21
+ supportsVml.supported = b ? typeof b.adj == "object" : true;
22
+ a.parentNode.removeChild( a );
23
+
24
+ }
25
+
26
+ return supportsVml.supported;
27
+
28
+ };
29
+
30
+ dphelper.supportsVml();
31
+
32
+ /**************************************************************************************************/
33
+ /**************************************************************************************************/
34
+
35
+ dphelper.initConnection = function( container, source1, source2, cb ) {
36
+
37
+ if( $( container ).find( 'svg' ) ) {
38
+ removeConnection( container );
39
+ }
40
+
41
+ source1 = setConnector( source1[ 0 ], source1[ 1 ] );
42
+ source2 = setConnector( source2[ 0 ], source2[ 1 ] );
43
+
44
+ let parentCoords = container.getBoundingClientRect();
45
+
46
+ let xmlns = "http://www.w3.org/2000/svg";
47
+ let boxWidth = container.offsetWidth * 10;
48
+ let boxHeight = container.offsetHeight * 10;
49
+
50
+ // create svg container
51
+ let svgElem = document.createElementNS( xmlns, "svg" );
52
+
53
+ svgElem.setAttribute( "xmlns" , xmlns );
54
+ svgElem.setAttributeNS( null , "id" , "pathConnection" );
55
+ svgElem.setAttributeNS( null , "viewBox" , "0 0 " + boxWidth + " " + boxHeight );
56
+ svgElem.setAttributeNS( null , "width" , boxWidth );
57
+ svgElem.setAttributeNS( null , "height" , boxHeight );
58
+ svgElem.style.display = "block";
59
+
60
+ /*
61
+ // TO DO: smaller cyrcle
62
+ // DARIO: probably is too invasive on UI, I change just border on parts_container_
63
+
64
+ // create arrow
65
+ let defs = document.createElementNS(xmlns, "defs");
66
+ let marker = document.createElementNS(xmlns, "marker");
67
+ let path = document.createElementNS(xmlns, "path");
68
+ marker.setAttributeNS(null, 'id', 'head');
69
+ marker.setAttributeNS(null, 'orient', 'auto');
70
+ marker.setAttributeNS(null, 'markerWidth', '20');
71
+ marker.setAttributeNS(null, 'markerHeight', '40');
72
+ marker.setAttributeNS(null, 'refX', '0');
73
+ marker.setAttributeNS(null, 'refY', '3');
74
+ path.setAttributeNS(null, 'd', 'M0,0 V6 L3,3 Z');
75
+ marker.appendChild(path);
76
+ defs.appendChild(marker);
77
+ svgElem.appendChild(defs);
78
+ */
79
+
80
+ // create rect which overlaps source1
81
+ let rect1 = document.createElementNS( xmlns , "rect" );
82
+ let coords = source1.getBoundingClientRect();
83
+
84
+ rect1.setAttributeNS( null, 'x', coords.left - parentCoords.left );
85
+ rect1.setAttributeNS( null, 'y', coords.top - parentCoords.top );
86
+ rect1.setAttributeNS( null, 'width', coords.width );
87
+ rect1.setAttributeNS( null, 'height', coords.height );
88
+ svgElem.appendChild( rect1 );
89
+
90
+ // create rect which overlaps source2
91
+ let rect2 = document.createElementNS( xmlns, "rect" );
92
+ coords = source2.getBoundingClientRect();
93
+
94
+ rect2.setAttributeNS( null, 'x', coords.left - parentCoords.left );
95
+ rect2.setAttributeNS( null, 'y', coords.top - parentCoords.top );
96
+ rect2.setAttributeNS( null, 'width', coords.width );
97
+ rect2.setAttributeNS( null, 'height', coords.height );
98
+ svgElem.appendChild( rect2 );
99
+
100
+ // create path connecting both rects
101
+ let path = document.createElementNS( xmlns, "path" );
102
+
103
+ path.setAttributeNS( null, 'id', 'connection' );
104
+ path.setAttributeNS( null, 'marker-end', 'url(#head)' );
105
+ svgElem.appendChild( path );
106
+
107
+ container.appendChild( svgElem );
108
+
109
+ updateConnection( $( rect1 )[0], $( rect2 )[0], $( '#connection' )[0]);
110
+
111
+ if( typeof cb == 'function' ) {
112
+ cb( source1, source2 );
113
+ }
114
+
115
+ };
116
+
117
+ /**************************************************************************************************/
118
+
119
+ dphelper.updateConnection = function( rect1 , rect2 , cxn ) {
120
+
121
+ // Top left coordinates
122
+ let x1 = parseFloat( rect1.getAttribute( 'x' ) );
123
+ let y1 = parseFloat( rect1.getAttribute( 'y' ) );
124
+ let x2 = parseFloat( rect2.getAttribute( 'x') );
125
+ let y2 = parseFloat( rect2.getAttribute( 'y' ) );
126
+
127
+ // Half widths and half heights
128
+ let w1 = parseFloat( rect1.getAttribute( 'width' ) ) / 2;
129
+ let h1 = parseFloat( rect1.getAttribute( 'height' ) ) / 2;
130
+ let w2 = parseFloat( rect2.getAttribute( 'width' ) ) / 2;
131
+ let h2 = parseFloat( rect2.getAttribute( 'height' ) ) / 2;
132
+
133
+ // Center coordinates
134
+ let cx1 = x1 + w1;
135
+ let cy1 = y1 + h1;
136
+ let cx2 = x2 + w2;
137
+ let cy2 = y2 + h2;
138
+
139
+ // Distance between centers
140
+ let dx = cx2 - cx1;
141
+ let dy = cy2 - cy1;
142
+
143
+ let p1 = getIntersection( dx , dy , cx1 , cy1 , w1 , h1 );
144
+ let p2 = getIntersection( -dx , -dy , cx2 , cy2 , w2 , h2 );
145
+
146
+ // Distance between edges
147
+ let dx1 = p2[ 0 ] - p1[ 0 ];
148
+
149
+ let d = getCurve( p1 , p2 , dx1 );
150
+
151
+ // Set a path connector
152
+ cxn.setAttributeNS( null , 'd' , "M" + cx1 + "," + cy1 + d + cx2 + "," + cy2 );
153
+
154
+ // Set a line connector
155
+ // cxn.setAttributeNS( null , 'x1' , p1[0] );
156
+ // cxn.setAttributeNS( null , 'y1' , p1[1] );
157
+ // cxn.setAttributeNS( null , 'x2' , p2[0] );
158
+ // cxn.setAttributeNS( null , 'y2' , p2[1] );
159
+
160
+ };
161
+
162
+ /**************************************************************************************************/
163
+
164
+ dphelper.getCurve = function( p1 , p2 , dx ) {
165
+
166
+ let curve = dx / 2;
167
+ let d = " C" + ( curve + p1[0] ) + "," + p1[1] + " " + ( p2[0] - curve ) + "," + p2[1] + " ";
168
+ return d;
169
+
170
+ };
171
+
172
+ dphelper.getIntersection = function( dx , dy , cx , cy , w , h ) {
173
+
174
+ if ( Math.abs( dy / dx ) < h / w )
175
+ return [ cx + ( dx > 0 ? w : -w ), cy + dy * w / Math.abs( dx ) ];
176
+ else
177
+ return [ cx + dx * h / Math.abs( dy ), cy + ( dy > 0 ? h : -h ) ];
178
+
179
+ };
180
+
181
+ /**************************************************************************************************/
182
+
183
+ dphelper.makeScrollable = function( svgContainer , scrollContainer , elm1 , elm2 , rect1 , rect2 ) {
184
+
185
+ //let scrollCoords = scrollContainer.getBoundingClientRect();
186
+ let svgCoords = svgContainer.getBoundingClientRect();
187
+
188
+ let el = [ elm1 , elm2 ];
189
+ let rec = [ rect1 , rect2 ];
190
+ let coords = [];
191
+
192
+ for( let i = 0; i < el.length; i++ ){
193
+
194
+ coords[ i ] = el[ i ].getBoundingClientRect();
195
+
196
+ rec[ i ].setAttributeNS( null, 'x', coords[ i ].left - svgCoords.left );
197
+ rec[ i ].setAttributeNS( null, 'y', coords[ i ].top - svgCoords.top );
198
+ rec[ i ].setAttributeNS( null, 'width', coords[ i ].width );
199
+ rec[ i ].setAttributeNS( null, 'height', coords[ i ].height );
200
+
201
+ }
202
+
203
+ //***************************************************************
204
+
205
+ updateConnection( $( rect1 )[ 0 ], $( rect2 )[ 0 ], $( '#connection' )[ 0 ]);
206
+
207
+ };
208
+
209
+ /**************************************************************************************************/
210
+
211
+ dphelper.makeDraggable = function( evt ) {
212
+
213
+ let svg = evt.target;
214
+ svg.addEventListener( 'mousedown' , startDrag );
215
+ svg.addEventListener( 'mousemove' , drag );
216
+ svg.addEventListener( 'mouseup' , endDrag );
217
+
218
+ function getMousePosition( e ) {
219
+ let CTM = svg.getScreenCTM();
220
+ return {
221
+ x: ( evt.clientX - CTM.e ) / CTM.a,
222
+ y: ( evt.clientY - CTM.f ) / CTM.d
223
+ };
224
+ }
225
+
226
+ let selectedElement, offset;
227
+
228
+ function startDrag( evt ) {
229
+
230
+ if ( evt.target.classList.contains( 'draggable' ) ) {
231
+ selectedElement = evt.target;
232
+ offset = getMousePosition( evt );
233
+ offset.x -= parseFloat( selectedElement.getAttributeNS( null , "x" ) );
234
+ offset.y -= parseFloat( selectedElement.getAttributeNS( null , "y" ) );
235
+ }
236
+
237
+ }
238
+
239
+ function drag( evt ) {
240
+
241
+ if ( selectedElement ) {
242
+ let coord = getMousePosition( evt );
243
+ selectedElement.setAttributeNS( null, "x" , coord.x - offset.x );
244
+ selectedElement.setAttributeNS( null, "y" , coord.y - offset.y );
245
+ updateConnection();
246
+ }
247
+
248
+ }
249
+
250
+ function endDrag( evt ) {
251
+ selectedElement = null;
252
+ }
253
+
254
+ };
255
+
256
+ /**************************************************************************************************/
257
+
258
+ dphelper.setConnector = function( source , side ) {
259
+
260
+ let style;
261
+ let span = $( '<span class="connector"></span>' );
262
+
263
+ $( source ).css( 'position' , 'relative' );
264
+
265
+ span.css({
266
+ position: 'absolute',
267
+ width: '5px',
268
+ height: '5px',
269
+ });
270
+
271
+ switch( side ) {
272
+ case 'top':
273
+ style = {
274
+ left: '50%',
275
+ top: '2.5px',
276
+ marginLeft: '2.5px'
277
+ };
278
+ break;
279
+ case 'right':
280
+ style = {
281
+ top: '50%',
282
+ right: '2.5px',
283
+ marginTop: '-2.5px'
284
+ };
285
+ break;
286
+ case 'bottom':
287
+ style = {
288
+ left: '50%',
289
+ bottom: '-2.5px',
290
+ marginLeft: '2.5px'
291
+ };
292
+ break;
293
+ case 'left':
294
+ style = {
295
+ top: '50%',
296
+ left: '-2.5px',
297
+ marginTop: '-2.5px'
298
+ };
299
+ break;
300
+ default:
301
+ style = {};
302
+ }
303
+
304
+ span.css( style );
305
+
306
+ $( source ).append( span );
307
+
308
+ return $( span )[ 0 ];
309
+ };
310
+
311
+ /**************************************************************************************************/
312
+
313
+ dphelper.handleSvgToggle = function( evt , container , source1 , source2 ) {
314
+
315
+ if( $( evt.target ).prop( 'checked' ) && $( source1 ).length && $( source2 ).length ) {
316
+
317
+ wng.storeCookie.set( $( evt.target ).attr( 'id' ), 1, 365 );
318
+
319
+ initConnection( container[0], [ $( source1 )[0], 'right' ], [ $( source2 )[0], 'left' ], function( source1 , source2 ) {
320
+
321
+ $( '#parts-left-body' ).on( 'scroll', function( evt ){
322
+ makeScrollable( $( container )[0], $( '#parts-left-body' )[0], $( source1 )[0],
323
+ $( source2 )[0], $( '#parts svg rect' )[0], $( '#parts svg rect' )[ 1 ] );
324
+ });
325
+
326
+ });
327
+
328
+ } else {
329
+
330
+ dphelper.removeConnection( container );
331
+ $( '#parts-left-body' ).unbind( 'scroll' );
332
+ wng.storeCookie.set( $( evt.target ).attr( 'id' ), 0, 365 );
333
+
334
+ }
335
+
336
+ };
337
+
338
+ /**************************************************************************************************/
339
+
340
+ dphelper.removeConnection = function( container ) {
341
+
342
+ $( container ).find( 'svg#pathConnection' ).each( function( i , elm ) {
343
+ $( elm ).remove();
344
+ });
345
+
346
+ };
@@ -0,0 +1,24 @@
1
+ /*!
2
+ * dpHelper <https://github.com/passariello/dpHelper>
3
+ *
4
+ * capitalize, lower, upper
5
+ *
6
+ * Copyright (c) 2021, Dario Passariello.
7
+ * Licensed under the Apache-2.0 License.
8
+ */
9
+
10
+ /***********************************************************************/
11
+
12
+ dphelper.capitalize = (txt) => {
13
+ return txt.toLowerCase().replace(/\b\w/g, function (l) { return l.toUpperCase(); });
14
+ };
15
+
16
+ /******************************************************************************/
17
+ dphelper.lower = (txt) => {
18
+ return txt.toLowerCase();
19
+ };
20
+
21
+ /******************************************************************************/
22
+ dphelper.upper = (txt) => {
23
+ return txt.toUpperCase();
24
+ };