dphelper 0.2.31 → 0.2.35

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 (52) hide show
  1. package/package.json +1 -1
  2. package/scripts/array.js +1 -1
  3. package/scripts/console.js +1 -1
  4. package/scripts/cookie.js +1 -1
  5. package/scripts/date.js +1 -1
  6. package/scripts/disable.js +8 -6
  7. package/scripts/{addListenerMulti.js → event.js} +15 -8
  8. package/scripts/font.js +1 -1
  9. package/scripts/form.js +1 -1
  10. package/scripts/function.js +47 -0
  11. package/scripts/indexedDB.js +1 -1
  12. package/scripts/json.js +1 -1
  13. package/scripts/load.js +1 -1
  14. package/scripts/noCache.js +1 -1
  15. package/scripts/number.js +66 -0
  16. package/scripts/obj.js +1 -1
  17. package/scripts/onBeforeUnLoad.js +1 -1
  18. package/scripts/path.js +14 -14
  19. package/scripts/{.OLD/~pathQuery.js → promise.js} +14 -7
  20. package/scripts/pushState.js +1 -1
  21. package/scripts/screen.js +3 -3
  22. package/scripts/scrollbar.js +2 -2
  23. package/scripts/storage.js +1 -1
  24. package/scripts/text.js +30 -1
  25. package/scripts/time.js +1 -1
  26. package/scripts/{.OLD/~loadJson.js → timer.js} +14 -6
  27. package/scripts/trigger.js +10 -1
  28. package/scripts/type.js +56 -0
  29. package/scripts/.OLD/~date2Iso.js +0 -31
  30. package/scripts/.OLD/~date2MMDDYYYY.js +0 -27
  31. package/scripts/.OLD/~dateConvert.js +0 -31
  32. package/scripts/.OLD/~dateIso2Epoch.js +0 -28
  33. package/scripts/.OLD/~dateLocal-ISOTime.js +0 -28
  34. package/scripts/.OLD/~dateUTC.js +0 -25
  35. package/scripts/.OLD/~disableSpellCheck.js +0 -32
  36. package/scripts/.OLD/~loadJsonExternal.js +0 -44
  37. package/scripts/.OLD/~object2array.js +0 -28
  38. package/scripts/.OLD/~parseDate.js +0 -30
  39. package/scripts/.OLD/~pathHash.js +0 -27
  40. package/scripts/.OLD/~pathRail.js +0 -27
  41. package/scripts/.OLD/~scrollIndicator.js +0 -67
  42. package/scripts/.OLD/~scrollMemory.js +0 -26
  43. package/scripts/.OLD/~scrollSmooth.js +0 -74
  44. package/scripts/.OLD/~scrollToElement.js +0 -25
  45. package/scripts/.OLD/~svgSupport.js +0 -346
  46. package/scripts/camelCase.js +0 -41
  47. package/scripts/isPromise.js +0 -26
  48. package/scripts/nl2br.js +0 -26
  49. package/scripts/printInfo.js +0 -28
  50. package/scripts/randomNum.js +0 -26
  51. package/scripts/randomNumTmr.js +0 -26
  52. package/scripts/sleep.js +0 -26
