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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/src/js/index.js +15 -1
  3. data/src/js/utils/dom.js +56 -0
  4. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc8e595696f351d27825c440fc48825dc0360b4a0aeeb23d8ff88f51d70e7794
4
- data.tar.gz: f65dc6990f6962438dc867f2eb6f29f50658f8ac474b52cb13765621ffbf358a
3
+ metadata.gz: 1470e47dc62c7839462cdd74565a9083e47a85250ed63b58f203a6482d1a8da8
4
+ data.tar.gz: 2961eca0b85bb238d8239d7a881cbc2b5e70696f952428ea52b47d6a0404f596
5
5
  SHA512:
6
- metadata.gz: d5b3863f1fd9a07e8ccc2c086c5ca2292e9c40a2e40fbd860935dbff10378f3421d7294be5557c894affae7a5f665a63b1bf4a11de0dfc5549174b9947a58a08
7
- data.tar.gz: f5319191d5a32812c4a18ecd28e1bce0d56fa1f16c69f72c7db633d805d1a61edc6fad8b589658f61e8bd604882704ec1e6d589e6ea9faf11ceadf0469f11ddc
6
+ metadata.gz: 465587c35573cfed1c8f48c20a030049fc8ddf61a6d6c1973ebc9387745e73ca3e4b5270591a46df29222ad28d21d4a7ae199d1f857e60f7f5e3f447879a1e1d
7
+ data.tar.gz: 85aa502b424f9499893afe803e425e4bc7ec14500342297e869abcbdb27f70720aca4e062fe678e81d97f58d2ce7c9bce498babf3e30cf3ae5a71ec167b4ce29
@@ -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
- unbindAll
63
+ load,
64
+ on,
65
+ onload,
66
+ onunload,
67
+ unbindAll,
68
+ unload
55
69
  }
@@ -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.217
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