material 0.4.2 → 0.5.0

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 (168) hide show
  1. package/dist/tracks.svg +10 -0
  2. package/package.json +1 -1
  3. package/src/appbar.js +1 -2
  4. package/src/control/button.js +263 -0
  5. package/src/control/button.new.js +190 -0
  6. package/src/control/datehour.js +65 -0
  7. package/src/control/dialog.js +174 -0
  8. package/src/control/file.js +123 -0
  9. package/src/control/image.js +92 -0
  10. package/src/control/link.js +61 -0
  11. package/src/control/list.js +77 -0
  12. package/src/control/loading.js +128 -0
  13. package/src/control/module/addclass.js +16 -0
  14. package/src/control/module/attributes.js +21 -0
  15. package/src/control/search.js +98 -0
  16. package/src/control/select.js +130 -0
  17. package/src/control/selecter.js +246 -0
  18. package/src/control/switch.js +272 -0
  19. package/src/control/switcher.js +245 -0
  20. package/src/control/text.js +66 -0
  21. package/src/control/textfield.js +177 -0
  22. package/src/field/image.js +9 -3
  23. package/src/form/build.js +60 -6
  24. package/src/form/cancel.js +7 -3
  25. package/src/form/controller.js +90 -0
  26. package/src/form/create.js +12 -6
  27. package/src/form/data.js +82 -0
  28. package/src/form/delete.js +2 -1
  29. package/src/form/fetch.js +30 -0
  30. package/src/form/render.js +14 -19
  31. package/src/form/set.js +27 -12
  32. package/src/form/submit.js +24 -49
  33. package/src/form/update.js +46 -0
  34. package/src/layout.js +26 -22
  35. package/src/list/add.js +34 -0
  36. package/src/list/build.js +100 -6
  37. package/src/list/click.js +10 -5
  38. package/src/list/collection.js +187 -0
  39. package/src/list/create.js +21 -11
  40. package/src/list/display.js +78 -0
  41. package/src/list/empty.js +4 -1
  42. package/src/list/filter.js +114 -0
  43. package/src/list/load.js +2 -2
  44. package/src/list/remove.js +17 -4
  45. package/src/list/render.js +32 -9
  46. package/src/list/request.js +182 -0
  47. package/src/list/search.js +118 -35
  48. package/src/list/select.js +151 -30
  49. package/src/list/status.js +10 -3
  50. package/src/list/update.js +49 -8
  51. package/src/list/virtual.js +195 -127
  52. package/src/map/build.js +103 -0
  53. package/src/map/countries.js +114 -0
  54. package/src/map/display.js +135 -0
  55. package/src/map/focus.js +39 -0
  56. package/src/map/init.js +24 -0
  57. package/src/map/label.js +0 -0
  58. package/src/map/mode.js +44 -0
  59. package/src/map/mouse.js +65 -0
  60. package/src/map/select.js +68 -0
  61. package/src/map/set.js +71 -0
  62. package/src/map/viewport.js +46 -0
  63. package/src/map.js +71 -0
  64. package/src/module/attach.js +15 -16
  65. package/src/module/extract.js +35 -28
  66. package/src/module/mediator.js +56 -0
  67. package/src/module/object.js +17 -1
  68. package/src/module/observer.js +1 -1
  69. package/src/module/passive.js +17 -0
  70. package/src/module/remove.js +74 -0
  71. package/src/module/scrollbar.js +48 -0
  72. package/src/module/smoothscroll.js +20 -0
  73. package/src/module/viewport.js +20 -0
  74. package/src/selector.js +239 -0
  75. package/src/skin/material/base/body.sass +3 -0
  76. package/src/skin/material/button/file.sass +1 -1
  77. package/src/skin/material/container/container.sass +1 -1
  78. package/src/skin/material/container/dialog.sass +57 -1
  79. package/src/skin/material/container/drawer.sass +3 -3
  80. package/src/skin/material/control/button.sass +125 -0
  81. package/src/skin/material/control/dialog.sass +0 -0
  82. package/src/skin/material/control/progress.sass +136 -0
  83. package/src/skin/material/control/search.sass +40 -0
  84. package/src/skin/material/control/selecter.sass +131 -0
  85. package/src/skin/material/control/selector.sass +38 -0
  86. package/src/skin/material/control/slider.sass +2 -2
  87. package/src/skin/material/control/switch.sass +146 -3
  88. package/src/skin/material/control/switcher.sass +41 -0
  89. package/src/skin/material/control/textfield.sass +2 -1
  90. package/src/skin/material/icon/cancel.svg +1 -0
  91. package/src/skin/material/material.sass +3 -0
  92. package/src/skin/material/view/list.sass +81 -188
  93. package/src/skin/material/view/listview.sass +187 -96
  94. package/src/skin/material/view/tabview.sass +7 -5
  95. package/src/skin/material.bak/base/body.sass +52 -0
  96. package/src/skin/material.bak/base/elevation.sass +50 -0
  97. package/src/skin/material.bak/base/grid.sass +63 -0
  98. package/src/skin/material.bak/base/typo.sass +107 -0
  99. package/src/skin/material.bak/button/action.sass +89 -0
  100. package/src/skin/material.bak/button/button.sass +183 -0
  101. package/src/skin/material.bak/button/file.sass +24 -0
  102. package/src/skin/material.bak/button/floating.sass +113 -0
  103. package/src/skin/material.bak/button/raised.sass +101 -0
  104. package/src/skin/material.bak/button/stroked.sass +71 -0
  105. package/src/skin/material.bak/component/component.sass +7 -0
  106. package/src/skin/material.bak/component/divider.sass +17 -0
  107. package/src/skin/material.bak/component/image.sass +6 -0
  108. package/src/skin/material.bak/component/label.sass +2 -0
  109. package/src/skin/material.bak/component/progress.sass +138 -0
  110. package/src/skin/material.bak/component/subheader.sass +3 -0
  111. package/src/skin/material.bak/component/text.sass +85 -0
  112. package/src/skin/material.bak/container/appbar.sass +167 -0
  113. package/src/skin/material.bak/container/banner.sass +38 -0
  114. package/src/skin/material.bak/container/card.sass +18 -0
  115. package/src/skin/material.bak/container/container.sass +1 -0
  116. package/src/skin/material.bak/container/dialog.sass +184 -0
  117. package/src/skin/material.bak/container/drawer.sass +159 -0
  118. package/src/skin/material.bak/container/drawernew.sass +159 -0
  119. package/src/skin/material.bak/container/menu.sass +58 -0
  120. package/src/skin/material.bak/container/snackbar.sass +18 -0
  121. package/src/skin/material.bak/container/tabs.sass +75 -0
  122. package/src/skin/material.bak/container/toolbar.sass +161 -0
  123. package/src/skin/material.bak/control/button.sass +125 -0
  124. package/src/skin/material.bak/control/checkbox.sass +105 -0
  125. package/src/skin/material.bak/control/dialog.sass +0 -0
  126. package/src/skin/material.bak/control/search.sass +40 -0
  127. package/src/skin/material.bak/control/selecter.sass +128 -0
  128. package/src/skin/material.bak/control/slider.sass +181 -0
  129. package/src/skin/material.bak/control/switch.sass +284 -0
  130. package/src/skin/material.bak/control/switcher.sass +35 -0
  131. package/src/skin/material.bak/control/textfield.sass +126 -0
  132. package/src/skin/material.bak/control/tooltip.sass +36 -0
  133. package/src/skin/material.bak/icon/back.svg +5 -0
  134. package/src/skin/material.bak/icon/cancel.svg +1 -0
  135. package/src/skin/material.bak/icon/checkbox.svg +4 -0
  136. package/src/skin/material.bak/icon/forward.svg +5 -0
  137. package/src/skin/material.bak/icon/menu.svg +4 -0
  138. package/src/skin/material.bak/icon/pin.svg +4 -0
  139. package/src/skin/material.bak/layout/layout.sass +69 -0
  140. package/src/skin/material.bak/layout/resizer.sass +69 -0
  141. package/src/skin/material.bak/material.css +2042 -0
  142. package/src/skin/material.bak/material.css.map +7 -0
  143. package/src/skin/material.bak/material.sass +65 -0
  144. package/src/skin/material.bak/module/ripple.sass +9 -0
  145. package/src/skin/material.bak/theme/default.sass +50 -0
  146. package/src/skin/material.bak/theme/ocean.sass +29 -0
  147. package/src/skin/material.bak/theme/theme.sass +3 -0
  148. package/src/skin/material.bak/view/calendar.sass +193 -0
  149. package/src/skin/material.bak/view/form.sass +15 -0
  150. package/src/skin/material.bak/view/grid.sass +116 -0
  151. package/src/skin/material.bak/view/list.sass +89 -0
  152. package/src/skin/material.bak/view/listview.sass +195 -0
  153. package/src/skin/material.bak/view/map.sass +6 -0
  154. package/src/skin/material.bak/view/page.sass +4 -0
  155. package/src/skin/material.bak/view/tabview-bak.sass +40 -0
  156. package/src/skin/material.bak/view/tabview.sass +55 -0
  157. package/src/skin/material.bak/view/tree.sass +73 -0
  158. package/src/skin/material.bak/view/view.sass +7 -0
  159. package/src/switch.js +1 -1
  160. package/src/tabs/setup.js +0 -0
  161. package/src/tabview.js +64 -14
  162. package/src/tooltip.js +23 -5
  163. package/src/view/build.js +15 -3
  164. package/src/view/display.js +79 -7
  165. package/src/form/clean.js +0 -6
  166. package/src/form/mode.js +0 -16
  167. package/src/form/setup.js +0 -30
  168. package/src/list/fetch.js +0 -66
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
3
+ <title>album-24px</title>
4
+ <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
5
+ <g id="album-24px">
6
+ <polygon id="Path" points="0 0 24 0 24 24 0 24"></polygon>
7
+ <path d="M12,2 C6.48,2 2,6.48 2,12 C2,17.52 6.48,22 12,22 C17.52,22 22,17.52 22,12 C22,6.48 17.52,2 12,2 Z M12,16.5 C9.51,16.5 7.5,14.49 7.5,12 C7.5,9.51 9.51,7.5 12,7.5 C14.49,7.5 16.5,9.51 16.5,12 C16.5,14.49 14.49,16.5 12,16.5 Z M12,11 C11.45,11 11,11.45 11,12 C11,12.55 11.45,13 12,13 C12.55,13 13,12.55 13,12 C13,11.45 12.55,11 12,11 Z" id="Shape" fill="#FFFFFF" fill-rule="nonzero"></path>
8
+ </g>
9
+ </g>
10
+ </svg>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "material",
3
- "version": "0.4.2",
3
+ "version": "0.5.0",
4
4
  "description": "A lightweight implementation of Material Design Components - ES6",
