beyond-rails 0.0.188 → 0.0.189

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: a72c8e57a80e8c6a653ea5356f23c3be9ce034f88d23ec5e42c3a2a6256bda6f
4
- data.tar.gz: cb191ff4300f1f09c79162109b85d44f0e07f0c86f4926b40654f83f25d2dc98
3
+ metadata.gz: d267ba7a547c15723330eee12769f3902a397c29827ca1f86ca869ce532e0f95
4
+ data.tar.gz: 9591c982bac2e9f92c4e6615f7220fe30b4c0801a3cee29c21529f45aacaa0e3
5
5
  SHA512:
6
- metadata.gz: 12b25834e8759f6c421a785e1fc6e41d5095e197a383f8df7c8f8c85ed9cb35bd6651793e63dfcdb8071cf7a94cb495ac95b42c924f02c453b9e45599a25af00
7
- data.tar.gz: 6b308a81c3ae0cadb78dcacf76fcf41ef76b5f0bae1b79685333632938eb697690093cba2f4db84d3fb131e9fdb934a9b57407809191c9f7d86719c962f8118c
6
+ metadata.gz: 28c9d93b2579b5dfc806702ecacb468aecf10684a00068afd4e44552da0fecdda0b195d0b3d4fe08f877122df51febf9d0fe9730735b96661c812b1bfbca96aa
7
+ data.tar.gz: 19b3c86011070fc942892147d0b57402798c1862fea976f58f01e9be431d82eca5b067739ae7078229007ab79aad8aacf0bd3a4e0889b8a74c1fb3da053b1620
@@ -1,6 +1,8 @@
1
1
  import supportDom from '../utils/supportDom'
2
2
  import { noop } from '../utils'
3
3
 
4
+ let globalModalId = 0
5
+
4
6
  @supportDom
