material 0.9.6 → 0.9.7

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.
package/src/map/build.js DELETED
@@ -1,103 +0,0 @@
1
- import observer from '../module/element/observer'
2
- import Islands from '../view/islands'
3
- import preventPullRefresh from '../module/preventPullRefresh'
4
- import touch from '../module/touchscreen'
5
- import PinchZoom from '../module/pinchzoom'
6
- import PanZoom from '../module/panzoom'
7
- // import PinchZoomElement from '../../module/pinch-zoom'
8
-
9
- export default {
10
-
11
- /**
12
- * Build worlddmap related methods
13
- * @return {void} This class instance
14
- */
15
- build () {
16
- this.element = document.createElement(this.options.tag)
17
- this.element.classList.add(this.options.class)
18
-
19
- if (this.options.container) {
20
- this.options.container.appendChild(this.element)
21
- }
22
-
23
- this.label = document.createElement('div')
24
- this.label.classList.add('country-label')
25
- document.body.appendChild(this.label)
26
-
27
- this.buildMap()
28
- this.screenSize()
29
-
30
- observer.insert(this.element, () => {
31
- // if (touch()) {
32
- // // console.log('pinchzoom', this.options.pichZoom)
33
- // this.draggable = new PinchZoom(this.slide, {
34
- // maxZoom: 128,
35
- // minZoom: 3,
36
- // setOffsetsOnce: true,
37
- // verticalPadding: 64,
38
- // horizontalPadding: 64,
39
- // onZoomStart: function (object, event) {
40
- // object.el.classList.add('zoom')
41
- // },
42
- // onZoomEnd: function (object, event) {
43
- // object.el.classList.remove('zoom')
44
- // },
45
- // onDragStart: function (object, event) {
46
- // object.el.classList.add('drag')
47
- // },
48
- // onDragEnd: function (object, event) {
49
- // object.el.classList.remove('drag')
50
- // }
51
-
52
- // })
53
- // } else {
54
- // console.log('panzoom')
55
- this.draggable = new PanZoom(this.slide, {
56
- maxZoom: 16,
57
- minZoom: 1
58
- })
59
- // }
60
-
61
- this.rect = this.element.getBoundingClientRect()
62
-
63
- this.screen = {
64
- y: window.pageYOffset,
65
- x: window.pageXOffset,
66
- height: window.innerHeight,
67
- width: window.innerWidth
68
- }
69
- })
70
-
71
- this.islands = new Islands({
72
- container: this.options.container,
73
- map: this.map
74
- })
75
-
76
- return this
77
- },
78
-
79
- /**
80
- * BuildMmap method for container background and vector map
81
- * @return {[type]} [description]
82
- */
83
- buildMap () {
84
- // console.log('buildmap')
85
- this.slide = document.createElement('div')
86
- this.slide.classList.add('slide')
87
- this.element.appendChild(this.slide)
88
-
89
- this.map = document.createElement('div')
90
- this.map.classList.add('map')
91
- this.slide.appendChild(this.map)
92
-
93
- this.bg = document.createElement('div')
94
- this.bg.classList.add('bg')
95
- this.map.appendChild(this.bg)
96
-
97
- this.svg = document.createElement('div')
98
- this.svg.classList.add('svg')
99
- this.map.appendChild(this.svg)
100
-
101
- preventPullRefresh(this.map)
102
- }
103
- }
@@ -1,114 +0,0 @@
1
-
2
- export default {
3
- /**
4
- * [updateCountries description]
5
- * @param {[type]} countries [description]
6
- * @return {[type]} [description]
7
- */
8
- updateCountries (isocodes) {
9
- // console.log('updateCountries', isocodes.length)
10
- const list = document.querySelectorAll('svg.mapsvg g')
11
- // console.log('svg', list)
12
-
13
- for (let i = 0; i < list.length; i++) {
14
- if (isocodes.indexOf(list[i].dataset.isocode) > -1) {
15
- list[i].classList.remove('empty')
16
- } else {
17
- list[i].classList.add('empty')
18
- }
19
- }
20
-
21
- // set a random isocode if not defined
22
- // if (!this.isocode) {
23
- // this.random(isocodes)
24
- // }
25
- },
26
-
27
- /**
28
- * [random description]
29
- * @param {[type]} isocodes [description]
30
- * @return {[type]} [description]
31
- */
32
- random (isocodes) {
33
- // console.log('random', isocodes.length)
34
- const i = Math.floor(Math.random() * isocodes.length)
35
- this.isocodes = isocodes[i]
36
- this.highlight(this.isocodes)
37
-
38
- this.emit('select', this.isocodes)
39
- },
40
-
41
- /**
42
- * [setAllCountries description]
43
- */
44
- setAllCountries () {
45
- const list = document.querySelectorAll('svg.mapsvg g')
46
- // console.log('svg', list)
47
-
48
- for (let i = 0; i < list.length; i++) {
49
- list[i].classList.remove('empty')
50
- }
51
- },
52
-
53
- /**
54
- * Highlight/unhighlight country on the for the given isocode
55
- * @param {[type]} isocode [description]
56
- * @param {[type]} option [description]
57
- * @return {[type]} [description]
58
- */
59
- highlight (isocodes, option) {
60
- // console.log('highlight', isocode, option)
61
-
62
- if (!isocodes) return
63
-
64
- if (typeof isocodes === 'string') {
65
- this.highlightCountry(isocodes, option)
66
- } else {
67
- for (let i = 0; i < isocodes.length; i++) {
68
- this.highlightCountry(isocodes[i], option)
69
- }
70
- }
71
- },
72
-
73
- /**
74
- * [highlightCountry description]
75
- * @param {[type]} isocode [description]
76
- * @param {[type]} option [description]
77
- * @return {[type]} [description]
78
- */
79
- highlightCountry (isocode, option) {
80
- // console.log('highlightCountry', isocode, option)
81
- const group = this.map.querySelector('[data-isocode="' + isocode + '"]')
82
-
83
- if (!group) return
84
-
85
- if (option === false) {
86
- group.classList.remove('selected')
87
- } else {
88
- group.classList.add('selected')
89
- }
90
-
91
- if (option === 'playing') {
92
- this.removePlaying()
93
- }
94
- },
95
-
96
- /**
97
- * Highlight/unhighlight country on the for the given isocode
98
- * @param {[type]} isocode [description]
99
- * @param {[type]} option [description]
100
- * @return {[type]} [description]
101
- */
102
- highlightGroup (group) {
103
- // console.log('highlightGroup', group)
104
-
105
- if (!group) return
106
-
107
- group.classList.add('selected')
108
- },
109
-
110
- removePlaying () {
111
- const group = document.querySelector('svg.mapsvg g.playing')
112
- group.classList.remove('playing')
113
- }
114
- }
@@ -1,135 +0,0 @@
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
- const 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
- const 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
- const parts = this.map.querySelectorAll('g[data-isocode]')
56
- const country = {}
57
-
58
- for (let i = 0; i < parts.length; i++) {
59
- const part = parts[i]
60
- const 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.element.offsetWidth
86
- this.offsetY = this.screen.height - this.element.offsetHeight
87
-
88
- // console.log('--', this.offsetX / 2 + 'px')
89
-
90
- this.element.style.left = (this.offsetX / 2) + 'px'
91
- this.element.style.top = (this.offsetY / 2) + 'px'
92
-
93
- // if (isTouchScreen()) {
94
- // this.element.style.top = (this.offsetY / 2) + 70 + 'px'
95
- // } else {
96
- // this.element.style.top = -1200 + 'px'
97
- // }
98
- },
99
-
100
- updateMap () {
101
- const offsetX = this.element.offsetWidth - this.map.offsetWidth
102
- // var offsetY = this.element.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
- const width = window.innerWidth ||
118
- document.documentElement.clientWidth ||
119
- document.body.clientWidth
120
-
121
- const height = window.innerHeight ||
122
- document.documentElement.clientHeight ||
123
- document.body.clientHeight
124
-
125
- const screen = {
126
- width,
127
- height
128
- }
129
-
130
- this.screen = screen
131
-
132
- return screen
133
- }
134
-
135
- }
package/src/map/focus.js DELETED
@@ -1,39 +0,0 @@
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
- const 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
- const parts = this.map.querySelectorAll('[data-isocode="' + country + '"]')
19
- // console.log('parts', parts)
20
-
21
- return this.getBiggestPart(parts)
22
- },
23
-
24
- getBiggestPart (parts) {
25
- let surface = 0
26
- let biggest = null
27
- for (let i = 0; i < parts.length; i++) {
28
- const part = parts[i]
29
- const 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
- }
package/src/map/init.js DELETED
@@ -1,24 +0,0 @@
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
- }
package/src/map/label.js DELETED
File without changes
package/src/map/mode.js DELETED
@@ -1,44 +0,0 @@
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
- }
package/src/map/mouse.js DELETED
@@ -1,65 +0,0 @@
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
- }
package/src/map/select.js DELETED
@@ -1,68 +0,0 @@
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
- const 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
- const 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 DELETED
@@ -1,71 +0,0 @@
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
- const l = this.isocodes.length
58
- for (let i = 0; i < l; i++) {
59
- const 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
- }