bigpipe-util 0.2.0 → 0.2.1

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
@@ -39,3 +39,12 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
39
39
 
40
40
  ### Fixed
41
41
  - Backdrop for 2+ opened dialogs
42
+
43
+ ## v0.2.1 - 2022-06-02
44
+
45
+ ### Added
46
+ - Prevent links from being double-clicked
47
+ - Support for keyboard (close by escape)
48
+
49
+ ### Fixed
50
+ - Closing dialogs with [esc] in the correct order
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bigpipe-util",
3
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.0",
4
+ "version": "0.2.1",
5
5
  "keywords": [
6
6
  "bigpipe",
7
7
  "xhr",
package/src/Primer.js CHANGED
@@ -19,6 +19,11 @@ export default function Primer() {
19
19
  let relationship = linkNodeOnClicked.rel && linkNodeOnClicked.rel.match(RELATIONSHIP_REGEX);
20
20
  relationship = relationship && relationship[0];
21
21
 
22
+ if (linkNodeOnClicked.classList.contains('async-saving')) {
23
+ event.preventDefault();
24
+ return;
25
+ }
26
+
22
27
  switch (relationship) {
23
28
  case "async":
24
29
  case "async-post":
@@ -26,6 +31,15 @@ export default function Primer() {
26
31
 
27
32
  (new AsyncRequest(linkNodeOnClicked.getAttribute("ajaxify")))
28
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
+ })
29
43
  .setMethod(relationship === "async-post" ? "POST" : "GET")
30
44
  .send();
31
45
  break;
@@ -34,6 +48,15 @@ export default function Primer() {
34
48
 
35
49
  (new AsyncRequest(linkNodeOnClicked.getAttribute("ajaxify")))
36
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
+ })
37
60
  .setMethod("POST")
38
61
  .send();
39
62
  break;
@@ -8,6 +8,16 @@ let modalId = 1;
8
8
  let zIndex;
9
9
  let originalBodyPad = null;
10
10
 
11
+ Modal.prototype._handleKeydownEvent = function(e) {
12
+ if (e.which === 27 && this._options.keyboard) {
13
+ const currentModal = stack[stack.length - 1];
14
+ if (currentModal.el.isEqualNode(this.el)) {
15
+ this.emit('dismiss', this, e, null);
16
+ this.hide();
17
+ }
18
+ }
19
+ }
20
+
11
21
  export default class Dialog {
12
22
  close() {
13
23
  stack.forEach((dialog) => dialog.hide())
@@ -29,6 +39,7 @@ export default class Dialog {
29
39
  const _dialog = this._show({
30
40
  el: document.getElementById(this.id),
31
41
  animate: false,
42
+ keyboard: options.keyboard ?? true,
32
43
  backdrop: options.backdrop ?? true,
33
44
  transition: options.transition ?? 0,
34
45
  backdropTransition: options.backdropTransition ?? 0,
@@ -43,6 +54,7 @@ export default class Dialog {
43
54
  content: model.body,
44
55
  footer: model.footer || false,
45
56
  animate: false,
57
+ keyboard: model.keyboard ?? true,
46
58
  backdrop: model.backdrop ?? true,
47
59
  transition: model.transition ?? 0,
48
60
  backdropTransition: model.backdropTransition ?? 0,