rails_design 0.0.1

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 (123) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +20 -0
  3. data/README.md +18 -0
  4. data/Rakefile +18 -0
  5. data/app/assets/images/image-square.png +0 -0
  6. data/app/assets/images/logo.png +0 -0
  7. data/app/assets/javascripts/default_form/datetime.js +31 -0
  8. data/app/assets/javascripts/default_form/default_valid.js +101 -0
  9. data/app/assets/javascripts/default_form/field.js +33 -0
  10. data/app/assets/javascripts/default_form/index.js +9 -0
  11. data/app/assets/javascripts/default_form/valid_weui.js +17 -0
  12. data/app/assets/javascripts/rails_design/attachment.js +295 -0
  13. data/app/assets/javascripts/rails_design/cable.js +3 -0
  14. data/app/assets/javascripts/rails_design/dataset.js +39 -0
  15. data/app/assets/javascripts/rails_design/index.js +4 -0
  16. data/app/assets/javascripts/rails_design/stimulus.js +19 -0
  17. data/app/assets/javascripts/rails_design/turbo.js +35 -0
  18. data/app/assets/javascripts/stimulus_com/checkbox.js +77 -0
  19. data/app/assets/javascripts/stimulus_com/choice.js +18 -0
  20. data/app/assets/javascripts/stimulus_com/common.js +52 -0
  21. data/app/assets/javascripts/stimulus_com/count_down.js +27 -0
  22. data/app/assets/javascripts/stimulus_com/former.js +26 -0
  23. data/app/assets/javascripts/stimulus_com/hover.js +40 -0
  24. data/app/assets/javascripts/stimulus_com/index.js +58 -0
  25. data/app/assets/javascripts/stimulus_com/input.js +36 -0
  26. data/app/assets/javascripts/stimulus_com/menu.js +34 -0
  27. data/app/assets/javascripts/stimulus_com/modal.js +85 -0
  28. data/app/assets/javascripts/stimulus_com/modal_show.js +16 -0
  29. data/app/assets/javascripts/stimulus_com/navbar.js +11 -0
  30. data/app/assets/javascripts/stimulus_com/notice.js +10 -0
  31. data/app/assets/javascripts/stimulus_com/picture.js +85 -0
  32. data/app/assets/javascripts/stimulus_com/show.js +26 -0
  33. data/app/assets/javascripts/stimulus_com/showcase.js +34 -0
  34. data/app/assets/javascripts/stimulus_com/slide.js +188 -0
  35. data/app/assets/javascripts/stimulus_com/slide_y.js +189 -0
  36. data/app/assets/javascripts/stimulus_com/sortable.js +41 -0
  37. data/app/assets/javascripts/stimulus_com/sticky.js +11 -0
  38. data/app/assets/javascripts/stimulus_com/swipe.js +78 -0
  39. data/app/assets/javascripts/stimulus_com/taxon.js +45 -0
  40. data/app/assets/javascripts/stimulus_com/time.js +19 -0
  41. data/app/assets/javascripts/stimulus_com/touch.js +83 -0
  42. data/app/assets/javascripts/stimulus_com/tree.js +34 -0
  43. data/app/assets/javascripts/stimulus_com/tree_remote.js +64 -0
  44. data/app/assets/javascripts/stimulus_com/typer.js +41 -0
  45. data/app/assets/javascripts/stimulus_com/visit.js +61 -0
  46. data/app/assets/javascripts/stimulus_phone/index.js +19 -0
  47. data/app/assets/javascripts/stimulus_phone/qq_map.js +29 -0
  48. data/app/assets/javascripts/stimulus_phone/search.js +37 -0
  49. data/app/assets/javascripts/stimulus_phone/wechat.js +80 -0
  50. data/app/assets/javascripts/stimulus_phone/weui-actionsheet.js +43 -0
  51. data/app/assets/javascripts/stimulus_phone/weui-datepicker.js +38 -0
  52. data/app/assets/javascripts/stimulus_phone/weui-dialog.js +24 -0
  53. data/app/assets/javascripts/stimulus_phone/weui-picker.js +54 -0
  54. data/app/assets/javascripts/stimulus_phone/wxpay.js +29 -0
  55. data/app/assets/stylesheets/app.scss +3 -0
  56. data/app/assets/stylesheets/ext_bulma/base/_all.scss +5 -0
  57. data/app/assets/stylesheets/ext_bulma/base/_choices.scss +3 -0
  58. data/app/assets/stylesheets/ext_bulma/base/_global.scss +19 -0
  59. data/app/assets/stylesheets/ext_bulma/base/_main.scss +15 -0
  60. data/app/assets/stylesheets/ext_bulma/components/_all.scss +10 -0
  61. data/app/assets/stylesheets/ext_bulma/components/_box.scss +15 -0
  62. data/app/assets/stylesheets/ext_bulma/components/_breadcrumb.scss +17 -0
  63. data/app/assets/stylesheets/ext_bulma/components/_card.scss +12 -0
  64. data/app/assets/stylesheets/ext_bulma/components/_level.scss +8 -0
  65. data/app/assets/stylesheets/ext_bulma/components/_media.scss +14 -0
  66. data/app/assets/stylesheets/ext_bulma/components/_menu.scss +76 -0
  67. data/app/assets/stylesheets/ext_bulma/components/_pagination.scss +9 -0
  68. data/app/assets/stylesheets/ext_bulma/components/_panel.scss +5 -0
  69. data/app/assets/stylesheets/ext_bulma/elements/_all.scss +7 -0
  70. data/app/assets/stylesheets/ext_bulma/elements/_button.scss +14 -0
  71. data/app/assets/stylesheets/ext_bulma/elements/_fa.scss +4 -0
  72. data/app/assets/stylesheets/ext_bulma/elements/_image.scss +38 -0
  73. data/app/assets/stylesheets/ext_bulma/elements/_table.scss +52 -0
  74. data/app/assets/stylesheets/ext_bulma/elements/_title.scss +9 -0
  75. data/app/assets/stylesheets/ext_bulma/expand/_all.scss +2 -0
  76. data/app/assets/stylesheets/ext_bulma/expand/_slide.scss +26 -0
  77. data/app/assets/stylesheets/ext_bulma/expand/_sortable.scss +4 -0
  78. data/app/assets/stylesheets/ext_bulma/form/_all.scss +34 -0
  79. data/app/assets/stylesheets/ext_bulma/form/_checkbox.scss +267 -0
  80. data/app/assets/stylesheets/ext_bulma/form/_file.scss +23 -0
  81. data/app/assets/stylesheets/ext_bulma/form/_select.scss +5 -0
  82. data/app/assets/stylesheets/ext_bulma/form/_tools.scss +30 -0
  83. data/app/assets/stylesheets/ext_bulma/grid/_all.scss +3 -0
  84. data/app/assets/stylesheets/ext_bulma/grid/_columns.scss +13 -0
  85. data/app/assets/stylesheets/ext_bulma/helpers/_all.scss +5 -0
  86. data/app/assets/stylesheets/ext_bulma/helpers/_dot.scss +11 -0
  87. data/app/assets/stylesheets/ext_bulma/helpers/_drawable.scss +3 -0
  88. data/app/assets/stylesheets/ext_bulma/helpers/_grid.scss +10 -0
  89. data/app/assets/stylesheets/ext_bulma/index.scss +22 -0
  90. data/app/assets/stylesheets/ext_bulma/layout/_all.scss +4 -0
  91. data/app/assets/stylesheets/ext_bulma/layout/_footer.scss +4 -0
  92. data/app/assets/stylesheets/ext_bulma/layout/_level.scss +1 -0
  93. data/app/assets/stylesheets/ext_choices/index.scss +16 -0
  94. data/app/assets/stylesheets/ext_font/index.scss +4 -0
  95. data/app/assets/stylesheets/ext_weui/index.scss +24 -0
  96. data/app/assets/stylesheets/ext_weui/widget/_actionsheet.scss +3 -0
  97. data/app/assets/stylesheets/ext_weui/widget/_article.scss +7 -0
  98. data/app/assets/stylesheets/ext_weui/widget/_button.scss +7 -0
  99. data/app/assets/stylesheets/ext_weui/widget/_cell.scss +17 -0
  100. data/app/assets/stylesheets/ext_weui/widget/_form.scss +3 -0
  101. data/app/assets/stylesheets/ext_weui/widget/_half_screen_dialog.scss +10 -0
  102. data/app/assets/stylesheets/ext_weui/widget/_icon.scss +9 -0
  103. data/app/assets/stylesheets/ext_weui/widget/_media.scss +43 -0
  104. data/app/assets/stylesheets/ext_weui/widget/_panel.scss +4 -0
  105. data/app/assets/stylesheets/ext_weui/widget/_preview.scss +5 -0
  106. data/app/assets/stylesheets/ext_weui/widget/_search.scss +5 -0
  107. data/app/assets/stylesheets/ext_weui/widget/_tab.scss +10 -0
  108. data/app/assets/stylesheets/ext_weui/widget/_tabbar.scss +12 -0
  109. data/app/assets/stylesheets/ext_weui/widget/_uploader.scss +14 -0
  110. data/app/assets/stylesheets/phone.scss +6 -0
  111. data/app/assets/stylesheets/slide/index.scss +208 -0
  112. data/app/assets/stylesheets/ui_tooltip/_mixins.scss +46 -0
  113. data/app/assets/stylesheets/ui_tooltip/_variables.scss +5 -0
  114. data/app/assets/stylesheets/ui_tooltip/index.scss +278 -0
  115. data/app/controllers/design/base_controller.rb +4 -0
  116. data/app/controllers/design/home_controller.rb +13 -0
  117. data/app/views/design/home/swipe.html.erb +7 -0
  118. data/app/views/layouts/ui/base.html.erb +5 -0
  119. data/config/routes.rb +11 -0
  120. data/lib/rails_design/config.rb +8 -0
  121. data/lib/rails_design/engine.rb +5 -0
  122. data/lib/rails_design.rb +2 -0
  123. metadata +181 -0
