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,135 @@
1
+
2
+ export default {
3
+ setMap (decades, cb) {
4
+ // console.log('setMap', decades)
5
+ // object used to cache map by decade
6
+ this.mapsvg = this.mapsvg || {}
7
+
8
+ var decade = decades[0]
9
+
10
+ // do not update map when in taxi mode
11
+ // if (typeof decade !== 'number') {
12
+ // return
13
+ // }
14
+
15
+ // map is cached, use it
16
+ if (this.mapsvg[decade]) {
17
+ this.initMap(this.mapsvg[decade], decades)
18
+
19
+ // execute callback
20
+ if (cb) cb()
21
+ } else {
22
+ // fetch map for the corresponding decade
23
+ var url = this.options.path + decade + '.svg'
24
+ // console.log(url)
25
+ fetch(url).then((response) => {
26
+ response.text().then((map) => {
27
+ this.mapsvg[decade] = map
28
+ this.initMap(map, decades)
29
+
30
+ // execute callback
31
+ if (cb) cb()
32
+ })
33
+ })
34
+ }
35
+ },
36
+
37
+ initMap (map, decades) {
38
+ // console.log('initMap', decades)
39
+ this.insertMap(map)
40
+
41
+ this.highlight(this.isocodes)
42
+ this.publish('mapReady', decades)
43
+
44
+ // this.optimizeMap(decades[0])
45
+
46
+ // this is the beginning of the map that will hide path
47
+ // if out of the viewport
48
+
49
+ // this.updatePaths()
50
+ // this.updateViewport()
51
+ },
52
+
53
+ optimizeMap (decade) {
54
+ // console.log('optimizing map', decade)
55
+ var parts = this.map.querySelectorAll('g[data-isocode]')
56
+ var country = {}
57
+
58
+ for (var i = 0; i < parts.length; i++) {
59
+ var part = parts[i]
60
+ var code = part.dataset.isocode
61
+ if (!country[code]) {
62
+ country[code] = part
63
+ } else {
64
+ country[code].appendChild(part.firstChild)
65
+ part.parentNode.removeChild(part)
66
+ }
67
+ }
68
+ },
69
+
70
+ insertMap (map) {
71
+ this.svg.innerHTML = map
72
+ // this.updateSize()
73
+ this.updatePosition()
74
+ },
75
+
76
+ updatePosition () {
77
+ // console.log('updatePosition')
78
+ // this.screenSize()
79
+ // this.updateRoot()
80
+ this.map.classList.add('show')
81
+ // this.updateMap()
82
+ },
83
+
84
+ updateRoot () {
85
+ this.offsetX = this.screen.width - this.root.offsetWidth
86
+ this.offsetY = this.screen.height - this.root.offsetHeight
87
+
88
+ // console.log('--', this.offsetX / 2 + 'px')
89
+
90
+ this.root.style.left = (this.offsetX / 2) + 'px'
91
+ this.root.style.top = (this.offsetY / 2) + 'px'
92
+
93
+ // if (isTouchScreen()) {
94
+ // this.root.style.top = (this.offsetY / 2) + 70 + 'px'
95
+ // } else {
96
+ // this.root.style.top = -1200 + 'px'
97
+ // }
98
+ },
99
+
100
+ updateMap () {
101
+ var offsetX = this.root.offsetWidth - this.map.offsetWidth
102
+ // var offsetY = this.root.height - this.map.offsetHeight
103
+
104
+ // console.log('--', this.offsetX / 2 + 'px')
105
+
106
+ this.map.style.left = (offsetX / 2) + 'px'
107
+
108
+ // if (isTouchScreen()) {
109
+ // this.map.style.top = (offsetY / 2) + 70 + 'px'
110
+ // } else {
111
+ // this.map.style.top = -1200 + 'px'
112
+ // }
113
+ },
114
+
115
+ screenSize () {
116
+ // console.log('screensize')
117
+ var width = window.innerWidth ||
118
+ document.documentElement.clientWidth ||
119
+ document.body.clientWidth
120
+
121
+ var height = window.innerHeight ||
122
+ document.documentElement.clientHeight ||
123
+ document.body.clientHeight
124
+
125
+ var screen = {
126
+ width: width,
127
+ height: height
128
+ }
129
+
130
+ this.screen = screen
131
+
132
+ return screen
133
+ }
134
+
135
+ }
@@ -0,0 +1,39 @@
1
+ export default {
2
+ /**
3
+ * Focus on country
4
+ * @param {[type]} country isocode
5
+ * @return {[type]} [description]
6
+ */
7
+ focus (country) {
8
+ // console.log('focus', country)
9
+ var part = this.getCountryParts(country)
10
+ // console.log('focus on part', part)
11
+ this.draggable.focus(part)
12
+
13
+ return part
14
+ },
15
+
16
+ getCountryParts (country) {
17
+ // console.log('focus', country)
18
+ var parts = this.map.querySelectorAll('[data-isocode="' + country + '"]')
19
+ // console.log('parts', parts)
20
+
21
+ return this.getBiggestPart(parts)
22
+ },
23
+
24
+ getBiggestPart (parts) {
25
+ var surface = 0
26
+ var biggest = null
27
+ for (var i = 0; i < parts.length; i++) {
28
+ var part = parts[i]
29
+ var rect = part.getBoundingClientRect()
30
+
31
+ if (rect.width * rect.height > surface) {
32
+ surface = rect.width * rect.height
33
+ biggest = part
34
+ }
35
+ }
36
+
37
+ return biggest
38
+ }
39
+ }
@@ -0,0 +1,24 @@
1
+ import mediator from '../module/mediator'
2
+ import { isocode } from '../data/country'
3
+
4
+ export default {
5
+ /**
6
+ * init method
7
+ * @param {Object} Options object
8
+ * @return {void} Null
9
+ */
10
+ init (options) {
11
+ this.initMediator()
12
+
13
+ this.mode = this.options.mode
14
+ this.country = isocode
15
+ this.isocodes = []
16
+ this.zoom = this.options.zoom
17
+ this.playing = null
18
+ this.isocodes = this.options.isocodes || []
19
+ },
20
+
21
+ initMediator () {
22
+ mediator.installTo(this)
23
+ }
24
+ }
File without changes
@@ -0,0 +1,44 @@
1
+ export default {
2
+ setMode (mode, options) {
3
+ // console.log('setMode', mode, this.options)
4
+ if (this.mode === mode) return
5
+
6
+ if (mode === 'unique') {
7
+ this.setUnique()
8
+ } else if (mode === 'multiple') {
9
+ this.setMultiple()
10
+ }
11
+ this.mode = mode
12
+
13
+ return this
14
+ },
15
+
16
+ setUnique () {
17
+ this.isocodes = this.isocodes || []
18
+
19
+ if (this.isocodes.length > 0) {
20
+ this.list = this.isocodes.slice()
21
+ }
22
+
23
+ this.highlight(this.isocodes, false)
24
+
25
+ this.isocodes = this.info.slice()
26
+ this.highlight(this.isocodes)
27
+ },
28
+
29
+ setMultiple () {
30
+ // console.log('setMultiple')
31
+
32
+ this.info = this.isocodes.slice()
33
+
34
+ this.highlight(this.isocodes, false)
35
+
36
+ if (this.list) {
37
+ this.isocodes = this.list.slice()
38
+ }
39
+
40
+ this.highlight(this.isocodes)
41
+
42
+ return this
43
+ }
44
+ }
@@ -0,0 +1,65 @@
1
+ import isTouch from '../module/touchscreen'
2
+
3
+ export default {
4
+ mouseUp (event) {
5
+ // console.log('mouseup', event.target)
6
+ if (this.clickSelect || !this.slide.classList.contains('dragging')) {
7
+ if (event.target.classList.contains('empty')) { return }
8
+
9
+ event.preventDefault()
10
+ event.target.classList.remove('dragging')
11
+
12
+ if (event.target.dataset.island !== undefined) {
13
+ this.selectIsland(event.target)
14
+ }
15
+
16
+ if (event.target.parentNode.dataset.isocode !== undefined) {
17
+ this.select(event.target.parentNode.dataset.isocode, event.target.parentNode)
18
+ }
19
+ }
20
+ },
21
+
22
+ mouseDown (event) {
23
+ // if (isTouch()) return
24
+ // console.log('mouseup', this.clickSelect)
25
+ this.clickSelect = true
26
+ this.clickTimeOut = setTimeout(() => {
27
+ this.clickSelect = false
28
+ }, 200)
29
+ },
30
+
31
+ mouseMove (event) {
32
+ // console.log('over', event.relatedTarget, event.clientX, event.clientY)
33
+ if (event.target.parentNode.dataset.isocode !== undefined) {
34
+ // console.log('enter', event.clientX, event.clientY)
35
+ this.label.innerHTML = this.country[event.target.parentNode.dataset.isocode]
36
+ if (!isTouch()) {
37
+ this.label.style.left = (event.clientX - 24) + 'px'
38
+ this.label.style.top = (event.clientY - 36) + 'px'
39
+ }
40
+ this.label.classList.add('show')
41
+ } else if (event.target.dataset.island !== undefined) {
42
+ this.label.innerHTML = event.target.dataset.island
43
+ this.label.style.left = (event.clientX - 24) + 'px'
44
+ this.label.style.top = (event.clientY - 36) + 'px'
45
+ this.label.classList.add('show')
46
+ } else {
47
+ this.label.innerHTML = ''
48
+ this.label.classList.remove('show')
49
+ }
50
+ },
51
+
52
+ mouseLeave () {
53
+ this.label.innerHTML = ''
54
+ this.label.classList.remove('show')
55
+ },
56
+
57
+ mouseOut () {
58
+ this.label.innerHTML = ''
59
+ this.label.classList.remove('show')
60
+ },
61
+
62
+ mouseClick (event) {
63
+ event.preventDefault()
64
+ }
65
+ }
@@ -0,0 +1,68 @@
1
+ export default {
2
+ select (isocode, group) {
3
+ this.isocodes = this.isocodes || []
4
+ // console.log('select', isocode)
5
+ if (!isocode) {
6
+ return
7
+ }
8
+
9
+ // console.log('islands', this.islands)
10
+
11
+ this.unSelectIsland()
12
+
13
+ if (this.mode !== 'multiple') {
14
+ if (this.isocodes[0] === isocode) return
15
+ this.highlight(this.isocodes[0], false)
16
+ this.highlight(isocode)
17
+ this.isocodes = [isocode]
18
+ } else {
19
+ this.isocodes = this.isocodes || []
20
+ var index = this.isocodes.indexOf(isocode)
21
+ if (index > -1) {
22
+ this.isocodes.splice(index, 1)
23
+ this.highlight(isocode, false)
24
+ } else {
25
+ this.isocodes.push(isocode)
26
+ this.highlight(isocode)
27
+ }
28
+ }
29
+
30
+ this.publish('countrySelect', this.isocodes)
31
+
32
+ return this
33
+ },
34
+
35
+ selectIsland (island) {
36
+ // console.log('selectIsland', island)
37
+ if (this.island === island) return
38
+
39
+ if (this.island) {
40
+ this.island.classList.remove('selected')
41
+ }
42
+
43
+ this.island = island
44
+ this.island.classList.add('selected')
45
+ this.islands.splashScreen(island.dataset.splash)
46
+
47
+ this.islands.selectecd = island
48
+
49
+ if (this.isocodes && this.isocodes[0]) {
50
+ this.highlight(this.isocodes, false)
51
+ }
52
+
53
+ this.isocodes = null
54
+
55
+ // console.log('islands list', this.islands.list, island.dataset.id)
56
+
57
+ var info = this.islands.list[island.dataset.id]
58
+
59
+ this.emit('island', info)
60
+ },
61
+
62
+ unSelectIsland () {
63
+ if (this.island) {
64
+ this.island.classList.remove('selected')
65
+ this.island = null
66
+ }
67
+ }
68
+ }
package/src/map/set.js ADDED
@@ -0,0 +1,71 @@
1
+
2
+ export default {
3
+ /**
4
+ * Setter
5
+ * @param {string} prop
6
+ * @param {string} value
7
+ */
8
+ set (prop, value, options) {
9
+ // console.log('set worldmap', prop, value)
10
+ switch (prop) {
11
+ case 'isocodes':
12
+ this.setIsocodes(value)
13
+ break
14
+ case 'zoom':
15
+ this.setZoom(value, options)
16
+ break
17
+ case 'selected':
18
+ this.highlight(value, options)
19
+ break
20
+ case 'map':
21
+ this.setMap(value)
22
+ break
23
+ case 'mode':
24
+ this.setMode(value)
25
+ break
26
+ default:
27
+ this.setIsocodes(prop)
28
+ break
29
+ }
30
+
31
+ return this
32
+ },
33
+
34
+ get (prop) {
35
+ // console.log('set worldmap', prop, value)
36
+ switch (prop) {
37
+ case 'zoom':
38
+ return this.zoom
39
+ break
40
+ case 'isocodes':
41
+ return this.isocodes
42
+ break
43
+ case 'map':
44
+ return this.map
45
+ break
46
+ case 'mode':
47
+ return this.mode
48
+ break
49
+ default:
50
+ return this.isocodes
51
+ break
52
+ }
53
+ },
54
+
55
+ setIsocodes (isocodes) {
56
+ this.isocodes = this.isocodes || []
57
+ var l = this.isocodes.length
58
+ for (var i = 0; i < l; i++) {
59
+ var isocode = this.isocodes.splice(0, 1)
60
+ this.highlight(isocode, false)
61
+ }
62
+
63
+ this.isocodes = isocodes
64
+ this.highlight(this.isocodes)
65
+ },
66
+
67
+ setZoom (delta) {
68
+ // console.log('set zoom', delta)
69
+ if (this.draggable.setZoom) { this.draggable.setZoom(delta) }
70
+ }
71
+ }
@@ -0,0 +1,46 @@
1
+ export default {
2
+
3
+ updatePaths () {
4
+ this.path = {}
5
+ this.paths = []
6
+ var paths = this.paths = this.map.querySelectorAll('path')
7
+ this.path = this.path || {}
8
+
9
+ for (var i = 0; i < paths.length; i++) {
10
+ var path = paths[i]
11
+ var rect = path.getBoundingClientRect()
12
+ this.path[i] = rect
13
+ }
14
+ },
15
+
16
+ updateViewport () {
17
+ console.log('updateViewport', this.rect, this.screen)
18
+ var paths = this.paths
19
+ for (var i = 0; i < paths.length; i++) {
20
+ var path = paths[i]
21
+ if (this.viewport(this.path[i])) {
22
+ path.classList.remove('hide')
23
+ } else {
24
+ path.classList.add('hide')
25
+ }
26
+ }
27
+ },
28
+
29
+ viewport (rect) {
30
+ if (!rect) return
31
+
32
+ // *var rect = this.path[path]
33
+
34
+ var top = rect.top
35
+ var left = rect.left
36
+ var width = rect.width
37
+ var height = rect.height
38
+
39
+ return (
40
+ top >= this.screen.y &&
41
+ left >= this.screen.x &&
42
+ (top + height) <= (this.screen.y + this.screen.height) &&
43
+ (left + width) <= (this.screen.x + this.screen.width)
44
+ )
45
+ }
46
+ }
package/src/map.js ADDED
@@ -0,0 +1,71 @@
1
+
2
+ import mediator from '../module/mediator'
3
+ import emitter from 'material/src/module/emitter'
4
+ import attach from 'material/src/module/attach'
5
+
6
+ import init from './map/init'
7
+ import build from './map/build'
8
+ import viewport from './map/viewport'
9
+ import countries from './map/countries'
10
+ import set from './map/set'
11
+ import mouse from './map/mouse'
12
+ import display from './map/display'
13
+ import mode from './map/mode'
14
+ import select from './map/select'
15
+ import focus from './map/focus'
16
+
17
+ const events = [
18
+ ['root.mousedown', 'mouseDown'],
19
+ ['root.mouseup', 'mouseUp'],
20
+ ['root.mousemove', 'mouseMove'],
21
+ ['root.mouseleave', 'mouseLeave'],
22
+ ['root.mouseout', 'mouseOut'],
23
+ ['root.click', 'mouseClick'],
24
+ ['root.touchStart', 'mouseClick']
25
+ ]
26
+
27
+ const defaults = {
28
+ class: 'worldmap',
29
+ tag: 'main',
30
+ zoom: 0.3,
31
+ isocodes: [],
32
+ mode: 'unique',
33
+ path: '/dist/map/',
34
+ pinchZoom: {
35
+ maxZoom: 128,
36
+ minZoom: 3,
37
+ setOffsetsOnce: true,
38
+ verticalPadding: 64,
39
+ horizontalPadding: 64,
40
+ tapZoomFactor: 0
41
+ }
42
+ }
43
+
44
+ class Map {
45
+ /**
46
+ * Constructor component options
47
+ * @return {Object} Class instance
48
+ */
49
+ constructor (options) {
50
+ this.options = Object.assign({}, defaults, options || {})
51
+
52
+ Object.assign(
53
+ this, attach, emitter, init, build, viewport, mouse,
54
+ mode, countries,
55
+ set, display, select, focus
56
+ )
57
+
58
+ mediator.installTo(this)
59
+
60
+ this.init(options)
61
+
62
+ this.build()
63
+ this.attach(events)
64
+
65
+ this.publish('initWorldmap')
66
+
67
+ return this
68
+ }
69
+ }
70
+
71
+ export default Map
@@ -1,5 +1,3 @@
1
- 'use strict'
2
-
3
1
  import extract from './extract'
