bigpipe-util 0.2.5 → 0.2.7
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/CHANGELOG.md +85 -75
- package/LICENSE +19 -19
- package/README.md +3 -0
- package/bigpipe.svg +13 -13
- package/package.json +25 -25
- package/src/Primer.js +151 -134
- package/src/ServerJS.js +40 -40
- package/src/async/AsyncDOM.js +56 -56
- package/src/async/AsyncRequest.js +206 -206
- package/src/async/AsyncResponse.js +21 -21
- package/src/core/$.js +3 -3
- package/src/core/Arbiter.js +53 -53
- package/src/core/DOM.js +41 -41
- package/src/core/Dialog.js +143 -129
- package/src/core/Parent.js +38 -38
- package/src/core/ReloadPage.js +9 -9
- package/src/core/ServerRedirect.js +7 -7
- package/src/core/copyProperties.js +46 -46
- package/src/core/replaceTransportMarkers.js +27 -27
package/CHANGELOG.md
CHANGED
|
@@ -1,75 +1,85 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to `bigpipe-util` will be documented in this file.
|
|
4
|
-
|
|
5
|
-
Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
|
|
6
|
-
|
|
7
|
-
## v0.2.
|
|
8
|
-
|
|
9
|
-
### Added
|
|
10
|
-
- Added `
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
###
|
|
24
|
-
-
|
|
25
|
-
|
|
26
|
-
## v0.2.
|
|
27
|
-
|
|
28
|
-
### Fixed
|
|
29
|
-
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
### Fixed
|
|
39
|
-
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
###
|
|
75
|
-
-
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `bigpipe-util` will be documented in this file.
|
|
4
|
+
|
|
5
|
+
Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
|
|
6
|
+
|
|
7
|
+
## v0.2.7 - 2025-03-22
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- Added `timeout` to open dialog with a delay
|
|
11
|
+
|
|
12
|
+
## v0.2.6 - 2025-01-16
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
- Added `limit` parameter to `Dialog.js` for limiting the number of closed dialogs
|
|
16
|
+
|
|
17
|
+
## v0.2.5 - 2023-03-07
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
- Added `Arbiter.js` event system
|
|
21
|
+
- Added methods `byClass`, `byAttribute`, `find` to `Parent.js`
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
- Fixed controller calling
|
|
25
|
+
|
|
26
|
+
## v0.2.4 - 2023-02-03
|
|
27
|
+
|
|
28
|
+
### Fixed
|
|
29
|
+
- Fixed controller calling
|
|
30
|
+
|
|
31
|
+
## v0.2.3 - 2023-02-04
|
|
32
|
+
|
|
33
|
+
### Added
|
|
34
|
+
- Added setFinallyHandler for AsyncRequest
|
|
35
|
+
|
|
36
|
+
## v0.2.2 - 2022-08-03
|
|
37
|
+
|
|
38
|
+
### Fixed
|
|
39
|
+
- Calls for modules without constructor
|
|
40
|
+
- Dialog opening when using instant closing
|
|
41
|
+
|
|
42
|
+
## v0.2.1 - 2022-06-02
|
|
43
|
+
|
|
44
|
+
### Added
|
|
45
|
+
- Prevent links from being double-clicked
|
|
46
|
+
- Support for keyboard (close by escape)
|
|
47
|
+
|
|
48
|
+
### Fixed
|
|
49
|
+
- Closing dialogs with [esc] in the correct order
|
|
50
|
+
|
|
51
|
+
## v0.2.0 - 2022-05-17
|
|
52
|
+
|
|
53
|
+
### Added
|
|
54
|
+
- Shield to prevent "JSON Hijacking"
|
|
55
|
+
- Invalid node checking for AsyncDOM
|
|
56
|
+
|
|
57
|
+
### Fixed
|
|
58
|
+
- Backdrop for 2+ opened dialogs
|
|
59
|
+
|
|
60
|
+
## v0.1.4 - 2022-05-06
|
|
61
|
+
|
|
62
|
+
### Added
|
|
63
|
+
- Async requests counter
|
|
64
|
+
- Support for extra arguments in dialog controller
|
|
65
|
+
|
|
66
|
+
### Fixed
|
|
67
|
+
- Arguments for non-method require calls
|
|
68
|
+
|
|
69
|
+
## v0.1.3 - 2022-04-27
|
|
70
|
+
|
|
71
|
+
### Added
|
|
72
|
+
- Method to close only current dialog
|
|
73
|
+
|
|
74
|
+
### Fixed
|
|
75
|
+
- Dialog z-index
|
|
76
|
+
|
|
77
|
+
## v0.1.2 - 2022-04-14
|
|
78
|
+
|
|
79
|
+
### Added
|
|
80
|
+
- Dialogs support.
|
|
81
|
+
|
|
82
|
+
## v0.1.1 - 2022-03-27
|
|
83
|
+
|
|
84
|
+
### Added
|
|
85
|
+
- Part of BigPipe implementation for Webpack.
|
package/LICENSE
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
Copyright (C) 2017 Richard Dobroň
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
-
in the Software without restriction, including without limitation the rights
|
|
6
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
-
furnished to do so, subject to the following conditions:
|
|
9
|
-
|
|
10
|
-
The above copyright notice and this permission notice shall be included in
|
|
11
|
-
all copies or substantial portions of the Software.
|
|
12
|
-
|
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
-
THE SOFTWARE.
|
|
1
|
+
Copyright (C) 2017 Richard Dobroň
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -6,6 +6,9 @@ This library currently implements small part of [Facebook BigPipe][blog] so far,
|
|
|
6
6
|
## Demo App
|
|
7
7
|
Try the app with [live demo](http://bigpipe.xf.cz).
|
|
8
8
|
|
|
9
|
+
## Full documentation
|
|
10
|
+
https://richarddobron.github.io/bigpipe-php/
|
|
11
|
+
|
|
9
12
|
## Requirements
|
|
10
13
|
* PHP 7.1 or higher
|
|
11
14
|
* Webpack
|
package/bigpipe.svg
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
<svg width="254.23999568394254" height="64.8" viewBox="0 0 254.23999568394254 64.8" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
-
<g transform="matrix(3.0856473041983374,0,0,3.0856473041983374,-6.171373325690784,-6.1698442238608315)" fill="#0C056D">
|
|
3
|
-
<g xmlns="http://www.w3.org/2000/svg">
|
|
4
|
-
<path d="M2.2427,8.9287a.5.5,0,0,1,0-.8574l10-6a.4971.4971,0,0,1,.5146,0l10,6a.5.5,0,0,1,0,.8574l-10,6a.5.5,0,0,1-.5146,0Zm20,3.1426L12.5,17.917,2.7573,12.0713a.5.5,0,0,0-.5146.8574l10,6a.5.5,0,0,0,.5146,0l10-6a.5.5,0,0,0-.5146-.8574Zm0,4L12.5,21.917,2.7573,16.0713a.5.5,0,0,0-.5146.8574l10,6a.5.5,0,0,0,.5146,0l10-6a.5.5,0,0,0-.5146-.8574Z"></path>
|
|
5
|
-
</g>
|
|
6
|
-
</g>
|
|
7
|
-
<g transform="matrix(2.500000066227385,0,0,2.500000066227385,81.99999920527138,0.49999675485814166)" fill="#0C056D">
|
|
8
|
-
<path d="M8.92 12.24 c1.48 0.4 2.88 1.72 2.88 3.66 c0 2.54 -1.6 4.1 -5.08 4.1 l-5.52 0 l0 -14 l5.22 0 c2.9 0 4.36 1.64 4.36 3.52 c0 1.48 -0.96 2.32 -1.86 2.72 z M6.14 8.56 l-2.02 0 l0 2.82 l2.02 0 c1.24 0 1.74 -0.58 1.74 -1.42 c0 -0.9 -0.58 -1.4 -1.74 -1.4 z M6.56 17.44 c1.6 0 2.32 -0.66 2.32 -1.9 c0 -1.06 -0.72 -1.8 -2.44 -1.8 l-2.32 0 l0 3.7 l2.44 0 z M16.62 6 l0 14 l-2.92 0 l0 -14 l2.92 0 z M32.2 12.559999999999999 c0.62 4.7 -2.44 7.64 -6.22 7.64 c-3.98 0 -7.26 -2.94 -7.26 -7.2 s3.36 -7.2 7.26 -7.2 c1.86 0 3.5 0.6 4.7 1.66 l-1.76 1.98 c-0.74 -0.52 -1.74 -0.9 -2.76 -0.9 c-2.54 0 -4.4 1.86 -4.4 4.46 s1.8 4.46 4.22 4.46 c1.84 0 3.12 -0.66 3.52 -2.42 l-3.3 0 l0 -2.48 l6 0 z"></path>
|
|
9
|
-
</g>
|
|
10
|
-
<g transform="matrix(2.5714285714285716,0,0,2.5714285714285716,166.91428559167045,-0.4285714285714306)" fill="#0C056D">
|
|
11
|
-
<path d="M5.46 6 c3.14 0 4.8 1.94 4.8 4.3 c0 2.42 -1.66 4.34 -4.8 4.34 l-3.68 0 l0 5.36 l-0.58 0 l0 -14 l4.26 0 z M5.54 14.04 c2.52 0 4.14 -1.46 4.14 -3.74 c0 -2.32 -1.62 -3.72 -4.14 -3.72 l-3.76 0 l0 7.46 l3.76 0 z M12.74 6 l0 14 l-0.58 0 l0 -14 l0.58 0 z M19.400000000000002 6 c3.14 0 4.8 1.94 4.8 4.3 c0 2.42 -1.66 4.34 -4.8 4.34 l-3.68 0 l0 5.36 l-0.58 0 l0 -14 l4.26 0 z M19.48 14.04 c2.52 0 4.14 -1.46 4.14 -3.74 c0 -2.32 -1.62 -3.72 -4.14 -3.72 l-3.76 0 l0 7.46 l3.76 0 z M26.680000000000003 19.42 l7.28 0 l0 0.58 l-7.68 0 l-0.18 0 l0 -14 l0.58 0 l7.1 0 l0 0.58 l-7.1 0 l0 6.1 l5.66 0 l0 0.58 l-5.66 0 l0 6.16 z"></path>
|
|
12
|
-
</g>
|
|
13
|
-
</svg>
|
|
1
|
+
<svg width="254.23999568394254" height="64.8" viewBox="0 0 254.23999568394254 64.8" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<g transform="matrix(3.0856473041983374,0,0,3.0856473041983374,-6.171373325690784,-6.1698442238608315)" fill="#0C056D">
|
|
3
|
+
<g xmlns="http://www.w3.org/2000/svg">
|
|
4
|
+
<path d="M2.2427,8.9287a.5.5,0,0,1,0-.8574l10-6a.4971.4971,0,0,1,.5146,0l10,6a.5.5,0,0,1,0,.8574l-10,6a.5.5,0,0,1-.5146,0Zm20,3.1426L12.5,17.917,2.7573,12.0713a.5.5,0,0,0-.5146.8574l10,6a.5.5,0,0,0,.5146,0l10-6a.5.5,0,0,0-.5146-.8574Zm0,4L12.5,21.917,2.7573,16.0713a.5.5,0,0,0-.5146.8574l10,6a.5.5,0,0,0,.5146,0l10-6a.5.5,0,0,0-.5146-.8574Z"></path>
|
|
5
|
+
</g>
|
|
6
|
+
</g>
|
|
7
|
+
<g transform="matrix(2.500000066227385,0,0,2.500000066227385,81.99999920527138,0.49999675485814166)" fill="#0C056D">
|
|
8
|
+
<path d="M8.92 12.24 c1.48 0.4 2.88 1.72 2.88 3.66 c0 2.54 -1.6 4.1 -5.08 4.1 l-5.52 0 l0 -14 l5.22 0 c2.9 0 4.36 1.64 4.36 3.52 c0 1.48 -0.96 2.32 -1.86 2.72 z M6.14 8.56 l-2.02 0 l0 2.82 l2.02 0 c1.24 0 1.74 -0.58 1.74 -1.42 c0 -0.9 -0.58 -1.4 -1.74 -1.4 z M6.56 17.44 c1.6 0 2.32 -0.66 2.32 -1.9 c0 -1.06 -0.72 -1.8 -2.44 -1.8 l-2.32 0 l0 3.7 l2.44 0 z M16.62 6 l0 14 l-2.92 0 l0 -14 l2.92 0 z M32.2 12.559999999999999 c0.62 4.7 -2.44 7.64 -6.22 7.64 c-3.98 0 -7.26 -2.94 -7.26 -7.2 s3.36 -7.2 7.26 -7.2 c1.86 0 3.5 0.6 4.7 1.66 l-1.76 1.98 c-0.74 -0.52 -1.74 -0.9 -2.76 -0.9 c-2.54 0 -4.4 1.86 -4.4 4.46 s1.8 4.46 4.22 4.46 c1.84 0 3.12 -0.66 3.52 -2.42 l-3.3 0 l0 -2.48 l6 0 z"></path>
|
|
9
|
+
</g>
|
|
10
|
+
<g transform="matrix(2.5714285714285716,0,0,2.5714285714285716,166.91428559167045,-0.4285714285714306)" fill="#0C056D">
|
|
11
|
+
<path d="M5.46 6 c3.14 0 4.8 1.94 4.8 4.3 c0 2.42 -1.66 4.34 -4.8 4.34 l-3.68 0 l0 5.36 l-0.58 0 l0 -14 l4.26 0 z M5.54 14.04 c2.52 0 4.14 -1.46 4.14 -3.74 c0 -2.32 -1.62 -3.72 -4.14 -3.72 l-3.76 0 l0 7.46 l3.76 0 z M12.74 6 l0 14 l-0.58 0 l0 -14 l0.58 0 z M19.400000000000002 6 c3.14 0 4.8 1.94 4.8 4.3 c0 2.42 -1.66 4.34 -4.8 4.34 l-3.68 0 l0 5.36 l-0.58 0 l0 -14 l4.26 0 z M19.48 14.04 c2.52 0 4.14 -1.46 4.14 -3.74 c0 -2.32 -1.62 -3.72 -4.14 -3.72 l-3.76 0 l0 7.46 l3.76 0 z M26.680000000000003 19.42 l7.28 0 l0 0.58 l-7.68 0 l-0.18 0 l0 -14 l0.58 0 l7.1 0 l0 0.58 l-7.1 0 l0 6.1 l5.66 0 l0 0.58 l-5.66 0 l0 6.16 z"></path>
|
|
12
|
+
</g>
|
|
13
|
+
</svg>
|
package/package.json
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "bigpipe-util",
|
|
3
|
-
"description": "This library currently implements small part of Facebook BigPipe so far, but the advantage is to efficiently insert/replace content and work with the DOM. It is also possible to easily call JavaScript modules from PHP.",
|
|
4
|
-
"version": "0.2.
|
|
5
|
-
"keywords": [
|
|
6
|
-
"bigpipe",
|
|
7
|
-
"xhr",
|
|
8
|
-
"html",
|
|
9
|
-
"dom",
|
|
10
|
-
"async",
|
|
11
|
-
"javascript"
|
|
12
|
-
],
|
|
13
|
-
"homepage": "https://github.com/richardDobron/bigpipe-util",
|
|
14
|
-
"author": "Richard Dobroň",
|
|
15
|
-
"repository": {
|
|
16
|
-
"type": "git",
|
|
17
|
-
"url": "git://github.com/richardDobron/bigpipe-util.git"
|
|
18
|
-
},
|
|
19
|
-
"bugs:": "https://github.com/richardDobron/bigpipe-util/issues",
|
|
20
|
-
"license": "MIT",
|
|
21
|
-
"dependencies": {
|
|
22
|
-
"fbjs": "^3.0.4",
|
|
23
|
-
"modal-vanilla": "^0.9.0"
|
|
24
|
-
}
|
|
25
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "bigpipe-util",
|
|
3
|
+
"description": "This library currently implements small part of Facebook BigPipe so far, but the advantage is to efficiently insert/replace content and work with the DOM. It is also possible to easily call JavaScript modules from PHP.",
|
|
4
|
+
"version": "0.2.7",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"bigpipe",
|
|
7
|
+
"xhr",
|
|
8
|
+
"html",
|
|
9
|
+
"dom",
|
|
10
|
+
"async",
|
|
11
|
+
"javascript"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/richardDobron/bigpipe-util",
|
|
14
|
+
"author": "Richard Dobroň",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git://github.com/richardDobron/bigpipe-util.git"
|
|
18
|
+
},
|
|
19
|
+
"bugs:": "https://github.com/richardDobron/bigpipe-util/issues",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"fbjs": "^3.0.4",
|
|
23
|
+
"modal-vanilla": "^0.9.0"
|
|
24
|
+
}
|
|
25
|
+
}
|
package/src/Primer.js
CHANGED
|
@@ -1,134 +1,151 @@
|
|
|
1
|
-
import AsyncRequest from "./async/AsyncRequest";
|
|
2
|
-
import {byTag} from "./core/Parent";
|
|
3
|
-
|
|
4
|
-
export default function Primer() {
|
|
5
|
-
const rootElement = document.documentElement;
|
|
6
|
-
|
|
7
|
-
const RELATIONSHIP_REGEX = /async(?:-post)?|dialog/;
|
|
8
|
-
|
|
9
|
-
rootElement.onclick = function (event) {
|
|
10
|
-
event = event || window.event;
|
|
11
|
-
const elementOnClicked = event.target || event.srcElement;
|
|
12
|
-
|
|
13
|
-
const linkNodeOnClicked = byTag(elementOnClicked, "A");
|
|
14
|
-
|
|
15
|
-
if (!linkNodeOnClicked) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
.
|
|
52
|
-
linkNodeOnClicked.classList.
|
|
53
|
-
})
|
|
54
|
-
.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
1
|
+
import AsyncRequest from "./async/AsyncRequest";
|
|
2
|
+
import {byTag} from "./core/Parent";
|
|
3
|
+
|
|
4
|
+
export default function Primer() {
|
|
5
|
+
const rootElement = document.documentElement;
|
|
6
|
+
|
|
7
|
+
const RELATIONSHIP_REGEX = /async(?:-post)?|dialog/;
|
|
8
|
+
|
|
9
|
+
rootElement.onclick = function (event) {
|
|
10
|
+
event = event || window.event;
|
|
11
|
+
const elementOnClicked = event.target || event.srcElement;
|
|
12
|
+
|
|
13
|
+
const linkNodeOnClicked = byTag(elementOnClicked, "A");
|
|
14
|
+
|
|
15
|
+
if (!linkNodeOnClicked) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const ajaxHref = linkNodeOnClicked.getAttribute("ajaxify")
|
|
20
|
+
const realHref = linkNodeOnClicked.href
|
|
21
|
+
let relationship = linkNodeOnClicked.rel && linkNodeOnClicked.rel.match(RELATIONSHIP_REGEX);
|
|
22
|
+
relationship = relationship && relationship[0];
|
|
23
|
+
|
|
24
|
+
if (ajaxHref && realHref && !/#$/.test(realHref)) {
|
|
25
|
+
const isMiddleMouseButton = event.which && event.which === 2;
|
|
26
|
+
const hasModifierKey = event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;
|
|
27
|
+
|
|
28
|
+
if (isMiddleMouseButton || hasModifierKey) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (linkNodeOnClicked.classList.contains('async-saving')) {
|
|
34
|
+
event.preventDefault();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
switch (relationship) {
|
|
39
|
+
case "async":
|
|
40
|
+
case "async-post":
|
|
41
|
+
event.preventDefault();
|
|
42
|
+
|
|
43
|
+
(new AsyncRequest(ajaxHref))
|
|
44
|
+
.setRelative(linkNodeOnClicked)
|
|
45
|
+
.setInitialHandler(() => {
|
|
46
|
+
linkNodeOnClicked.classList.add("async-saving");
|
|
47
|
+
})
|
|
48
|
+
.setHandler(() => {
|
|
49
|
+
linkNodeOnClicked.classList.remove("async-saving");
|
|
50
|
+
})
|
|
51
|
+
.setErrorHandler(() => {
|
|
52
|
+
linkNodeOnClicked.classList.remove("async-saving");
|
|
53
|
+
})
|
|
54
|
+
.setMethod(relationship === "async-post" ? "POST" : "GET")
|
|
55
|
+
.send();
|
|
56
|
+
break;
|
|
57
|
+
case "dialog":
|
|
58
|
+
event.preventDefault();
|
|
59
|
+
|
|
60
|
+
(new AsyncRequest(linkNodeOnClicked.getAttribute("ajaxify")))
|
|
61
|
+
.setRelative(linkNodeOnClicked)
|
|
62
|
+
.setInitialHandler(() => {
|
|
63
|
+
linkNodeOnClicked.classList.add("async-saving");
|
|
64
|
+
})
|
|
65
|
+
.setHandler(() => {
|
|
66
|
+
linkNodeOnClicked.classList.remove("async-saving");
|
|
67
|
+
})
|
|
68
|
+
.setErrorHandler(() => {
|
|
69
|
+
linkNodeOnClicked.classList.remove("async-saving");
|
|
70
|
+
})
|
|
71
|
+
.setMethod("POST")
|
|
72
|
+
.send();
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
rootElement.onsubmit = function (event) {
|
|
78
|
+
event = event || window.event;
|
|
79
|
+
const eventTarget = event.target || event.srcElement;
|
|
80
|
+
|
|
81
|
+
if (eventTarget &&
|
|
82
|
+
eventTarget.nodeName === "FORM" &&
|
|
83
|
+
eventTarget.getAttribute("rel") === "async") {
|
|
84
|
+
event.preventDefault();
|
|
85
|
+
|
|
86
|
+
const submitter = event.submitter || eventTarget.querySelector("button[type='submit']");
|
|
87
|
+
const activeControls = eventTarget.querySelectorAll("input:not([readonly]),select:not([readonly]),textarea:not([readonly])");
|
|
88
|
+
|
|
89
|
+
(new AsyncRequest(eventTarget.getAttribute("ajaxify") || eventTarget.getAttribute("action")))
|
|
90
|
+
.setMethod(eventTarget.method || "POST")
|
|
91
|
+
.setRelative(eventTarget)
|
|
92
|
+
.setData(new FormData(eventTarget))
|
|
93
|
+
.setInitialHandler(function () {
|
|
94
|
+
eventTarget.classList.add("async-saving");
|
|
95
|
+
|
|
96
|
+
if (!eventTarget.classList.contains("disable-prevent-form")) {
|
|
97
|
+
activeControls.forEach(function (control) {
|
|
98
|
+
control.setAttribute("readonly", "readonly");
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
if (submitter) {
|
|
102
|
+
submitter.disabled = true;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (eventTarget) {
|
|
107
|
+
const loader = eventTarget.querySelector(".form-loader");
|
|
108
|
+
|
|
109
|
+
if (loader) {
|
|
110
|
+
loader.classList.add("loading");
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
.setHandler(function (response) {
|
|
115
|
+
eventTarget.classList.remove("async-saving");
|
|
116
|
+
|
|
117
|
+
activeControls.forEach(function (control) {
|
|
118
|
+
control.removeAttribute("readonly");
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
if (submitter) {
|
|
122
|
+
submitter.disabled = false;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (eventTarget) {
|
|
126
|
+
const loader = eventTarget.querySelector(".small-loader");
|
|
127
|
+
|
|
128
|
+
if (loader) {
|
|
129
|
+
loader.classList.remove("loading");
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
.setErrorHandler(function () {
|
|
134
|
+
eventTarget.classList.add("async-saving");
|
|
135
|
+
|
|
136
|
+
activeControls.forEach(function (control) {
|
|
137
|
+
control.removeAttribute("readonly");
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
if (eventTarget) {
|
|
141
|
+
const loader = eventTarget.querySelector(".small-loader");
|
|
142
|
+
|
|
143
|
+
if (loader) {
|
|
144
|
+
loader.classList.remove("loading");
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
})
|
|
148
|
+
.send();
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|