@@ -0,0 +1,34 @@
1
+ import { Controller } from '@hotwired/stimulus'
2
+
3
+ // data-controller="menu"
4
+ export default class extends Controller {
5
+
6
+ static values = {
7
+ openClass: String,
8
+ closeClass: String,
9
+ }
10
+
11
+ toggle() {
12
+ this.element.classList.toggle('is-active')
13
+ }
14
+
15
+ expand(event) {
16
+ let expander = event.currentTarget
17
+ if (expander.nextElementSibling !== null) {
18
+ expander.nextElementSibling.classList.toggle('is-hidden')
19
+ }
20
+ if (expander.lastElementChild !== null) {
21
+ expander.lastElementChild.classList.toggle(this.closeClass)
22
+ expander.lastElementChild.classList.toggle(this.openClass)
23
+ }
24
+ }
25
+
26
+ get closeClass() {
27
+ return this.openClassValue || 'fa-angle-left'
28
+ }
29
+
30
+ get openClass() {
31
+ return this.closeClassValue || 'fa-angle-down'
32
+ }
33
+
34
+ }
@@ -0,0 +1,85 @@
1
+ import { Controller } from '@hotwired/stimulus'
2
+
3
+ // data-controller="modal"
4
+ export default class extends Controller {
5
+ static values = {
6
+ urls: Array,
7
+ redirect: String
8
+ }
9
+
10
+ connect() {
11
+ console.debug('modal refer:', document.referrer)
12
+ this.observer = new MutationObserver(this.loaded)
13
+ this.observer.observe(this.modal, { childList: true })
14
+ }
15
+
16
+ close() {
17
+ this.removeClass()
18
+ this.urlsValue = this.urlsValue.slice(0, this.urlsValue.length - 1)
19
+ let url = this.urlsValue.pop()
20
+ if (url) {
21
+ this.urlsValue = this.urlsValue.slice(0, this.urlsValue.length - 1)
22
+ this.modal.src = url
23
+ } else {
24
+ this.modal.removeAttribute('src')
25
+ }
26
+ }
27
+
28
+ reloadClose() {
29
+ this.removeClass()
30
+ Turbo.visit(location.href, { action: 'replace' })
31
+ }
32
+
33
+ disconnect() {
34
+ console.debug('disconnected:', this.identifier)
35
+ this.observer.disconnect()
36
+ delete this.observer
37
+ }
38
+
39
+ // NOTICE: here this becomes observer
40
+ loaded(list, observer) {
41
+ let item = list[0]
42
+ let ele = item.target.parentNode.parentNode
43
+ let con = application.getControllerForElementAndIdentifier(ele, 'modal')
44
+ switch(item.type) {
45
+ case 'childList':
46
+ if (typeof item.target.src === 'undefined' || item.target.src === null) {
47
+ break
48
+ }
49
+ ele.classList.add('is-active')
50
+ document.documentElement.classList.add('is-clipped')
51
+ if (con.urlsValue.length > 0 && !con.hasRedirectValue) {
52
+ con.redirectValue = item.target.src
53
+ con.addEvent()
54
+ }
55
+ con.urlsValue = con.urlsValue.concat(item.target.src)
56
+ }
57
+ }
58
+
59
+ addEvent() {
60
+ document.addEventListener('turbo:before-fetch-request', this.addHeader)
61
+ }
62
+
63
+ removeEvent() {
64
+ document.removeEventListener('turbo:before-fetch-request', this.addHeader)
65
+ }
66
+
67
+ // NOTICE: here this become document
68
+ addHeader(event) {
69
+ let xhr = event.detail.fetchOptions
70
+ let ele = document.getElementById('modal').parentNode.parentNode
71
+ let con = application.getControllerForElementAndIdentifier(ele, 'modal')
72
+ console.debug('add redirect headers')
73
+ xhr.headers['Redirect'] = con.redirectValue
74
+ }
75
+
76
+ removeClass() {
77
+ this.element.classList.remove('is-active')
78
+ document.documentElement.classList.remove('is-clipped')
79
+ }
80
+
81
+ get modal() {
82
+ return document.getElementById('modal')
83
+ }
84
+
85
+ }
@@ -0,0 +1,16 @@
1
+ import { Controller } from '@hotwired/stimulus'
2
+
3
+ // data-controller="modal_show"
4
+ export default class extends Controller {
5
+
6
+ connect() {
7
+ this.modal.classList.add('is-active')
8
+ document.documentElement.classList.add('is-clipped')
9
+ this.element.remove()
10
+ }
11
+
12
+ get modal() {
13
+ return document.getElementById('modal').parentNode.parentNode
14
+ }
15
+
16
+ }
@@ -0,0 +1,11 @@
1
+ import { Controller } from '@hotwired/stimulus'
2
+
3
+ export default class extends Controller {
4
+ static targets = ['menu']
5
+
6
+ toggle(element) {
7
+ element.currentTarget.classList.toggle('is-active')
8
+ this.menuTarget.classList.toggle('is-active')
9
+ }
10
+
11
+ }
@@ -0,0 +1,10 @@
1
+ import { Controller } from '@hotwired/stimulus'
2
+
3
+ // data-controller="notice"
4
+ export default class extends Controller {
5
+
6
+ close() {
7
+ this.element.remove()
8
+ }
9
+
10
+ }
@@ -0,0 +1,85 @@
1
+ import { DirectUploadController } from '@rails/activestorage/src/direct_upload_controller'
2
+ import { Controller } from '@hotwired/stimulus'
3
+
4
+ // <input type="file" data-controller="picture">
5
+ export default class extends Controller {
6
+ static targets = ['src', 'filename', 'preview', 'uploadDiv']
7
+
8
+ /*
9
+ * <input type="file" data-action="picture#upload">
10
+ **/
11
+ upload(event) {
12
+ let input = event.currentTarget
13
+ let button = input.form.querySelector('input[type=submit], button[type=submit]')
14
+ input.disabled = true
15
+ button.disabled = true
16
+ Array.from(input.files).forEach(file => {
17
+ this.filenameTarget.innerText = file.name
18
+ // todo file is image
19
+ this.previewFile(file)
20
+ let controller = new DirectUploadController(input, file)
21
+ if (controller) {
22
+ controller.start(error => {
23
+ if (error) {
24
+ input.disabled = false
25
+ callback(error)
26
+ this.dispatch('end')
27
+ }
28
+ button.disabled = false
29
+ })
30
+ }
31
+ })
32
+ }
33
+
34
+ dropFile(event) {
35
+ event.preventDefault()
36
+ event.stopPropagation()
37
+ for (var i = 0; i < event.dataTransfer.files.length; i++) {
38
+ var file = e.dataTransfer.files[i]
39
+ console.debug('drop文件', file.name)
40
+ }
41
+ }
42
+
43
+ pasteFile(event) {
44
+ var result = false,
45
+ clipboardData = event.clipboardData,
46
+ items
47
+
48
+ if (typeof clipboardData === 'object') {
49
+ items = clipboardData.items || clipboardData.files || []
50
+
51
+ for (var i = 0; i < items.length; i++) {
52
+ var item = items[i]
53
+ console.debug('粘贴', item)
54
+ }
55
+ }
56
+
57
+ if (result) { event.preventDefault() }
58
+ }
59
+
60
+ previewFile(file) {
61
+ let template = this.previewTarget
62
+ let cloned = template.cloneNode(true)
63
+ cloned.style.display = 'block'
64
+
65
+ let img = cloned.querySelector('img')
66
+ img.src = window.URL.createObjectURL(file) //创建一个object URL,并不是你的本地路径
67
+ img.onload = function(e) {
68
+ console.debug(e)
69
+ window.URL.revokeObjectURL(img.src) //图片加载后,释放object URL
70
+ }
71
+
72
+ template.after(cloned)
73
+ }
74
+
75
+ removePreview(event) {
76
+ let wrap = event.currentTarget.parentNode.parentNode
77
+ wrap.style.display = 'none'
78
+ wrap.querySelector('input').remove()
79
+ let up = this.uploadDivTarget
80
+ let input = up.querySelector('input[type=file]')
81
+ up.style.display = 'block'
82
+ input.disabled = false
83
+ }
84
+
85
+ }
@@ -0,0 +1,26 @@
1
+ import { Controller } from '@hotwired/stimulus'
2
+
3
+ export default class extends Controller {
4
+ static targets = ['src', 'item']
5
+
6
+ initEvent() {
7
+ let ele = this.element
8
+ ele.addEventListener('mouseenter', this.showItem)
9
+ ele.addEventListener('mouseleave', this.hideItem)
10
+ }
11
+
12
+ show() {
13
+ //console.log(this)
14
+ this.itemTargets.forEach(el => {
15
+ el.style.visibility = 'visible'
16
+ })
17
+ }
18
+
19
+ hide(event) {
20
+ //console.log(event.target)
21
+ this.itemTargets.forEach(el => {
22
+ el.style.visibility = 'hidden'
23
+ })
24
+ }
25
+
26
+ }
@@ -0,0 +1,34 @@
1
+ import { Controller } from '@hotwired/stimulus'
2
+
3
+ // 商品橱窗展示,
4
+ // 点击小图显示对应图片
5
+ // 点击切换箭头,显示上一张或者下一张图片
6
+ export default class extends Controller {
7
+ static targets = [
8
+ 'window'
9
+ ]
10
+ static classes = [
11
+ 'hover'
12
+ ]
13
+
14
+ // data-action="mouseover->showcase#show"
15
+ show(event) {
16
+ let ele = event.currentTarget
17
+ ele.classList.add(this.hoverClass)
18
+ for (const el of ele.parentElement.children) {
19
+ if (el !== ele) {
20
+ el.classList.remove(this.hoverClass)
21
+ }
22
+ }
23
+
24
+ let target = this.windowTarget.querySelector(`[data-index="${ele.dataset.index}"`)
25
+ target.style.zIndex = 1
26
+
27
+ for (const el of this.windowTarget.children) {
28
+ if (el.dataset.index !== ele.dataset.index) {
29
+ el.style.zIndex = 0
30
+ }
31
+ }
32
+ }
33
+
34
+ }
@@ -0,0 +1,188 @@
1
+ import TouchController from './touch'
2
+
3
+ // z-index: 0, 当前显示的图片;
4
+ // z-index: -1, 即将显示的图片,touch move 时动态设定;
5
+ // z-index: -2, 未显示的图片;
6
+ export default class extends TouchController {
7
+
8
+ connect() {
9
+ this.element.addEventListener('touchstart', (event) => {
10
+ this.start(event)
11
+ }, { passive: true })
12
+ }
13
+
14
+ // data-action="touchmove->slide#move:passive"
15
+ move(event) {
16
+ let ele = event.currentTarget
17
+ console.debug('touch moved by:', ele.dataset.index)
18
+ if (this.zoomed(event)) {
19
+ console.error('scale')
20
+ return
21
+ }
22
+ let offset = this.offset(event)
23
+ let pad = Math.abs(offset.x)
24
+ let isScrolling = pad > Math.abs(offset.y) ? 1 : 0 // 1 左右滑动,0 上下滑动
25
+ if (isScrolling === 0) {
26
+ return
27
+ }
28
+
29
+ if (offset.x < 0) { // offset.x < 0 表示向左滑动
30
+ const next = ele.nextElementSibling
31
+ if (next) {
32
+ this.slidingToLeft(ele, next, pad)
33
+ }
34
+ } else if (offset.x > 0) { // offset.x > 0 表示向右滑动
35
+ const prev = ele.previousElementSibling
36
+ if (prev) {
37
+ this.slidingToRight(ele, prev, pad)
38
+ }
39
+ }
40
+ }
41
+
42
+ // data-action="touchend->slide#end:passive"
43
+ end(event) {
44
+ if (this.zoomed(event)) {
45
+ return
46
+ }
47
+ let ele = event.currentTarget
48
+ let offset = this.offset(event)
49
+ let pad = Math.abs(offset.x)
50
+ let isScrolling = pad > Math.abs(offset.y) ? 1 : 0 // 1 左右滑动,0 上下滑动
51
+ if (isScrolling === 0) {
52
+ console.debug('not scrolling')
53
+ this.rollback(offset, ele)
54
+ }
55
+
56
+ if (this.effective(pad)) {
57
+ this.going(offset, ele)
58
+ } else {
59
+ this.rollback(offset, ele)
60
+ }
61
+ }
62
+
63
+ // 执行翻页
64
+ going(offset, ele) {
65
+ const next = ele.nextElementSibling
66
+ const prev = ele.previousElementSibling
67
+
68
+ if (offset.x < 0 && next) {
69
+ this.closeToLeft(next)
70
+ next.style.zIndex = 0
71
+ this.toCurrent(next)
72
+
73
+ this.awayFromRight(ele)
74
+ ele.style.zIndex = -1
75
+ this.beenCurrent(ele)
76
+ }
77
+
78
+ if (offset.x > 0 && prev) {
79
+ this.closeToRight(prev)
80
+ prev.style.zIndex = 0
81
+ this.toCurrent(prev)
82
+
83
+ this.awayFromLeft(ele)
84
+ ele.style.zIndex = -1
85
+ this.beenCurrent(ele)
86
+ }
87
+ }
88
+
89
+ // 回退到之前的状态
90
+ rollback(offset, ele) {
91
+ const next = ele.nextElementSibling
92
+ const prev = ele.previousElementSibling
93
+
94
+ if (offset.x < 0 && next) {
95
+ this.closeToRight(ele)
96
+ this.toCurrent(ele)
97
+
98
+ this.awayFromLeft(next)
99
+ this.beenCurrent(next)
100
+ }
101
+
102
+ if (offset.x > 0 && prev) {
103
+ this.closeToLeft(ele)
104
+ this.toCurrent(ele)
105
+
106
+ this.awayFromRight(prev)
107
+ this.beenCurrent(prev)
108
+ }
109
+ }
110
+
111
+ // 左滑
112
+ slidingToLeft(ele, next, pad) {
113
+ ele.style.right = pad + 'px'
114
+ next.style.zIndex = -1
115
+ next.style.left = (this.element.clientWidth - pad) + 'px'
116
+ }
117
+
118
+ // 右滑
119
+ slidingToRight(ele, prev, pad) {
120
+ ele.style.left = pad + 'px'
121
+ prev.style.zIndex = -1
122
+ prev.style.right = (this.element.clientWidth - pad) + 'px'
123
+ }
124
+
125
+ // xx
126
+ resetIndex(event) {
127
+ ['left', 'right', 'transition-property', 'transition-duration'].forEach(rule => {
128
+ event.currentTarget.style.removeProperty(rule)
129
+ })
130
+ event.currentTarget.style.zIndex = -2
131
+ }
132
+
133
+ // 不再展示
134
+ beenCurrent(ele) {
135
+ console.debug('add transition event listener for been', ele.dataset.index)
136
+ ele.addEventListener('transitionend', this.resetIndex, { once: true })
137
+ ele.addEventListener('transitioncancel', (event) => {
138
+ this.resetIndex(event)
139
+ ele.removeEventListener('transitionend', this.resetIndex)
140
+ }, { once: true })
141
+ }
142
+
143
+ // 即将展示
144
+ toCurrent(ele) {
145
+ console.debug('add transition event listener for to', ele.dataset.index)
146
+ ele.addEventListener('transitionend', (event) => {
147
+ this.clearStyle(event.currentTarget)
148
+ }, { once: true })
149
+ ele.addEventListener('transitioncancel', (event) => {
150
+ this.clearStyle(event.currentTarget)
151
+ }, { once: true })
152
+ }
153
+
154
+ // 接近左侧
155
+ closeToLeft(ele) {
156
+ ele.style.left = 0
157
+ ele.style.transitionProperty = 'left'
158
+ ele.style.transitionDuration = this.duration
159
+ }
160
+
161
+ // 接近右侧
162
+ closeToRight(ele) {
163
+ ele.style.right = 0
164
+ ele.style.transitionProperty = 'right'
165
+ ele.style.transitionDuration = this.duration
166
+ }
167
+
168
+ // 远离右侧
169
+ awayFromRight(ele) {
170
+ ele.style.right = this.element.clientWidth + 'px'
171
+ ele.style.transitionProperty = 'right'
172
+ ele.style.transitionDuration = this.duration
173
+ }
174
+
175
+ // 远离左侧
176
+ awayFromLeft(ele) {
177
+ ele.style.left = this.element.clientWidth + 'px'
178
+ ele.style.transitionProperty = 'left'
179
+ ele.style.transitionDuration = this.duration
180
+ }
181
+
182
+ clearStyle(ele) {
183
+ ['left', 'right', 'transition-property', 'transition-duration'].forEach(rule => {
184
+ ele.style.removeProperty(rule)
185
+ })
186
+ }
187
+
188
+ }