material 0.4.3 → 0.5.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 (166) hide show
  1. package/dist/tracks.svg +10 -0
  2. package/package.json +4 -4
  3. package/src/appbar.js +1 -2
  4. package/src/control/button.js +127 -44
  5. package/src/control/button.new.js +190 -0
  6. package/src/control/dialog.js +174 -0
  7. package/src/control/{upload.js → file.js} +33 -8
  8. package/src/control/link.js +61 -0
  9. package/src/control/list.js +77 -0
  10. package/src/control/loading.js +128 -0
  11. package/src/control/module/addclass.js +16 -0
  12. package/src/control/module/attributes.js +3 -1
  13. package/src/control/search.js +98 -0
  14. package/src/control/select.js +80 -22
  15. package/src/control/selecter.js +246 -0
  16. package/src/control/switch.js +272 -0
  17. package/src/control/switcher.js +245 -0
  18. package/src/control/text.js +18 -3
  19. package/src/control/textfield.js +89 -15
  20. package/src/field/image.js +9 -3
  21. package/src/form/build.js +28 -4
  22. package/src/form/cancel.js +7 -3
  23. package/src/form/controller.js +90 -0
  24. package/src/form/create.js +11 -7
  25. package/src/form/data.js +82 -0
  26. package/src/form/delete.js +2 -1
  27. package/src/form/fetch.js +5 -3
  28. package/src/form/render.js +11 -9
  29. package/src/form/set.js +27 -12
  30. package/src/form/submit.js +11 -37
  31. package/src/form/update.js +35 -16
  32. package/src/layout.js +25 -21
  33. package/src/list/add.js +34 -0
  34. package/src/list/build.js +96 -12
  35. package/src/list/click.js +10 -5
  36. package/src/list/collection.js +187 -0
  37. package/src/list/create.js +21 -11
  38. package/src/list/display.js +78 -0
  39. package/src/list/empty.js +4 -1
  40. package/src/list/filter.js +114 -0
  41. package/src/list/load.js +2 -2
  42. package/src/list/remove.js +17 -4
  43. package/src/list/render.js +32 -9
  44. package/src/list/request.js +182 -0
  45. package/src/list/search.js +118 -35
  46. package/src/list/select.js +151 -30
  47. package/src/list/status.js +10 -3
  48. package/src/list/update.js +49 -8
  49. package/src/list/virtual.js +195 -127
  50. package/src/map/build.js +103 -0
  51. package/src/map/countries.js +114 -0
  52. package/src/map/display.js +135 -0
  53. package/src/map/focus.js +39 -0
  54. package/src/map/init.js +24 -0
  55. package/src/map/label.js +0 -0
  56. package/src/map/mode.js +44 -0
  57. package/src/map/mouse.js +65 -0
  58. package/src/map/select.js +68 -0
  59. package/src/map/set.js +71 -0
  60. package/src/map/viewport.js +46 -0
  61. package/src/map.js +71 -0
  62. package/src/module/attach.js +9 -2
  63. package/src/module/mediator.js +56 -0
  64. package/src/module/object.js +17 -1
  65. package/src/module/observer.js +1 -1
  66. package/src/module/passive.js +17 -0
  67. package/src/module/remove.js +74 -0
  68. package/src/module/scrollbar.js +48 -0
  69. package/src/module/smoothscroll.js +20 -0
  70. package/src/module/viewport.js +20 -0
  71. package/src/selector.js +239 -0
  72. package/src/skin/material/base/body.sass +3 -0
  73. package/src/skin/material/button/file.sass +1 -1
  74. package/src/skin/material/container/container.sass +1 -1
  75. package/src/skin/material/container/dialog.sass +57 -1
  76. package/src/skin/material/container/drawer.sass +3 -3
  77. package/src/skin/material/control/button.sass +125 -0
  78. package/src/skin/material/control/dialog.sass +0 -0
  79. package/src/skin/material/control/progress.sass +136 -0
  80. package/src/skin/material/control/search.sass +40 -0
  81. package/src/skin/material/control/selecter.sass +131 -0
  82. package/src/skin/material/control/selector.sass +38 -0
  83. package/src/skin/material/control/slider.sass +2 -2
  84. package/src/skin/material/control/switch.sass +146 -3
  85. package/src/skin/material/control/switcher.sass +41 -0
  86. package/src/skin/material/control/textfield.sass +2 -1
  87. package/src/skin/material/icon/cancel.svg +1 -0
  88. package/src/skin/material/material.sass +3 -0
  89. package/src/skin/material/view/list.sass +81 -188
  90. package/src/skin/material/view/listview.sass +187 -96
  91. package/src/skin/material/view/tabview.sass +6 -4
  92. package/src/skin/material.bak/base/body.sass +52 -0
  93. package/src/skin/material.bak/base/elevation.sass +50 -0
  94. package/src/skin/material.bak/base/grid.sass +63 -0
  95. package/src/skin/material.bak/base/typo.sass +107 -0
  96. package/src/skin/material.bak/button/action.sass +89 -0
  97. package/src/skin/material.bak/button/button.sass +183 -0
  98. package/src/skin/material.bak/button/file.sass +24 -0
  99. package/src/skin/material.bak/button/floating.sass +113 -0
  100. package/src/skin/material.bak/button/raised.sass +101 -0
  101. package/src/skin/material.bak/button/stroked.sass +71 -0
  102. package/src/skin/material.bak/component/component.sass +7 -0
  103. package/src/skin/material.bak/component/divider.sass +17 -0
  104. package/src/skin/material.bak/component/image.sass +6 -0
  105. package/src/skin/material.bak/component/label.sass +2 -0
  106. package/src/skin/material.bak/component/progress.sass +138 -0
  107. package/src/skin/material.bak/component/subheader.sass +3 -0
  108. package/src/skin/material.bak/component/text.sass +85 -0
  109. package/src/skin/material.bak/container/appbar.sass +167 -0
  110. package/src/skin/material.bak/container/banner.sass +38 -0
  111. package/src/skin/material.bak/container/card.sass +18 -0
  112. package/src/skin/material.bak/container/container.sass +1 -0
  113. package/src/skin/material.bak/container/dialog.sass +184 -0
  114. package/src/skin/material.bak/container/drawer.sass +159 -0
  115. package/src/skin/material.bak/container/drawernew.sass +159 -0
  116. package/src/skin/material.bak/container/menu.sass +58 -0
  117. package/src/skin/material.bak/container/snackbar.sass +18 -0
  118. package/src/skin/material.bak/container/tabs.sass +75 -0
  119. package/src/skin/material.bak/container/toolbar.sass +161 -0
  120. package/src/skin/material.bak/control/button.sass +125 -0
  121. package/src/skin/material.bak/control/checkbox.sass +105 -0
  122. package/src/skin/material.bak/control/dialog.sass +0 -0
  123. package/src/skin/material.bak/control/search.sass +40 -0
  124. package/src/skin/material.bak/control/selecter.sass +128 -0
  125. package/src/skin/material.bak/control/slider.sass +181 -0
  126. package/src/skin/material.bak/control/switch.sass +284 -0
  127. package/src/skin/material.bak/control/switcher.sass +35 -0
  128. package/src/skin/material.bak/control/textfield.sass +126 -0
  129. package/src/skin/material.bak/control/tooltip.sass +36 -0
  130. package/src/skin/material.bak/icon/back.svg +5 -0
  131. package/src/skin/material.bak/icon/cancel.svg +1 -0
  132. package/src/skin/material.bak/icon/checkbox.svg +4 -0
  133. package/src/skin/material.bak/icon/forward.svg +5 -0
  134. package/src/skin/material.bak/icon/menu.svg +4 -0
  135. package/src/skin/material.bak/icon/pin.svg +4 -0
  136. package/src/skin/material.bak/layout/layout.sass +69 -0
  137. package/src/skin/material.bak/layout/resizer.sass +69 -0
  138. package/src/skin/material.bak/material.css +2042 -0
  139. package/src/skin/material.bak/material.css.map +7 -0
  140. package/src/skin/material.bak/material.sass +65 -0
  141. package/src/skin/material.bak/module/ripple.sass +9 -0
  142. package/src/skin/material.bak/theme/default.sass +50 -0
  143. package/src/skin/material.bak/theme/ocean.sass +29 -0
  144. package/src/skin/material.bak/theme/theme.sass +3 -0
  145. package/src/skin/material.bak/view/calendar.sass +193 -0
  146. package/src/skin/material.bak/view/form.sass +15 -0
  147. package/src/skin/material.bak/view/grid.sass +116 -0
  148. package/src/skin/material.bak/view/list.sass +89 -0
  149. package/src/skin/material.bak/view/listview.sass +195 -0
  150. package/src/skin/material.bak/view/map.sass +6 -0
  151. package/src/skin/material.bak/view/page.sass +4 -0
  152. package/src/skin/material.bak/view/tabview-bak.sass +40 -0
  153. package/src/skin/material.bak/view/tabview.sass +55 -0
  154. package/src/skin/material.bak/view/tree.sass +73 -0
  155. package/src/skin/material.bak/view/view.sass +7 -0
  156. package/src/switch.js +1 -1
  157. package/src/tabs/setup.js +0 -0
  158. package/src/tabview.js +64 -14
  159. package/src/tooltip.js +23 -5
  160. package/src/view/build.js +13 -1
  161. package/src/view/display.js +63 -2
  162. package/src/form/clean.js +0 -6
  163. package/src/form/controls.js +0 -56
  164. package/src/form/mode.js +0 -8
  165. package/src/form/setup.js +0 -5
  166. 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,18 +1,18 @@
1
1
  {
2
2
  "name": "material",
3
- "version": "0.4.3",
3
+ "version": "0.5.1",
4
4
  "description": "A lightweight implementation of Material Design Components - ES6",
5
5
  "main": "index.js",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "https://github.com/floor/material.git"
8
+ "url": "https://github.com/alkaloid/material.git"
9
9
  },
10
10
  "author": "Jérôme Vial <jerome.vial@gmail.com>",
11
11
  "license": "MIT",
12
12
  "bugs": {
13
- "url": "https://github.com/floor/material/issues"
13
+ "url": "https://github.com/alkaloid/material/issues"
14
14
  },
15
- "homepage": "https://github.com/floor/material",
15
+ "homepage": "https://github.com/alkaloid/material",
16
16
  "keywords": [
17
17
  "lightweight material design component es6 es2015 vanilla javascript"
18
18
  ],
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'
@@ -1,25 +1,29 @@
1
1
  import emitter from '../module/emitter'
2
+ import attach from '../module/attach'
3
+
2
4
  import dataset from '../view/dataset'
3
5
 
4
6
  const defaults = {
5
7
  class: 'button',
6
8
  tag: 'button',
7
9
  styles: ['style', 'color'],
8
- components: ['label', 'icon'],
9
- component: {
10
- label: {
11
- tag: 'label'
12
- },
13
- icon: {
14
- tag: 'i'
15
- }
16
- }
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
+
17
20
  }
