beyond-rails 0.0.215 → 0.0.220
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/src/js/decorators/supportDom.js +0 -45
- data/src/js/index.js +19 -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: b1ef85aad3c8a5799f0ea97067be6810e25005157c81e1c152e3c8d16dde6943
|
4
|
+
data.tar.gz: 1be3c704a9aae2e12ae193012a3d0886b42bd82e0320c82a7320ebd3596d269f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b32274411e7ee48785ad15059861a46f8239730c343081c1441c34fa977d67acb376806e40df050fdef87d92ad6ef1125a73b6f72a3d62eb4155f558a1c3625
|
7
|
+
data.tar.gz: 6f1ad38f4abaf2adaf7fe8930766b81602f0cbfd158d33504fba1f263d26d0222a23b785c8a2796437e0e16ee471007374f7786da9d89f16062c1923e71714ec
|
@@ -1,21 +1,11 @@
|
|
1
1
|
import { isFunction } from '../utils'
|
2
2
|
import createdComponents from '../consts/createdComponents'
|
3
3
|
|
4
|
-
const domMap = new Map()
|
5
|
-
|
6
4
|
export default function supportDom(target) {
|
7
5
|
|
8
|
-
const targetName = target.name
|
9
|
-
|
10
6
|
return class extends target {
|
11
7
|
|
12
8
|
init() {
|
13
|
-
if (this.classNameUsed) {
|
14
|
-
console.warn(`This dom has already been initialized by ${targetName}`, this.dom)
|
15
|
-
return
|
16
|
-
}
|
17
|
-
this.setClassNameByDom(target)
|
18
|
-
|
19
9
|
this._listeners = []
|
20
10
|
this._externalListeners = []
|
21
11
|
if (isFunction(super.init)) {
|
@@ -24,40 +14,6 @@ export default function supportDom(target) {
|
|
24
14
|
createdComponents.push(this)
|
25
15
|
}
|
26
16
|
|
27
|
-
get classNameUsed() {
|
28
|
-
if (this._skipDomChecking) {
|
29
|
-
return false
|
30
|
-
}
|
31
|
-
const classnames = domMap.get(this.dom) || []
|
32
|
-
return classnames.includes(targetName)
|
33
|
-
}
|
34
|
-
|
35
|
-
setClassNameByDom(target) {
|
36
|
-
const { dom } = this
|
37
|
-
if (dom) {
|
38
|
-
const classes = domMap.get(dom) || []
|
39
|
-
classes.push(targetName)
|
40
|
-
domMap.set(dom, classes)
|
41
|
-
}
|
42
|
-
}
|
43
|
-
|
44
|
-
deleteClassNameByDom(target) {
|
45
|
-
const { dom } = this
|
46
|
-
if (! dom) {
|
47
|
-
return
|
48
|
-
}
|
49
|
-
const { name } = target
|
50
|
-
const classnames = (domMap.get(dom) || [])
|
51
|
-
.filter(classname => classname !== name)
|
52
|
-
|
53
|
-
if (classnames.length === 0) {
|
54
|
-
domMap.delete(dom)
|
55
|
-
}
|
56
|
-
else {
|
57
|
-
domMap.set(dom, classnames)
|
58
|
-
}
|
59
|
-
}
|
60
|
-
|
61
17
|
on(name, func) {
|
62
18
|
this._externalListeners.push({ name, func })
|
63
19
|
}
|
@@ -80,7 +36,6 @@ export default function supportDom(target) {
|
|
80
36
|
}
|
81
37
|
|
82
38
|
destroy() {
|
83
|
-
this.deleteClassNameByDom(target)
|
84
39
|
this._externalListeners.length = 0
|
85
40
|
this.removeEvents()
|
86
41
|
if (isFunction(super.destroy)) {
|
data/src/js/index.js
CHANGED
@@ -27,6 +27,16 @@ 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
|
+
$,
|
32
|
+
$$,
|
33
|
+
allOff,
|
34
|
+
load,
|
35
|
+
on,
|
36
|
+
onload,
|
37
|
+
onunload,
|
38
|
+
unload
|
39
|
+
} from './utils/dom'
|
30
40
|
|
31
41
|
export {
|
32
42
|
Alert,
|
@@ -49,7 +59,15 @@ export {
|
|
49
59
|
Timepicker,
|
50
60
|
Toast,
|
51
61
|
Tooltip,
|
62
|
+
$,
|
63
|
+
$$,
|
52
64
|
bind,
|
65
|
+
allOff,
|
53
66
|
docReady,
|
54
|
-
|
67
|
+
load,
|
68
|
+
on,
|
69
|
+
onload,
|
70
|
+
onunload,
|
71
|
+
unbindAll,
|
72
|
+
unload
|
55
73
|
}
|
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.220
|
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
|