@bbn/bbn 2.0.111 → 2.0.113

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/dist/env.d.ts CHANGED
@@ -27,6 +27,7 @@ declare const _default: {
27
27
  params: any[];
28
28
  isInit: boolean;
29
29
  isFocused: boolean;
30
+ isVisible: boolean;
30
31
  timeoff: number;
31
32
  loggingLevel: number;
32
33
  ignoreUnload: boolean;
package/dist/env.js CHANGED
@@ -39,6 +39,7 @@ export default {
39
39
  params: [],
40
40
  isInit: false,
41
41
  isFocused: false,
42
+ isVisible: !document.hidden,
42
43
  timeoff: Math.round((new Date()).getTime() / 1000),
43
44
  loggingLevel: 5,
44
45
  ignoreUnload: false,
package/dist/fn/init.d.ts CHANGED
@@ -11,4 +11,4 @@
11
11
  * @param {Object} cfg
12
12
  * @returns
13
13
  */
14
- export default function init(cfg: any, force: any): void;
14
+ export default function init(cfg?: object, force?: boolean): void;
package/dist/fn/init.js CHANGED
@@ -3,13 +3,43 @@ import each from './loop/each.js';
3
3
  import extend from './object/extend.js';
4
4
  import addColors from './style/addColors.js';
5
5
  import link from './ajax/link.js';
6
- import submit from './form/submit.js';
7
6
  import resize from './style/resize.js';
8
7
  import isMobile from './browser/isMobile.js';
9
8
  import isTabletDevice from './browser/isTabletDevice.js';
10
9
  import isFunction from './type/isFunction.js';
11
10
  import log from './browser/log.js';
12
11
  import timestamp from './datetime/timestamp.js';
12
+ const onActivity = (e) => {
13
+ bbn.env.last_focus = bbn.dt().unix();
14
+ if (bbn.env.nav !== "ajax") {
15
+ return;
16
+ }
17
+ let target = e.target;
18
+ if (target instanceof HTMLElement && target.tagName !== "A") {
19
+ let p = target;
20
+ while (p && p.tagName !== "A") {
21
+ if (p.tagName === "BODY") {
22
+ break;
23
+ }
24
+ p = p.parentElement;
25
+ }
26
+ if (p && p.tagName === "A") {
27
+ target = p;
28
+ }
29
+ else {
30
+ target = null;
31
+ }
32
+ }
33
+ if (target instanceof HTMLElement &&
34
+ target.hasAttribute("href") &&
35
+ !target.hasAttribute("target") &&
36
+ !target.classList.contains("bbn-no")) {
37
+ e.preventDefault();
38
+ e.stopPropagation();
39
+ link(target.getAttribute("href"));
40
+ return false;
41
+ }
42
+ };
13
43
  /**
14
44
  * Initializes the library bbn basing on the given configuration object.
15
45
  * - Gives to the environment the dimension of the window.innerWidth and window.innerHeight
@@ -48,56 +78,33 @@ export default function init(cfg, force) {
48
78
  addColors(bbn.var.colors);
49
79
  }
50
80
  document.addEventListener("visibilitychange", () => {
51
- if (document.hidden && bbn.env.isFocused) {
52
- bbn.env.isFocused = false;
81
+ if (document.hidden) {
82
+ bbn.env.isVisible = false;
53
83
  }
54
- else if (!document.hidden && !bbn.env.isFocused) {
55
- bbn.env.isFocused = true;
84
+ else {
85
+ bbn.env.isVisible = true;
56
86
  }
57
87
  });
58
- document.addEventListener("focusin", (e) => {
88
+ document.addEventListener("focus", (e) => {
59
89
  if (e.target instanceof HTMLElement &&
60
90
  !e.target.classList.contains("bbn-no")) {
61
91
  bbn.env.focused = e.target;
62
92
  }
93
+ bbn.env.isFocused = true;
63
94
  bbn.env.last_focus = timestamp();
64
95
  });
65
- document.addEventListener("click", (e) => {
66
- bbn.env.last_focus = timestamp();
67
- if (bbn.env.nav !== "ajax") {
68
- return;
69
- }
70
- let target = e.target;
71
- if (target instanceof HTMLElement && target.tagName !== "A") {
72
- let p = target;
73
- while (p && p.tagName !== "A") {
74
- if (p.tagName === "BODY") {
75
- break;
76
- }
77
- p = p.parentElement;
78
- }
79
- if (p && p.tagName === "A") {
80
- target = p;
81
- }
82
- else {
83
- target = null;
84
- }
85
- }
86
- if (target instanceof HTMLElement &&
87
- target.hasAttribute("href") &&
88
- !target.hasAttribute("target") &&
89
- !target.classList.contains("bbn-no")) {
90
- e.preventDefault();
91
- e.stopPropagation();
92
- link(target.getAttribute("href"));
93
- return false;
96
+ document.addEventListener("blur", (e) => {
97
+ if (e.target instanceof HTMLElement &&
98
+ !e.target.classList.contains("bbn-no")) {
99
+ bbn.env.focused = e.target;
94
100
  }
101
+ bbn.env.isFocused = false;
102
+ bbn.env.last_focus = timestamp();
95
103
  });
96
- each(document.querySelectorAll("form:not(.bbn-no), form:not(.bbn-form)"), (ele) => {
97
- ele.addEventListener("submit", (e) => {
98
- submit(ele, e);
99
- });
100
- });
104
+ document.addEventListener("click", onActivity);
105
+ document.addEventListener("keydown", onActivity);
106
+ document.addEventListener("focusin", onActivity);
107
+ document.addEventListener("focusout", onActivity);
101
108
  window.addEventListener("hashchange", () => {
102
109
  bbn.env.hashChanged = new Date().getTime();
103
110
  }, false);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbn/bbn",
3
- "version": "2.0.111",
3
+ "version": "2.0.113",
4
4
  "description": "Javascript toolkit",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",