material 0.8.9 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +24 -9
- package/package.json +1 -1
- package/scripts/doccoAssistant.js +25 -0
- package/src/appbar.js +2 -4
- package/src/badge.js +6 -13
- package/src/button.js +10 -18
- package/src/calendar.js +23 -48
- package/src/card.js +2 -4
- package/src/checkbox.js +2 -7
- package/src/class/component.js +19 -0
- package/src/class/control.js +33 -0
- package/src/component.js +7 -41
- package/src/datehour.js +2 -4
- package/src/dialog.js +3 -5
- package/src/drawer.js +12 -12
- package/src/element.js +16 -20
- package/src/file.js +6 -4
- package/src/form/build.js +2 -2
- package/src/form.js +9 -22
- package/src/icon.js +6 -34
- package/src/image.js +1 -3
- package/src/item.js +3 -3
- package/src/link.js +1 -3
- package/src/list/build.js +2 -2
- package/src/list/render.js +2 -2
- package/src/list/select.js +4 -2
- package/src/list/update.js +2 -2
- package/src/list.js +12 -13
- package/src/loader.js +4 -7
- package/src/loading.js +2 -8
- package/src/map.js +27 -32
- package/src/menu.js +78 -19
- package/src/mixin/build.js +68 -0
- package/src/mixin/emitter.js +0 -2
- package/src/mixin/position.js +20 -9
- package/src/module/build.js +51 -46
- package/src/module/clone.js +15 -0
- package/src/module/dot.js +15 -9
- package/src/module/events.js +2 -0
- package/src/module/layout.js +76 -0
- package/src/module/merge.js +22 -0
- package/src/navigation.js +4 -3
- package/src/progress.js +9 -24
- package/src/search.js +3 -2
- package/src/select.js +2 -2
- package/src/selecter.js +5 -4
- package/src/selector.js +23 -41
- package/src/slider.js +33 -55
- package/src/snackbar.js +1 -1
- package/src/switch.js +1 -1
- package/src/switcher.js +1 -1
- package/src/tabs.js +12 -19
- package/src/tabview.js +1 -1
- package/src/text.js +2 -4
- package/src/textfield.js +1 -3
- package/src/toolbar.js +6 -20
- package/src/tooltip.js +14 -24
- package/src/tree.js +10 -14
- package/src/view.js +2 -2
- package/src/divider.js +0 -60
- package/src/layout.js +0 -106
package/src/form.js
CHANGED
|
@@ -5,31 +5,18 @@ import events from './module/events'
|
|
|
5
5
|
import controller from './mixin/controller'
|
|
6
6
|
|
|
7
7
|
// import component
|
|
8
|
-
import
|
|
8
|
+
import { create } from './module/layout'
|
|
9
9
|
|
|
10
|
-
const defaults = {
|
|
11
|
-
prefix: 'material',
|
|
12
|
-
class: 'form',
|
|
13
|
-
tag: 'div',
|
|
14
|
-
controls: ['textfield', 'checkbox', 'slider', 'switch']
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Form class
|
|
19
|
-
*
|
|
20
|
-
* @class
|
|
21
|
-
* @return {Class} This class instance
|
|
22
|
-
*/
|
|
23
10
|
class Form {
|
|
24
|
-
static
|
|
11
|
+
static defaults = {
|
|
12
|
+
prefix: 'material',
|
|
13
|
+
class: 'form',
|
|
14
|
+
tag: 'div',
|
|
15
|
+
controls: ['textfield', 'checkbox', 'slider', 'switch']
|
|
16
|
+
}
|
|
25
17
|
|
|
26
|
-
/**
|
|
27
|
-
* Constructor
|
|
28
|
-
* @param {Object} options - Component options
|
|
29
|
-
* @return {Object} Class instance
|
|
30
|
-
*/
|
|
31
18
|
constructor (options) {
|
|
32
|
-
this.options = Object.assign({}, defaults, options || {})
|
|
19
|
+
this.options = Object.assign({}, Form.defaults, options || {})
|
|
33
20
|
|
|
34
21
|
this.init()
|
|
35
22
|
this.build()
|
|
@@ -78,7 +65,7 @@ class Form {
|
|
|
78
65
|
// complete layout options
|
|
79
66
|
this.options.root = this.element
|
|
80
67
|
|
|
81
|
-
this.layout =
|
|
68
|
+
this.layout = create(this.options.layout, this.element)
|
|
82
69
|
|
|
83
70
|
this._initControls(this.layout.controls)
|
|
84
71
|
|
package/src/icon.js
CHANGED
|
@@ -1,27 +1,13 @@
|
|
|
1
1
|
import insert from './mixin/insert'
|
|
2
2
|
import * as css from './module/css'
|
|
3
3
|
|
|
4
|
-
var defaults = {
|
|
5
|
-
prefix: 'material',
|
|
6
|
-
class: 'icon',
|
|
7
|
-
tag: 'div'
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* The item class is used for example as item list
|
|
12
|
-
*
|
|
13
|
-
* @class
|
|
14
|
-
* @extends {Component}
|
|
15
|
-
* @return {Object} The class instance
|
|
16
|
-
* @example new Item(object);
|
|
17
|
-
*/
|
|
18
4
|
class Icon {
|
|
19
|
-
static
|
|
5
|
+
static defaults = {
|
|
6
|
+
prefix: 'material',
|
|
7
|
+
class: 'icon',
|
|
8
|
+
tag: 'div'
|
|
9
|
+
}
|
|
20
10
|
|
|
21
|
-
/**
|
|
22
|
-
* init
|
|
23
|
-
* @return {Object} The class options
|
|
24
|
-
*/
|
|
25
11
|
constructor (options) {
|
|
26
12
|
this.init(options)
|
|
27
13
|
this.build()
|
|
@@ -29,20 +15,11 @@ class Icon {
|
|
|
29
15
|
return this
|
|
30
16
|
}
|
|
31
17
|
|
|
32
|
-
/**
|
|
33
|
-
* [init description]
|
|
34
|
-
* @param {?} options [description]
|
|
35
|
-
* @return {?} [description]
|
|
36
|
-
*/
|
|
37
18
|
init (options) {
|
|
38
|
-
this.options = Object.assign({}, defaults, options || {})
|
|
19
|
+
this.options = Object.assign({}, Icon.defaults, options || {})
|
|
39
20
|
Object.assign(this, insert)
|
|
40
21
|
}
|
|
41
22
|
|
|
42
|
-
/**
|
|
43
|
-
* Build function for item
|
|
44
|
-
* @return {Object} This class instance
|
|
45
|
-
*/
|
|
46
23
|
build (options) {
|
|
47
24
|
options = options || this.options
|
|
48
25
|
|
|
@@ -66,11 +43,6 @@ class Icon {
|
|
|
66
43
|
}
|
|
67
44
|
}
|
|
68
45
|
|
|
69
|
-
/**
|
|
70
|
-
* Get or set text value of the element
|
|
71
|
-
* @param {string} value The text to set
|
|
72
|
-
* @returns {*}
|
|
73
|
-
*/
|
|
74
46
|
set (value) {
|
|
75
47
|
if (value) {
|
|
76
48
|
if (this.element.innerText) {
|
package/src/image.js
CHANGED
package/src/item.js
CHANGED
package/src/link.js
CHANGED
package/src/list/build.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import scrollbar from '../module/scrollbar'
|
|
2
2
|
import dataset from '../module/dataset'
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import { create } from '../module/layout'
|
|
5
5
|
import Virtual from './virtual'
|
|
6
6
|
import Loading from '../loading'
|
|
7
7
|
|
|
@@ -30,7 +30,7 @@ export default {
|
|
|
30
30
|
dataset(this.element, this.options.data)
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
this.layout =
|
|
33
|
+
this.layout = create(this.options.layout.main, this.element)
|
|
34
34
|
this.ui = this.layout.component
|
|
35
35
|
|
|
36
36
|
// prepare loading
|
package/src/list/render.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Element from '../element'
|
|
2
|
-
import
|
|
2
|
+
import { create } from '../module/layout'
|
|
3
3
|
|
|
4
4
|
import dot from '../module/dot'
|
|
5
5
|
|
|
@@ -59,7 +59,7 @@ export default {
|
|
|
59
59
|
}
|
|
60
60
|
} else {
|
|
61
61
|
const itemName = this.options.itemName || 'item'
|
|
62
|
-
layout =
|
|
62
|
+
layout = create(this.options.layout[itemName], element)
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
// console.log('translate', layout)
|
package/src/list/select.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import clone from '../module/clone'
|
|
2
|
+
|
|
1
3
|
export default {
|
|
2
4
|
select (item, silent) {
|
|
3
5
|
// console.log('select', item.dataset.id)
|
|
@@ -42,11 +44,11 @@ export default {
|
|
|
42
44
|
},
|
|
43
45
|
|
|
44
46
|
getInfoById (id) {
|
|
45
|
-
return
|
|
47
|
+
return clone(this.dataStore[id])
|
|
46
48
|
},
|
|
47
49
|
|
|
48
50
|
getSelectedInfo () {
|
|
49
|
-
return
|
|
51
|
+
return clone(this.dataStore[this.id])
|
|
50
52
|
},
|
|
51
53
|
|
|
52
54
|
getItemById (id, silent) {
|
package/src/list/update.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { create } from '../module/layout'
|
|
2
2
|
|
|
3
3
|
export default {
|
|
4
4
|
update (info) {
|
|
@@ -53,7 +53,7 @@ export default {
|
|
|
53
53
|
const item = this.ui.body.querySelector('[data-id="' + info[this.dataId] + '"]')
|
|
54
54
|
if (item) {
|
|
55
55
|
item.innerHTML = ''
|
|
56
|
-
const layout =
|
|
56
|
+
const layout = create(this.options.layout.item, item)
|
|
57
57
|
|
|
58
58
|
this.renderInfo(layout, info)
|
|
59
59
|
}
|
package/src/list.js
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import * as css from './module/css'
|
|
2
2
|
|
|
3
|
-
const defaults = {
|
|
4
|
-
className: 'text',
|
|
5
|
-
tag: 'span',
|
|
6
|
-
seprator: ' | '
|
|
7
|
-
}
|
|
8
|
-
|
|
9
3
|
class List {
|
|
10
|
-
static
|
|
4
|
+
static defaults = {
|
|
5
|
+
className: 'text',
|
|
6
|
+
tag: 'span',
|
|
7
|
+
seprator: ' | '
|
|
8
|
+
}
|
|
11
9
|
|
|
12
10
|
constructor (options) {
|
|
13
|
-
this.
|
|
14
|
-
|
|
11
|
+
this.init(options)
|
|
15
12
|
this.build()
|
|
13
|
+
}
|
|
16
14
|
|
|
17
|
-
|
|
15
|
+
init (otions) {
|
|
16
|
+
this.options = { ...List.defaults, ...options }
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
build () {
|
|
@@ -37,9 +36,9 @@ class List {
|
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
set (list) {
|
|
40
|
-
|
|
39
|
+
let text = ''
|
|
41
40
|
|
|
42
|
-
for (
|
|
41
|
+
for (let i = 0; i < list.length; i++) {
|
|
43
42
|
if (i < list.length - 1) {
|
|
44
43
|
text = text + list[i] + this.options.seprator
|
|
45
44
|
} else {
|
|
@@ -50,7 +49,7 @@ class List {
|
|
|
50
49
|
// console.log('set', text)
|
|
51
50
|
if (text === undefined) return
|
|
52
51
|
|
|
53
|
-
|
|
52
|
+
const label = this.options.label || ''
|
|
54
53
|
|
|
55
54
|
this.element.innerHTML = label + text
|
|
56
55
|
|
package/src/loader.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
class Loader {
|
|
2
|
-
static uid = "material-loader";
|
|
3
|
-
|
|
4
2
|
static defaults = {
|
|
5
3
|
class: 'loader'
|
|
6
4
|
}
|
|
7
5
|
|
|
8
6
|
constructor (options) {
|
|
9
|
-
this.
|
|
10
|
-
|
|
11
|
-
// Object.assign(this, mediator, build)
|
|
12
|
-
|
|
7
|
+
this.init(options)
|
|
13
8
|
this.build()
|
|
9
|
+
}
|
|
14
10
|
|
|
15
|
-
|
|
11
|
+
init (options) {
|
|
12
|
+
this.options = { ...Loader.defaults, ...options }
|
|
16
13
|
}
|
|
17
14
|
|
|
18
15
|
build () {
|
package/src/loading.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import build from './
|
|
1
|
+
import build from './mixin/build'
|
|
2
2
|
|
|
3
3
|
class Loading {
|
|
4
|
-
static uid = "material-loading";
|
|
5
|
-
|
|
6
|
-
static isComponent () {
|
|
7
|
-
return true
|
|
8
|
-
}
|
|
9
|
-
|
|
10
4
|
static defaults = {
|
|
11
5
|
class: 'loading',
|
|
12
6
|
tag: 'div',
|
|
@@ -24,7 +18,7 @@ class Loading {
|
|
|
24
18
|
}
|
|
25
19
|
|
|
26
20
|
init (options) {
|
|
27
|
-
this.options =
|
|
21
|
+
this.options = { ...Loading.defaults, ...options }
|
|
28
22
|
Object.assign(this, build)
|
|
29
23
|
}
|
|
30
24
|
|
package/src/map.js
CHANGED
|
@@ -13,42 +13,37 @@ import mode from './map/mode'
|
|
|
13
13
|
import select from './map/select'
|
|
14
14
|
import focus from './map/focus'
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
['root.mousedown', 'mouseDown'],
|
|
18
|
-
['root.mouseup', 'mouseUp'],
|
|
19
|
-
['root.mousemove', 'mouseMove'],
|
|
20
|
-
['root.mouseleave', 'mouseLeave'],
|
|
21
|
-
['root.mouseout', 'mouseOut'],
|
|
22
|
-
['root.click', 'mouseClick'],
|
|
23
|
-
['root.touchStart', 'mouseClick']
|
|
24
|
-
]
|
|
25
|
-
|
|
26
|
-
const defaults = {
|
|
27
|
-
class: 'worldmap',
|
|
28
|
-
tag: 'main',
|
|
29
|
-
zoom: 0.3,
|
|
30
|
-
isocodes: [],
|
|
31
|
-
mode: 'unique',
|
|
32
|
-
path: '/dist/map/',
|
|
33
|
-
pinchZoom: {
|
|
34
|
-
maxZoom: 128,
|
|
35
|
-
minZoom: 3,
|
|
36
|
-
setOffsetsOnce: true,
|
|
37
|
-
verticalPadding: 64,
|
|
38
|
-
horizontalPadding: 64,
|
|
39
|
-
tapZoomFactor: 0
|
|
40
|
-
}
|
|
41
|
-
}
|
|
16
|
+
// Depracted
|
|
42
17
|
|
|
43
18
|
class Map {
|
|
44
|
-
static
|
|
19
|
+
static defaults = {
|
|
20
|
+
class: 'worldmap',
|
|
21
|
+
tag: 'main',
|
|
22
|
+
zoom: 0.3,
|
|
23
|
+
isocodes: [],
|
|
24
|
+
mode: 'unique',
|
|
25
|
+
path: '/dist/map/',
|
|
26
|
+
pinchZoom: {
|
|
27
|
+
maxZoom: 128,
|
|
28
|
+
minZoom: 3,
|
|
29
|
+
setOffsetsOnce: true,
|
|
30
|
+
verticalPadding: 64,
|
|
31
|
+
horizontalPadding: 64,
|
|
32
|
+
tapZoomFactor: 0
|
|
33
|
+
},
|
|
34
|
+
events: [
|
|
35
|
+
['root.mousedown', 'mouseDown'],
|
|
36
|
+
['root.mouseup', 'mouseUp'],
|
|
37
|
+
['root.mousemove', 'mouseMove'],
|
|
38
|
+
['root.mouseleave', 'mouseLeave'],
|
|
39
|
+
['root.mouseout', 'mouseOut'],
|
|
40
|
+
['root.click', 'mouseClick'],
|
|
41
|
+
['root.touchStart', 'mouseClick']
|
|
42
|
+
]
|
|
43
|
+
}
|
|
45
44
|
|
|
46
|
-
/**
|
|
47
|
-
* Constructor component options
|
|
48
|
-
* @return {Object} Class instance
|
|
49
|
-
*/
|
|
50
45
|
constructor (options) {
|
|
51
|
-
this.options =
|
|
46
|
+
this.options = { ...Map.defaults, ...options }
|
|
52
47
|
|
|
53
48
|
Object.assign(
|
|
54
49
|
this, emitter, init, build, viewport, mouse,
|
package/src/menu.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import EventEmitter from './mixin/emitter'
|
|
2
2
|
// menu related modules
|
|
3
|
-
import build from './
|
|
3
|
+
import build from './mixin/build'
|
|
4
4
|
import events from './module/events'
|
|
5
5
|
import display from './mixin/display'
|
|
6
6
|
import position from './mixin/position'
|
|
7
7
|
|
|
8
8
|
import Element from './element'
|
|
9
|
-
import Button from './button'
|
|
10
9
|
|
|
11
10
|
class Menu extends EventEmitter {
|
|
12
11
|
static defaults = {
|
|
@@ -23,10 +22,8 @@ class Menu extends EventEmitter {
|
|
|
23
22
|
],
|
|
24
23
|
events: [
|
|
25
24
|
['element.click', 'onClick'],
|
|
26
|
-
['
|
|
27
|
-
['
|
|
28
|
-
['element.mouseleave', 'close'],
|
|
29
|
-
['options.target.mouseleave', 'close']
|
|
25
|
+
['select', 'destroy'],
|
|
26
|
+
['underlay.click', 'close']
|
|
30
27
|
]
|
|
31
28
|
}
|
|
32
29
|
|
|
@@ -35,6 +32,7 @@ class Menu extends EventEmitter {
|
|
|
35
32
|
|
|
36
33
|
this.init(options)
|
|
37
34
|
this.build(this.constructor)
|
|
35
|
+
this.buildUnderlay()
|
|
38
36
|
this.setup()
|
|
39
37
|
|
|
40
38
|
this.render(this.options.items)
|
|
@@ -43,13 +41,27 @@ class Menu extends EventEmitter {
|
|
|
43
41
|
}
|
|
44
42
|
|
|
45
43
|
init (options) {
|
|
46
|
-
this.options =
|
|
44
|
+
this.options = { ...Menu.defaults, ...options }
|
|
47
45
|
Object.assign(this, build, display, position)
|
|
46
|
+
|
|
47
|
+
this.menus = []
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
buildUnderlay () {
|
|
51
|
+
if (!this.options.parentName) {
|
|
52
|
+
this.underlay = new Element({
|
|
53
|
+
class: 'menu-underlay'
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
this.options.container.appendChild(this.underlay)
|
|
57
|
+
}
|
|
48
58
|
}
|
|
49
59
|
|
|
50
60
|
setup () {
|
|
51
61
|
events.attach(this.options.events, this)
|
|
52
62
|
this.closeTimeout = null
|
|
63
|
+
|
|
64
|
+
document.addEventListener('click', this.handleDocumentClick)
|
|
53
65
|
}
|
|
54
66
|
|
|
55
67
|
render (items) {
|
|
@@ -64,34 +76,81 @@ class Menu extends EventEmitter {
|
|
|
64
76
|
|
|
65
77
|
add (obj) {
|
|
66
78
|
if (typeof obj !== 'object') return this
|
|
79
|
+
|
|
67
80
|
let item
|
|
81
|
+
|
|
68
82
|
if (obj.type === 'divider') {
|
|
69
83
|
item = new Element({ tag: 'li', class: 'divider' })
|
|
70
84
|
} else {
|
|
71
|
-
obj.
|
|
72
|
-
|
|
85
|
+
obj.tag = 'li'
|
|
86
|
+
obj.class = obj.class ? obj.class + ' item' : 'item'
|
|
87
|
+
item = new Element(obj)
|
|
88
|
+
|
|
89
|
+
item.addEventListener('mouseenter', () => {
|
|
90
|
+
if (this.menu) {
|
|
91
|
+
this.menu.destroy()
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
if (obj.items && Array.isArray(obj.items)) {
|
|
96
|
+
item.classList.add('sub')
|
|
97
|
+
|
|
98
|
+
item.addEventListener('mouseenter', () => {
|
|
99
|
+
this.menu = new Menu({
|
|
100
|
+
class: 'floating',
|
|
101
|
+
target: item,
|
|
102
|
+
container: this.options.container,
|
|
103
|
+
parentName: obj.name,
|
|
104
|
+
items: obj.items
|
|
105
|
+
}).position(item, {
|
|
106
|
+
align: 'left',
|
|
107
|
+
vAlign: 'inline',
|
|
108
|
+
offsetX: 8,
|
|
109
|
+
offsetY: 8
|
|
110
|
+
}).show()
|
|
111
|
+
|
|
112
|
+
this.menu.on('select', (name) => {
|
|
113
|
+
this.emit('select', `${obj.name}:${name}`)
|
|
114
|
+
}).on('destroy', () => {
|
|
115
|
+
this.menu = null
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
this.menus.push(this.menu)
|
|
119
|
+
})
|
|
120
|
+
}
|
|
73
121
|
}
|
|
74
|
-
|
|
122
|
+
this.ui.list.appendChild(item)
|
|
75
123
|
return this
|
|
76
124
|
}
|
|
77
125
|
|
|
78
|
-
onMouseEnter () {
|
|
79
|
-
clearTimeout(this.closeTimeout)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
126
|
onClick (ev) {
|
|
83
|
-
|
|
127
|
+
if (ev.target.classList.contains('sub')) return
|
|
84
128
|
const name = ev.target.getAttribute('name')
|
|
85
129
|
if (name) {
|
|
86
130
|
this.emit('select', name)
|
|
87
131
|
}
|
|
88
|
-
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
destroyMenu (menu) {
|
|
135
|
+
// Trouver l'index de menuToDestroy dans this.menus
|
|
136
|
+
const index = this.menus.indexOf(menu)
|
|
137
|
+
|
|
138
|
+
// Si trouvé, supprimer le menu du tableau
|
|
139
|
+
if (index > -1) {
|
|
140
|
+
this.menus.splice(index, 1)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Appeler la méthode destroy sur le menuToDestroy
|
|
144
|
+
menu.destroy()
|
|
89
145
|
}
|
|
90
146
|
|
|
91
147
|
close () {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
148
|
+
// console.log('')
|
|
149
|
+
this.menus.forEach(menu => {
|
|
150
|
+
menu.destroy()
|
|
151
|
+
})
|
|
152
|
+
this.menus = []
|
|
153
|
+
this.destroy()
|
|
95
154
|
}
|
|
96
155
|
}
|
|
97
156
|
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import * as css from '../module/css'
|
|
2
|
+
import dataset from '../module/dataset'
|
|
3
|
+
|
|
4
|
+
import { create } from '../module/layout'
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
build () {
|
|
8
|
+
this.element = document.createElement(this.options.tag || 'div')
|
|
9
|
+
|
|
10
|
+
const defaults = this.constructor.defaults || {}
|
|
11
|
+
|
|
12
|
+
if (defaults.base) css.add(this.element, defaults.base)
|
|
13
|
+
if (defaults.class) css.add(this.element, defaults.class)
|
|
14
|
+
|
|
15
|
+
if (this.options.class !== defaults.class) {
|
|
16
|
+
css.add(this.element, this.options.class)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (this.options.data) {
|
|
20
|
+
dataset(this.element, this.options.data)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (this.options.base === 'view' || this.options.base === 'app') {
|
|
24
|
+
this.container = this.options.container || document.body
|
|
25
|
+
} else {
|
|
26
|
+
this.container = this.options.container
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (this.container) this.appendTo(this.container)
|
|
30
|
+
|
|
31
|
+
if (this.options.layout) {
|
|
32
|
+
this.layout = create(this.options.layout, this.element)
|
|
33
|
+
this.ui = this.layout.component
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
this.ui = this.ui || {}
|
|
37
|
+
|
|
38
|
+
if (this.options.icon) this.buildIcon()
|
|
39
|
+
if (this.options.label) this.buildLabel()
|
|
40
|
+
|
|
41
|
+
if (this.options.show === true && this.show) this.show()
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
buildLabel () {
|
|
45
|
+
if (!this.options.label) return
|
|
46
|
+
|
|
47
|
+
this.ui.label = document.createElement('label')
|
|
48
|
+
this.ui.label.classList.add('label')
|
|
49
|
+
this.ui.label.innerHTML = this.options.label
|
|
50
|
+
|
|
51
|
+
this.element.appendChild(this.ui.label)
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
buildIcon () {
|
|
55
|
+
if (!this.options.icon) return
|
|
56
|
+
|
|
57
|
+
this.ui.icon = document.createElement('i')
|
|
58
|
+
this.ui.icon.classList.add('icon')
|
|
59
|
+
this.ui.icon.innerHTML = this.options.icon
|
|
60
|
+
|
|
61
|
+
this.element.appendChild(this.ui.icon)
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
appendTo (container) {
|
|
65
|
+
// console.log('appendTo', container)
|
|
66
|
+
container.appendChild(this.element)
|
|
67
|
+
}
|
|
68
|
+
}
|
package/src/mixin/emitter.js
CHANGED
package/src/mixin/position.js
CHANGED
|
@@ -8,8 +8,10 @@ export default {
|
|
|
8
8
|
|
|
9
9
|
if (!target) return
|
|
10
10
|
|
|
11
|
+
// console.log('container', this.options.container)
|
|
12
|
+
|
|
11
13
|
const caller = target.getBoundingClientRect()
|
|
12
|
-
const screen = this.
|
|
14
|
+
const screen = this.options.container.getBoundingClientRect()
|
|
13
15
|
const element = this.element.getBoundingClientRect()
|
|
14
16
|
|
|
15
17
|
let left, top
|
|
@@ -21,7 +23,6 @@ export default {
|
|
|
21
23
|
case 'right':
|
|
22
24
|
left = caller.left
|
|
23
25
|
if (left + element.width + offsetX > screen.width) {
|
|
24
|
-
console.log('out boundaries')
|
|
25
26
|
left = caller.left - element.width + caller.width
|
|
26
27
|
}
|
|
27
28
|
break
|
|
@@ -34,10 +35,16 @@ export default {
|
|
|
34
35
|
|
|
35
36
|
// ensure that the element remains within the limits of its container
|
|
36
37
|
|
|
38
|
+
// if (left < 0) left = offsetX
|
|
39
|
+
|
|
40
|
+
// if (left + element.width + offsetX > screen.width) {
|
|
41
|
+
// left = screen.width - element.width - offsetX
|
|
42
|
+
// }
|
|
43
|
+
|
|
37
44
|
if (left < 0) left = offsetX
|
|
38
45
|
|
|
39
|
-
if (left + element.width
|
|
40
|
-
left =
|
|
46
|
+
if (left + element.width > screen.width) {
|
|
47
|
+
left = caller.left - element.width
|
|
41
48
|
}
|
|
42
49
|
|
|
43
50
|
// console.log('left', left)
|
|
@@ -46,15 +53,13 @@ export default {
|
|
|
46
53
|
|
|
47
54
|
const scrollY = window.scrollY
|
|
48
55
|
|
|
49
|
-
// console.log('class', name)
|
|
50
|
-
// console.log('scrollY', scrollY)
|
|
51
|
-
// console.log('vAlign', vAlign)
|
|
52
|
-
// console.log('target top', caller.top)
|
|
53
|
-
|
|
54
56
|
switch (vAlign) {
|
|
55
57
|
case 'top':
|
|
56
58
|
top = caller.top + scrollY - element.height
|
|
57
59
|
break
|
|
60
|
+
case 'inline':
|
|
61
|
+
top = caller.top + scrollY
|
|
62
|
+
break
|
|
58
63
|
case 'bottom':
|
|
59
64
|
top = caller.top + caller.height + scrollY
|
|
60
65
|
break
|
|
@@ -71,6 +76,12 @@ export default {
|
|
|
71
76
|
top = caller.top + scrollY + (caller.height / 2) - (element.height / 2)
|
|
72
77
|
}
|
|
73
78
|
|
|
79
|
+
// console.log('screen height', screen.height, element.height, offsetX)
|
|
80
|
+
|
|
81
|
+
if (top + element.height + offsetY > screen.height) {
|
|
82
|
+
top = screen.height - element.height - offsetX
|
|
83
|
+
}
|
|
84
|
+
|
|
74
85
|
this.element.style.left = `${left}px`
|
|
75
86
|
this.element.style.top = `${top}px`
|
|
76
87
|
|