beyond-rails 0.0.265 → 0.0.270

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: 9fa71792acbc2210ebcf05fdeee2d1d24c79674c73530d106b267c2ecdd1f865
4
- data.tar.gz: 67d1de4755f5f311e510ac0687007570cddd7b5232250881400b8eb978687b0d
3
+ metadata.gz: 7c96df07fe7ae22477b03cdaa6dd2f966dd483d11eabacc634fd2044be11a534
4
+ data.tar.gz: ac13284fabfac310664793f94618c1d7c763137c23bb33c1ac4d8afe983e4d3e
5
5
  SHA512:
6
- metadata.gz: 6387d12405e74a62e999421ee5c51eceb3cdcdc0de2f2b259f225cc952f85285cc1536ed7e798e3cee48758d7cc7d910c5b7099da76adeee275bd520473461d7
7
- data.tar.gz: 412df9e788a1647796cd264f26c9e260095d0cb5e72b0c9b5edd2df4ca174426c8edefe2144e5ac54ad876b81b3bab5fcab0122ba7c48b5c321e942b0917af53
6
+ metadata.gz: 130618e8992dd06fa092f3f2314e39ead96119a5912b9723ada96bd64482d65d50d0933f9d47f417f2e6a8dfc0da0481adceb5435b565e1d0b5f48ebb0b86735
7
+ data.tar.gz: 50067515dd03207b0323f6535d38d2d7a5e6d3ee2a16468382cd69482e9fb91013f7cfd62da5c739ece7938748e5b43a6946ece2e13758a646d55fab282d5aa3
@@ -59,6 +59,8 @@ export default class Modal {
59
59
 
60
60
  if (this.isVisible && html) {
61
61
  this.replace(html)
62
+ this.modal.classList.add('js-active')
63
+ this.modal.style.display = 'block'
62
64
  return this.triggerShowEventIfNeeded()
63
65
  }
64
66
 
@@ -25,12 +25,15 @@ export default class SearchDropdown {
25
25
  this.offset = options.offset || 14
26
26
  this.offsetTop = options.offsetTop || 0
27
27
  this.offsetLeft = options.offsetLeft || 0
28
+ this.noDataMsg = options.noDataMsg || '沒有資料'
28
29
  this.isMenuVisible = false
29
30
  this.lastKeyword = null
30
31
  this.selectedIndex = 0
31
32
  this.items = []
32
33
  this.compositionStarted = false
33
34
  this.compositionJustEnded = false
35
+ this.noDataMsgVisible = false
36
+ this.loading = true
34
37
  this.init()
35
38
  }
36
39
 
@@ -77,6 +80,19 @@ export default class SearchDropdown {
77
80
 
78
81
  inputWrap.appendChild(input)
79
82
 
83
+ const loader = document.createElement('div')
84
+ loader.className = 'search-dropdown-loader'
85
+
86
+ loader.innerHTML = `
87
+ <div class="fb-loader">
88
+ <div></div>
89
+ <div></div>
90
+ <div></div>
91
+ </div>
92
+ `
93
+
94
+ inputWrap.appendChild(loader)
95
+
80
96
  if (this.options.placeholder) {
81
97
  input.setAttribute('placeholder', this.options.placeholder)
82
98
  }
@@ -88,6 +104,20 @@ export default class SearchDropdown {
88
104
  this.menu = menu
89
105
  this.input = input
90
106
  this.menuContent = menuContent
107
+ this.loader = loader
108
+ }
109
+
110
+ setLoading(loading) {
111
+ this.loading = loading
112
+
113
+ if (loading) {
114
+ this.input.classList.add('loading')
115
+ this.loader.style.display = 'block'
116
+ }
117
+ else {
118
+ this.input.classList.remove('loading')
119
+ this.loader.style.display = 'none'
120
+ }
91
121
  }
92
122
 
93
123
  setMenuContentActive(active) {
@@ -150,15 +180,23 @@ export default class SearchDropdown {
150
180
  }
151
181
 
152
182
  renderMenu() {
153
- const { menuContent, items } = this
154
- menuContent.innerHTML = items.map((item, i) => {
155
- return this.options.renderItem(item, i, (this.selectedIndex === i))
183
+ const { menuContent, items, selectedIndex } = this
184
+ const { renderItem } = this.options
185
+
186
+ const menuItems = items.map((item, i) => {
187
+ return renderItem(item, i, (selectedIndex === i))
156
188
  })
157
- .join('')
189
+
190
+ if (this.noDataMsgVisible) {
191
+ menuItems.unshift(`<div class="search-dropdown-menu-item">${this.noDataMsg}</div>`)
192
+ }
193
+
194
+ menuContent.innerHTML = menuItems.join('')
195
+
158
196
  this.setMenuContentActive(items.length > 0)
159
197
 
160
198
  const menuItemEls = this.getMenuItemEls()
161
- const selectedEl = menuItemEls[this.selectedIndex]
199
+ const selectedEl = menuItemEls[selectedIndex]
162
200
  if (selectedEl) {
163
201
  const scrollTop = menuContent.scrollTop
164
202
  const contentTop = menuContent.offsetTop
@@ -168,10 +206,10 @@ export default class SearchDropdown {
168
206
  const elBottom = elTop + elHeight
169
207
 
170
208
  if (elTop < contentTop) {
171
- this.menuContent.scrollTop -= elHeight
209
+ menuContent.scrollTop -= elHeight
172
210
  }
173
211
  else if (elBottom > contentBottom) {
174
- this.menuContent.scrollTop += elHeight
212
+ menuContent.scrollTop += elHeight
175
213
  }
176
214
  }
177
215
  }
@@ -187,8 +225,19 @@ export default class SearchDropdown {
187
225
  }
188
226
  this.resetSelectedIndex()
189
227
  this.lastKeyword = keyword
228
+ this.noDataMsgVisible = false
229
+ this.setItems([])
230
+
231
+ this.setLoading(true)
232
+
190
233
  const items = await this.options.getData(keyword)
191
234
 
235
+ this.setLoading(false)
236
+
237
+ if (items.length === 0) {
238
+ this.noDataMsgVisible = true
239
+ }
240
+
192
241
  if (this.lastKeyword === this.input.value) {
193
242
  this.setItems(items)
194
243
  }
@@ -202,7 +251,7 @@ export default class SearchDropdown {
202
251
  const rows = this.getMenuItemEls()
203
252
  let node = target
204
253
  while (node.parentNode !== parent) {
205
- if ('item' in node.dataset) {
254
+ if (node.dataset && ('item' in node.dataset)) {
206
255
  const index = rows.findIndex(row => row === node)
207
256
  return this.items[index]
208
257
  }
@@ -350,5 +399,9 @@ export default class SearchDropdown {
350
399
 
351
400
  destroy() {
352
401
  this.menu.remove()
402
+ this.menu = null
403
+ this.input = null
404
+ this.menuContent = null
405
+ this.loader = null
353
406
  }
354
407
  }
@@ -2,10 +2,24 @@
2
2
  width: 420px;
3
3
  padding: 0;
4
4
  .search-dropdown-input-wrap {
5
+ position: relative;
5
6
  padding: 14px;
6
7
  }
7
8
  .search-dropdown-input.input {
8
9
  width: 100%;
10
+ &.loading {
11
+ padding-right: 40px;
12
+ }
13
+ }
14
+ .search-dropdown-loader {
15
+ display: none;
16
+ position: absolute;
17
+ right: 20px;
18
+ top: 0;
19
+ bottom: 0;
20
+ margin-top: auto;
21
+ margin-bottom: auto;
22
+ height: 32px;
9
23
  }
10
24
  .search-dropdown-menu.active {
11
25
  border-top: 1px solid rgba(60, 66, 87, .16);
@@ -6,6 +6,16 @@
6
6
  transform: rotate(360deg);
7
7
  }
8
8
  }
9
+ @keyframes fb-loader {
10
+ 0% {
11
+ top: 6px;
12
+ height: 25px;
13
+ }
14
+ 50%, 100% {
15
+ top: 10px;
16
+ height: 12px;
17
+ }
18
+ }
9
19
 
10
20
  .loader {
11
21
  margin: 50px auto;
@@ -77,3 +87,30 @@
77
87
  .ring-loader div:nth-child(3) {
78
88
  animation-delay: -0.15s;
79
89
  }
90
+
91
+ .fb-loader {
92
+ display: inline-block;
93
+ position: relative;
94
+ @include size(32px);
95
+ }
96
+
97
+ .fb-loader div {
98
+ display: inline-block;
99
+ position: absolute;
100
+ left: 0;
101
+ width: 4px;
102
+ background: $bg-primary-ex;
103
+ animation: fb-loader 1.2s cubic-bezier(0, 0.5, 0.5, 1) infinite;
104
+ }
105
+ .fb-loader div:nth-child(1) {
106
+ left: 6px;
107
+ animation-delay: -0.24s;
108
+ }
109
+ .fb-loader div:nth-child(2) {
110
+ left: 14px;
111
+ animation-delay: -0.12s;
112
+ }
113
+ .fb-loader div:nth-child(3) {
114
+ left: 22px;
115
+ animation-delay: 0;
116
+ }
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.265
4
+ version: 0.0.270
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-12-04 00:00:00.000000000 Z
12
+ date: 2020-12-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sassc