5
7
  export default class Modal {
6
8
 
@@ -15,19 +17,41 @@ export default class Modal {
15
17
  }
16
18
 
17
19
  init() {
18
- this.modalId = this.dom.dataset.modalOpener
19
- const selector = `[data-modal="${this.modalId}"]`
20
- this.modal = document.querySelector(selector)
21
- if (! this.modal) {
22
- throw new Error(`${selector} is not defined.`)
23
- }
20
+ this.bindEvents()
21
+ }
22
+
23
+ bindEvents() {
24
+ this.setModalDom()
24
25
  this.closeBtn = this.modal.querySelector('[data-close]')
25
26
  this.cancelBtn = this.modal.querySelector('[data-cancel]')
26
27
  this.confirmBtn = this.modal.querySelector('[data-confirm]')
27
28
  this.addEvents()
28
29
  }
29
30
 
30
- show() {
31
+ setModalDom() {
32
+ const { modalOpener, modal } = this.dom.dataset
33
+
34
+ if (modalOpener) {
35
+ this.modalId = this.dom.dataset.modalOpener
36
+ const selector = `[data-modal="${this.modalId}"]`
37
+ this.modal = document.querySelector(selector)
38
+ return
39
+ }
40
+
41
+ if (modal) {
42
+ this.modalId = modal
43
+ }
44
+ else {
45
+ this.modalId = `modal-${++globalModalId}`
46
+ this.dom.dataset.modal = this.modalId
47
+ }
48
+ this.modal = this.dom
49
+ }
50
+
51
+ show(html) {
52
+ if (html) {
53
+ this.replace(html)
54
+ }
31
55
  this.isVisible = true
32
56
  this.modal.style.display = 'block'
33
57
  setTimeout(() => {
@@ -43,24 +67,47 @@ export default class Modal {
43
67
  }, 300)
44
68
  }
45
69
 
46
- addEvents() {
47
- this.addEvent(this.dom, 'click', () => this.show())
70
+ replace(html) {
71
+ this.destroy()
72
+ this.modalId = null
48
73
 
49
- if (this.closeBtn) {
50
- this.addEvent(this.closeBtn, 'click', () => {
51
- this.hide()
52
- this.options.cancel('close')
53
- })
74
+ // replace with new dom
75
+ const div = document.createElement('div')
76
+ div.innerHTML = html.trim()
77
+ const dom = div.firstChild
78
+ this.dom.parentNode.replaceChild(dom, this.dom)
79
+
80
+ this.dom = dom
81
+ this.dom._modal = this
82
+ this.init()
83
+ }
84
+
85
+ visible() {
86
+ return this.isVisible
87
+ }
88
+
89
+ addEventIfDomExists(dom, event, cb) {
90
+ if (dom) {
91
+ this.addEvent(dom, event, cb)
54
92
  }
93
+ }
55
94
 
56
- if (this.cancelBtn) {
57
- this.addEvent(this.cancelBtn, 'click', () => {
58
- this.hide()
59
- this.options.cancel('cancel')
60
- })
95
+ addEvents() {
96
+ if (this.dom.dataset.modalOpener) {
97
+ this.addEventIfDomExists(this.dom, 'click', () => this.show())
61
98
  }
62
99
 
63
- this.addEvent(this.modal, 'click', event => {
100
+ this.addEventIfDomExists(this.closeBtn, 'click', () => {
101
+ this.hide()
102
+ this.options.cancel('close')
103
+ })
104
+
105
+ this.addEventIfDomExists(this.cancelBtn, 'click', () => {
106
+ this.hide()
107
+ this.options.cancel('cancel')
108
+ })
109
+
110
+ this.addEventIfDomExists(this.modal, 'click', event => {
64
111
  // is backdrop
65
112
  if (event.target.dataset.modal === this.modalId) {
66
113
  this.hide()
@@ -68,15 +115,13 @@ export default class Modal {
68
115
  }
69
116
  })
70
117
 
71
- if (this.confirmBtn) {
72
- this.addEvent(this.confirmBtn, 'click', () => {
73
- if (typeof this.options.confirm === 'function') {
74
- this.options.confirm()
75
- }
76
- else {
77
- this.hide()
78
- }
79
- })
80
- }
118
+ this.addEventIfDomExists(this.confirmBtn, 'click', () => {
119
+ if (typeof this.options.confirm === 'function') {
120
+ this.options.confirm()
121
+ }
122
+ else {
123
+ this.hide()
124
+ }
125
+ })
81
126
  }
82
127
  }
@@ -1,14 +1,65 @@
1
1
  export default function bindModalFn(beyond, $) {
2
2
 
3
- const { Modal } = beyond
4
-
5
- $.fn.modal = function(settings) {
3
+ $.fn.modal = function(settings, html) {
6
4
 
7
- const options = $.extend({}, $.fn.modal.defaults, settings)
8
- const modals = this.map((i, dom) => new Modal(dom, options))
5
+ if (typeof settings === 'string') {
6
+ const method = settings
7
+ initModals(this, $.fn.modal.defaults)
8
+ if (method === 'open?') {
9
+ return this.map((i, dom) => dom._modal.visible())
10
+ }
11
+ this.each((i, dom) => dom._modal[method](html))
12
+ }
13
+ else {
14
+ const options = $.extend({}, $.fn.modal.defaults, settings)
15
+ initModals(this, options)
16
+ }
9
17
 
10
- this.destroy = () => modals.each((i, m) => m.destroy())
18
+ this.destroy = () => this.each((i, dom) => dom._modal && dom._modal.destroy())
11
19
 
12
20
  return this
13
21
  }
22
+
23
+ $.uniqModal = getUniqModalSelector
24
+ }
25
+
26
+ function initModals(self, options) {
27
+ const { Modal } = beyond
28
+ self.each((i, dom) => {
29
+ if (! dom._modal) {
30
+ dom._modal = new Modal(dom, options)
31
+ }
32
+ })
33
+ }
34
+
35
+ function getUniqModalSelector() {
36
+ const id = 'beyond-uniq-modal'
37
+ const dom = document.getElementById(id)
38
+ if (dom) {
39
+ return $(`#${id}`)
40
+ }
41
+ const div = document.createElement('div')
42
+ div.id = id
43
+ div.className = 'modal'
44
+ div.innerHTML = `
45
+ <div class="modal-dialog">
46
+ <div class="modal-content">
47
+ <div class="modal-header">
48
+ <h5 class="modal-title">視窗標題</h5>
49
+ <button type="button" class="btn-close" data-close aria-label="Close">
50
+ <i class="icon icon-cross"></i>
51
+ </button>
52
+ </div>
53
+ <div class="modal-body bg-content">
54
+ 視窗內文
55
+ </div>
56
+ <div class="modal-footer">
57
+ <button data-cancel class="btn btn-outline">取消</button>
58
+ <button data-confirm class="btn btn-primary">確認</button>
59
+ </div>
60
+ </div>
61
+ </div>
62
+ `
63
+ document.body.appendChild(div)
64
+ return $(div)
14
65
  }
@@ -14,4 +14,7 @@
14
14
  .breadcrumb-item.active {
15
15
  color: #6c757d;
16
16
  }
17
+ .breadcrumb-item a {
18
+ color: #000;
19
+ }
17
20
  }
@@ -1,6 +1,16 @@
1
+ $mega-menu-text-color: #0a2540;
2
+ $mega-menu-text-color-ex: #8A8D90;
3
+
4
+ @mixin mega-menu-text() {
5
+ transition: .3s color;
6
+ color: $mega-menu-text-color;
7
+ &:hover {
8
+ color: $mega-menu-text-color-ex;
9
+ }
10
+ }
11
+
1
12
  .mega-menu {
2
- padding-top: .2rem;
3
- padding-bottom: .2rem;
13
+ font-size: .9375rem;
4
14
  }
5
15
  .mega-menu-divider {
6
16
  border-bottom: 1px solid #ebebeb;
@@ -8,35 +18,16 @@
8
18
  .mega-menu-col {
9
19
  padding: .7rem 1.5rem;
10
20
  flex-grow: 1;
11
- transition: .3s background-color;
12
21
  min-width: 180px;
13
- color: $text-color;
14
22
  display: flex;
15
23
  align-items: center;
16
- &:hover {
17
- color: $text-color-strong;
18
- background-color: #f6f6f6;
19
- }
20
- i {
21
- margin-right: .6rem;
22
- }
23
- }
24
- .mega-menu-label {
25
- padding-left: 1.5rem;
26
- margin-top: 1rem;
27
- margin-bottom: .5rem;
28
- color: $text-color-light;
29
- font-size: 12px;
24
+ @include mega-menu-text;
30
25
  }
31
26
  .mega-menu-item {
32
27
  transition: .3s background-color;
33
- color: $text-color;
34
28
  display: block;
35
- padding: .5rem 2.2rem;
36
- &:hover {
37
- color: $text-color-strong;
38
- background-color: #f6f6f6;
39
- }
29
+ padding: .7rem 1.5rem;
30
+ @include mega-menu-text;
40
31
  }
41
32
  .mega-menu-icon-box {
42
33
  display: table;
@@ -49,14 +40,17 @@
49
40
  cursor: pointer;
50
41
  transition: .3s all;
51
42
  display: table-cell;
52
- padding: 1rem 1.8rem;
53
- color: $color-primary;
43
+ padding: 1rem 1.5rem;
54
44
  text-align: center;
45
+ @include mega-menu-text;
55
46
  &:hover {
56
- color: $text-color-strong;
57
- background-color: #f6f6f6;
47
+ i {
48
+ color: $mega-menu-text-color;
49
+ }
58
50
  }
59
51
  i {
52
+ transition: .3s color;
53
+ color: #88add2;
60
54
  display: block;
61
55
  margin-bottom: .4rem;
62
56
  }
@@ -43,6 +43,7 @@
43
43
  margin-right: .8rem;
44
44
  }
45
45
  }
46
+ .nav-item:active,
46
47
  .nav-item.active {
47
48
  color: $color-primary;
48
49
  }
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.188
4
+ version: 0.0.189
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-08-31 00:00:00.000000000 Z
12
+ date: 2020-09-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sassc
@@ -18,6 +18,9 @@ dependencies:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: 2.0.0
21
+ - - "~>"
22
+ - !ruby/object:Gem::Version
23
+ version: '2.0'
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -25,46 +28,55 @@ dependencies:
25
28
  - - ">="
26
29
  - !ruby/object:Gem::Version
27
30
  version: 2.0.0
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
28
34
  - !ruby/object:Gem::Dependency
29
35
  name: autoprefixer-rails
30
36
  requirement: !ruby/object:Gem::Requirement
31
37
  requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '9.7'
32
41
  - - ">="
33
42
  - !ruby/object:Gem::Version
34
- version: 5.2.1
43
+ version: 9.7.6
35
44
  type: :runtime
36
45
  prerelease: false
37
46
  version_requirements: !ruby/object:Gem::Requirement
38
47
  requirements:
48
+ - - "~>"
49
+ - !ruby/object:Gem::Version
50
+ version: '9.7'
39
51
  - - ">="
40
52
  - !ruby/object:Gem::Version
41
- version: 5.2.1
53
+ version: 9.7.6
42
54
  - !ruby/object:Gem::Dependency
43
55
  name: actionpack
44
56
  requirement: !ruby/object:Gem::Requirement
45
57
  requirements:
46
- - - ">="
58
+ - - "~>"
47
59
  - !ruby/object:Gem::Version
48
60
  version: '5.0'
49
61
  type: :runtime
50
62
  prerelease: false
51
63
  version_requirements: !ruby/object:Gem::Requirement
52
64
  requirements:
53
- - - ">="
65
+ - - "~>"
54
66
  - !ruby/object:Gem::Version
55
67
  version: '5.0'
56
68
  - !ruby/object:Gem::Dependency
57
69
  name: activemodel
58
70
  requirement: !ruby/object:Gem::Requirement
59
71
  requirements:
60
- - - ">="
72
+ - - "~>"
61
73
  - !ruby/object:Gem::Version
62
74
  version: '5.0'
63
75
  type: :runtime
64
76
  prerelease: false
65
77
  version_requirements: !ruby/object:Gem::Requirement
66
78
  requirements:
67
- - - ">="
79
+ - - "~>"
68
80
  - !ruby/object:Gem::Version
69
81
  version: '5.0'
70
82
  description: