material 0.7.1 → 0.7.2
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/README.md +1 -5
- package/dist/demo-bundle.js +2281 -2
- package/dist/demo-bundle.js.map +7 -1
- package/dist/demo.js +13 -13
- package/esbuild.js +22 -0
- package/esbuild.watch.js +25 -0
- package/package.json +7 -20
- package/src/badge.js +1 -1
- package/src/button.js +50 -100
- package/src/calendar.js +53 -53
- package/src/card.js +1 -1
- package/src/checkbox.js +5 -53
- package/src/datehour.js +7 -7
- package/src/dialog.js +5 -5
- package/src/divider.js +1 -1
- package/src/drawer.js +1 -17
- package/src/element/attribute.js +7 -10
- package/src/element/build.js +6 -7
- package/src/element/create.js +3 -6
- package/src/element/event.js +2 -2
- package/src/element/insert.js +6 -17
- package/src/element/observer.js +22 -0
- package/src/element/offset.js +2 -2
- package/src/element/style.js +12 -12
- package/src/element.js +2 -2
- package/src/field/email.js +9 -44
- package/src/field/image.js +17 -51
- package/src/file.js +1 -1
- package/src/form/build.js +7 -7
- package/src/form/controller.js +8 -8
- package/src/form/create.js +1 -1
- package/src/form/data.js +9 -9
- package/src/form/delete.js +1 -1
- package/src/form/render.js +9 -9
- package/src/form/set.js +1 -1
- package/src/form/submit.js +6 -6
- package/src/form/update.js +3 -3
- package/src/form/verify.js +4 -4
- package/src/form.js +9 -9
- package/src/icon.js +4 -4
- package/src/image.js +7 -7
- package/src/item.js +1 -1
- package/src/layout.js +14 -14
- package/src/link.js +1 -1
- package/src/list/build.js +8 -8
- package/src/list/click.js +3 -3
- package/src/list/filter.js +11 -11
- package/src/list/image.js +3 -3
- package/src/list/render.js +15 -15
- package/src/list/request.js +7 -7
- package/src/list/search.js +9 -9
- package/src/list/select.js +18 -18
- package/src/list/status.js +1 -1
- package/src/list/update.js +6 -6
- package/src/list/virtual.js +20 -20
- package/src/list/virtual.new.js +5 -5
- package/src/list.js +8 -8
- package/src/map/build.js +2 -2
- package/src/map/countries.js +8 -8
- package/src/map/display.js +13 -13
- package/src/map/focus.js +7 -7
- package/src/map/select.js +2 -2
- package/src/map/set.js +3 -3
- package/src/map/viewport.js +11 -11
- package/src/menu.js +12 -12
- package/src/mixin/control.js +3 -3
- package/src/mixin/controller.js +5 -5
- package/src/mixin/create.js +1 -1
- package/src/mixin/display.js +1 -1
- package/src/mixin/events.js +4 -16
- package/src/mixin/focus.js +1 -1
- package/src/mixin/icon.js +2 -2
- package/src/mixin/init.js +2 -2
- package/src/mixin/insert.js +5 -5
- package/src/mixin/label.js +2 -2
- package/src/mixin/settings.js +5 -5
- package/src/module/attach.js +35 -49
- package/src/module/attributes.js +2 -2
- package/src/module/build.js +7 -10
- package/src/module/classify.js +4 -4
- package/src/module/controller.js +5 -32
- package/src/module/css.js +12 -84
- package/src/module/dataset.js +1 -1
- package/src/module/dom.js +8 -3
- package/src/module/dot.js +4 -4
- package/src/module/emitter.js +1 -1
- package/src/module/event.js +2 -2
- package/src/module/events.js +29 -35
- package/src/module/extract.js +10 -10
- package/src/module/last.js +18 -0
- package/src/module/mediator.js +1 -13
- package/src/module/object.js +4 -4
- package/src/module/observer.js +43 -16
- package/src/module/remove.js +10 -10
- package/src/module/ripple.js +19 -24
- package/src/module/scrollbar.js +10 -14
- package/src/module/smoothscroll.js +5 -9
- package/src/module/utils.js +14 -23
- package/src/module/viewport.js +5 -5
- package/src/progress.js +1 -9
- package/src/search.js +24 -29
- package/src/select.js +6 -6
- package/src/selecter.js +39 -39
- package/src/selector.js +3 -3
- package/src/skin/material/component/navigation.sass +9 -1
- package/src/slider.js +1 -1
- package/src/snackbar.js +8 -7
- package/src/switch.js +1 -1
- package/src/switcher.js +15 -15
- package/src/tabs.js +4 -5
- package/src/tabview.js +26 -46
- package/src/text.js +1 -1
- package/src/textfield.js +1 -1
- package/src/toolbar.js +12 -12
- package/src/tooltip.js +7 -7
- package/src/tree.js +10 -66
- package/src/view/build.js +2 -2
- package/src/view/dataset.js +1 -1
- package/src/view.js +9 -74
- package/rollup.config.js +0 -34
- package/src/element/ripple.js +0 -90
- package/src/module/addclass.js +0 -16
package/src/mixin/events.js
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
export default {
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* cross browser addEvent
|
|
5
|
-
* @param {string} event The event to add
|
|
6
|
-
* @param {Function} fn [description]
|
|
7
|
-
*/
|
|
8
2
|
addEvent (event, fn) {
|
|
9
|
-
|
|
3
|
+
const element = this.element
|
|
10
4
|
// avoid memory overhead of new anonymous functions for every event handler that's installed
|
|
11
5
|
// by using local functions
|
|
12
6
|
function listenHandler (e) {
|
|
13
|
-
|
|
7
|
+
const ret = fn.apply(this, arguments)
|
|
14
8
|
if (ret === false) {
|
|
15
9
|
e.stopPropagation()
|
|
16
10
|
e.preventDefault()
|
|
@@ -21,7 +15,7 @@ export default {
|
|
|
21
15
|
function attachHandler () {
|
|
22
16
|
// set the this pointer same as addEventListener when fn is called
|
|
23
17
|
// and make sure the event is passed to the fn also so that works the same too
|
|
24
|
-
|
|
18
|
+
const ret = fn.call(element, window.event)
|
|
25
19
|
if (ret === false) {
|
|
26
20
|
window.event.returnValue = false
|
|
27
21
|
window.event.cancelBubble = true
|
|
@@ -38,14 +32,8 @@ export default {
|
|
|
38
32
|
return this
|
|
39
33
|
},
|
|
40
34
|
|
|
41
|
-
/**
|
|
42
|
-
* cross browser removeEvent
|
|
43
|
-
* @param {string} event The event to remove
|
|
44
|
-
* @param {Function} fn [description]
|
|
45
|
-
* @return {Object} [description]
|
|
46
|
-
*/
|
|
47
35
|
removeEvent (event, fn) {
|
|
48
|
-
|
|
36
|
+
const element = this.element
|
|
49
37
|
|
|
50
38
|
if (element.removeEventListener) {
|
|
51
39
|
element.removeEventListener(event, fn, false)
|
package/src/mixin/focus.js
CHANGED
package/src/mixin/icon.js
CHANGED
|
@@ -11,12 +11,12 @@ function icon (root, svg, options) {
|
|
|
11
11
|
return
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
let position = 'top'
|
|
15
15
|
if (options && options.type === 'text-icon') {
|
|
16
16
|
position = 'bottom'
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
const element = create('i', options.class + '-icon')
|
|
20
20
|
insert(element, root, position)
|
|
21
21
|
|
|
22
22
|
element.innerHTML = svg
|
package/src/mixin/init.js
CHANGED
|
@@ -10,9 +10,9 @@ function init (instance) {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
function modules (instance) {
|
|
13
|
-
|
|
13
|
+
const modules = instance.options.modules
|
|
14
14
|
|
|
15
|
-
for (
|
|
15
|
+
for (let i = 0; i < modules.length; i++) {
|
|
16
16
|
if (typeof modules[i] === 'function') {
|
|
17
17
|
modules[i](instance)
|
|
18
18
|
} else {
|
package/src/mixin/insert.js
CHANGED
|
@@ -5,7 +5,7 @@ import dom from '../module/dom'
|
|
|
5
5
|
export default {
|
|
6
6
|
|
|
7
7
|
insert (container, context) {
|
|
8
|
-
|
|
8
|
+
const element = this.element
|
|
9
9
|
|
|
10
10
|
this.insertElement(element, container, context)
|
|
11
11
|
|
|
@@ -27,15 +27,15 @@ export default {
|
|
|
27
27
|
|
|
28
28
|
context = context || 'bottom'
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
const contexts = ['top', 'bottom', 'after', 'before']
|
|
31
|
+
const methods = ['prepend', 'append', 'after', 'before']
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
const index = contexts.indexOf(context)
|
|
34
34
|
if (index === -1) {
|
|
35
35
|
return
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
const method = methods[index]
|
|
39
39
|
|
|
40
40
|
// this.emit('insert');
|
|
41
41
|
|
package/src/mixin/label.js
CHANGED
|
@@ -10,9 +10,9 @@ const prefix = 'material'
|
|
|
10
10
|
function label (root, text, options) {
|
|
11
11
|
text = text || null
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
const prefix = options.class || options.prefix
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
const label = create('label', prefix + '-label')
|
|
16
16
|
label.textContent = text
|
|
17
17
|
label.setAttribute('for', options.name)
|
|
18
18
|
insert(label, root)
|
package/src/mixin/settings.js
CHANGED
|
@@ -2,9 +2,9 @@ import cookies from '../module/cookies'
|
|
|
2
2
|
import merge from '../module/merge'
|
|
3
3
|
|
|
4
4
|
function set (key, value) {
|
|
5
|
-
|
|
5
|
+
const text = cookies.get(key)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
let current = {}
|
|
8
8
|
|
|
9
9
|
if (text) {
|
|
10
10
|
current = JSON.parse(text)
|
|
@@ -12,7 +12,7 @@ function set (key, value) {
|
|
|
12
12
|
|
|
13
13
|
console.log('settings value', current, value)
|
|
14
14
|
// settings = [settings, value].reduce(Object.assign, {});
|
|
15
|
-
|
|
15
|
+
const settings = merge(current, value)
|
|
16
16
|
|
|
17
17
|
console.log('settings ' + key, settings)
|
|
18
18
|
|
|
@@ -20,12 +20,12 @@ function set (key, value) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
function get (key) {
|
|
23
|
-
|
|
23
|
+
const json = cookies.get(key)
|
|
24
24
|
|
|
25
25
|
if (!json) {
|
|
26
26
|
return null
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
const value = JSON.parse(json)
|
|
29
29
|
|
|
30
30
|
console.log('settings' + key, value)
|
|
31
31
|
|
package/src/module/attach.js
CHANGED
|
@@ -1,72 +1,58 @@
|
|
|
1
|
+
// Assuming extract is imported or defined elsewhere
|
|
1
2
|
import extract from './extract'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* @module module/attach
|
|
6
|
-
* @category module
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* [attach description]
|
|
11
|
-
* @param {object} component [description]
|
|
12
|
-
* @param {[type]} events [description]
|
|
13
|
-
* @return {[type]} [description]
|
|
14
|
-
*/
|
|
15
|
-
export default {
|
|
16
|
-
attach: function (events) {
|
|
17
|
-
// console.log('attach', events)
|
|
4
|
+
const attachModule = {
|
|
5
|
+
attach (events) {
|
|
18
6
|
events = events || this.options.events
|
|
19
7
|
if (!events) return
|
|
20
8
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
9
|
+
events.map(([eventDef, funcDef, option]) => {
|
|
10
|
+
const e = extract.e(this, eventDef)
|
|
11
|
+
const isFunction = typeof funcDef === 'function'
|
|
12
|
+
let f = null
|
|
13
|
+
let keys = []
|
|
14
|
+
|
|
15
|
+
if (!isFunction) {
|
|
16
|
+
f = extract.f(this, funcDef)
|
|
17
|
+
keys = funcDef.split('.')
|
|
18
|
+
keys.pop()
|
|
19
|
+
}
|
|
27
20
|
|
|
28
|
-
|
|
21
|
+
const bound = this.last(keys.join('.'))
|
|
29
22
|
|
|
30
|
-
|
|
31
|
-
var bound = this.last(keys.join('.'))
|
|
23
|
+
let handler = null
|
|
32
24
|
|
|
33
|
-
if (
|
|
34
|
-
|
|
25
|
+
if (isFunction) {
|
|
26
|
+
handler = funcDef.bind(this)
|
|
27
|
+
} else if (f && bound) {
|
|
28
|
+
handler = f.bind(bound)
|
|
29
|
+
} else {
|
|
30
|
+
// console.error(`Can't bind function for ${eventDef}`)
|
|
31
|
+
return
|
|
32
|
+
}
|
|
35
33
|
|
|
34
|
+
if (handler && e && e.element && e.element.addEventListener) {
|
|
36
35
|
if (option) {
|
|
37
|
-
e.element.addEventListener(e.name,
|
|
36
|
+
e.element.addEventListener(e.name, handler, option)
|
|
38
37
|
} else {
|
|
39
|
-
e.element.addEventListener(e.name,
|
|
38
|
+
e.element.addEventListener(e.name, handler)
|
|
40
39
|
}
|
|
41
|
-
} else if (e && e.element && e.element.on &&
|
|
42
|
-
e.element.on(e.name,
|
|
40
|
+
} else if (e && e.element && e.element.on && handler) {
|
|
41
|
+
e.element.on(e.name, handler)
|
|
43
42
|
} else {
|
|
44
|
-
// console.
|
|
43
|
+
// console.error(`Can't attach ${eventDef}`)
|
|
45
44
|
}
|
|
46
45
|
})
|
|
47
46
|
|
|
48
47
|
return this
|
|
49
48
|
},
|
|
50
49
|
|
|
51
|
-
|
|
52
|
-
* Return the last reference from an object
|
|
53
|
-
* @param {string} str Object path for example key1.key2.key3
|
|
54
|
-
* @return {value} The value of the last reference
|
|
55
|
-
*/
|
|
56
|
-
last: function (str) {
|
|
57
|
-
// console.log('_path', str)
|
|
50
|
+
last (str) {
|
|
58
51
|
if (!str) return this
|
|
59
|
-
|
|
60
|
-
var last
|
|
61
|
-
|
|
62
|
-
var keys = str.split('.')
|
|
63
|
-
for (var i = 0, l = keys.length; i < l; i++) {
|
|
64
|
-
var key = keys[i]
|
|
52
|
+
if (!str.includes('.')) return this[str]
|
|
65
53
|
|
|
66
|
-
|
|
67
|
-
last = last[key]
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return last
|
|
54
|
+
return str.split('.').reduce((acc, key) => acc[key], this)
|
|
71
55
|
}
|
|
72
56
|
}
|
|
57
|
+
|
|
58
|
+
export default attachModule
|
package/src/module/attributes.js
CHANGED
|
@@ -5,8 +5,8 @@ function attributes (element, o) {
|
|
|
5
5
|
|
|
6
6
|
if (!element) return
|
|
7
7
|
|
|
8
|
-
for (
|
|
9
|
-
|
|
8
|
+
for (let i = 0; i < o.attributes.length; i++) {
|
|
9
|
+
const attribute = o.attributes[i]
|
|
10
10
|
|
|
11
11
|
if (o[attribute] && o[attribute] !== 'undefined') {
|
|
12
12
|
if (special.indexOf(attribute) > -1) {
|
package/src/module/build.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import * as css from './css'
|
|
1
2
|
import dataset from './dataset'
|
|
3
|
+
|
|
2
4
|
import Layout from '../layout'
|
|
3
5
|
|
|
4
6
|
export default {
|
|
@@ -7,14 +9,15 @@ export default {
|
|
|
7
9
|
|
|
8
10
|
const defaults = this.constructor.defaults || {}
|
|
9
11
|
|
|
10
|
-
if (defaults.base) this.element
|
|
11
|
-
|
|
12
|
-
if (defaults.class) this.element.classList.add(defaults.class)
|
|
12
|
+
if (defaults.base) css.add(this.element, defaults.base)
|
|
13
|
+
if (defaults.class) css.add(this.element, defaults.class)
|
|
13
14
|
|
|
14
15
|
if (this.options.class !== defaults.class) {
|
|
15
|
-
|
|
16
|
+
css.add(this.element, this.options.class)
|
|
16
17
|
}
|
|
17
18
|
|
|
19
|
+
if (defaults.class === 'account') console.log('data')
|
|
20
|
+
|
|
18
21
|
if (this.options.data) {
|
|
19
22
|
dataset(this.element, this.options.data)
|
|
20
23
|
}
|
|
@@ -37,11 +40,5 @@ export default {
|
|
|
37
40
|
|
|
38
41
|
appendTo (container) {
|
|
39
42
|
container.appendChild(this.element)
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
addClass (clss) {
|
|
43
|
-
const c = clss.replace(/\s+/g, ' ').trim()
|
|
44
|
-
const list = c.split(' ')
|
|
45
|
-
list.forEach(item => this.element.classList.add(item))
|
|
46
43
|
}
|
|
47
44
|
}
|
package/src/module/classify.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import css from '../module/css'
|
|
1
|
+
import * as css from '../module/css'
|
|
2
2
|
|
|
3
3
|
function classify (element, options) {
|
|
4
4
|
css.add(element, options.prefix + '-' + options.class)
|
|
@@ -34,14 +34,14 @@ function classify (element, options) {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
if (options.style) {
|
|
37
|
-
|
|
38
|
-
for (
|
|
37
|
+
const styles = options.style.split(' ')
|
|
38
|
+
for (let i = 0; i < styles.length; i++) {
|
|
39
39
|
css.add(element, 'style-' + styles[i])
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
if (options.data) {
|
|
44
|
-
for (
|
|
44
|
+
for (const property in options.data) {
|
|
45
45
|
if (options.data.hasOwnProperty(property)) {
|
|
46
46
|
element.dataset[property] = options.data[property]
|
|
47
47
|
}
|
package/src/module/controller.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
var controller = {
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* [register description]
|
|
10
|
-
* @param {component} component [description]
|
|
11
|
-
* @return {Object} The class instance
|
|
12
|
-
*/
|
|
1
|
+
const controller = {
|
|
13
2
|
register (instance, group) {
|
|
14
3
|
group = group || 'component'
|
|
15
4
|
this[group + 's'] = this[group + 's'] || []
|
|
@@ -24,12 +13,6 @@ var controller = {
|
|
|
24
13
|
return this
|
|
25
14
|
},
|
|
26
15
|
|
|
27
|
-
/**
|
|
28
|
-
* This method subscribes to a specific topic
|
|
29
|
-
* @param {string} topic
|
|
30
|
-
* @param {Function} callback
|
|
31
|
-
* @return {boolean} true
|
|
32
|
-
*/
|
|
33
16
|
subscribe (topic, callback) {
|
|
34
17
|
this._topics = this._topics || {}
|
|
35
18
|
|
|
@@ -42,12 +25,6 @@ var controller = {
|
|
|
42
25
|
return true
|
|
43
26
|
},
|
|
44
27
|
|
|
45
|
-
/**
|
|
46
|
-
* This method unsubscribes to a specific topic
|
|
47
|
-
* @param {string} topic
|
|
48
|
-
* @param {Function} callback
|
|
49
|
-
* @return {boolean} true
|
|
50
|
-
*/
|
|
51
28
|
unsunscribe (topic, callback) {
|
|
52
29
|
this._topics = this._topics || {}
|
|
53
30
|
// _log.debug('unsubscribe', topic);
|
|
@@ -55,7 +32,7 @@ var controller = {
|
|
|
55
32
|
return false
|
|
56
33
|
}
|
|
57
34
|
|
|
58
|
-
for (
|
|
35
|
+
for (let i = 0, len = this._topics[topic].length; i < len; i++) {
|
|
59
36
|
if (this._topics[topic][i] === callback) {
|
|
60
37
|
this._topics[topic].splice(i, 1)
|
|
61
38
|
return true
|
|
@@ -65,21 +42,17 @@ var controller = {
|
|
|
65
42
|
return false
|
|
66
43
|
},
|
|
67
44
|
|
|
68
|
-
/**
|
|
69
|
-
* [publish description]
|
|
70
|
-
* @return {?} [description]
|
|
71
|
-
*/
|
|
72
45
|
publish () {
|
|
73
46
|
this._topics = this._topics || {}
|
|
74
47
|
|
|
75
|
-
|
|
76
|
-
|
|
48
|
+
const args = Array.prototype.slice.call(arguments)
|
|
49
|
+
const topic = args.shift()
|
|
77
50
|
// _log.debug('publish', topic);
|
|
78
51
|
if (!this._topics.hasOwnProperty(topic)) {
|
|
79
52
|
return false
|
|
80
53
|
}
|
|
81
54
|
|
|
82
|
-
for (
|
|
55
|
+
for (let i = 0, len = this._topics[topic].length; i < len; i++) {
|
|
83
56
|
this._topics[topic][i].apply(undefined, args)
|
|
84
57
|
}
|
|
85
58
|
return true
|
package/src/module/css.js
CHANGED
|
@@ -1,51 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* @since 0.0.6
|
|
5
|
-
* @module css/has
|
|
6
|
-
* @category Element
|
|
7
|
-
* @param {...Array} [arrays] The arrays to process.
|
|
8
|
-
* @param {Function} iteratee The function to combine
|
|
9
|
-
* grouped values.
|
|
10
|
-
* @returns {Array} Returns the new array of grouped elements.
|
|
11
|
-
* @see unzip, unzipWith, zip, zipObject, zipObjectDeep, zipWith
|
|
12
|
-
* @example
|
|
13
|
-
*
|
|
14
|
-
* has(element, 'show');
|
|
15
|
-
* // => [111, 222]
|
|
16
|
-
*/
|
|
17
|
-
function has(element, className) {
|
|
18
|
-
if (!element || !className) {
|
|
19
|
-
return false
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return !!element.className.match(new RegExp('(\\s|^)' + className + '(\\s|$)'))
|
|
1
|
+
const has = (element, className) => {
|
|
2
|
+
if (!element || !className) return false
|
|
3
|
+
return !!element.className.match(new RegExp(`(\\s|^)${className}(\\s|$)`))
|
|
23
4
|
}
|
|
24
5
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*
|
|
28
|
-
* @since 0.0.6
|
|
29
|
-
* @module css/add
|
|
30
|
-
* @category css
|
|
31
|
-
* @param {HTMLElement} element Related element
|
|
32
|
-
* @param {String} className the className to add
|
|
33
|
-
* grouped values.
|
|
34
|
-
* @returns {HTMLElement} The augmented element
|
|
35
|
-
* @example
|
|
36
|
-
*
|
|
37
|
-
* add(element, 'hidden');
|
|
38
|
-
* // => <div class="element hidden">...</div>
|
|
39
|
-
*/
|
|
40
|
-
function add(element, className) {
|
|
41
|
-
if (!element || !className) {
|
|
42
|
-
return
|
|
43
|
-
}
|
|
6
|
+
const add = (element, className) => {
|
|
7
|
+
if (!element || !className) return
|
|
44
8
|
|
|
45
|
-
|
|
9
|
+
const sanitizedClassName = className.trim().replace(/\s+/g, ' ')
|
|
10
|
+
const classNames = sanitizedClassName.split(' ')
|
|
46
11
|
|
|
47
|
-
for (
|
|
48
|
-
var cn = classNames[i]
|
|
12
|
+
for (const cn of classNames) {
|
|
49
13
|
if (!has(element, cn)) {
|
|
50
14
|
element.classList.add(cn)
|
|
51
15
|
}
|
|
@@ -53,55 +17,19 @@ function add(element, className) {
|
|
|
53
17
|
return element
|
|
54
18
|
}
|
|
55
19
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
*
|
|
59
|
-
* @since 0.0.6
|
|
60
|
-
* @module css/remove
|
|
61
|
-
* @category css
|
|
62
|
-
* @param {HTMLElement} element Related element
|
|
63
|
-
* @param {String} className the className to add
|
|
64
|
-
* @returns {HTMLElement} The element with the removed className
|
|
65
|
-
* @example
|
|
66
|
-
*
|
|
67
|
-
* remove(element, 'hidden');
|
|
68
|
-
* // => <div class="element">...</div>
|
|
69
|
-
*/
|
|
70
|
-
function remove(element, className) {
|
|
71
|
-
if (!element || !className) {
|
|
72
|
-
return
|
|
73
|
-
}
|
|
74
|
-
|
|
20
|
+
const remove = (element, className) => {
|
|
21
|
+
if (!element || !className) return
|
|
75
22
|
element.classList.remove(className)
|
|
76
|
-
|
|
77
23
|
return element
|
|
78
24
|
}
|
|
79
25
|
|
|
80
|
-
|
|
81
|
-
* This function toggles className from the element's attribute class
|
|
82
|
-
*
|
|
83
|
-
* @since 0.0.6
|
|
84
|
-
* @module css/toggle
|
|
85
|
-
* @category Element
|
|
86
|
-
* @param {HTMLElement} element Related element
|
|
87
|
-
* @param {String} className the className to add
|
|
88
|
-
* grouped values.
|
|
89
|
-
* @returns {HTMLElement} The modified element
|
|
90
|
-
* @example
|
|
91
|
-
*
|
|
92
|
-
* toggle(element, 'hidden');
|
|
93
|
-
* // => <div class="element">...</div>
|
|
94
|
-
* toggle(element, 'hidden');
|
|
95
|
-
* // => <div class="element hidden">...</div>
|
|
96
|
-
*/
|
|
97
|
-
function toggle(element, className) {
|
|
26
|
+
const toggle = (element, className) => {
|
|
98
27
|
if (has(element, className)) {
|
|
99
28
|
remove(element, className)
|
|
100
29
|
} else {
|
|
101
30
|
add(element, className)
|
|
102
31
|
}
|
|
103
|
-
|
|
104
32
|
return element
|
|
105
33
|
}
|
|
106
34
|
|
|
107
|
-
export
|
|
35
|
+
export { has, add, remove, toggle }
|
package/src/module/dataset.js
CHANGED
package/src/module/dom.js
CHANGED
|
@@ -22,12 +22,12 @@ function replace (container, element) {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
function remove (element) {
|
|
25
|
-
|
|
25
|
+
const parent = element.parentNode
|
|
26
26
|
return parent.removeChild(element)
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
function dispose (element) {
|
|
30
|
-
|
|
30
|
+
const el = element
|
|
31
31
|
return (el.parentNode) ? el.parentNode.removeChild(el) : el
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -38,7 +38,12 @@ function empty (element) {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
function destroy (element) {
|
|
41
|
-
|
|
41
|
+
if (element && element.parentNode) {
|
|
42
|
+
return element.parentNode.removeChild(element)
|
|
43
|
+
} else {
|
|
44
|
+
// console.error('Element or its parent node is null')
|
|
45
|
+
return null
|
|
46
|
+
}
|
|
42
47
|
}
|
|
43
48
|
|
|
44
49
|
export default { append, prepend, after, before, replace, remove, destroy, empty, dispose }
|
package/src/module/dot.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
|
|
2
2
|
function dot (obj) {
|
|
3
|
-
|
|
3
|
+
const res = {}
|
|
4
4
|
function recurse (obj, current) {
|
|
5
|
-
for (
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
for (const key in obj) {
|
|
6
|
+
const value = obj[key]
|
|
7
|
+
const newKey = (current ? current + '.' + key : key)
|
|
8
8
|
if (value && typeof value === 'object') {
|
|
9
9
|
recurse(value, newKey)
|
|
10
10
|
} else {
|
package/src/module/emitter.js
CHANGED
|
@@ -14,7 +14,7 @@ export default {
|
|
|
14
14
|
emit (event /* , args... */) {
|
|
15
15
|
this.event = this.event || {}
|
|
16
16
|
if (event in this.event === false) return
|
|
17
|
-
for (
|
|
17
|
+
for (let i = 0; i < this.event[event].length; i++) {
|
|
18
18
|
this.event[event][i].apply(this, Array.prototype.slice.call(arguments, 1))
|
|
19
19
|
}
|
|
20
20
|
return this
|
package/src/module/event.js
CHANGED
|
@@ -9,7 +9,7 @@ export default {
|
|
|
9
9
|
// avoid memory overhead of new anonymous functions for every event handler that's installed
|
|
10
10
|
// by using local functions
|
|
11
11
|
function listenHandler (e) {
|
|
12
|
-
|
|
12
|
+
const ret = fn.apply(this, arguments)
|
|
13
13
|
if (ret === false) {
|
|
14
14
|
e.stopPropagation()
|
|
15
15
|
e.preventDefault()
|
|
@@ -20,7 +20,7 @@ export default {
|
|
|
20
20
|
function attachHandler () {
|
|
21
21
|
// set the this pointer same as addEventListener when fn is called
|
|
22
22
|
// and make sure the event is passed to the fn also so that works the same too
|
|
23
|
-
|
|
23
|
+
const ret = fn.call(element, window.event)
|
|
24
24
|
if (ret === false) {
|
|
25
25
|
window.event.returnValue = false
|
|
26
26
|
window.event.cancelBubble = true
|