beyond-rails 0.0.217 → 0.0.218
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.
- checksums.yaml +4 -4
- data/src/js/index.js +15 -1
- data/src/js/utils/dom.js +56 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1470e47dc62c7839462cdd74565a9083e47a85250ed63b58f203a6482d1a8da8
|
4
|
+
data.tar.gz: 2961eca0b85bb238d8239d7a881cbc2b5e70696f952428ea52b47d6a0404f596
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 465587c35573cfed1c8f48c20a030049fc8ddf61a6d6c1973ebc9387745e73ca3e4b5270591a46df29222ad28d21d4a7ae199d1f857e60f7f5e3f447879a1e1d
|
7
|
+
data.tar.gz: 85aa502b424f9499893afe803e425e4bc7ec14500342297e869abcbdb27f70720aca4e062fe678e81d97f58d2ce7c9bce498babf3e30cf3ae5a71ec167b4ce29
|
data/src/js/index.js
CHANGED
@@ -27,6 +27,14 @@ import Tooltip from './components/Tooltip'
|
|
27
27
|
import bind from './utils/bind'
|
28
28
|
import docReady from './utils/docReady'
|
29
29
|
import unbindAll from './utils/unbindAll'
|
30
|
+
import {
|
31
|
+
allOff,
|
32
|
+
load,
|
33
|
+
on,
|
34
|
+
onload,
|
35
|
+
onunload,
|
36
|
+
unload
|
37
|
+
} from './utils/dom'
|
30
38
|
|
31
39
|
export {
|
32
40
|
Alert,
|
@@ -50,6 +58,12 @@ export {
|
|
50
58
|
Toast,
|
51
59
|
Tooltip,
|
52
60
|
bind,
|
61
|
+
allOff,
|
53
62
|
docReady,
|
54
|
-
|
63
|
+
load,
|
64
|
+
on,
|
65
|
+
onload,
|
66
|
+
onunload,
|
67
|
+
unbindAll,
|
68
|
+
unload
|
55
69
|
}
|
data/src/js/utils/dom.js
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
const offFns = []
|
2
|
+
const loadRows = []
|
3
|
+
const unloadRows = []
|
4
|
+
|
5
|
+
const onPage = row => {
|
6
|
+
const { controller, action } = row
|
7
|
+
const { dataset } = document.body
|
8
|
+
return (dataset.controller === controller) && (dataset.action === action)
|
9
|
+
}
|
10
|
+
|
11
|
+
export const $ = (selector, dom = document) => dom.querySelector(selector)
|
12
|
+
|
13
|
+
export const $$ = (selector, dom = document) => Array.from(dom.querySelectorAll(selector))
|
14
|
+
|
15
|
+
export const on = (dom, event, cb, useCapture = false) => {
|
16
|
+
dom.addEventListener(event, cb, useCapture)
|
17
|
+
const off = () => dom.removeEventListener(event, cb, useCapture)
|
18
|
+
offFns.push(off)
|
19
|
+
|
20
|
+
return () => {
|
21
|
+
const index = offFns.findIndex(fn => fn === off)
|
22
|
+
if (index !== -1) {
|
23
|
+
offFns.splice(index, 1)
|
24
|
+
}
|
25
|
+
off()
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
export const allOff = () => {
|
30
|
+
offFns.forEach(fn => fn())
|
31
|
+
offFns.length = 0
|
32
|
+
}
|
33
|
+
|
34
|
+
export const onload = (controller, action, fn) => {
|
35
|
+
loadRows.push({ controller, action, fn })
|
36
|
+
}
|
37
|
+
|
38
|
+
export const load = () => {
|
39
|
+
loadRows.forEach(row => {
|
40
|
+
if (onPage(row)) {
|
41
|
+
row.fn()
|
42
|
+
}
|
43
|
+
})
|
44
|
+
}
|
45
|
+
|
46
|
+
export const onunload = (controller, action, fn) => {
|
47
|
+
unloadRows.push({ controller, action, fn })
|
48
|
+
}
|
49
|
+
|
50
|
+
export const unload = () => {
|
51
|
+
unloadRows.forEach(row => {
|
52
|
+
if (onPage(row)) {
|
53
|
+
row.fn()
|
54
|
+
}
|
55
|
+
})
|
56
|
+
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: beyond-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.218
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kmsheng
|
@@ -173,6 +173,7 @@ files:
|
|
173
173
|
- src/js/utils/dateGt.js
|
174
174
|
- src/js/utils/dateLt.js
|
175
175
|
- src/js/utils/docReady.js
|
176
|
+
- src/js/utils/dom.js
|
176
177
|
- src/js/utils/domEval.js
|
177
178
|
- src/js/utils/getFloatedTargetPos.js
|
178
179
|
- src/js/utils/getKey.js
|