beyond-rails 0.0.216 → 0.0.221

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9fe01a2e2f9bee54d4f3f5e44b26bca8b223666c0749383fcde789ffae9fca6c
4
- data.tar.gz: 56434ea193d4294f2c74d70ab41acfc85fa531b53ec8888d862d3729861a56de
3
+ metadata.gz: fcaf483b7501fa330c379d3c95aa48b0b03a919779f826d3de924419712ef5a7
4
+ data.tar.gz: 7261373eabc32b8320c6dfb103191af62f58c184591c2be03640ea7d92578d82
5
5
  SHA512:
6
- metadata.gz: d64f68417f19ff8e8640a052d917df93eb49dd05b87c6c727ea0ed42056ad45d34258ba2396f3aa7da5a5ea4c03879a4448f934fdf83fe24e885484495351dcf
7
- data.tar.gz: 9226d6dadae03caf44bf49f13b0c3545ac3ecab2af677704c4be0a5d2bf18a847d65e77db81bbe51ab03d3ac6ed327f4ef790694c0418e58396053b6f7483463
6
+ metadata.gz: 386edb5bdf6ccf290a4d471004fd457c61d5ec63b67d0ef0c032e513b9a9b3d0dbff099e4ddca788940bd4e4f14fcca894410a0e1169279edf168a45f55a6f67
7
+ data.tar.gz: b09ce56ee589e899f5fe66294fc09fe385e6b4ecc2e5ecebecec786e91b729a43957e59628c1a9a45e0cc0189993ed2f0a51731fd466d3357d9039edb13ee56a
@@ -49,7 +49,19 @@ export default class Modal {
49
49
  this.modal = this.dom
50
50
  }
51
51
 
52
+ triggerShowEventIfNeeded() {
53
+ if (typeof $ === 'function') {
54
+ $(this.dom).trigger('beyond.modal.show')
55
+ }
56
+ }
57
+
52
58
  show(html) {
59
+
60
+ if (this.isVisible && html) {
61
+ this.replace(html)
62
+ return this.triggerShowEventIfNeeded()
63
+ }
64
+
53
65
  if (html) {
54
66
  this.replace(html)
55
67
  }
@@ -57,9 +69,7 @@ export default class Modal {
57
69
  this.modal.style.display = 'block'
58
70
  setTimeout(() => {
59
71
  this.modal.classList.add('js-active')
60
- if (typeof $ === 'function') {
61
- $(this.dom).trigger('beyond.modal.show')
62
- }
72
+ this.triggerShowEventIfNeeded()
63
73
  }, 50)
64
74
  }
65
75
 
@@ -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)) {
@@ -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
- unbindAll
67
+ load,
68
+ on,
69
+ onload,
70
+ onunload,
71
+ unbindAll,
72
+ unload
55
73
  }
@@ -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.216
4
+ version: 0.0.221
5
5
  platform: ruby
6
6
  authors:
7
7
  - kmsheng
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-09-30 00:00:00.000000000 Z
12
+ date: 2020-10-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sassc
@@ -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