5
5
  "main": "index.js",
6
6
  "repository": {
package/src/appbar.js CHANGED
@@ -1,5 +1,4 @@
1
- 'use strict'
2
-
1
+ import passiveEvents from './module/passive'
3
2
  import create from './component/create'
4
3
  import insert from './component/insert'
5
4
  import offset from './element/offset'
@@ -0,0 +1,263 @@
1
+ import emitter from '../module/emitter'
2
+ import attach from '../module/attach'
3
+
4
+ import dataset from '../view/dataset'
5
+
6
+ const defaults = {
7
+ class: 'button',
8
+ tag: 'button',
9
+ styles: ['style', 'color'],
10
+ stopPropagation: false,
11
+ events: [
12
+ ['root.click', 'click'],
13
+ ['root.mousedown', 'mousedown'],
14
+ ['root.mouseup', 'mouseup'],
15
+ ['root.mouseleave', 'mouseup'],
16
+ ['root.touchstart', 'mousedown'],
17
+ ['root.touchend', 'mouseup']
18
+ ]
19
+
20
+ }
21
+
22
+ class Button {
23
+ static isComponent () {
24
+ return true
25
+ }
26
+
27
+ /**
28
+ * Constructor
29
+ * @param {Object} options - Component options
30
+ * @return {Object} Class instance
31
+ */
32
+ constructor (options) {
33
+ this.options = Object.assign({}, defaults, options || {})
34
+ Object.assign(this, emitter, attach)
35
+ // console.log('options', options)
36
+
37
+ this.init()
38
+
39
+ return this
40
+ }
41
+
42
+ init () {
43
+ this.build()
44
+ this.setup()
45
+ this.attach()
46
+
47
+ if (this.options.container) {
48
+ this.append(this.options.container)
49
+ }
50
+ }
51
+
52
+ /**
53
+ * Build Method
54
+ * @return {Object} This class instance
55
+ */
56
+ build () {
57
+ this.root = document.createElement(this.options.tag)
58
+
59
+ if (this.options.class !== 'button') {
60
+ this.root.setAttribute('class', 'button ' + this.options.class)
61
+ } else {
62
+ this.root.classList.add('button')
63
+ }
64
+
65
+ this.styleAttributes()
66
+
67
+ this.buildIcon()
68
+ this.buildLabel()
69
+
70
+ if (this.options.text) {
71
+ this.root.innerHTML = this.root.innerHTML + this.options.text
72
+ }
73
+
74
+ return this
75
+ }
76
+
77
+ setup () {
78
+ if (this.options.data) {
79
+ dataset(this.root, this.options.data)
80
+ }
81
+
82
+ if (this.options.type) {
83
+ this.root.setAttribute('type', this.options.type)
84
+ } else {
85
+ this.root.setAttribute('type', 'button')
86
+ }
87
+
88
+ if (this.options.name) {
89
+ this.root.setAttribute('name', this.options.name)
90
+ }
91
+
92
+ if (this.options.value) {
93
+ this.root.setAttribute('value', this.options.value)
94
+ }
95
+
96
+ if (this.options.title) {
97
+ this.root.setAttribute('title', this.options.title)
98
+ }
99
+
100
+ this.root.setAttribute('aria-label', this.options.text || this.options.label || this.options.class)
101
+
102
+ if (this.options.tooltip) {
103
+ this.root.setAttribute('data-tooltip', this.options.tooltip)
104
+ }
105
+
106
+ if (this.options.case) {
107
+ this.root.classList.add(this.options.case + '-case')
108
+ }
109
+ }
110
+
111
+ append (container) {
112
+ container = container || this.options.container
113
+ if (this.options.container) {
114
+ container.appendChild(this.root)
115
+ }
116
+ }
117
+
118
+ buildLabel () {
119
+ if (!this.options.label) return
120
+
121
+ if (this.options.label) {
122
+ this.label = document.createElement('label')
123
+ this.label.classList.add('label')
124
+ this.label.innerHTML = this.options.label
125
+
126
+ this.root.appendChild(this.label)
127
+ }
128
+ }
129
+
130
+ buildIcon () {
131
+ if (!this.options.icon) return
132
+
133
+ if (this.options.icon) {
134
+ this.icon = document.createElement('i')
135
+ this.icon.classList.add('icon')
136
+ this.icon.innerHTML = this.options.icon
137
+
138
+ this.root.appendChild(this.icon)
139
+ }
140
+ }
141
+
142
+ styleAttributes () {
143
+ if (this.options.style) {
144
+ this.root.classList.add('style-' + this.options.style)
145
+ }
146
+
147
+ if (this.options.size) {
148
+ this.root.classList.add(this.options.size + '-size')
149
+ }
150
+
151
+ if (this.options.color) {
152
+ this.root.classList.add('color-' + this.options.color)
153
+ }
154
+
155
+ if (this.options.bold) {
156
+ this.root.classList.add('bold')
157
+ }
158
+ }
159
+
160
+ /**
161
+ * Setter
162
+ * @param {string} prop
163
+ * @param {string} value
164
+ * @return {Object} The class instance
165
+ */
166
+ set (prop, value) {
167
+ // console.log('set', this.root, prop, value)
168
+ switch (prop) {
169
+ case 'value':
170
+ this.root.value = value
171
+ break
172
+ case 'label':
173
+ if (this.label) {
174
+ this.label.innerHTML = value
175
+ }
176
+ break
177
+ case 'text':
178
+ this.root.innerHTML = value
179
+ break
180
+ case 'icon':
181
+ if (this.label) {
182
+ this.icon.innerHTML = value
183
+ }
184
+ break
185
+ default:
186
+ // console.log('prop', prop)
187
+ this.root.innerHTML = prop
188
+ }
189
+
190
+ return this
191
+ }
192
+
193
+ setLabel (value) {
194
+ // console.log('setLabel', value)
195
+ this.label.innerHTML = value
196
+ }
197
+
198
+ setText (value) {
199
+ // console.log('setText', value)
200
+ if (this.label) {
201
+ this.setLabel(value)
202
+ } else {
203
+ this.root.innerHTML = value
204
+ }
205
+ }
206
+
207
+ /**
208
+ * Setter
209
+ * @param {string} prop
210
+ * @param {string} value
211
+ * @return {Object} The class instance
212
+ */
213
+ get (prop, value) {
214
+ switch (prop) {
215
+ case 'value':
216
+ return this.root.value
217
+ case 'label':
218
+ return this.label.innerHTML
219
+ default:
220
+ return this.root.value
221
+ }
222
+ }
223
+
224
+ disable () {
225
+ this.root.disabled = true
226
+ }
227
+
228
+ enable () {
229
+ this.root.disabled = false
230
+ }
231
+
232
+ hide () {
233
+ this.root.classList.add('hide')
234
+ }
235
+
236
+ show () {
237
+ this.root.classList.remove('hide')
238
+ }
239
+
240
+ destroy () {
241
+ if (this.root && this.root.parentNode) {
242
+ this.root.parentNode.removeChild(this.root)
243
+ }
244
+ }
245
+
246
+ click (ev) {
247
+ if (this.options.stopPropagation === true) {
248
+ ev.stopPropagation()
249
+ }
250
+
251
+ this.emit('click', ev)
252
+ }
253
+
254
+ mousedown (ev) {
255
+ this.root.classList.add('pushed')
256
+ }
257
+
258
+ mouseup (ev) {
259
+ this.root.classList.remove('pushed')
260
+ }
261
+ }
262
+
263
+ export default Button
@@ -0,0 +1,190 @@
1
+ import emitter from '../module/emitter'
2
+ import dataset from '../view/dataset'
3
+
4
+ const defaults = {
5
+ class: 'button',
6
+ tag: 'button',
7
+ styles: ['style', 'color']
8
+ }
9
+
10
+ class Button {
11
+ static isComponent () {
12
+ return true
13
+ }
14
+ /**
15
+ * Constructor
16
+ * @param {Object} options - Component options
17
+ * @return {Object} Class instance
18
+ */
19
+ constructor (options) {
20
+ this.options = Object.assign({}, defaults, options || {})
21
+ Object.assign(this, emitter)
22
+ // console.log('options', options)
23
+
24
+ this.init()
25
+
26
+ return this
27
+ }
28
+
29
+ init () {
30
+ this.build()
31
+ this.setup()
32
+ this.attach()
33
+
34
+ if (this.options.container) {
35
+ this.append(this.options.container)
36
+ }
37
+ }
38
+
39
+ /**
40
+ * Build Method
41
+ * @return {Object} This class instance
42
+ */
43
+ build () {
44
+ this.root = document.createElement(this.options.tag)
45
+
46
+ if (this.options.class !== 'button') {
47
+ this.root.classList.add('button')
48
+ }
49
+
50
+ this.root.classList.add(this.options.class)
51
+ this.styleAttributes()
52
+
53
+ if (this.options.text) {
54
+ this.root.innerHTML = this.options.text
55
+ }
56
+
57
+ if (this.options.label) {
58
+ this.buildLabel()
59
+ }
60
+
61
+ return this
62
+ }
63
+
64
+ setup () {
65
+ if (this.options.data) {
66
+ dataset(this.root, this.options.data)
67
+ }
68
+
69
+ if (this.options.type) {
70
+ this.root.setAttribute('type', this.options.type)
71
+ } else {
72
+ this.root.setAttribute('type', 'button')
73
+ }
74
+
75
+ if (this.options.name) {
76
+ this.root.setAttribute('name', this.options.name)
77
+ }
78
+
79
+ this.root.setAttribute('aria-label', this.options.text || this.options.label || this.options.class)
80
+
81
+ if (this.options.tooltip) {
82
+ this.root.setAttribute('data-tooltip', this.options.tooltip)
83
+ }
84
+
85
+ if (this.options.case) {
86
+ this.root.classList.add(this.options.case + '-case')
87
+ }
88
+ }
89
+
90
+ append (container) {
91
+ if (this.options.container) {
92
+ this.options.container.appendChild(this.root)
93
+ }
94
+ }
95
+
96
+ buildLabel () {
97
+ if (this.options.label) {
98
+ this.label = document.createElement('label')
99
+ this.label.innerHTML = this.options.label
100
+ this.root.appendChild(this.label)
101
+ }
102
+ }
103
+
104
+ buildIcon () {
105
+ if (this.options.icon) {
106
+ this.label = document.createElement('label')
107
+ this.label.innerHTML = this.options.label
108
+ this.root.appendChild(this.label)
109
+ }
110
+ }
111
+
112
+ styleAttributes () {
113
+ if (this.options.style) {
114
+ this.root.classList.add('style-' + this.options.style)
115
+ }
116
+
117
+ if (this.options.color) {
118
+ this.root.classList.add('color-' + this.options.color)
119
+ }
120
+
121
+ if (this.options.bold) {
122
+ this.root.classList.add('bold')
123
+ }
124
+ }
125
+
126
+ attach () {
127
+ this.root.addEventListener('click', (ev) => {
128
+ this.emit('click', ev)
129
+ })
130
+ }
131
+
132
+ /**
133
+ * Setter
134
+ * @param {string} prop
135
+ * @param {string} value
136
+ * @return {Object} The class instance
137
+ */
138
+ set (prop, value) {
139
+ switch (prop) {
140
+ case 'value':
141
+ this.root.value = value
142
+ break
143
+ case 'label':
144
+ if (this.ui.label) {
145
+ this.ui.label.innerHTML = value
146
+ }
147
+ break
148
+ case 'icon':
149
+ if (this.ui.label) {
150
+ this.ui.icon.innerHTML = value
151
+ }
152
+ break
153
+ default:
154
+ this.root.value = value
155
+ }
156
+
157
+ return this
158
+ }
159
+
160
+ /**
161
+ * Setter
162
+ * @param {string} prop
163
+ * @param {string} value
164
+ * @return {Object} The class instance
165
+ */
166
+ get (prop, value) {
167
+ switch (prop) {
168
+ case 'value':
169
+ return this.root.value
170
+ case 'label':
171
+ return this.ui.label.innerHTML
172
+ default:
173
+ return this.root.value
174
+ }
175
+ }
176
+
177
+ disable () {
178
+ this.root.disabled = true
179
+ }
180
+
181
+ enable () {
182
+ this.root.disabled = false
183
+ }
184
+
185
+ destroy () {
186
+ this.root.parentNode.removeChild(this.root)
187
+ }
188
+ }
189
+
190
+ export default Button
@@ -0,0 +1,65 @@
1
+
2
+ const defaults = {
3
+ class: 'date',
4
+ tag: 'span'
5
+ }
6
+
7
+ /**
8
+ * Class representing an image.
9
+ *
10
+ * @extends Date
11
+ * @return {parent} The class instance
12
+ * @example new Date({
13
+ * date: date,
14
+ * container: document.body
15
+ * });
16
+ */
17
+ class DateHour {
18
+ /**
19
+ * Constructor
20
+ * @param {Object} options - Component options
21
+ * @return {Object} Class instance
22
+ */
23
+ constructor (options) {
24
+ this.options = Object.assign({}, defaults, options || {})
25
+
26
+ this.build()
27
+
28
+ return this
29
+ }
30
+
31
+ /**
32
+ * Build Method
33
+ * @return {Object} This class instance
34
+ */
35
+ build () {
36
+ this.root = document.createElement(this.options.tag)
37
+ this.root.classList.add(this.options.class)
38
+
39
+ if (this.options.container) {
40
+ this.options.container.appendChild(this.root)
41
+ }
42
+
43
+ return this
44
+ }
45
+
46
+ set (date) {
47
+ // console.log('set', src)
48
+ var d = new Date(date)
49
+ var formatted = this.format(d)
50
+ this.root.innerHTML = formatted
51
+ }
52
+
53
+ format (date) {
54
+ var hours = date.getHours()
55
+ var minutes = date.getMinutes()
56
+ var ampm = hours >= 12 ? 'pm' : 'am'
57
+ hours = hours % 12
58
+ hours = hours || 12 // the hour '0' should be '12'
59
+ minutes = minutes < 10 ? '0' + minutes : minutes
60
+ var strTime = hours + ':' + minutes + ' ' + ampm
61
+ return date.getMonth() + 1 + '/' + date.getDate() + '/' + date.getFullYear() + ' ' + strTime
62
+ }
63
+ }
64
+
65
+ export default DateHour
@@ -0,0 +1,174 @@
1
+ 'use strict'
2
+
3
+ // dialog related modules
4
+ import emitter from '../module/emitter'
5
+ import attach from '../module/attach'
6
+ import display from '../view/display'
7
+
8
+ import Element from '../element'
9
+ import Text from './text'
10
+ import Button from './button'
11
+ import Layout from '../layout'
12
+
13
+ let defaults = {
14
+ class: 'dialog',
15
+ close: true,
16
+ layout: [
17
+ [Element, 'head', { class: 'head' },
18
+ [Text, 'title', { class: 'title' }],
19
+ [Button, 'close', { class: 'close' }]
20
+ ],
21
+ [Element, 'body', { class: 'body' },
22
+ [Text, 'content', { class: 'content' }]
23
+ ],
24
+ [Element, 'foot', { class: 'foot' },
25
+ [Element, { class: 'divider' }],
26
+ [Button, 'ok', { class: 'ok', text: 'Ok', color: 'primary' }]
27
+ ]
28
+ ],
29
+ events: [
30
+ ['root.click', 'onClickRoot'],
31
+ ['surface.click', 'onClick'],
32
+ ['ui.ok.click', 'ok'],
33
+ ['ui.cancel.click', 'cancel'],
34
+ ['ui.close.click', 'close']
35
+ ]
36
+ }
37
+
38
+ class Dialog {
39
+ /**
40
+ * Constructor
41
+ * @param {Object} options - Component options
42
+ * @return {Object} Class instance
43
+ */
44
+ constructor (options) {
45
+ this.options = Object.assign({}, defaults, options || {})
46
+
47
+ // implement modules
48
+ Object.assign(this, emitter, attach, display)
49
+
50
+ this.build()
51
+ this.render()
52
+ this.attach()
53
+
54
+ return this
55
+ }
56
+
57
+ /**
58
+ * build the component using the super method
59
+ * @return {Object} The class instance
60
+ */
61
+ build () {
62
+ this.root = document.createElement('div')
63
+ this.root.classList.add('dialog')
64
+
65
+ if (this.options.class !== 'dialog') {
66
+ this.root.classList.add(this.options.class)
67
+ }
68
+
69
+ if (this.options.position) {
70
+ this.root.classList.add('position-' + this.options.position)
71
+ }
72
+
73
+ this.surface = document.createElement('div')
74
+ this.surface.classList.add('surface')
75
+ this.root.appendChild(this.surface)
76
+
77
+ this.layout = new Layout(this.options.layout, this.surface)
78
+ this.ui = this.layout.component
79
+
80
+ if (this.options.container) {
81
+ this.options.container.appendChild(this.root)
82
+ }
83
+
84
+ if (this.options.display === 'show') {
85
+ this.show()
86
+ }
87
+ }
88
+
89
+ render () {
90
+ if (this.options.title && this.ui.title) {
91
+ this.ui.title.set(this.options.title)
92
+ }
93
+
94
+ if (this.options.content && this.ui.content) {
95
+ this.ui.content.set(this.options.content)
96
+ }
97
+
98
+ if (this.options.cancel && this.ui.cancel) {
99
+ this.ui.cancel.set('text', this.options.cancel)
100
+ }
101
+
102
+ if (this.options.ok && this.ui.ok) {
103
+ this.ui.ok.set('text', this.options.ok)
104
+ }
105
+
106
+ if (this.options.target) {
107
+ this.setPosition()
108
+ }
109
+ }
110
+
111
+ setPosition () {
112
+ var coord = this.options.target.getBoundingClientRect()
113
+ var surface_coord = this.surface.getBoundingClientRect()
114
+
115
+ if (this.options.position === 'right') {
116
+ this.surface.style.top = coord.top + 'px'
117
+ this.surface.style.left = coord.left + coord.width // surface_coord.width + 'px'
118
+ } else {
119
+ this.surface.style.top = coord.top + 'px'
120
+ this.surface.style.left = coord.left - surface_coord.width + 'px'
121
+ }
122
+ }
123
+
124
+ ok () {
125
+ this.emit('ok')
126
+ if (this.options.close) {
127
+ this.destroy()
128
+ }
129
+ }
130
+
131
+ cancel () {
132
+ this.emit('cancel')
133
+
134
+ if (this.options.close) {
135
+ this.destroy()
136
+ }
137
+ }
138
+
139
+ close () {
140
+ // this.hide()
141
+
142
+ if (this.options.close) {
143
+ this.destroy()
144
+ }
145
+ }
146
+
147
+ onClick (e) {
148
+ e.stopPropagation()
149
+ }
150
+
151
+ onClickRoot (e) {
152
+ e.stopPropagation()
153
+ if (!this.options.modal) {
154
+ this.destroy()
155
+ }
156
+ }
157
+
158
+ emphase () {
159
+ this.root.classList.add('emphase')
160
+ var it
161
+ it = setTimeout(() => {
162
+ clearTimeout(it)
163
+ this.root.classList.remove('emphase')
164
+ }, 100)
165
+ }
166
+
167
+ set (prop, value) {
168
+ if (this.ui[prop]) {
169
+ this.ui[prop].set(value)
170
+ }
171
+ }
172
+ }
173
+
174
+ export default Dialog