wallace 0.0.1 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/wrapper.js DELETED
@@ -1,152 +0,0 @@
1
- import {doc} from './helpers'
2
-
3
-
4
- /**
5
- * A wrapper around a DOM element.
6
- * All transformative methods return this (except transitions as they return promises)
7
- * This means those methods can be chained.
8
- */
9
- export function Wrapper(element) {
10
- this.e = element
11
- this._pool = undefined
12
- }
13
-
14
- Wrapper.prototype = {
15
- /**
16
- * Get element as 'e' from item, else return text node.
17
- */
18
- __ge: function(item) {
19
- return item.e || doc.createTextNode(item)
20
- },
21
- /**
22
- * Gets an attribute from the element. Cannot be chained.
23
- */
24
- getAtt: function(name) {
25
- return this.e[name]
26
- },
27
- /**
28
- * Gets the element's value. Cannot be chained.
29
- */
30
- getValue: function() {
31
- return this.e.value
32
- },
33
- isChecked: function() {
34
- return this.e.checked
35
- },
36
- /* Every method below must return 'this' so it can be chained */
37
- append: function(item) {
38
- this.e.appendChild(this.__ge(item))
39
- return this
40
- },
41
- att: function(name, value) {
42
- this.e.setAttribute(name, value)
43
- return this
44
- },
45
- atts: function(atts) {
46
- for (let name in atts) {
47
- this.att(name, atts[name])
48
- }
49
- return this
50
- },
51
- pool: function(pool) {
52
- this._pool = pool
53
- return this
54
- },
55
- clear: function() {
56
- this.e.innerHTML = ''
57
- this.e.textContent = ''
58
- this.e.value = ''
59
- return this
60
- },
61
- checked: function(value) {
62
- this.e.checked = !!value
63
- return this
64
- },
65
- child: function(wrapper) {
66
- this.e.innerHTML = ''
67
- this.e.appendChild(wrapper.e)
68
- return this
69
- },
70
- css: function(style) {
71
- this.e.className = style
72
- return this
73
- },
74
- cssAdd: function(style) {
75
- this.e.classList.add(style)
76
- return this
77
- },
78
- cssRemove: function(style) {
79
- this.e.classList.remove(style)
80
- return this
81
- },
82
- cssToggle: function(style) {
83
- this.e.classList.toggle(style)
84
- return this
85
- },
86
- disabled: function(disabled) {
87
- this.e.disabled = disabled
88
- return this
89
- },
90
- href: function(value) {
91
- return this.att('href', value)
92
- },
93
- html: function(html) {
94
- this.e.innerHTML = html
95
- return this
96
- },
97
- id: function(value) {
98
- return this.att('id', value)
99
- },
100
- /*
101
- * Set inner as individual item or array. Not optimised.
102
- */
103
- inner: function(items) {
104
- if (!Array.isArray(items)) {
105
- items = [items]
106
- }
107
- const e = this.e
108
- e.innerHTML = ''
109
- for (var i=0, il=items.length; i<il; i++) {
110
- e.appendChild(this.__ge(items[i]))
111
- }
112
- return this
113
- },
114
- /*
115
- * Set items from pool.
116
- */
117
- items: function(items, parent) {
118
- this._pool.patch(this.e, items, parent)
119
- return this
120
- },
121
- on: function(event, callback) {
122
- this.e.addEventListener(event, e => callback(this, e))
123
- return this
124
- },
125
- replace: function(el) {
126
- this.e.parentNode.replaceChild(el, this.e)
127
- return this
128
- },
129
- src: function(value) {
130
- return this.att('src', value)
131
- },
132
- style: function(name, value) {
133
- this.e.style[name] = value
134
- return this
135
- },
136
- swap: function(key, parent) {
137
- this.child(this._pool.getOne(key, parent))
138
- return this
139
- },
140
- text: function(value) {
141
- this.e.textContent = value
142
- return this
143
- },
144
- visible: function(visible) {
145
- this.e.classList.toggle('hidden', !visible)
146
- return this
147
- },
148
- value: function(value) {
149
- this.e.value = value
150
- return this
151
- }
152
- }