@bbn/bbn 2.0.110 → 2.0.112

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.
@@ -87,6 +87,7 @@ export declare abstract class bbnDt<TValue extends bbnDtTemporal> {
87
87
  get S(): string;
88
88
  get WW(): string;
89
89
  get W(): string;
90
+ unix(ms?: boolean | number): number | bbnDt<any>;
90
91
  format(format?: string): string;
91
92
  matchFormat(value: any, format: string): boolean;
92
93
  getWeekday(n: 0 | 1 | 2 | 3 | 4 | 5 | 6, mode?: string, locale?: string): string | object;
@@ -624,6 +624,14 @@ export class bbnDt {
624
624
  }
625
625
  return undefined;
626
626
  }
627
+ unix(ms = false) {
628
+ if (typeof ms === 'number') {
629
+ const Ctor = this.constructor;
630
+ const d = new Date(ms);
631
+ return new Ctor(d);
632
+ }
633
+ return ms ? this.toEpochMs() : Math.floor(this.toEpochMs() / 1000);
634
+ }
627
635
  format(format = 'YYYY-MM-DD HH:II:SS') {
628
636
  let str = '';
629
637
  if (format) {
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
@@ -10,6 +10,37 @@ import isTabletDevice from './browser/isTabletDevice.js';
10
10
  import isFunction from './type/isFunction.js';
11
11
  import log from './browser/log.js';
12
12
  import timestamp from './datetime/timestamp.js';
13
+ const onActivity = (e) => {
14
+ bbn.env.last_focus = bbn.dt().unix();
15
+ if (bbn.env.nav !== "ajax") {
16
+ return;
17
+ }
18
+ let target = e.target;
19
+ if (target instanceof HTMLElement && target.tagName !== "A") {
20
+ let p = target;
21
+ while (p && p.tagName !== "A") {
22
+ if (p.tagName === "BODY") {
23
+ break;
24
+ }
25
+ p = p.parentElement;
26
+ }
27
+ if (p && p.tagName === "A") {
28
+ target = p;
29
+ }
30
+ else {
31
+ target = null;
32
+ }
33
+ }
34
+ if (target instanceof HTMLElement &&
35
+ target.hasAttribute("href") &&
36
+ !target.hasAttribute("target") &&
37
+ !target.classList.contains("bbn-no")) {
38
+ e.preventDefault();
39
+ e.stopPropagation();
40
+ link(target.getAttribute("href"));
41
+ return false;
42
+ }
43
+ };
13
44
  /**
14
45
  * Initializes the library bbn basing on the given configuration object.
15
46
  * - Gives to the environment the dimension of the window.innerWidth and window.innerHeight
@@ -48,51 +79,31 @@ export default function init(cfg, force) {
48
79
  addColors(bbn.var.colors);
49
80
  }
50
81
  document.addEventListener("visibilitychange", () => {
51
- if (document.hidden && bbn.env.isFocused) {
52
- bbn.env.isFocused = false;
82
+ if (document.hidden) {
83
+ bbn.env.isVisible = false;
53
84
  }
54
- else if (!document.hidden && !bbn.env.isFocused) {
55
- bbn.env.isFocused = true;
85
+ else {
86
+ bbn.env.isVisible = true;
56
87
  }
57
88
  });
58
- document.addEventListener("focusin", (e) => {
89
+ document.addEventListener("focus", (e) => {
59
90
  if (e.target instanceof HTMLElement &&
60
91
  !e.target.classList.contains("bbn-no")) {
61
92
  bbn.env.focused = e.target;
62
93
  }
94
+ bbn.env.isFocused = true;
63
95
  bbn.env.last_focus = timestamp();
64
96
  });
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;
97
+ document.addEventListener("blur", (e) => {
98
+ if (e.target instanceof HTMLElement &&
99
+ !e.target.classList.contains("bbn-no")) {
100
+ bbn.env.focused = e.target;
94
101
  }
102
+ bbn.env.isFocused = false;
103
+ bbn.env.last_focus = timestamp();
95
104
  });
105
+ document.addEventListener("click", onActivity);
106
+ document.addEventListener("keydown", onActivity);
96
107
  each(document.querySelectorAll("form:not(.bbn-no), form:not(.bbn-form)"), (ele) => {
97
108
  ele.addEventListener("submit", (e) => {
98
109
  submit(ele, e);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbn/bbn",
3
- "version": "2.0.110",
3
+ "version": "2.0.112",
4
4
  "description": "Javascript toolkit",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",