material 0.4.3 → 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 +127 -44
- package/src/control/button.new.js +190 -0
- package/src/control/dialog.js +174 -0
- package/src/control/{upload.js → file.js} +33 -8
- 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 +3 -1
- package/src/control/search.js +98 -0
- package/src/control/select.js +80 -22
- 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 +18 -3
- package/src/control/textfield.js +89 -15
- package/src/field/image.js +9 -3
- package/src/form/build.js +28 -4
- package/src/form/cancel.js +7 -3
- package/src/form/controller.js +90 -0
- package/src/form/create.js +11 -7
- package/src/form/data.js +82 -0
- package/src/form/delete.js +2 -1
- package/src/form/fetch.js +5 -3
- package/src/form/render.js +11 -9
- package/src/form/set.js +27 -12
- package/src/form/submit.js +11 -37
- package/src/form/update.js +35 -16
- package/src/layout.js +25 -21
- package/src/list/add.js +34 -0
- package/src/list/build.js +96 -12
- 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 +9 -2
- 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 +6 -4
- 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 +13 -1
- package/src/view/display.js +63 -2
- package/src/form/clean.js +0 -6
- package/src/form/controls.js +0 -56
- package/src/form/mode.js +0 -8
- package/src/form/setup.js +0 -5
- package/src/list/fetch.js +0 -66
|
@@ -3,11 +3,11 @@ import dataset from '../view/dataset'
|
|
|
3
3
|
import attributes from './module/attributes'
|
|
4
4
|
|
|
5
5
|
const defaults = {
|
|
6
|
-
class: '
|
|
7
|
-
attributes: ['name', 'accept', 'required', 'disabled']
|
|
6
|
+
class: 'file',
|
|
7
|
+
attributes: ['name', 'accept', 'required', 'disabled', 'multiple']
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
class
|
|
10
|
+
class File {
|
|
11
11
|
/**
|
|
12
12
|
* Constructor
|
|
13
13
|
* @param {Object} options - Component options
|
|
@@ -29,9 +29,9 @@ class Upload {
|
|
|
29
29
|
*/
|
|
30
30
|
build () {
|
|
31
31
|
this.root = document.createElement('div')
|
|
32
|
-
this.root.classList.add('
|
|
32
|
+
this.root.classList.add('file')
|
|
33
33
|
|
|
34
|
-
if (this.options.class !== '
|
|
34
|
+
if (this.options.class !== 'file') {
|
|
35
35
|
this.root.classList.add(this.options.class)
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -55,7 +55,8 @@ class Upload {
|
|
|
55
55
|
|
|
56
56
|
buildLabel () {
|
|
57
57
|
if (this.options.label) {
|
|
58
|
-
this.label = document.createElement('
|
|
58
|
+
this.label = document.createElement('label')
|
|
59
|
+
this.label.classList.add('label')
|
|
59
60
|
this.label.innerHTML = this.options.label
|
|
60
61
|
this.root.appendChild(this.label)
|
|
61
62
|
}
|
|
@@ -85,14 +86,38 @@ class Upload {
|
|
|
85
86
|
})
|
|
86
87
|
}
|
|
87
88
|
|
|
89
|
+
image (e) {
|
|
90
|
+
// console.log('image', e.target)
|
|
91
|
+
// if (input.files && input.files[0]) {
|
|
92
|
+
// var reader = new FileReader()
|
|
93
|
+
|
|
94
|
+
// reader.onload = (e) => {
|
|
95
|
+
// cover.style.backgroundImage = 'url("' + e.target.result + '")'
|
|
96
|
+
// }
|
|
97
|
+
|
|
98
|
+
// reader.readAsDataURL(input.files[0])
|
|
99
|
+
// }
|
|
100
|
+
}
|
|
101
|
+
|
|
88
102
|
reset () {
|
|
89
103
|
// console.log('reset')
|
|
90
104
|
this.input.value = ''
|
|
91
105
|
}
|
|
92
106
|
|
|
93
107
|
set (image) {
|
|
94
|
-
console.log('set', image)
|
|
108
|
+
// console.log('set', image)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
setLabel (value) {
|
|
112
|
+
// console.log('setLabel', value)
|
|
113
|
+
if (this.label) {
|
|
114
|
+
this.label.innerHTML = value
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
setText (value) {
|
|
119
|
+
this.setLabel(value)
|
|
95
120
|
}
|
|
96
121
|
}
|
|
97
122
|
|
|
98
|
-
export default
|
|
123
|
+
export default File
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const defaults = {
|
|
4
|
+
class: 'link',
|
|
5
|
+
tag: 'a'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
class Link {
|
|
9
|
+
/**
|
|
10
|
+
* Constructor
|
|
11
|
+
* @param {Object} options - Component options
|
|
12
|
+
* @return {Object} Class instance
|
|
13
|
+
*/
|
|
14
|
+
constructor (options) {
|
|
15
|
+
this.options = Object.assign({}, defaults, options || {})
|
|
16
|
+
|
|
17
|
+
this.build()
|
|
18
|
+
|
|
19
|
+
return this
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Build Method
|
|
24
|
+
* @return {Object} This class instance
|
|
25
|
+
*/
|
|
26
|
+
build () {
|
|
27
|
+
this.root = document.createElement(this.options.tag)
|
|
28
|
+
this.root.classList.add(this.options.class)
|
|
29
|
+
|
|
30
|
+
if (this.options.class !== 'link') {
|
|
31
|
+
this.root.classList.add('link')
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (this.options.link) {
|
|
35
|
+
this.set(this.options.link)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (this.options.target) {
|
|
39
|
+
this.root.target = this.options.target
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (this.options.container) {
|
|
43
|
+
this.options.container.appendChild(this.root)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (this.options.text) {
|
|
47
|
+
this.root.innerHTML = this.options.text
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return this
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
set (link) {
|
|
54
|
+
// console.log('set', text)
|
|
55
|
+
if (link === undefined) return
|
|
56
|
+
|
|
57
|
+
this.root.href = link
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export default Link
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import addClass from './module/addclass'
|
|
2
|
+
|
|
3
|
+
const defaults = {
|
|
4
|
+
class: 'text',
|
|
5
|
+
tag: 'span',
|
|
6
|
+
seprator: ' | '
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
class List {
|
|
10
|
+
/**
|
|
11
|
+
* Constructor
|
|
12
|
+
* @param {Object} options - Component options
|
|
13
|
+
* @return {Object} Class instance
|
|
14
|
+
*/
|
|
15
|
+
constructor (options) {
|
|
16
|
+
this.options = Object.assign({}, defaults, options || {})
|
|
17
|
+
|
|
18
|
+
// console.log('options', this.options)
|
|
19
|
+
|
|
20
|
+
this.build()
|
|
21
|
+
|
|
22
|
+
return this
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Build Method
|
|
27
|
+
* @return {Object} This class instance
|
|
28
|
+
*/
|
|
29
|
+
build () {
|
|
30
|
+
this.root = document.createElement(this.options.tag)
|
|
31
|
+
addClass(this.root, this.options.class)
|
|
32
|
+
|
|
33
|
+
if (this.options.class !== 'text') {
|
|
34
|
+
this.root.classList.add('text')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (this.options.list) {
|
|
38
|
+
this.set(this.options.list)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (this.options.container) {
|
|
42
|
+
this.options.container.appendChild(this.root)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return this
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
set (list) {
|
|
49
|
+
var text = ''
|
|
50
|
+
|
|
51
|
+
for (var i = 0; i < list.length; i++) {
|
|
52
|
+
if (i < list.length - 1) {
|
|
53
|
+
text = text + list[i] + this.options.seprator
|
|
54
|
+
} else {
|
|
55
|
+
text = text + list[i]
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// console.log('set', text)
|
|
60
|
+
if (text === undefined) return
|
|
61
|
+
|
|
62
|
+
var label = this.options.label || ''
|
|
63
|
+
|
|
64
|
+
this.root.innerHTML = label + text
|
|
65
|
+
|
|
66
|
+
if (this.options.spaceAfter) {
|
|
67
|
+
this.root.innerHTML = this.root.innerHTML + ' '
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
setText (text) {
|
|
72
|
+
// console.log('setText', text)
|
|
73
|
+
this.root.innerHTML = text
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export default List
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import emitter from '../module/emitter'
|
|
2
|
+
import attach from '../module/attach'
|
|
3
|
+
|
|
4
|
+
import dataset from '../view/dataset'
|
|
5
|
+
|
|
6
|
+
var defaults = {
|
|
7
|
+
class: 'loading',
|
|
8
|
+
tag: 'div',
|
|
9
|
+
delay: 1000,
|
|
10
|
+
type: 'indeterminate',
|
|
11
|
+
circular: `<svg class="progress" width="65px" height="65px" viewBox="0 0 66 66" xmlns="http://www.w3.org/2000/svg">
|
|
12
|
+
<circle class="path" fill="none" stroke-width="6" stroke-linecap="round" cx="33" cy="33" r="30"></circle>
|
|
13
|
+
</svg>`
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The class represents an item ie for list
|
|
18
|
+
*
|
|
19
|
+
* @class
|
|
20
|
+
* @return {Object} The class instance
|
|
21
|
+
* @example new Item(object);
|
|
22
|
+
*/
|
|
23
|
+
class Loading {
|
|
24
|
+
static isComponent () {
|
|
25
|
+
return true
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* init
|
|
30
|
+
* @return {Object} The class options
|
|
31
|
+
*/
|
|
32
|
+
constructor (options) {
|
|
33
|
+
this.options = Object.assign({}, defaults, options || {})
|
|
34
|
+
Object.assign(this, emitter, attach)
|
|
35
|
+
// console.log('options', options)
|
|
36
|
+
|
|
37
|
+
this.init()
|
|
38
|
+
|
|
39
|
+
return this
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Setter
|
|
44
|
+
* @param {string} prop
|
|
45
|
+
* @param {string} value
|
|
46
|
+
* @return {Object} The class instance
|
|
47
|
+
*/
|
|
48
|
+
init () {
|
|
49
|
+
this.build()
|
|
50
|
+
// this.setup()
|
|
51
|
+
// this.attach()
|
|
52
|
+
|
|
53
|
+
if (this.options.container) {
|
|
54
|
+
this.append(this.options.container)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return this
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Build function for item
|
|
62
|
+
* @return {Object} This class instance
|
|
63
|
+
*/
|
|
64
|
+
build (options) {
|
|
65
|
+
this.root = document.createElement(this.options.tag)
|
|
66
|
+
this.classify()
|
|
67
|
+
|
|
68
|
+
if (this.options.type === 'circular') {
|
|
69
|
+
this.root.innerHTML = this.options.circular
|
|
70
|
+
} if (this.options.type === 'indeterminate') {
|
|
71
|
+
this.bar = document.createElement(this.options.tag)
|
|
72
|
+
this.bar.classList.add('bar')
|
|
73
|
+
this.root.classList.add('type-indeterminate')
|
|
74
|
+
this.root.appendChild(this.bar)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return this
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
classify () {
|
|
81
|
+
if (this.options.class !== 'loading') {
|
|
82
|
+
this.root.setAttribute('class', this.options.class + ' ' + this.options.class)
|
|
83
|
+
} else {
|
|
84
|
+
this.root.classList.add(this.options.class)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
append (container) {
|
|
89
|
+
container = container || this.options.container
|
|
90
|
+
if (this.options.container) {
|
|
91
|
+
container.appendChild(this.root)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
set (progress) {
|
|
96
|
+
this.bar.setAttribute('style', 'width: ' + progress)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
show (delay) {
|
|
100
|
+
delay = delay || this.options.delay
|
|
101
|
+
|
|
102
|
+
clearTimeout(this.showTimeout)
|
|
103
|
+
this.showTimeout = setTimeout(() => {
|
|
104
|
+
this.root.classList.add('show')
|
|
105
|
+
}, this.options.delay)
|
|
106
|
+
|
|
107
|
+
this.visible = true
|
|
108
|
+
|
|
109
|
+
return this
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
showNow () {
|
|
113
|
+
this.root.classList.add('show')
|
|
114
|
+
|
|
115
|
+
this.visible
|
|
116
|
+
|
|
117
|
+
return this
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
hide () {
|
|
121
|
+
clearTimeout(this.showTimeout)
|
|
122
|
+
this.root.classList.remove('show')
|
|
123
|
+
this.visible = false
|
|
124
|
+
return this
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export default Loading
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
function setClass (element, className) {
|
|
3
|
+
// console.log('attributes', o.attributes, element)
|
|
4
|
+
|
|
5
|
+
if (!element || !className) return
|
|
6
|
+
|
|
7
|
+
let classNames = className.split(' ')
|
|
8
|
+
|
|
9
|
+
for (var i = 0; i < classNames.length; i++) {
|
|
10
|
+
var name = classNames[i]
|
|
11
|
+
element.classList.add(name)
|
|
12
|
+
}
|
|
13
|
+
return element
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default setClass
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
const special = ['required', 'disabled']
|
|
1
|
+
const special = ['required', 'disabled', 'multiple', 'checked']
|
|
2
2
|
|
|
3
3
|
function setAttributes (element, o) {
|
|
4
4
|
// console.log('attributes', o.attributes, element)
|
|
5
5
|
|
|
6
|
+
if (!element) return
|
|
7
|
+
|
|
6
8
|
for (var i = 0; i < o.attributes.length; i++) {
|
|
7
9
|
var attribute = o.attributes[i]
|
|
8
10
|
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// search control
|
|
2
|
+
|
|
3
|
+
import emitter from '../module/emitter'
|
|
4
|
+
import Button from '../control/button'
|
|
5
|
+
import cancel from '../skin/material/icon/cancel.svg'
|
|
6
|
+
|
|
7
|
+
const defaults = {
|
|
8
|
+
class: 'search-input',
|
|
9
|
+
minChar: 4,
|
|
10
|
+
iconCancel: cancel,
|
|
11
|
+
timeout: 200
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Class representing a search input
|
|
16
|
+
*
|
|
17
|
+
* @return {parent} The class instance
|
|
18
|
+
* @example new Search({
|
|
19
|
+
* container: document.body
|
|
20
|
+
* });
|
|
21
|
+
*/
|
|
22
|
+
class Search {
|
|
23
|
+
/**
|
|
24
|
+
* Constructor
|
|
25
|
+
* @param {Object} options - Component options
|
|
26
|
+
* @return {Object} Class instance
|
|
27
|
+
*/
|
|
28
|
+
constructor (options) {
|
|
29
|
+
this.options = Object.assign({}, defaults, options || {})
|
|
30
|
+
Object.assign(this, emitter)
|
|
31
|
+
|
|
32
|
+
this.build()
|
|
33
|
+
this.attach()
|
|
34
|
+
|
|
35
|
+
return this
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Build Method
|
|
40
|
+
* @return {Object} This class instance
|
|
41
|
+
*/
|
|
42
|
+
build () {
|
|
43
|
+
this.root = document.createElement('div')
|
|
44
|
+
this.root.classList.add('search')
|
|
45
|
+
|
|
46
|
+
if (this.options.class !== 'search') {
|
|
47
|
+
this.root.classList.add(this.options.class)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (this.options.icon) {
|
|
51
|
+
this.icon = document.createElement('i')
|
|
52
|
+
this.icon.classList.add('icon')
|
|
53
|
+
this.icon.innerHTML = this.options.icon
|
|
54
|
+
this.root.appendChild(this.icon)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
this.input = document.createElement('input')
|
|
58
|
+
this.input.classList.add('input')
|
|
59
|
+
this.root.appendChild(this.input)
|
|
60
|
+
|
|
61
|
+
this.cancel = new Button({
|
|
62
|
+
container: this.root,
|
|
63
|
+
class: 'clear',
|
|
64
|
+
icon: this.options.iconCancel
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
if (this.options.container) {
|
|
68
|
+
this.options.container.appendChild(this.root)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return this
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
attach () {
|
|
75
|
+
this.input.addEventListener('input', () => {
|
|
76
|
+
if (this.input.value.length < this.options.minChar) return
|
|
77
|
+
|
|
78
|
+
clearTimeout(this.timeout)
|
|
79
|
+
|
|
80
|
+
this.timeout = setTimeout(() => {
|
|
81
|
+
this.emit('change', this.input.value)
|
|
82
|
+
}, this.options.timeout)
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
this.cancel.on('click', () => {
|
|
86
|
+
this.input.value = ''
|
|
87
|
+
this.input.focus()
|
|
88
|
+
this.emit('cancel')
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
set (email) {
|
|
93
|
+
this.root.innerHTML = email
|
|
94
|
+
this.root.setAttribute('href', 'mailto:' + email)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export default Search
|
package/src/control/select.js
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
+
import emitter from '..//module/emitter'
|
|
2
|
+
import attach from '../module/attach'
|
|
3
|
+
import attributes from './module/attributes'
|
|
4
|
+
import dataset from '../view/dataset'
|
|
1
5
|
|
|
2
6
|
const defaults = {
|
|
3
|
-
|
|
4
|
-
|
|
7
|
+
type: 'list', // native
|
|
8
|
+
class: 'select',
|
|
9
|
+
first: null,
|
|
10
|
+
attributes: ['type', 'name', 'autocomplete', 'required']
|
|
5
11
|
}
|
|
6
12
|
|
|
7
|
-
class
|
|
13
|
+
class Select {
|
|
8
14
|
/**
|
|
9
15
|
* Constructor
|
|
10
16
|
* @param {Object} options - Component options
|
|
@@ -12,10 +18,10 @@ class Text {
|
|
|
12
18
|
*/
|
|
13
19
|
constructor (options) {
|
|
14
20
|
this.options = Object.assign({}, defaults, options || {})
|
|
15
|
-
|
|
16
|
-
// console.log('options', options)
|
|
21
|
+
Object.assign(this, emitter, attach, dataset)
|
|
17
22
|
|
|
18
23
|
this.build()
|
|
24
|
+
this.attach()
|
|
19
25
|
|
|
20
26
|
return this
|
|
21
27
|
}
|
|
@@ -25,48 +31,100 @@ class Text {
|
|
|
25
31
|
* @return {Object} This class instance
|
|
26
32
|
*/
|
|
27
33
|
build () {
|
|
28
|
-
|
|
29
|
-
this.root.
|
|
34
|
+
var tag = this.options.tag || 'span'
|
|
35
|
+
this.root = document.createElement(tag)
|
|
36
|
+
this.root.classList.add('select')
|
|
37
|
+
|
|
38
|
+
if (this.options.class !== 'select') {
|
|
39
|
+
this.root.classList.add(this.options.class)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
this.buildLabel()
|
|
43
|
+
this.buildInput()
|
|
44
|
+
|
|
45
|
+
if (this.container) {
|
|
46
|
+
this.container.appendChild(this.root)
|
|
47
|
+
}
|
|
30
48
|
|
|
49
|
+
return this
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
buildLabel () {
|
|
31
53
|
if (this.options.label) {
|
|
32
54
|
this.label = document.createElement('span')
|
|
55
|
+
this.label.classList.add('label')
|
|
33
56
|
this.label.innerHTML = this.options.label
|
|
34
57
|
this.root.appendChild(this.label)
|
|
35
58
|
}
|
|
59
|
+
}
|
|
36
60
|
|
|
37
|
-
|
|
61
|
+
buildInput () {
|
|
62
|
+
this.input = document.createElement('select')
|
|
63
|
+
this.input.classList.add('input')
|
|
38
64
|
this.root.appendChild(this.input)
|
|
39
65
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
66
|
+
this.input.addEventListener('change', () => {
|
|
67
|
+
// console.log('change', this.input[this.input.selectedIndex].value)
|
|
68
|
+
this.emit('change', this.input[this.input.selectedIndex].value)
|
|
69
|
+
})
|
|
43
70
|
|
|
44
|
-
if (this.options.
|
|
45
|
-
this.
|
|
71
|
+
if (this.options.data) {
|
|
72
|
+
dataset(this.data, this.options.data)
|
|
46
73
|
}
|
|
47
74
|
|
|
48
|
-
|
|
49
|
-
|
|
75
|
+
attributes(this.input, this.options)
|
|
76
|
+
|
|
77
|
+
if (this.options.options) {
|
|
78
|
+
this.setOptions(this.options.options)
|
|
50
79
|
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
setOptions (options) {
|
|
83
|
+
// console.log('buildCountry', this.input)
|
|
51
84
|
|
|
52
|
-
|
|
53
|
-
|
|
85
|
+
var first = this.options.first
|
|
86
|
+
|
|
87
|
+
if (first && first[0] && first[1]) {
|
|
88
|
+
this.input.options[0] = new Option(first[1], first[0])
|
|
54
89
|
}
|
|
55
90
|
|
|
56
|
-
|
|
57
|
-
this.
|
|
91
|
+
for (var i = 0; i < options.length; i++) {
|
|
92
|
+
this.addOption(options[i][1], options[i][0])
|
|
58
93
|
}
|
|
94
|
+
}
|
|
59
95
|
|
|
60
|
-
|
|
96
|
+
addOption (name, value) {
|
|
97
|
+
// console.log('addOption', name, value)
|
|
98
|
+
this.input.options[this.input.options.length] = new Option(name, value)
|
|
61
99
|
}
|
|
62
100
|
|
|
63
101
|
set (value) {
|
|
102
|
+
// console.log('set', value)
|
|
64
103
|
this.input.value = value
|
|
104
|
+
|
|
105
|
+
return this
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
setLabel (value) {
|
|
109
|
+
console.log('setLabel', value)
|
|
110
|
+
if (this.label) {
|
|
111
|
+
this.label.innerHTML = value
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
setText (value) {
|
|
116
|
+
this.setLabel(value)
|
|
65
117
|
}
|
|
66
118
|
|
|
67
119
|
get () {
|
|
68
|
-
|
|
120
|
+
var value = null
|
|
121
|
+
|
|
122
|
+
if (this.input[this.input.selectedIndex]) {
|
|
123
|
+
value = this.input[this.input.selectedIndex].value
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return value
|
|
69
127
|
}
|
|
70
128
|
}
|
|
71
129
|
|
|
72
|
-
export default
|
|
130
|
+
export default Select
|