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.
- package/dist/tracks.svg +10 -0
- package/package.json +1 -1
- package/src/appbar.js +1 -2
- package/src/control/button.js +263 -0
- package/src/control/button.new.js +190 -0
- package/src/control/datehour.js +65 -0
- package/src/control/dialog.js +174 -0
- package/src/control/file.js +123 -0
- package/src/control/image.js +92 -0
- package/src/control/link.js +61 -0
- package/src/control/list.js +77 -0
- package/src/control/loading.js +128 -0
- package/src/control/module/addclass.js +16 -0
- package/src/control/module/attributes.js +21 -0
- package/src/control/search.js +98 -0
- package/src/control/select.js +130 -0
- package/src/control/selecter.js +246 -0
- package/src/control/switch.js +272 -0
- package/src/control/switcher.js +245 -0
- package/src/control/text.js +66 -0
- package/src/control/textfield.js +177 -0
- package/src/field/image.js +9 -3
- package/src/form/build.js +60 -6
- package/src/form/cancel.js +7 -3
- package/src/form/controller.js +90 -0
- package/src/form/create.js +12 -6
- package/src/form/data.js +82 -0
- package/src/form/delete.js +2 -1
- package/src/form/fetch.js +30 -0
- package/src/form/render.js +14 -19
- package/src/form/set.js +27 -12
- package/src/form/submit.js +24 -49
- package/src/form/update.js +46 -0
- package/src/layout.js +26 -22
- package/src/list/add.js +34 -0
- package/src/list/build.js +100 -6
- package/src/list/click.js +10 -5
- package/src/list/collection.js +187 -0
- package/src/list/create.js +21 -11
- package/src/list/display.js +78 -0
- package/src/list/empty.js +4 -1
- package/src/list/filter.js +114 -0
- package/src/list/load.js +2 -2
- package/src/list/remove.js +17 -4
- package/src/list/render.js +32 -9
- package/src/list/request.js +182 -0
- package/src/list/search.js +118 -35
- package/src/list/select.js +151 -30
- package/src/list/status.js +10 -3
- package/src/list/update.js +49 -8
- package/src/list/virtual.js +195 -127
- package/src/map/build.js +103 -0
- package/src/map/countries.js +114 -0
- package/src/map/display.js +135 -0
- package/src/map/focus.js +39 -0
- package/src/map/init.js +24 -0
- package/src/map/label.js +0 -0
- package/src/map/mode.js +44 -0
- package/src/map/mouse.js +65 -0
- package/src/map/select.js +68 -0
- package/src/map/set.js +71 -0
- package/src/map/viewport.js +46 -0
- package/src/map.js +71 -0
- package/src/module/attach.js +15 -16
- package/src/module/extract.js +35 -28
- package/src/module/mediator.js +56 -0
- package/src/module/object.js +17 -1
- package/src/module/observer.js +1 -1
- package/src/module/passive.js +17 -0
- package/src/module/remove.js +74 -0
- package/src/module/scrollbar.js +48 -0
- package/src/module/smoothscroll.js +20 -0
- package/src/module/viewport.js +20 -0
- package/src/selector.js +239 -0
- package/src/skin/material/base/body.sass +3 -0
- package/src/skin/material/button/file.sass +1 -1
- package/src/skin/material/container/container.sass +1 -1
- package/src/skin/material/container/dialog.sass +57 -1
- package/src/skin/material/container/drawer.sass +3 -3
- package/src/skin/material/control/button.sass +125 -0
- package/src/skin/material/control/dialog.sass +0 -0
- package/src/skin/material/control/progress.sass +136 -0
- package/src/skin/material/control/search.sass +40 -0
- package/src/skin/material/control/selecter.sass +131 -0
- package/src/skin/material/control/selector.sass +38 -0
- package/src/skin/material/control/slider.sass +2 -2
- package/src/skin/material/control/switch.sass +146 -3
- package/src/skin/material/control/switcher.sass +41 -0
- package/src/skin/material/control/textfield.sass +2 -1
- package/src/skin/material/icon/cancel.svg +1 -0
- package/src/skin/material/material.sass +3 -0
- package/src/skin/material/view/list.sass +81 -188
- package/src/skin/material/view/listview.sass +187 -96
- package/src/skin/material/view/tabview.sass +7 -5
- package/src/skin/material.bak/base/body.sass +52 -0
- package/src/skin/material.bak/base/elevation.sass +50 -0
- package/src/skin/material.bak/base/grid.sass +63 -0
- package/src/skin/material.bak/base/typo.sass +107 -0
- package/src/skin/material.bak/button/action.sass +89 -0
- package/src/skin/material.bak/button/button.sass +183 -0
- package/src/skin/material.bak/button/file.sass +24 -0
- package/src/skin/material.bak/button/floating.sass +113 -0
- package/src/skin/material.bak/button/raised.sass +101 -0
- package/src/skin/material.bak/button/stroked.sass +71 -0
- package/src/skin/material.bak/component/component.sass +7 -0
- package/src/skin/material.bak/component/divider.sass +17 -0
- package/src/skin/material.bak/component/image.sass +6 -0
- package/src/skin/material.bak/component/label.sass +2 -0
- package/src/skin/material.bak/component/progress.sass +138 -0
- package/src/skin/material.bak/component/subheader.sass +3 -0
- package/src/skin/material.bak/component/text.sass +85 -0
- package/src/skin/material.bak/container/appbar.sass +167 -0
- package/src/skin/material.bak/container/banner.sass +38 -0
- package/src/skin/material.bak/container/card.sass +18 -0
- package/src/skin/material.bak/container/container.sass +1 -0
- package/src/skin/material.bak/container/dialog.sass +184 -0
- package/src/skin/material.bak/container/drawer.sass +159 -0
- package/src/skin/material.bak/container/drawernew.sass +159 -0
- package/src/skin/material.bak/container/menu.sass +58 -0
- package/src/skin/material.bak/container/snackbar.sass +18 -0
- package/src/skin/material.bak/container/tabs.sass +75 -0
- package/src/skin/material.bak/container/toolbar.sass +161 -0
- package/src/skin/material.bak/control/button.sass +125 -0
- package/src/skin/material.bak/control/checkbox.sass +105 -0
- package/src/skin/material.bak/control/dialog.sass +0 -0
- package/src/skin/material.bak/control/search.sass +40 -0
- package/src/skin/material.bak/control/selecter.sass +128 -0
- package/src/skin/material.bak/control/slider.sass +181 -0
- package/src/skin/material.bak/control/switch.sass +284 -0
- package/src/skin/material.bak/control/switcher.sass +35 -0
- package/src/skin/material.bak/control/textfield.sass +126 -0
- package/src/skin/material.bak/control/tooltip.sass +36 -0
- package/src/skin/material.bak/icon/back.svg +5 -0
- package/src/skin/material.bak/icon/cancel.svg +1 -0
- package/src/skin/material.bak/icon/checkbox.svg +4 -0
- package/src/skin/material.bak/icon/forward.svg +5 -0
- package/src/skin/material.bak/icon/menu.svg +4 -0
- package/src/skin/material.bak/icon/pin.svg +4 -0
- package/src/skin/material.bak/layout/layout.sass +69 -0
- package/src/skin/material.bak/layout/resizer.sass +69 -0
- package/src/skin/material.bak/material.css +2042 -0
- package/src/skin/material.bak/material.css.map +7 -0
- package/src/skin/material.bak/material.sass +65 -0
- package/src/skin/material.bak/module/ripple.sass +9 -0
- package/src/skin/material.bak/theme/default.sass +50 -0
- package/src/skin/material.bak/theme/ocean.sass +29 -0
- package/src/skin/material.bak/theme/theme.sass +3 -0
- package/src/skin/material.bak/view/calendar.sass +193 -0
- package/src/skin/material.bak/view/form.sass +15 -0
- package/src/skin/material.bak/view/grid.sass +116 -0
- package/src/skin/material.bak/view/list.sass +89 -0
- package/src/skin/material.bak/view/listview.sass +195 -0
- package/src/skin/material.bak/view/map.sass +6 -0
- package/src/skin/material.bak/view/page.sass +4 -0
- package/src/skin/material.bak/view/tabview-bak.sass +40 -0
- package/src/skin/material.bak/view/tabview.sass +55 -0
- package/src/skin/material.bak/view/tree.sass +73 -0
- package/src/skin/material.bak/view/view.sass +7 -0
- package/src/switch.js +1 -1
- package/src/tabs/setup.js +0 -0
- package/src/tabview.js +64 -14
- package/src/tooltip.js +23 -5
- package/src/view/build.js +15 -3
- package/src/view/display.js +79 -7
- package/src/form/clean.js +0 -6
- package/src/form/mode.js +0 -16
- package/src/form/setup.js +0 -30
- package/src/list/fetch.js +0 -66
package/src/list/update.js
CHANGED
|
@@ -2,19 +2,60 @@ import Layout from '../layout'
|
|
|
2
2
|
|
|
3
3
|
export default {
|
|
4
4
|
update (info) {
|
|
5
|
-
console.log('update', info)
|
|
6
|
-
// console.log('selected', this.info, this.item)
|
|
5
|
+
// console.log('update', info)
|
|
7
6
|
|
|
8
|
-
this.info
|
|
7
|
+
this.getUpdatedInfo(info[this.dataId])
|
|
8
|
+
},
|
|
9
|
+
|
|
10
|
+
getUpdatedIndex (id) {
|
|
11
|
+
// console.log('getUpdatedIndex', id)
|
|
12
|
+
var index = null
|
|
13
|
+
for (var i = 0; i < this.data.length; i++) {
|
|
14
|
+
// console.log('--', this.data[i][this.dataId], id)
|
|
15
|
+
if (this.data[i][this.dataId] === id) {
|
|
16
|
+
index = i
|
|
17
|
+
break
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return index
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
getUpdatedInfo (id) {
|
|
25
|
+
// console.log('getUpdatedInfo', id)
|
|
26
|
+
var index = this.getUpdatedIndex(id)
|
|
27
|
+
// console.log('index', index)
|
|
28
|
+
var route = this.buildRoute(index + 1, 1)
|
|
29
|
+
// console.log('roote', route)
|
|
30
|
+
fetch(route).then((resp) => {
|
|
31
|
+
return resp.json()
|
|
32
|
+
}).then((data) => {
|
|
33
|
+
// console.log('info', data)
|
|
34
|
+
this.updateUpdatedInfo(data[0], index, id)
|
|
35
|
+
})
|
|
36
|
+
},
|
|
9
37
|
|
|
10
|
-
|
|
38
|
+
updateUpdatedInfo (info, index, id) {
|
|
39
|
+
// console.log('updateUpdatedInfo', info, index)
|
|
40
|
+
|
|
41
|
+
if (!info) return
|
|
42
|
+
if (info[this.dataId] !== id) return
|
|
43
|
+
|
|
44
|
+
this.info = info
|
|
11
45
|
|
|
12
|
-
|
|
46
|
+
// update datalist
|
|
47
|
+
this.data[index] = info
|
|
13
48
|
|
|
14
|
-
|
|
49
|
+
// update datastore
|
|
50
|
+
this.dataStore[info[this.dataId]] = info
|
|
15
51
|
|
|
16
|
-
|
|
52
|
+
// update item if on the screen
|
|
53
|
+
var item = this.ui.body.querySelector('[data-id="' + info[this.dataId] + '"]')
|
|
54
|
+
if (item) {
|
|
55
|
+
item.innerHTML = ''
|
|
56
|
+
var layout = new Layout(this.options.layout.item, item)
|
|
17
57
|
|
|
18
|
-
|
|
58
|
+
this.renderInfo(layout, info)
|
|
59
|
+
}
|
|
19
60
|
}
|
|
20
61
|
}
|
package/src/list/virtual.js
CHANGED
|
@@ -1,167 +1,235 @@
|
|
|
1
|
+
import passiveEvents from '../module/passive'
|
|
1
2
|
import emitter from '../module/emitter'
|
|
2
|
-
import observer from '../module/observer'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
class: 'virtual',
|
|
6
|
-
width: '100%',
|
|
7
|
-
height: '100%'
|
|
4
|
+
// based on https://sergimansilla.com/blog/virtual-scrolling/
|
|
8
5
|
|
|
6
|
+
function VirtualList (options) {
|
|
7
|
+
this.options = Object.assign({}, options || {})
|
|
8
|
+
Object.assign(this, emitter)
|
|
9
|
+
|
|
10
|
+
this.itemHeight = options.itemHeight
|
|
11
|
+
|
|
12
|
+
// console.log('itemHeight', this.itemHeight)
|
|
13
|
+
this.next = false
|
|
14
|
+
this.size = options.size
|
|
15
|
+
this.chunkSize = options.size
|
|
16
|
+
|
|
17
|
+
this.items = options.items
|
|
18
|
+
this.render = options.render
|
|
19
|
+
|
|
20
|
+
this.scroller = VirtualList.createScroller()
|
|
21
|
+
this.container = options.container
|
|
22
|
+
|
|
23
|
+
// get offset height
|
|
24
|
+
this.setOffset()
|
|
25
|
+
|
|
26
|
+
// console.log('itemBySreen', this.itemsByScreen)
|
|
27
|
+
|
|
28
|
+
window.addEventListener('resize', () => {
|
|
29
|
+
clearTimeout(this.resizeTimeout)
|
|
30
|
+
|
|
31
|
+
this.resizeTimeout = setTimeout(() => {
|
|
32
|
+
this.setOffset()
|
|
33
|
+
}, 50)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
this.container.classList.add('virtual')
|
|
9
37
|
}
|
|
10
38
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* Constructor
|
|
14
|
-
* @param {Object} options - Component options
|
|
15
|
-
* @return {Object} Class instance
|
|
16
|
-
*/
|
|
17
|
-
constructor (options) {
|
|
18
|
-
this.options = Object.assign({}, defaults, options || {})
|
|
19
|
-
Object.assign(this, emitter)
|
|
20
|
-
|
|
21
|
-
this.items = this.options.items
|
|
22
|
-
this.itemHeight = this.options.itemHeight
|
|
23
|
-
this.render = this.options.render
|
|
24
|
-
|
|
25
|
-
this.build()
|
|
26
|
-
this.setup()
|
|
27
|
-
this.attach()
|
|
28
|
-
|
|
29
|
-
return this
|
|
30
|
-
}
|
|
39
|
+
VirtualList.prototype._renderChunk = function (node, from, number) {
|
|
40
|
+
// console.log('_renderChunk', from, number, this.options.class)
|
|
31
41
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
this.root.classList.add(this.options.class)
|
|
42
|
+
var fragment = document.createDocumentFragment()
|
|
43
|
+
fragment.appendChild(this.scroller)
|
|
35
44
|
|
|
36
|
-
|
|
45
|
+
var last = from + number
|
|
46
|
+
if (last > this.count) last = this.count
|
|
37
47
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
}
|
|
48
|
+
for (var i = from; i < last; i++) {
|
|
49
|
+
var item = this.render(i)
|
|
42
50
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
this.scroller.classList.add('scroller')
|
|
47
|
-
this.root.appendChild(this.scroller)
|
|
51
|
+
item.style.position = 'absolute'
|
|
52
|
+
item.style.top = i * this.itemHeight + 'px'
|
|
53
|
+
fragment.appendChild(item)
|
|
48
54
|
}
|
|
49
55
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
this.itemPerView = Math.ceil(this.root.offsetHeight / this.itemHeight)
|
|
53
|
-
// console.log('itemPerView', this.itemPerView)
|
|
54
|
-
this.maxBuffer = this.itemPerView * this.itemHeight
|
|
55
|
-
// console.log('maxBuffer', this.maxBuffer)
|
|
56
|
+
node.innerHTML = ''
|
|
57
|
+
node.appendChild(fragment)
|
|
56
58
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
+
// console.log('last', last, 'count', this.count, 'size', this.size, 'chunk')
|
|
60
|
+
// console.log('---------------------------------')
|
|
61
|
+
// console.log('last && last > (this.count - this.size / 2)')
|
|
62
|
+
// console.log(last + '>' + '(' + this.count + '-' + this.size + '/' + '2)' + (this.count - this.size / 2))
|
|
59
63
|
|
|
60
|
-
|
|
64
|
+
if (this.next && last && last > (this.count - this.size / 2)) {
|
|
65
|
+
// console.log('emit next', last, this.count, this.size)
|
|
66
|
+
this.emit('next', this.count)
|
|
61
67
|
}
|
|
62
68
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
// the nodes that are not used anymore
|
|
68
|
-
this.rmNodeInterval = setInterval(() => {
|
|
69
|
-
if (Date.now() - this.lastScrolled > 100) {
|
|
70
|
-
var badNodes = this.root.querySelectorAll('[data-rm="1"]')
|
|
71
|
-
for (var i = 0, l = badNodes.length; i < l; i++) {
|
|
72
|
-
this.root.removeChild(badNodes[i])
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}, 300)
|
|
76
|
-
|
|
77
|
-
function onScroll (e) {
|
|
78
|
-
// console.log('this.lastRepaintY', self.lastRepaintY)
|
|
79
|
-
var scrollTop = e.target.scrollTop // Triggers reflow
|
|
80
|
-
if (!this.lastRepaintY || Math.abs(scrollTop - self.lastRepaintY) > self.maxBuffer) {
|
|
81
|
-
var first = parseInt(scrollTop / self.itemHeight) - self.itemPerView
|
|
82
|
-
self._renderChunk(first < 0 ? 0 : first)
|
|
83
|
-
self.lastRepaintY = scrollTop
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
this.lastScrolled = Date.now()
|
|
87
|
-
e.preventDefault && e.preventDefault()
|
|
88
|
-
}
|
|
69
|
+
this.next = true
|
|
70
|
+
|
|
71
|
+
// console.log('last', final, this.count)
|
|
72
|
+
}
|
|
89
73
|
|
|
90
|
-
|
|
74
|
+
VirtualList.prototype.set = function (items) {
|
|
75
|
+
// console.log('set', items.length)
|
|
76
|
+
this.next = false
|
|
77
|
+
this.items = items
|
|
78
|
+
this.count = items.length
|
|
91
79
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
80
|
+
// console.log('count', this.count)
|
|
81
|
+
|
|
82
|
+
if (this.count < 1 || this.count === undefined) return
|
|
83
|
+
|
|
84
|
+
this.container.innerHTML = ''
|
|
85
|
+
this.container.scrollTop = 0
|
|
86
|
+
|
|
87
|
+
var height = this.itemHeight * this.count
|
|
88
|
+
|
|
89
|
+
this.scroller.style.height = height + 'px'
|
|
90
|
+
|
|
91
|
+
this.itemsByScreen = Math.ceil(this.offsetHeight / this.itemHeight)
|
|
92
|
+
|
|
93
|
+
// console.log('offsetHeioght', this.container.offsetHeight)
|
|
94
|
+
// console.log('this.itemsByScreen', this.itemsByScreen)
|
|
95
|
+
|
|
96
|
+
// Cache 4 times the number of items that fit in the container viewport
|
|
97
|
+
var size = this.itemsByScreen * 4
|
|
98
|
+
this._renderChunk(this.container, 0, size)
|
|
99
|
+
|
|
100
|
+
this.size = size
|
|
101
|
+
|
|
102
|
+
// console.log('emit size', size)
|
|
103
|
+
this.emit('size', size)
|
|
104
|
+
|
|
105
|
+
var self = this
|
|
106
|
+
var lastRepaintY
|
|
107
|
+
var maxBuffer = this.itemsByScreen * this.itemHeight
|
|
108
|
+
|
|
109
|
+
function onScroll (e) {
|
|
110
|
+
// console.log('scroll', e.target.scrollTop, height)
|
|
111
|
+
var scrollTop = e.target.scrollTop
|
|
112
|
+
|
|
113
|
+
// console.log('itemsByScreen', self.itemsByScreen)
|
|
114
|
+
|
|
115
|
+
// console.log('offsetHeight', self.container.offsetHeight)
|
|
116
|
+
// console.log('size', self.size)
|
|
117
|
+
// if (this.itemsByScreen === 0) {
|
|
118
|
+
// size = self.size = this.itemsByScreen * 4
|
|
98
119
|
// }
|
|
120
|
+
|
|
121
|
+
// console.log('scrollTop', scrollTop)
|
|
122
|
+
|
|
123
|
+
if (scrollTop < 0) return
|
|
124
|
+
|
|
125
|
+
// console.log('itemsByScreen', self.itemsByScreen)
|
|
126
|
+
|
|
127
|
+
var first = parseInt(scrollTop / self.itemHeight) - self.itemsByScreen
|
|
128
|
+
first = first < 0 ? 0 : first
|
|
129
|
+
|
|
130
|
+
size = self.itemsByScreen * 4
|
|
131
|
+
|
|
132
|
+
if (!lastRepaintY || Math.abs(scrollTop - lastRepaintY) > maxBuffer) {
|
|
133
|
+
self._renderChunk(self.container, first, size)
|
|
134
|
+
lastRepaintY = scrollTop
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
var progress = Math.ceil((scrollTop / self.itemHeight) + self.itemsByScreen) - 1
|
|
138
|
+
// console.log('progress', progress)
|
|
139
|
+
self.emit('progress', progress)
|
|
140
|
+
|
|
141
|
+
// e.preventDefault && e.preventDefault()
|
|
99
142
|
}
|
|
100
143
|
|
|
101
|
-
|
|
102
|
-
this.itemPerView = Math.ceil(this.root.offsetHeight / this.itemHeight)
|
|
103
|
-
this.maxBuffer = this.itemPerView * this.itemHeight
|
|
144
|
+
// console.log('this.scrollEvents', this.scrollEvents)
|
|
104
145
|
|
|
105
|
-
|
|
146
|
+
if (!this.scrollEvents) {
|
|
147
|
+
this.container.addEventListener('scroll', onScroll, passiveEvents() ? { passive: true } : false)
|
|
148
|
+
this.scrollEvents = true
|
|
106
149
|
}
|
|
107
150
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (!items || Array.isArray(items) === false) {
|
|
111
|
-
return
|
|
112
|
-
}
|
|
151
|
+
// this.container.addEventListener('scroll', onScroll)
|
|
152
|
+
}
|
|
113
153
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
154
|
+
VirtualList.prototype.update = function (items) {
|
|
155
|
+
// console.log('update', items)
|
|
156
|
+
this.items = items || this.items
|
|
117
157
|
|
|
118
|
-
|
|
158
|
+
if (!this.items) return
|
|
119
159
|
|
|
120
|
-
|
|
121
|
-
this.itemsCount = items.length
|
|
160
|
+
this.count = this.items.length
|
|
122
161
|
|
|
123
|
-
|
|
162
|
+
// var itemsByScreen = Math.ceil(this.container.offsetHeight / this.itemHeight)
|
|
163
|
+
var cachedItemsLen = this.itemsByScreen * 4
|
|
164
|
+
var scrollTop = this.container.scrollTop
|
|
124
165
|
|
|
125
|
-
|
|
126
|
-
this.itemBuffer = this.itemPerView * 3
|
|
166
|
+
var height = this.itemHeight * this.count
|
|
127
167
|
|
|
128
|
-
|
|
129
|
-
}
|
|
168
|
+
this.scroller.style.height = height + 'px'
|
|
130
169
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
var item = this.render(i)
|
|
170
|
+
var first = parseInt(scrollTop / this.itemHeight) - this.itemsByScreen
|
|
171
|
+
first = first < 0 ? 0 : first
|
|
134
172
|
|
|
135
|
-
|
|
136
|
-
item.style.position = 'absolute'
|
|
137
|
-
item.style.top = (i * this.itemHeight) + 'px'
|
|
138
|
-
return item
|
|
139
|
-
}
|
|
173
|
+
// console.log('first', first, cachedItemsLen)
|
|
140
174
|
|
|
141
|
-
_renderChunk
|
|
142
|
-
|
|
143
|
-
var finalItem = from + this.itemBuffer
|
|
144
|
-
if (finalItem > this.itemsCount) { finalItem = this.itemsCount }
|
|
175
|
+
this._renderChunk(this.container, first, cachedItemsLen)
|
|
176
|
+
}
|
|
145
177
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
178
|
+
VirtualList.prototype.add = function (items) {
|
|
179
|
+
// console.log('add', items.length)
|
|
180
|
+
this.items = items || this.items
|
|
149
181
|
|
|
150
|
-
|
|
182
|
+
if (!this.items) return
|
|
151
183
|
|
|
152
|
-
|
|
153
|
-
fragment.appendChild(this.createRow(i))
|
|
154
|
-
}
|
|
184
|
+
this.count = this.items.length
|
|
155
185
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
186
|
+
var height = this.itemHeight * this.count
|
|
187
|
+
|
|
188
|
+
this.scroller.style.height = height + 'px'
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
VirtualList.prototype.reset = function () {
|
|
192
|
+
// console.log('reset')
|
|
193
|
+
this.items = []
|
|
194
|
+
this.count = 0
|
|
195
|
+
|
|
196
|
+
this.container.scrollTop = 0
|
|
197
|
+
|
|
198
|
+
this.scroller.style.height = 0
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
VirtualList.prototype.setOffset = function (info) {
|
|
202
|
+
// console.log('setOffset', info)
|
|
161
203
|
|
|
162
|
-
|
|
163
|
-
|
|
204
|
+
this.offsetHeight = this.container.offsetHeight
|
|
205
|
+
if (this.offsetHeight < 1) {
|
|
206
|
+
this.offsetHeight = window.innerHeight ||
|
|
207
|
+
document.documentElement.clientHeight ||
|
|
208
|
+
document.body.clientHeight
|
|
164
209
|
}
|
|
210
|
+
|
|
211
|
+
this.itemsByScreen = Math.ceil(this.offsetHeight / this.itemHeight)
|
|
212
|
+
|
|
213
|
+
// console.log('new itemsByScreen', this.itemsByScreen)
|
|
214
|
+
|
|
215
|
+
var itemsByScreen = Math.ceil(this.offsetHeight / this.itemHeight)
|
|
216
|
+
|
|
217
|
+
// Cache 4 times the number of items that fit in the container viewport
|
|
218
|
+
var size = itemsByScreen * 4
|
|
219
|
+
|
|
220
|
+
return size
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
VirtualList.prototype.getCount = function () {
|
|
224
|
+
// console.log('getCount')
|
|
225
|
+
|
|
226
|
+
return this.count
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
VirtualList.createScroller = function () {
|
|
230
|
+
var scroller = document.createElement('div')
|
|
231
|
+
scroller.classList.add('scroller')
|
|
232
|
+
return scroller
|
|
165
233
|
}
|
|
166
234
|
|
|
167
|
-
export default
|
|
235
|
+
export default VirtualList
|
package/src/map/build.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import observer from '../module/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.root = document.createElement(this.options.tag)
|
|
17
|
+
this.root.classList.add(this.options.class)
|
|
18
|
+
|
|
19
|
+
if (this.options.container) {
|
|
20
|
+
this.options.container.appendChild(this.root)
|
|
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.root, () => {
|
|
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.root.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.root.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
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
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
|
+
var list = document.querySelectorAll('svg.mapsvg g')
|
|
11
|
+
// console.log('svg', list)
|
|
12
|
+
|
|
13
|
+
for (var 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
|
+
let 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
|
+
var list = document.querySelectorAll('svg.mapsvg g')
|
|
46
|
+
// console.log('svg', list)
|
|
47
|
+
|
|
48
|
+
for (var 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 (var 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
|
+
var 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
|
+
var group = document.querySelector('svg.mapsvg g.playing')
|
|
112
|
+
group.classList.remove('playing')
|
|
113
|
+
}
|
|
114
|
+
}
|