@@ -1,346 +0,0 @@
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
- window.dphelper.svg_supportsVml = function () {
13
-
14
- if ( typeof window.dphelper.svg_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
- window.dphelper.svg_supportsVml.supported = b ? typeof b.adj == "object" : true;
22
- a.parentNode.removeChild( a );
23
-
24
- }
25
-
26
- return window.dphelper.svg_supportsVml.supported;
27
-
28
- };
29
-
30
- window.dphelper.svg_supportsVml();
31
-
32
- /**************************************************************************************************/
33
- /**************************************************************************************************/
34
-
35
- window.dphelper.svg_initConnection = function( container, source1, source2, cb ) {
36
-
37
- if( $( container ).find( 'svg' ) ) {
38
- window.dphelper.svg_removeConnection( container );
39
- }
40
-
41
- source1 = window.dphelper.svg_setConnector( source1[ 0 ], source1[ 1 ] );
42
- source2 = window.dphelper.svg_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
- window.dphelper.svg_updateConnection( $( rect1 )[0], $( rect2 )[0], $( '#connection' )[0]);
110
-
111
- if( typeof cb == 'function' ) {
112
- cb( source1, source2 );
113
- }
114
-
115
- };
116
-
117
- /**************************************************************************************************/
118
-
119
- window.dphelper.svg_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 = window.dphelper.svg_getIntersection( dx , dy , cx1 , cy1 , w1 , h1 );
144
- let p2 = window.dphelper.svg_getIntersection( -dx , -dy , cx2 , cy2 , w2 , h2 );
145
-
146
- // Distance between edges
147
- let dx1 = p2[ 0 ] - p1[ 0 ];
148
-
149
- let d = window.dphelper.svg_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
- window.dphelper.svg_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
- window.dphelper.svg_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
- window.dphelper.svg_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
- window.dphelper.svg_updateConnection( $( rect1 )[ 0 ], $( rect2 )[ 0 ], $( '#connection' )[ 0 ]);
206
-
207
- };
208
-
209
- /**************************************************************************************************/
210
-
211
- window.dphelper.svg_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
- window.dphelper.svg_updateConnection();
246
- }
247
-
248
- }
249
-
250
- function endDrag( evt ) {
251
- selectedElement = null;
252
- }
253
-
254
- };
255
-
256
- /**************************************************************************************************/
257
-
258
- window.dphelper.svg_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
- window.dphelper.svg_handleSvgToggle = function( evt , container , source1 , source2 ) {
314
-
315
- if( $( evt.target ).prop( 'checked' ) && $( source1 ).length && $( source2 ).length ) {
316
-
317
- window.dphelper.cookie.set( $( evt.target ).attr( 'id' ), 1, 365 );
318
-
319
- window.dphelper.svg_initConnection( container[0], [ $( source1 )[0], 'right' ], [ $( source2 )[0], 'left' ], function( source1 , source2 ) {
320
-
321
- $( '#parts-left-body' ).on( 'scroll', function( evt ){
322
- window.dphelper.svg_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
- window.dphelper.svg_removeConnection( container );
331
- $( '#parts-left-body' ).unbind( 'scroll' );
332
- window.dphelper.cookie.set( $( evt.target ).attr( 'id' ), 0, 365 );
333
-
334
- }
335
-
336
- };
337
-
338
- /**************************************************************************************************/
339
-
340
- window.dphelper.svg_removeConnection = function( container ) {
341
-
342
- $( container ).find( 'svg#pathConnection' ).each( function( i , elm ) {
343
- $( elm ).remove();
344
- });
345
-
346
- };
@@ -1,41 +0,0 @@
1
- /*!
2
- * dpHelper <https://github.com/passariello/dpHelper>
3
- * Copyright (c) 2021, Dario Passariello.
4
- * Licensed under the Apache-2.0 License.
5
- */
6
-
7
- /***********************************************************************/
8
-
9
- var description = {
10
- "name" : "Camel Case / Pascal Case",
11
- "description" : "test",
12
- "version" : "0.0.1",
13
- "command" : "camelCase",
14
- "subCommand" : [],
15
- "example" : "",
16
- "author" : "Dario Passariello",
17
- "active" : true
18
- };
19
-
20
- window.dphelper._list.scripts.push( description );
21
-
22
- /***********************************************************************/
23
-
24
- window.dphelper.camelCase = {
25
-
26
- // toSpace
27
- toSpace: ( string ) => {
28
- return string
29
- .replace(/([A-Z])/g, ' $1')
30
- .replace(/^./, function(str){ return str.toUpperCase(); })
31
- },
32
-
33
- // toUnderscore
34
- toUnderscore: ( string ) => {
35
- return string
36
- .replace(/\.?([A-Z])/g, function (x,y){ return "_" + y.toLowerCase()})
37
- .replace(/^_/, "");
38
- },
39
-
40
- };
41
-
@@ -1,26 +0,0 @@
1
- /*!
2
- * dpHelper <https://github.com/passariello/dpHelper>
3
- * Copyright (c) 2021, Dario Passariello.
4
- * Licensed under the Apache-2.0 License.
5
- */
6
-
7
- /***********************************************************************/
8
-
9
- var description = {
10
- "name" : "Check If It's a Promise",
11
- "description" : "test",
12
- "version" : "0.0.1",
13
- "command" : "isPromise",
14
- "subCommand" : [],
15
- "example" : "",
16
- "author" : "Dario Passariello",
17
- "active" : true
18
- };
19
-
20
- window.dphelper._list.scripts.push( description );
21
-
22
- /***********************************************************************/
23
-
24
- window.dphelper.isPromise = (p) => {
25
- return p && Object.prototype.toString.call(p) === "[object Promise]";
26
- };
package/scripts/nl2br.js DELETED
@@ -1,26 +0,0 @@
1
- /*!
2
- * dpHelper <https://github.com/passariello/dpHelper>
3
- * Copyright (c) 2021, Dario Passariello.
4
- * Licensed under the Apache-2.0 License.
5
- */
6
-
7
- /***********************************************************************/
8
-
9
- var description = {
10
- "name" : "New Line To Break Line ( nl 2 br )",
11
- "description" : "test",
12
- "version" : "0.0.1",
13
- "command" : "nl2br",
14
- "subCommand" : [],
15
- "example" : "",
16
- "author" : "Dario Passariello",
17
- "active" : true
18
- };
19
-
20
- window.dphelper._list.scripts.push( description );
21
-
22
- /***********************************************************************/
23
-
24
- window.dphelper.nl2br = (str) => {
25
- return str.replace(/(?:\r\n|\r|\n)/g, '<br>');
26
- };
@@ -1,28 +0,0 @@
1
- /*!
2
- * dpHelper <https://github.com/passariello/dpHelper>
3
- * Copyright (c) 2021, Dario Passariello.
4
- * Licensed under the Apache-2.0 License.
5
- */
6
-
7
- /***********************************************************************/
8
-
9
- var description = {
10
- "name" : "Print Console Info About dpHelper",
11
- "description" : "test",
12
- "version" : "0.0.1",
13
- "command" : "printInfo",
14
- "subCommand" : [],
15
- "example" : "",
16
- "author" : "Dario Passariello",
17
- "active" : true
18
- };
19
-
20
- window.dphelper._list.scripts.push( description );
21
-
22
- /***********************************************************************/
23
-
24
- window.dphelper.printInfo = () => {
25
- console.groupCollapsed('%cApi:%c', "color:orange", "");
26
- console.debug(dphelper.api);
27
- console.groupEnd();
28
- };
@@ -1,26 +0,0 @@
1
- /*!
2
- * dpHelper <https://github.com/passariello/dpHelper>
3
- * Copyright (c) 2021, Dario Passariello.
4
- * Licensed under the Apache-2.0 License.
5
- */
6
-
7
- /***********************************************************************/
8
-
9
- var description = {
10
- "name" : "Random Number Generator",
11
- "description" : "test",
12
- "version" : "0.0.1",
13
- "command" : "rnd",
14
- "subCommand" : [],
15
- "example" : "",
16
- "author" : "Dario Passariello",
17
- "active" : true
18
- };
19
-
20
- window.dphelper._list.scripts.push( description );
21
-
22
- /***********************************************************************/
23
-
24
- window.dphelper.rnd = () => {
25
- return Math.floor( 100000 + Math.random() * dphelper.tmr() );
26
- };
@@ -1,26 +0,0 @@
1
- /*!
2
- * dpHelper <https://github.com/passariello/dpHelper>
3
- * Copyright (c) 2021, Dario Passariello.
4
- * Licensed under the Apache-2.0 License.
5
- */
6
-
7
- /***********************************************************************/
8
-
9
- var description = {
10
- "name" : "Random Number From Timer",
11
- "description" : "test",
12
- "version" : "0.0.1",
13
- "command" : "tmr",
14
- "subCommand" : [],
15
- "example" : "",
16
- "author" : "Dario Passariello",
17
- "active" : true
18
- };
19
-
20
- window.dphelper._list.scripts.push( description );
21
-
22
- /***********************************************************************/
23
-
24
- window.dphelper.tmr = () => {
25
- return Math.round(dphelper.epoch() / 1000);
26
- };
package/scripts/sleep.js DELETED
@@ -1,26 +0,0 @@
1
- /*!
2
- * dpHelper <https://github.com/passariello/dpHelper>
3
- * Copyright (c) 2021, Dario Passariello.
4
- * Licensed under the Apache-2.0 License.
5
- */
6
-
7
- /***********************************************************************/
8
-
9
- var description = {
10
- "name" : "Sleep In ms",
11
- "description" : "test",
12
- "version" : "0.0.1",
13
- "command" : "sleep",
14
- "subCommand" : [],
15
- "example" : "",
16
- "author" : "Dario Passariello",
17
- "active" : true
18
- };
19
-
20
- window.dphelper._list.scripts.push( description );
21
-
22
- /***********************************************************************/
23
-
24
- window.dphelper.sleep = (ms) => {
25
- return new Promise( resolve => setTimeout( resolve, ms) );
26
- };