bigpipe-util 0.2.4 → 0.2.6

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 CHANGED
@@ -1,56 +1,80 @@
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.2 - 2022-08-03
8
-
9
- ### Fixed
10
- - calls for modules without constructor
11
- - dialog opening when using instant closing
12
-
13
- ## v0.2.1 - 2022-06-02
14
-
15
- ### Added
16
- - Prevent links from being double-clicked
17
- - Support for keyboard (close by escape)
18
-
19
- ### Fixed
20
- - Closing dialogs with [esc] in the correct order
21
-
22
- ## v0.2.0 - 2022-05-17
23
-
24
- ### Added
25
- - Shield to prevent "JSON Hijacking"
26
- - Invalid node checking for AsyncDOM
27
-
28
- ### Fixed
29
- - Backdrop for 2+ opened dialogs
30
-
31
- ## v0.1.4 - 2022-05-06
32
-
33
- ### Added
34
- - Async requests counter
35
- - Support for extra arguments in dialog controller
36
-
37
- ### Fixed
38
- - Arguments for non-method require calls
39
-
40
- ## v0.1.3 - 2022-04-27
41
-
42
- ### Added
43
- - Method to close only current dialog
44
-
45
- ### Fixed
46
- - Dialog z-index
47
-
48
- ## v0.1.2 - 2022-04-14
49
-
50
- ### Added
51
- - Dialogs support.
52
-
53
- ## v0.1.1 - 2022-03-27
54
-
55
- ### Added
56
- - Part of BigPipe implementation for Webpack.
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.6 - 2025-01-16
8
+
9
+ ### Added
10
+ - Added `limit` parameter to `Dialog.js` for limiting the number of closed dialogs
11
+
12
+ ## v0.2.5 - 2023-03-07
13
+
14
+ ### Added
15
+ - Added `Arbiter.js` event system
16
+ - Added methods `byClass`, `byAttribute`, `find` to `Parent.js`
17
+
18
+ ### Fixed
19
+ - Fixed controller calling
20
+
21
+ ## v0.2.4 - 2023-02-03
22
+
23
+ ### Fixed
24
+ - Fixed controller calling
25
+
26
+ ## v0.2.3 - 2023-02-04
27
+
28
+ ### Added
29
+ - Added setFinallyHandler for AsyncRequest
30
+
31
+ ## v0.2.2 - 2022-08-03
32
+
33
+ ### Fixed
34
+ - Calls for modules without constructor
35
+ - Dialog opening when using instant closing
36
+
37
+ ## v0.2.1 - 2022-06-02
38
+
39
+ ### Added
40
+ - Prevent links from being double-clicked
41
+ - Support for keyboard (close by escape)
42
+
43
+ ### Fixed
44
+ - Closing dialogs with [esc] in the correct order
45
+
46
+ ## v0.2.0 - 2022-05-17
47
+
48
+ ### Added
49
+ - Shield to prevent "JSON Hijacking"
50
+ - Invalid node checking for AsyncDOM
51
+
52
+ ### Fixed
53
+ - Backdrop for 2+ opened dialogs
54
+
55
+ ## v0.1.4 - 2022-05-06
56
+
57
+ ### Added
58
+ - Async requests counter
59
+ - Support for extra arguments in dialog controller
60
+
61
+ ### Fixed
62
+ - Arguments for non-method require calls
63
+
64
+ ## v0.1.3 - 2022-04-27
65
+
66
+ ### Added
67
+ - Method to close only current dialog
68
+
69
+ ### Fixed
70
+ - Dialog z-index
71
+
72
+ ## v0.1.2 - 2022-04-14
73
+
74
+ ### Added
75
+ - Dialogs support.
76
+
77
+ ## v0.1.1 - 2022-03-27
78
+
79
+ ### Added
80
+ - 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.4",
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.6",
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
- let relationship = linkNodeOnClicked.rel && linkNodeOnClicked.rel.match(RELATIONSHIP_REGEX);
20
- relationship = relationship && relationship[0];
21
-
22
- if (linkNodeOnClicked.classList.contains('async-saving')) {
23
- event.preventDefault();
24
- return;
25
- }
26
-
27
- switch (relationship) {
28
- case "async":
29
- case "async-post":
30
- event.preventDefault();
31
-
32
- (new AsyncRequest(linkNodeOnClicked.getAttribute("ajaxify")))
33
- .setRelative(linkNodeOnClicked)
34
- .setInitialHandler(() => {
35
- linkNodeOnClicked.classList.add("async-saving");
36
- })
37
- .setHandler(() => {
38
- linkNodeOnClicked.classList.remove("async-saving");
39
- })
40
- .setErrorHandler(() => {
41
- linkNodeOnClicked.classList.remove("async-saving");
42
- })
43
- .setMethod(relationship === "async-post" ? "POST" : "GET")
44
- .send();
45
- break;
46
- case "dialog":
47
- event.preventDefault();
48
-
49
- (new AsyncRequest(linkNodeOnClicked.getAttribute("ajaxify")))
50
- .setRelative(linkNodeOnClicked)
51
- .setInitialHandler(() => {
52
- linkNodeOnClicked.classList.add("async-saving");
53
- })
54
- .setHandler(() => {
55
- linkNodeOnClicked.classList.remove("async-saving");
56
- })
57
- .setErrorHandler(() => {
58
- linkNodeOnClicked.classList.remove("async-saving");
59
- })
60
- .setMethod("POST")
61
- .send();
62
- break;
63
- }
64
- };
65
-
66
- rootElement.onsubmit = function (event) {
67
- event = event || window.event;
68
- const eventTarget = event.target || event.srcElement;
69
-
70
- if (eventTarget &&
71
- eventTarget.nodeName === "FORM" &&
72
- eventTarget.getAttribute("rel") === "async") {
73
- event.preventDefault();
74
-
75
- const submitter = event.submitter || eventTarget.querySelector("button[type='submit']"),
76
- activeControls = eventTarget.querySelectorAll("input:not([readonly]),select:not([readonly]),textarea:not([readonly])");
77
-
78
- (new AsyncRequest(eventTarget.getAttribute("ajaxify") || eventTarget.getAttribute("action")))
79
- .setMethod(eventTarget.method || "POST")
80
- .setRelative(eventTarget)
81
- .setData(new FormData(eventTarget))
82
- .setInitialHandler(function () {
83
- if (!eventTarget.classList.contains("disable-prevent-form")) {
84
- activeControls.forEach(function (control) {
85
- control.setAttribute("readonly", "readonly");
86
- });
87
-
88
- if (submitter) {
89
- submitter.disabled = true;
90
- }
91
- }
92
-
93
- if (eventTarget) {
94
- const loader = eventTarget.querySelector(".form-loader");
95
-
96
- if (loader) {
97
- loader.classList.add("loading");
98
- }
99
- }
100
- })
101
- .setHandler(function (response) {
102
- activeControls.forEach(function (control) {
103
- control.removeAttribute("readonly");
104
- });
105
-
106
- if (submitter) {
107
- submitter.disabled = false;
108
- }
109
-
110
- if (eventTarget) {
111
- const loader = eventTarget.querySelector(".small-loader");
112
-
113
- if (loader) {
114
- loader.classList.remove("loading");
115
- }
116
- }
117
- })
118
- .setErrorHandler(function () {
119
- activeControls.forEach(function (control) {
120
- control.removeAttribute("readonly");
121
- });
122
-
123
- if (eventTarget) {
124
- const loader = eventTarget.querySelector(".small-loader");
125
-
126
- if (loader) {
127
- loader.classList.remove("loading");
128
- }
129
- }
130
- })
131
- .send();
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
+ }
package/src/ServerJS.js CHANGED
@@ -1,40 +1,40 @@
1
- import replaceTransportMarkers from "./core/replaceTransportMarkers";
2
-
3
- function handler(dependencies, guard, context) {
4
- return dependencies.map(function (args) {
5
- guard.apply(context, args);
6
- });
7
- }
8
-
9
- export default class ServerJS {
10
- constructor() {
11
- this._relativeTo = document.body;
12
- }
13
-
14
- handle(jsMods) {
15
- handler(jsMods.require || [], this._handleRequire, this);
16
- }
17
-
18
- _handleRequire(modulePath, method, marker) {
19
- if (method && typeof method === 'string') {
20
- if (marker) {
21
- replaceTransportMarkers(this._relativeTo, marker);
22
- }
23
-
24
- const factory = window.require(modulePath);
25
- const context = typeof factory === 'function' ? new factory : factory;
26
-
27
- if (!context[method]) {
28
- throw new TypeError(`Module ${modulePath} has no method "${method}"`);
29
- }
30
-
31
- context[method].apply(context, marker || []);
32
- } else {
33
- if (marker) {
34
- replaceTransportMarkers(this._relativeTo, marker);
35
- }
36
-
37
- new (window.require(modulePath))(...(marker || []));
38
- }
39
- }
40
- }
1
+ import replaceTransportMarkers from "./core/replaceTransportMarkers";
2
+
3
+ function handler(dependencies, guard, context) {
4
+ return dependencies.map(function (args) {
5
+ guard.apply(context, args);
6
+ });
7
+ }
8
+
9
+ export default class ServerJS {
10
+ constructor() {
11
+ this._relativeTo = document.body;
12
+ }
13
+
14
+ handle(jsMods) {
15
+ handler(jsMods.require || [], this._handleRequire, this);
16
+ }
17
+
18
+ _handleRequire(modulePath, method, marker) {
19
+ if (method && typeof method === 'string') {
20
+ if (marker) {
21
+ replaceTransportMarkers(this._relativeTo, marker);
22
+ }
23
+
24
+ const factory = window.require(modulePath);
25
+ const context = typeof factory === 'function' ? new factory : factory;
26
+
27
+ if (!context[method]) {
28
+ throw new TypeError(`Module ${modulePath} has no method "${method}"`);
29
+ }
30
+
31
+ context[method].apply(context, marker || []);
32
+ } else {
33
+ if (marker) {
34
+ replaceTransportMarkers(this._relativeTo, marker);
35
+ }
36
+
37
+ new (window.require(modulePath))(...(marker || []));
38
+ }
39
+ }
40
+ }