material 0.7.0 → 0.7.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/form.js +27 -0
- package/index.js +59 -58
- package/list.js +35 -0
- package/package.json +5 -1
- package/src/appbar.js +7 -204
- package/src/badge.js +27 -0
- package/src/button.js +155 -155
- package/src/calendar.js +0 -2
- package/src/card.js +0 -2
- package/src/checkbox.js +0 -2
- package/src/component.js +0 -2
- package/src/container.js +0 -2
- package/src/datehour.js +38 -0
- package/src/dialog.js +105 -152
- package/src/divider.js +0 -2
- package/src/drawer.js +0 -2
- package/src/{control/file.js → file.js} +15 -45
- package/src/form/verify.js +2 -2
- package/src/form.js +0 -2
- package/src/icon.js +0 -2
- package/src/image.js +39 -106
- package/src/item.js +0 -2
- package/src/{control/link.js → link.js} +13 -32
- package/src/list/build.js +2 -2
- package/src/list/collection.js +1 -1
- package/src/list/filter.js +2 -2
- package/src/list/request.js +1 -1
- package/src/list/search.js +5 -5
- package/src/list.js +29 -217
- package/src/loading.js +73 -0
- package/src/menu.js +60 -116
- package/src/mixin/display.js +0 -1
- package/src/mixin/insert.js +2 -24
- package/src/{control/module → module}/attributes.js +2 -2
- package/src/module/build.js +8 -5
- package/src/navigation.js +19 -0
- package/src/progress.js +0 -2
- package/src/search.js +71 -0
- package/src/select.js +57 -272
- package/src/{control/selecter.js → selecter.js} +5 -5
- package/src/skin/material/component/navigation.sass +1 -0
- package/src/skin/material/control/button.sass +10 -0
- package/src/slider.js +0 -2
- package/src/snackbar.js +72 -51
- package/src/switch.js +111 -103
- package/src/{control/switcher.js → switcher.js} +17 -20
- package/src/text.js +25 -74
- package/src/textfield.js +96 -233
- package/src/banner.js +0 -231
- package/src/control/button.js +0 -239
- package/src/control/button.new.js +0 -190
- package/src/control/datehour.js +0 -65
- package/src/control/dialog.js +0 -175
- package/src/control/image.js +0 -92
- package/src/control/list.js +0 -67
- package/src/control/loading.js +0 -128
- package/src/control/menu.js +0 -85
- package/src/control/search.js +0 -98
- package/src/control/select.js +0 -130
- package/src/control/snackbar.js +0 -91
- package/src/control/switch.js +0 -272
- package/src/control/text.js +0 -70
- package/src/control/textfield.js +0 -177
- package/src/tabs/setup.js +0 -0
- /package/src/{control/module → module}/addclass.js +0 -0
package/src/textfield.js
CHANGED
|
@@ -1,307 +1,170 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
1
|
import emitter from './module/emitter'
|
|
4
2
|
import attach from './module/attach'
|
|
3
|
+
import dataset from './module/dataset'
|
|
4
|
+
import attributes from './module/attributes'
|
|
5
5
|
|
|
6
|
-
var defaults = {
|
|
7
|
-
prefix: 'material',
|
|
8
|
-
class: 'textfield',
|
|
9
|
-
type: 'control',
|
|
10
|
-
tag: 'div',
|
|
11
|
-
events: [
|
|
12
|
-
// 'change': '_onChange',
|
|
13
|
-
['input.focus', 'focus'],
|
|
14
|
-
['input.blur', 'blur'],
|
|
15
|
-
// ['input.keypress', '_handleInputKeyPress',
|
|
16
|
-
['input.keyup', '_handleInputKeyPress']
|
|
17
|
-
// ['input.change', '_onChange']
|
|
18
|
-
// 'input.keydown': '_handleInputKeyPress'
|
|
19
|
-
|
|
20
|
-
]
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Textfield class
|
|
25
|
-
* @class
|
|
26
|
-
*/
|
|
27
6
|
class Textfield {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
* @return {Object} Class instance
|
|
32
|
-
*/
|
|
33
|
-
constructor (options) {
|
|
34
|
-
this.options = Object.assign({}, defaults, options || {})
|
|
7
|
+
static isComponent () {
|
|
8
|
+
return true
|
|
9
|
+
}
|
|
35
10
|
|
|
36
|
-
|
|
11
|
+
static defaults = {
|
|
12
|
+
class: 'textfield',
|
|
13
|
+
attributes: ['type', 'name', 'title', 'maxlength', 'pattern', 'min', 'max', 'placeholder', 'readonly', 'autocomplete', 'required', 'disabled'],
|
|
14
|
+
events: [
|
|
15
|
+
['input.input', 'onInput'],
|
|
16
|
+
['input.focus', 'onFocus'],
|
|
17
|
+
['input.blur', 'onBlur'],
|
|
18
|
+
['input.click', 'onClick']
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
constructor (options) {
|
|
23
|
+
this.init(options)
|
|
37
24
|
this.build()
|
|
38
25
|
this.attach()
|
|
39
|
-
|
|
40
|
-
return this
|
|
41
26
|
}
|
|
42
27
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
*/
|
|
48
|
-
init () {
|
|
49
|
-
Object.assign(this, emitter, attach)
|
|
50
|
-
|
|
51
|
-
this.value = this.options.value
|
|
52
|
-
this.readonly = this.options.readonly
|
|
53
|
-
this.disabled = this.options.disabled
|
|
54
|
-
|
|
55
|
-
return this
|
|
28
|
+
init (options) {
|
|
29
|
+
this.options = Object.assign({}, Textfield.defaults, options || {})
|
|
30
|
+
Object.assign(this, emitter, attach, dataset)
|
|
31
|
+
// console.log('options', options)
|
|
56
32
|
}
|
|
57
33
|
|
|
58
|
-
/**
|
|
59
|
-
* [build description]
|
|
60
|
-
* @return {Object} The class instance
|
|
61
|
-
*/
|
|
62
34
|
build () {
|
|
63
|
-
// create a new div as input element
|
|
64
35
|
var tag = this.options.tag || 'div'
|
|
36
|
+
|
|
65
37
|
this.element = document.createElement(tag)
|
|
66
|
-
this.element.classList.add(
|
|
38
|
+
this.element.classList.add('textfield')
|
|
39
|
+
|
|
40
|
+
if (this.options.class !== 'textfield') {
|
|
41
|
+
this.element.classList.add(this.options.class)
|
|
42
|
+
}
|
|
67
43
|
|
|
68
44
|
this.buildLabel()
|
|
69
45
|
this.buildInput()
|
|
70
|
-
this.buildUnderline()
|
|
71
46
|
|
|
72
|
-
if (this.
|
|
73
|
-
|
|
47
|
+
if (this.options.value) {
|
|
48
|
+
this.set(this.options.value)
|
|
74
49
|
}
|
|
75
50
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
// console.log(this.name, opts.container);
|
|
79
|
-
insert(this.element, this.options.container)
|
|
51
|
+
if (this.options.data) {
|
|
52
|
+
dataset(this.element, this.options.data)
|
|
80
53
|
}
|
|
54
|
+
|
|
55
|
+
if (this.container) {
|
|
56
|
+
this.container.appendChild(this.element)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return this
|
|
81
60
|
}
|
|
82
61
|
|
|
83
62
|
buildLabel () {
|
|
84
|
-
this.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
this.setLabel()
|
|
63
|
+
if (this.options.label) {
|
|
64
|
+
this.label = document.createElement('label')
|
|
65
|
+
this.label.classList.add('label')
|
|
66
|
+
this.label.innerHTML = this.options.label
|
|
67
|
+
this.element.appendChild(this.label)
|
|
90
68
|
}
|
|
91
69
|
}
|
|
92
70
|
|
|
93
|
-
/**
|
|
94
|
-
* [_initInput description]
|
|
95
|
-
* @return {Object} The class instance
|
|
96
|
-
*/
|
|
97
71
|
buildInput () {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
this.element.appendChild(this.input)
|
|
102
|
-
|
|
103
|
-
if (this.options.name) {
|
|
104
|
-
this.input.setAttribute('name', this.options.name)
|
|
72
|
+
let tag = 'input'
|
|
73
|
+
if (this.options.type === 'multiline') {
|
|
74
|
+
tag = 'textarea'
|
|
105
75
|
}
|
|
106
76
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (this.readonly) {
|
|
112
|
-
this.input.setAttribute('readonly', 'readonly')
|
|
113
|
-
this.input.setAttribute('tabindex', '-1')
|
|
114
|
-
}
|
|
77
|
+
this.input = document.createElement(tag)
|
|
78
|
+
this.input.classList.add('input')
|
|
115
79
|
|
|
116
|
-
|
|
117
|
-
}
|
|
80
|
+
this.element.appendChild(this.input)
|
|
118
81
|
|
|
119
|
-
|
|
120
|
-
* _initUnderline
|
|
121
|
-
* @return {Object} The class instance
|
|
122
|
-
*/
|
|
123
|
-
buildUnderline () {
|
|
124
|
-
this.underline = document.createElement('span')
|
|
125
|
-
this.underline.classList.add(this.options.class + '-underline')
|
|
126
|
-
this.element.appendChild(this.underline)
|
|
127
|
-
}
|
|
82
|
+
attributes(this.input, this.options)
|
|
128
83
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
* @param {string} prop
|
|
132
|
-
* @param {string} value
|
|
133
|
-
*/
|
|
134
|
-
set (prop, value, options) {
|
|
135
|
-
switch (prop) {
|
|
136
|
-
case 'value':
|
|
137
|
-
this.setValue(value, options)
|
|
138
|
-
break
|
|
139
|
-
case 'label':
|
|
140
|
-
this.setLabel(value, options)
|
|
141
|
-
break
|
|
142
|
-
case 'disabled':
|
|
143
|
-
if (value === true) {
|
|
144
|
-
this.disable()
|
|
145
|
-
} else if (value === false) {
|
|
146
|
-
this.enable()
|
|
147
|
-
}
|
|
148
|
-
break
|
|
149
|
-
default:
|
|
150
|
-
this.setValue(prop, value)
|
|
84
|
+
if (this.options.focus) {
|
|
85
|
+
this.input.focus()
|
|
151
86
|
}
|
|
152
|
-
|
|
153
|
-
return this
|
|
154
87
|
}
|
|
155
88
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
* @return {Object} The class instance
|
|
159
|
-
*/
|
|
160
|
-
setLabel (label) {
|
|
161
|
-
label = label || this.options.label
|
|
162
|
-
var text
|
|
163
|
-
|
|
164
|
-
if (label === null || label === false) {
|
|
165
|
-
text = ''
|
|
166
|
-
} else if (this.options.label) {
|
|
167
|
-
text = label
|
|
168
|
-
} else {
|
|
169
|
-
text = this.options.name
|
|
170
|
-
}
|
|
89
|
+
onInput (ev) {
|
|
90
|
+
// console.log('onInput', this.value, this.input.value)
|
|
171
91
|
|
|
172
|
-
this.
|
|
92
|
+
this.emit('change', ev)
|
|
173
93
|
}
|
|
174
94
|
|
|
175
|
-
|
|
176
|
-
this.
|
|
177
|
-
|
|
178
|
-
this.input.setAttribute('disabled', 'disabled')
|
|
179
|
-
this.element.classList.add('is-disabled')
|
|
180
|
-
return this
|
|
95
|
+
onFocus (ev) {
|
|
96
|
+
this.element.classList.add('focused')
|
|
97
|
+
this.emit('focus', ev)
|
|
181
98
|
}
|
|
182
99
|
|
|
183
|
-
|
|
184
|
-
this.
|
|
100
|
+
onBlur (ev) {
|
|
101
|
+
this.element.classList.remove('focused')
|
|
102
|
+
this.emit('blur', ev)
|
|
103
|
+
}
|
|
185
104
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
105
|
+
onClick (ev) {
|
|
106
|
+
// console.log('click')
|
|
107
|
+
this.emit('click', ev)
|
|
189
108
|
}
|
|
190
109
|
|
|
191
110
|
/**
|
|
192
|
-
*
|
|
111
|
+
* Setter
|
|
193
112
|
* @param {string} prop
|
|
194
113
|
* @param {string} value
|
|
114
|
+
* @return {Object} The class instance
|
|
195
115
|
*/
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
116
|
+
set (prop, value) {
|
|
117
|
+
// console.log('set', this.element, prop, value)
|
|
199
118
|
switch (prop) {
|
|
200
119
|
case 'value':
|
|
201
|
-
|
|
120
|
+
this.setValue(value)
|
|
202
121
|
break
|
|
203
|
-
case '
|
|
204
|
-
|
|
122
|
+
case 'label':
|
|
123
|
+
this.setLabel(value)
|
|
205
124
|
break
|
|
206
125
|
default:
|
|
207
|
-
|
|
126
|
+
// console.log('prop', prop)
|
|
127
|
+
this.setValue(prop)
|
|
208
128
|
}
|
|
209
129
|
|
|
210
|
-
return
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* [getValue description]
|
|
215
|
-
* @return {Object} The class instance
|
|
216
|
-
*/
|
|
217
|
-
getValue () {
|
|
218
|
-
// console.log('getValue', this);
|
|
219
|
-
return this.input.value
|
|
130
|
+
return this
|
|
220
131
|
}
|
|
221
132
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
// console.log('setValue', value, silent);
|
|
228
|
-
this.input.value = value
|
|
229
|
-
|
|
230
|
-
if (value) {
|
|
231
|
-
this.element.classList.remove('is-empty')
|
|
133
|
+
setValue (value) {
|
|
134
|
+
// console.log('set', typeof value, value)
|
|
135
|
+
if (value && value !== 'undefined') {
|
|
136
|
+
this.value = value
|
|
137
|
+
this.input.value = value
|
|
232
138
|
} else {
|
|
233
|
-
this.
|
|
139
|
+
this.input.value = ''
|
|
234
140
|
}
|
|
235
|
-
|
|
236
|
-
if (!silent) { this.emit('change', value) }
|
|
237
141
|
}
|
|
238
142
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
_initValue () {
|
|
244
|
-
var opts = this.options
|
|
245
|
-
|
|
246
|
-
// create a new div as input element
|
|
247
|
-
if (opts.value) {
|
|
248
|
-
this.setValue(opts.value)
|
|
143
|
+
setLabel (value) {
|
|
144
|
+
// console.log('setLabel', value)
|
|
145
|
+
if (this.label) {
|
|
146
|
+
this.label.innerHTML = value
|
|
249
147
|
}
|
|
250
148
|
}
|
|
251
149
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
* @return {Object} The class instance
|
|
255
|
-
*/
|
|
256
|
-
_handleInputKeyPress (e) {
|
|
257
|
-
// console.log('_handleInputKeyPress', e);
|
|
258
|
-
if (this.readonly) return
|
|
150
|
+
setText (value) {
|
|
151
|
+
this.setLabel(value)
|
|
259
152
|
|
|
260
|
-
if (this.
|
|
261
|
-
this.
|
|
262
|
-
} else {
|
|
263
|
-
this.element.classList.remove('is-empty')
|
|
153
|
+
if (this.options.placeholder) {
|
|
154
|
+
this.input.placeholder = value
|
|
264
155
|
}
|
|
265
|
-
|
|
266
|
-
this.emit('change', this.getValue())
|
|
267
156
|
}
|
|
268
157
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
* @return {?} [description]
|
|
272
|
-
*/
|
|
273
|
-
focus () {
|
|
274
|
-
if (this.disabled) return this
|
|
275
|
-
if (this.readonly) return this
|
|
276
|
-
|
|
277
|
-
this.element.classList.add('is-focused')
|
|
278
|
-
if (this.input !== document.activeElement) { this.input.focus() }
|
|
279
|
-
return this
|
|
158
|
+
hide () {
|
|
159
|
+
this.element.classList.add('hide')
|
|
280
160
|
}
|
|
281
161
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
* @return {?} [description]
|
|
285
|
-
*/
|
|
286
|
-
blur () {
|
|
287
|
-
if (this.readonly) return this
|
|
288
|
-
|
|
289
|
-
this.element.classList.remove('is-focused')
|
|
290
|
-
|
|
291
|
-
return this
|
|
162
|
+
show () {
|
|
163
|
+
this.element.classList.remove('hide')
|
|
292
164
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
*/
|
|
297
|
-
setError (error) {
|
|
298
|
-
if (error) {
|
|
299
|
-
this.addClass('field-error')
|
|
300
|
-
if (this.error) { this.error.set('html', error) }
|
|
301
|
-
} else {
|
|
302
|
-
if (this.error) { this.removeClass('field-error') }
|
|
303
|
-
if (this.error) { this.error.set('html', '') }
|
|
304
|
-
}
|
|
165
|
+
|
|
166
|
+
get () {
|
|
167
|
+
return this.input.value
|
|
305
168
|
}
|
|
306
169
|
}
|
|
307
170
|
|
package/src/banner.js
DELETED
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
import create from './mixin/create'
|
|
4
|
-
import insert from './element/insert'
|
|
5
|
-
import event from './element/event'
|
|
6
|
-
import offset from './element/offset'
|
|
7
|
-
import emitter from './module/emitter'
|
|
8
|
-
|
|
9
|
-
const defaults = {
|
|
10
|
-
prefix: 'material',
|
|
11
|
-
class: 'banner',
|
|
12
|
-
tag: 'div'
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Class representing a UI Container. Can add components.
|
|
17
|
-
*
|
|
18
|
-
* @extends Component
|
|
19
|
-
* @return {parent} The class instance
|
|
20
|
-
* @example new Container({
|
|
21
|
-
* container: document.body
|
|
22
|
-
* });
|
|
23
|
-
*/
|
|
24
|
-
class Banner {
|
|
25
|
-
/**
|
|
26
|
-
* Constructor
|
|
27
|
-
* @param {Object} options - Component options
|
|
28
|
-
* @return {Object} Class instance
|
|
29
|
-
*/
|
|
30
|
-
constructor (options) {
|
|
31
|
-
// init and build
|
|
32
|
-
this.init(options)
|
|
33
|
-
this.build()
|
|
34
|
-
this.attach()
|
|
35
|
-
|
|
36
|
-
return this
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Init class
|
|
41
|
-
* @params {Object} options The instance options
|
|
42
|
-
* @return {Object} This class instance
|
|
43
|
-
*/
|
|
44
|
-
init (options) {
|
|
45
|
-
this.options = Object.assign({}, defaults, options || {})
|
|
46
|
-
Object.assign(this, emitter)
|
|
47
|
-
|
|
48
|
-
return this
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* [build description]
|
|
53
|
-
* @return {Object} This class instance
|
|
54
|
-
*/
|
|
55
|
-
build () {
|
|
56
|
-
this.element = create(this.options)
|
|
57
|
-
|
|
58
|
-
if (this.options.container) {
|
|
59
|
-
insert(this.element, this.options.container)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return this
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
attach () {
|
|
66
|
-
event.add(this.element, 'click', (ev) => {
|
|
67
|
-
// console.log('click', ev.target)
|
|
68
|
-
|
|
69
|
-
if (ev.target && ev.target.classList.contains('material-button')) {
|
|
70
|
-
var name = ev.target.getAttribute('data-name')
|
|
71
|
-
// console.log('name', name)
|
|
72
|
-
this.emit('select', name)
|
|
73
|
-
this.dismiss(ev.target)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
ev.stopPropagation()
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
this.element.addEventListener('DOMNodeInserted', (e) => {
|
|
80
|
-
// console.log('DOMNodeInserted', e.target)
|
|
81
|
-
var textNode = e.target
|
|
82
|
-
|
|
83
|
-
if (textNode == this.element) {
|
|
84
|
-
// console.log('banner root inserted', e.target)
|
|
85
|
-
if (!this.wrapper) { this.wrap() }
|
|
86
|
-
this.scroll(this.view)
|
|
87
|
-
}
|
|
88
|
-
this.updatePaddingView()
|
|
89
|
-
|
|
90
|
-
// if (textNode !== this.element) return
|
|
91
|
-
})
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
dismiss () {
|
|
95
|
-
this.wrapper.classList.add('is-closed')
|
|
96
|
-
this.wrapper.style.height = '0'
|
|
97
|
-
this.updatePaddingView()
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
show () {
|
|
101
|
-
console.log('this.height', this.height)
|
|
102
|
-
this.wrapper.classList.remove('is-closed')
|
|
103
|
-
this.wrapper.style.height = this.height + 'px'
|
|
104
|
-
this.updatePaddingView()
|
|
105
|
-
this.updatePosition()
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
wrap () {
|
|
109
|
-
this.view = this.element.parentNode
|
|
110
|
-
|
|
111
|
-
// console.log('wrap', this.element, this.view)
|
|
112
|
-
this.wrapper = document.createElement('div')
|
|
113
|
-
|
|
114
|
-
this.wrapper.classList.add('banner-wrapper')
|
|
115
|
-
|
|
116
|
-
this.view.insertBefore(this.wrapper, this.element)
|
|
117
|
-
|
|
118
|
-
this.wrapper.appendChild(this.element)
|
|
119
|
-
|
|
120
|
-
// insert(this.wrapper, this.element, 'before')
|
|
121
|
-
|
|
122
|
-
// insert(this.element, this.wrapper)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
updatePaddingView () {
|
|
126
|
-
// console.log('updatePaddingView', this.view)
|
|
127
|
-
|
|
128
|
-
this.height = offset(this.element, 'height')
|
|
129
|
-
if (!this.paddingview) {
|
|
130
|
-
this.paddingview = window.getComputedStyle(this.view)['padding-top']
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// this.element.style.top = 'top: ' + this.paddingview
|
|
134
|
-
|
|
135
|
-
// console.log('paddingTop', padding)
|
|
136
|
-
// if (!padding) padding = window.getComputedStyle(this.element.parentNode, 'padding')
|
|
137
|
-
// console.log('padding', padding)
|
|
138
|
-
|
|
139
|
-
var padding = parseInt(this.paddingview, 10)
|
|
140
|
-
var size = parseInt(this.height, 10)
|
|
141
|
-
|
|
142
|
-
this.padding = padding
|
|
143
|
-
|
|
144
|
-
// console.log(' banner inserted in', size, 'padding', padding)
|
|
145
|
-
//
|
|
146
|
-
//
|
|
147
|
-
|
|
148
|
-
var ptop = this.ptop = padding
|
|
149
|
-
|
|
150
|
-
if (this.wrapper.classList.contains('is-fixed') && !this.wrapper.classList.contains('is-closed')) {
|
|
151
|
-
var ptop = this.ptop = size + padding
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
this.view.setAttribute('style', 'padding-top: ' + ptop + 'px')
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
scroll (view) {
|
|
158
|
-
// console.log('initScroll', offset(this.element, 'top'), offset(view, 'top'))
|
|
159
|
-
|
|
160
|
-
var isBody = false
|
|
161
|
-
|
|
162
|
-
var element = view
|
|
163
|
-
|
|
164
|
-
this.scrolling = view
|
|
165
|
-
|
|
166
|
-
if (view === document.body) {
|
|
167
|
-
isBody = true
|
|
168
|
-
element = document
|
|
169
|
-
this.scrolling = document.body
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// view.classList.add()
|
|
173
|
-
|
|
174
|
-
element.addEventListener('scroll', (e) => {
|
|
175
|
-
// console.log('scroll', this.view)
|
|
176
|
-
this.updatePosition()
|
|
177
|
-
})
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
updatePosition () {
|
|
181
|
-
var view = this.view
|
|
182
|
-
var scrollTop
|
|
183
|
-
if (view === document.body) {
|
|
184
|
-
scrollTop = (document.documentElement ||
|
|
185
|
-
document.body.parentNode ||
|
|
186
|
-
document.body).scrollTop
|
|
187
|
-
} else {
|
|
188
|
-
scrollTop = view.scrollTop
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// var o = offset(this.element, 'top') - offset(view, 'top')
|
|
192
|
-
// console.log('o', this.element.offsetTop)
|
|
193
|
-
|
|
194
|
-
var padding = this.paddingview
|
|
195
|
-
padding = parseInt(padding, 10)
|
|
196
|
-
|
|
197
|
-
// console.log('scroll', scrollTop, padding)
|
|
198
|
-
|
|
199
|
-
if (scrollTop > padding) {
|
|
200
|
-
var y = scrollTop - padding
|
|
201
|
-
// console.log('fixed', y)
|
|
202
|
-
this.wrapper.classList.add('is-fixed')
|
|
203
|
-
this.wrapper.style.transform = 'translateY(' + y + 'px)'
|
|
204
|
-
|
|
205
|
-
// this.update(scrollTop, padding)
|
|
206
|
-
// this.wrapper.setAttribute('style', 'top: ' + this.paddingview)
|
|
207
|
-
this.wrapper.style.top = this.paddingview
|
|
208
|
-
} else {
|
|
209
|
-
// console.log('relative')
|
|
210
|
-
this.wrapper.classList.remove('is-fixed')
|
|
211
|
-
this.wrapper.style.transform = 'translateY(' + 0 + 'px)'
|
|
212
|
-
this.wrapper.style.top = '0'
|
|
213
|
-
// this.wrapper.setAttribute('style', 'top: ' + this.paddingview)
|
|
214
|
-
// this.wrapper.setAttribute('style', 'top: 0')
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
this.updatePaddingView()
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
update (scrollTop, padding) {
|
|
221
|
-
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
insert (container, context) {
|
|
225
|
-
insert(this.element, container, context)
|
|
226
|
-
|
|
227
|
-
return this
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
export default Banner
|