18
21
 
19
22
  class Button {
20
23
  static isComponent () {
21
24
  return true
22
25
  }
26
+
23
27
  /**
24
28
  * Constructor
25
29
  * @param {Object} options - Component options
@@ -27,13 +31,22 @@ class Button {
27
31
  */
28
32
  constructor (options) {
29
33
  this.options = Object.assign({}, defaults, options || {})
30
- Object.assign(this, emitter)
34
+ Object.assign(this, emitter, attach)
31
35
  // console.log('options', options)
32
36
 
37
+ this.init()
38
+
39
+ return this
40
+ }
41
+
42
+ init () {
33
43
  this.build()
44
+ this.setup()
34
45
  this.attach()
35
46
 
36
- return this
47
+ if (this.options.container) {
48
+ this.append(this.options.container)
49
+ }
37
50
  }
38
51
 
39
52
  /**
@@ -44,22 +57,28 @@ class Button {
44
57
  this.root = document.createElement(this.options.tag)
45
58
 
46
59
  if (this.options.class !== 'button') {
60
+ this.root.setAttribute('class', 'button ' + this.options.class)
61
+ } else {
47
62
  this.root.classList.add('button')
48
63
  }
49
64
 
50
- this.root.classList.add(this.options.class)
51
65
  this.styleAttributes()
52
66
 
67
+ this.buildIcon()
68
+ this.buildLabel()
69
+
53
70
  if (this.options.text) {
54
- this.root.innerHTML = this.options.text
71
+ this.root.innerHTML = this.root.innerHTML + this.options.text
55
72
  }
56
73
 
74
+ return this
75
+ }
76
+
77
+ setup () {
57
78
  if (this.options.data) {
58
79
  dataset(this.root, this.options.data)
59
80
  }
60
81
 
61
- this.buildComponent()
62
-
63
82
  if (this.options.type) {
64
83
  this.root.setAttribute('type', this.options.type)
65
84
  } else {
@@ -70,37 +89,53 @@ class Button {
70
89
  this.root.setAttribute('name', this.options.name)
71
90
  }
72
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
+
73
106
  if (this.options.case) {
74
107
  this.root.classList.add(this.options.case + '-case')
75
108
  }
109
+ }
76
110
 
111
+ append (container) {
112
+ container = container || this.options.container
77
113
  if (this.options.container) {
78
- this.options.container.appendChild(this.root)
114
+ container.appendChild(this.root)
79
115
  }
80
-
81
- return this
82
116
  }
83
117
 
84
- buildComponent () {
85
- this.ui = this.ui || {}
86
-
87
- for (var i = 0; i < this.options.components.length; i++) {
88
- var component = this.options.components[i]
118
+ buildLabel () {
119
+ if (!this.options.label) return
89
120
 
90
- if (!this.options[component]) continue
121
+ if (this.options.label) {
122
+ this.label = document.createElement('label')
123
+ this.label.classList.add('label')
124
+ this.label.innerHTML = this.options.label
91
125
 
92
- var tag = 'div'
93
- if (this.options.component && this.options.component[component]) {
94
- tag = this.options.component[component].tag || tag
95
- }
126
+ this.root.appendChild(this.label)
127
+ }
128
+ }
96
129
 
97
- this.ui[component] = document.createElement(tag)
130
+ buildIcon () {
131
+ if (!this.options.icon) return
98
132
 
99
- if (component === 'label' || component === 'icon') {
100
- this.ui[component].innerHTML = this.options[component]
101
- }
133
+ if (this.options.icon) {
134
+ this.icon = document.createElement('i')
135
+ this.icon.classList.add('icon')
136
+ this.icon.innerHTML = this.options.icon
102
137
 
103
- this.root.appendChild(this.ui[component])
138
+ this.root.appendChild(this.icon)
104
139
  }
105
140
  }
106
141
 
@@ -109,6 +144,10 @@ class Button {
109
144
  this.root.classList.add('style-' + this.options.style)
110
145
  }
111
146
 
147
+ if (this.options.size) {
148
+ this.root.classList.add(this.options.size + '-size')
149
+ }
150
+
112
151
  if (this.options.color) {
113
152
  this.root.classList.add('color-' + this.options.color)
114
153
  }
@@ -118,12 +157,6 @@ class Button {
118
157
  }
119
158
  }
120
159
 
121
- attach () {
122
- this.root.addEventListener('click', (ev) => {
123
- this.emit('click', ev)
124
- })
125
- }
126
-
127
160
  /**
128
161
  * Setter
129
162
  * @param {string} prop
@@ -131,22 +164,46 @@ class Button {
131
164
  * @return {Object} The class instance
132
165
  */
133
166
  set (prop, value) {
167
+ // console.log('set', this.root, prop, value)
134
168
  switch (prop) {
135
169
  case 'value':
136
170
  this.root.value = value
137
171
  break
138
172
  case 'label':
139
- if (this.ui.label) {
140
- this.ui.label.innerHTML = value
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
141
183
  }
142
184
  break
143
185
  default:
144
- this.root.value = value
186
+ // console.log('prop', prop)
187
+ this.root.innerHTML = prop
145
188
  }
146
189
 
147
190
  return this
148
191
  }
149
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
+
150
207
  /**
151
208
  * Setter
152
209
  * @param {string} prop
@@ -158,7 +215,7 @@ class Button {
158
215
  case 'value':
159
216
  return this.root.value
160
217
  case 'label':
161
- return this.ui.label.innerHTML
218
+ return this.label.innerHTML
162
219
  default:
163
220
  return this.root.value
164
221
  }
@@ -172,8 +229,34 @@ class Button {
172
229
  this.root.disabled = false
173
230
  }
174
231
 
232
+ hide () {
233
+ this.root.classList.add('hide')
234
+ }
235
+
236
+ show () {
237
+ this.root.classList.remove('hide')
238
+ }
239
+
175
240
  destroy () {
176
- this.root.parentNode.removeChild(this.root)
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')
177
260
  }
178
261
  }
179
262
 
@@ -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,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