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.
- package/package.json +1 -1
- package/scripts/array.js +1 -1
- package/scripts/console.js +1 -1
- package/scripts/cookie.js +1 -1
- package/scripts/date.js +1 -1
- package/scripts/disable.js +8 -6
- package/scripts/{addListenerMulti.js → event.js} +15 -8
- package/scripts/font.js +1 -1
- package/scripts/form.js +1 -1
- package/scripts/function.js +47 -0
- package/scripts/indexedDB.js +1 -1
- package/scripts/json.js +1 -1
- package/scripts/load.js +1 -1
- package/scripts/noCache.js +1 -1
- package/scripts/number.js +66 -0
- package/scripts/obj.js +1 -1
- package/scripts/onBeforeUnLoad.js +1 -1
- package/scripts/path.js +14 -14
- package/scripts/{.OLD/~pathQuery.js → promise.js} +14 -7
- package/scripts/pushState.js +1 -1
- package/scripts/screen.js +3 -3
- package/scripts/scrollbar.js +2 -2
- package/scripts/storage.js +1 -1
- package/scripts/text.js +30 -1
- package/scripts/time.js +1 -1
- package/scripts/{.OLD/~loadJson.js → timer.js} +14 -6
- package/scripts/trigger.js +10 -1
- package/scripts/type.js +56 -0
- package/scripts/.OLD/~date2Iso.js +0 -31
- package/scripts/.OLD/~date2MMDDYYYY.js +0 -27
- package/scripts/.OLD/~dateConvert.js +0 -31
- package/scripts/.OLD/~dateIso2Epoch.js +0 -28
- package/scripts/.OLD/~dateLocal-ISOTime.js +0 -28
- package/scripts/.OLD/~dateUTC.js +0 -25
- package/scripts/.OLD/~disableSpellCheck.js +0 -32
- package/scripts/.OLD/~loadJsonExternal.js +0 -44
- package/scripts/.OLD/~object2array.js +0 -28
- package/scripts/.OLD/~parseDate.js +0 -30
- package/scripts/.OLD/~pathHash.js +0 -27
- package/scripts/.OLD/~pathRail.js +0 -27
- package/scripts/.OLD/~scrollIndicator.js +0 -67
- package/scripts/.OLD/~scrollMemory.js +0 -26
- package/scripts/.OLD/~scrollSmooth.js +0 -74
- package/scripts/.OLD/~scrollToElement.js +0 -25
- package/scripts/.OLD/~svgSupport.js +0 -346
- package/scripts/camelCase.js +0 -41
- package/scripts/isPromise.js +0 -26
- package/scripts/nl2br.js +0 -26
- package/scripts/printInfo.js +0 -28
- package/scripts/randomNum.js +0 -26
- package/scripts/randomNumTmr.js +0 -26
- package/scripts/sleep.js +0 -26
|
@@ -1,27 +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" : "Date To MMDDYYYY",
|
|
11
|
-
"description" : "test",
|
|
12
|
-
"version" : "0.0.1",
|
|
13
|
-
"command" : "date2MMDDYYYY",
|
|
14
|
-
"example" : "",
|
|
15
|
-
"author" : "Dario Passariello",
|
|
16
|
-
"active" : true
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
window.dphelper._list.scripts.push( description );
|
|
20
|
-
|
|
21
|
-
/***********************************************************************/
|
|
22
|
-
|
|
23
|
-
window.dphelper.date2MMDDYYYY = (value) => {
|
|
24
|
-
if (!value) value = '';
|
|
25
|
-
let date = new Date(value);
|
|
26
|
-
return ('0' + (date.getMonth() + 1)).slice(-2) + "" + ('0' + date.getDate()).slice(-2) + "" + date.getFullYear();
|
|
27
|
-
};
|
|
@@ -1,31 +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" : "Convert Date",
|
|
11
|
-
"description" : "test",
|
|
12
|
-
"version" : "0.0.1",
|
|
13
|
-
"command" : "dateConvert",
|
|
14
|
-
"example" : "",
|
|
15
|
-
"author" : "Dario Passariello",
|
|
16
|
-
"active" : true
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
window.dphelper._list.scripts.push( description );
|
|
20
|
-
|
|
21
|
-
/***********************************************************************/
|
|
22
|
-
|
|
23
|
-
window.dphelper.dateConvert = (value , format ) => {
|
|
24
|
-
if( !format) format = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
25
|
-
if (!value) return null;
|
|
26
|
-
let monthNames = format;
|
|
27
|
-
let month = value.substring(0, 2).replace('0', '');
|
|
28
|
-
let day = value.substring(2, 4);
|
|
29
|
-
let year = value.substring(value.length - 4);
|
|
30
|
-
return day + ' ' + monthNames[Number(month) - 1] + ' ' + year;
|
|
31
|
-
};
|
|
@@ -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" : "Date Iso To Epoch",
|
|
11
|
-
"description" : "test",
|
|
12
|
-
"version" : "0.0.1",
|
|
13
|
-
"command" : "dateIso2Epoch",
|
|
14
|
-
"example" : "",
|
|
15
|
-
"author" : "Dario Passariello",
|
|
16
|
-
"active" : true
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
window.dphelper._list.scripts.push( description );
|
|
20
|
-
|
|
21
|
-
/***********************************************************************/
|
|
22
|
-
|
|
23
|
-
window.dphelper.dateIso2Epoch = (value) => {
|
|
24
|
-
if (!value) value = '';
|
|
25
|
-
let date = new Date(value);
|
|
26
|
-
let milliseconds = date.getTime();
|
|
27
|
-
return milliseconds;
|
|
28
|
-
};
|
|
@@ -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" : "Local Iso Time",
|
|
11
|
-
"description" : "test",
|
|
12
|
-
"version" : "0.0.1",
|
|
13
|
-
"command" : "localISOTime",
|
|
14
|
-
"example" : "",
|
|
15
|
-
"author" : "Dario Passariello",
|
|
16
|
-
"active" : true
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
window.dphelper._list.scripts.push( description );
|
|
20
|
-
|
|
21
|
-
/***********************************************************************/
|
|
22
|
-
|
|
23
|
-
window.dphelper.localISOTime = (value) => {
|
|
24
|
-
if (!value) value = '';
|
|
25
|
-
let tzoffset = (new Date(value)).getTimezoneOffset() * 60000;
|
|
26
|
-
let localISOTime = (new Date(Date.now() - tzoffset)).toISOString().slice(0, -1);
|
|
27
|
-
return localISOTime;
|
|
28
|
-
};
|
package/scripts/.OLD/~dateUTC.js
DELETED
|
@@ -1,25 +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" : "Date UTC",
|
|
11
|
-
"description" : "test",
|
|
12
|
-
"version" : "0.0.1",
|
|
13
|
-
"command" : "dateUTC",
|
|
14
|
-
"example" : "",
|
|
15
|
-
"author" : "Dario Passariello",
|
|
16
|
-
"active" : true
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
window.dphelper._list.scripts.push( description );
|
|
20
|
-
|
|
21
|
-
/***********************************************************************/
|
|
22
|
-
|
|
23
|
-
window.dphelper.dateUTC = () => {
|
|
24
|
-
return moment().toISOString();
|
|
25
|
-
};
|
|
@@ -1,32 +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" : "Disable SpellCheck",
|
|
11
|
-
"description" : "test",
|
|
12
|
-
"version" : "0.0.1",
|
|
13
|
-
"command" : "disableSpellCheck",
|
|
14
|
-
"example" : "",
|
|
15
|
-
"author" : "Dario Passariello",
|
|
16
|
-
"active" : true
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
window.dphelper._list.scripts.push( description );
|
|
20
|
-
|
|
21
|
-
/***********************************************************************/
|
|
22
|
-
|
|
23
|
-
window.dphelper.disableSpellCheck = ( tmr = 5000 ) => {
|
|
24
|
-
setInterval( () => {
|
|
25
|
-
let inputs = document.querySelectorAll("input[type=text], textarea");
|
|
26
|
-
for(let i = 0; i < inputs.length; i++){
|
|
27
|
-
if( !inputs[i].getAttribute("spellcheck") ){
|
|
28
|
-
inputs[i].setAttribute("spellcheck", "false");
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}, tmr );
|
|
32
|
-
};
|
|
@@ -1,44 +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" : "Load External Json",
|
|
11
|
-
"description" : "test",
|
|
12
|
-
"version" : "0.0.1",
|
|
13
|
-
"command" : "loadJsonExternal",
|
|
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.loadJsonExternal = ( path, method='GET', type='application/json' ) => {
|
|
25
|
-
|
|
26
|
-
fetch( path ,{
|
|
27
|
-
method: method,
|
|
28
|
-
headers : {
|
|
29
|
-
'Content-Type': type
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
.then(
|
|
33
|
-
function(response) {
|
|
34
|
-
//return response.json();
|
|
35
|
-
return response;
|
|
36
|
-
}
|
|
37
|
-
)
|
|
38
|
-
.then(
|
|
39
|
-
function( myFile ) {
|
|
40
|
-
return myFile;
|
|
41
|
-
}
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
};
|
|
@@ -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" : "Convert Object To Array",
|
|
11
|
-
"description" : "test",
|
|
12
|
-
"version" : "0.0.1",
|
|
13
|
-
"command" : "obj2array",
|
|
14
|
-
"sub-command" : [],
|
|
15
|
-
"example" : "",
|
|
16
|
-
"author" : "Dario Passariello",
|
|
17
|
-
"active" : true
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
window.dphelper._list.scripts.push( description );
|
|
21
|
-
|
|
22
|
-
/***********************************************************************/
|
|
23
|
-
|
|
24
|
-
window.dphelper.obj2array = ( object ) => {
|
|
25
|
-
return Object
|
|
26
|
-
.entries( object )
|
|
27
|
-
.map( ( [ key, value ] ) => Object.assign( { key } , value && typeof value === 'object' ? { forms: ObjToArray( value ) } : { value, forms: [] } ) );
|
|
28
|
-
};
|
|
@@ -1,30 +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" : "MMDDYYYY To DD/MM/YYYY",
|
|
11
|
-
"description" : "test",
|
|
12
|
-
"version" : "0.0.1",
|
|
13
|
-
"command" : "parseDate",
|
|
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.parseDate = ( value , separator = '/' ) => {
|
|
25
|
-
if (!value) return null;
|
|
26
|
-
let month = value.substring(0, 2);
|
|
27
|
-
let day = value.substring(2, 4);
|
|
28
|
-
let year = value.substring(4, 8);
|
|
29
|
-
return month + separator + day + separator + year;
|
|
30
|
-
};
|
|
@@ -1,27 +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" : "Array From Hash Path",
|
|
11
|
-
"description" : "test",
|
|
12
|
-
"version" : "0.0.1",
|
|
13
|
-
"command" : "pathHash",
|
|
14
|
-
"subCommand" : [],
|
|
15
|
-
"example" : "",
|
|
16
|
-
"author" : "Dario Passariello",
|
|
17
|
-
"active" : true
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
window.dphelper._list.scripts.push( description );
|
|
21
|
-
|
|
22
|
-
/***********************************************************************/
|
|
23
|
-
// ALIAS
|
|
24
|
-
window.dphelper.pathHash = () => {
|
|
25
|
-
console.log( 'Please use "dphelper.path.hash()"' );
|
|
26
|
-
return window.dphelper.path.hash();
|
|
27
|
-
};
|
|
@@ -1,27 +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" : "Array From Rail",
|
|
11
|
-
"description" : "test",
|
|
12
|
-
"version" : "0.0.1",
|
|
13
|
-
"command" : "pathRail",
|
|
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.pathRail = () => {
|
|
25
|
-
console.log( 'Please use "dphelper.path.rail()"' );
|
|
26
|
-
return window.dphelper.path.rail();
|
|
27
|
-
};
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* dpHelper <https://github.com/passariello/dpHelper>
|
|
3
|
-
*
|
|
4
|
-
* scrollIndicator
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) 2021, Dario Passariello.
|
|
7
|
-
* Licensed under the Apache-2.0 License.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/***********************************************************************/
|
|
11
|
-
|
|
12
|
-
window.dphelper.scrollIndicator = ( props ) => {
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
/* This timeout it's to be suse that whole UI is loaded
|
|
16
|
-
/* Just smaller trick!
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
let cont = document.querySelector( props.el );
|
|
20
|
-
let sc = document.querySelector('.scrollindicator');
|
|
21
|
-
|
|
22
|
-
if( !sc ){
|
|
23
|
-
|
|
24
|
-
const createEl = document.createElement('div');
|
|
25
|
-
createEl.classList.add("scrollindicator");
|
|
26
|
-
document.querySelector('header').appendChild(createEl);
|
|
27
|
-
|
|
28
|
-
createEl.style.cssText = `
|
|
29
|
-
height:5px;
|
|
30
|
-
background:#65c45c;
|
|
31
|
-
position:absolute;
|
|
32
|
-
bottom:0;
|
|
33
|
-
left:0;
|
|
34
|
-
z-index:2
|
|
35
|
-
`;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if( !props.el && sc) {
|
|
39
|
-
sc.style.width = 0 + '%';
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
try{
|
|
44
|
-
let sc = document.querySelector('.scrollindicator');
|
|
45
|
-
cont.addEventListener( 'scroll' , function ( e ) {
|
|
46
|
-
|
|
47
|
-
sc.style.width = 0 + '%';
|
|
48
|
-
let winScroll = this.scrollTop || this.scrollTop;
|
|
49
|
-
let height = this.scrollHeight - this.clientHeight;
|
|
50
|
-
let scrolled = Math.min(Math.max(parseInt( (winScroll / height) * 100 ), 0), 100);
|
|
51
|
-
sc.style.width = scrolled + '%';
|
|
52
|
-
|
|
53
|
-
sc.click();
|
|
54
|
-
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
window.addEventListener('popstate', function ( e ) {
|
|
58
|
-
sc.style.width = 0;
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
}catch( e ){
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return null;
|
|
66
|
-
|
|
67
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
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
|
-
window.dphelper.setScrollPos = ( el ) => {
|
|
14
|
-
let ar = [ $( el ).scrollTop() , $( el ).scrollLeft() ];
|
|
15
|
-
if( ar[0] != null && ar[1] != null ){ window.dphelper.storage.set( el , ar ); }
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/*****************************************************************************************/
|
|
19
|
-
// LOAD OLD SCROLL POSITION
|
|
20
|
-
|
|
21
|
-
window.dphelper.getScrollPos = ( el ) => {
|
|
22
|
-
if( !window.dphelper.storage.get( el ) ) return;
|
|
23
|
-
let ar = window.dphelper.storage.get( el ).trim().split(',');
|
|
24
|
-
$( el ).scrollTop( ar[0] );
|
|
25
|
-
$( el ).scrollLeft( ar[1] );
|
|
26
|
-
};
|
|
@@ -1,74 +0,0 @@
|
|
|
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
|
-
window.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
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
window.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
|
-
};
|