4
2
 
5
3
  /**
@@ -25,26 +23,26 @@ export default {
25
23
  events.map((def) => {
26
24
  var e = extract.e(instance, def[0])
27
25
  var f = extract.f(instance, def[1])
28
- var o = def[2] || false
29
-
30
- // console.log('attach', def[0], def[1])
26
+ var option = def[2]
31
27
 
32
28
  var keys = def[1].split('.')
29
+
33
30
  keys.pop()
34
- var bound = this._path(keys.join('.'))
31
+ var bound = this.last(keys.join('.'))
32
+
33
+ if (f && bound && e && e.element && e.element.addEventListener) {
34
+ if (!f) { console.log('error') }
35
35
 
36
- if (e.element && e.element.addEventListener) {
37
- e.element.addEventListener(e.name, f.bind(bound), o)
38
- } else if (e.element && e.element.on) {
39
- // console.log('on', e.name)
40
- if (!f) {
41
- console.log('can\'t attach event', e.name, 'to', def[1])
36
+ if (option) {
37
+ e.element.addEventListener(e.name, f.bind(bound), option)
42
38
  } else {
43
- e.element.on(e.name, f.bind(bound))
39
+ e.element.addEventListener(e.name, f.bind(bound))
44
40
  }
41
+ } else if (e && e.element && e.element.on && f && bound) {
42
+ e.element.on(e.name, f.bind(bound))
45
43
  } else {
46
- console.log('can\'t attach', def[0], def[1])
47
- // console.log('--', e, f)
44
+ // console.trace('can\'t attach', def[0])
45
+ // console.log('can\'t attach', def[0])
48
46
  }
49
47
  })
50
48
 
@@ -56,7 +54,8 @@ export default {
56
54
  * @param {string} str Object path for example key1.key2.key3
57
55
  * @return {value} The value of the last reference
58
56
  */
59
- _path: function (str) {
57
+ last: function (str) {
58
+ // console.log('_path', str)
60
59
  if (!str) return this
61
60
  else if (!str.match(/\./)) return this[str]
62
61
  var last