@websy/websy-designs 1.1.1 → 1.1.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/dist/websy-designs.debug.js +187 -0
- package/dist/websy-designs.js +675 -0
- package/dist/websy-designs.min.css +5 -1
- package/dist/websy-designs.min.js +5 -1
- package/index.js +8 -8
- package/package.json +2 -2
|
@@ -22,7 +22,11 @@
|
|
|
22
22
|
APIService
|
|
23
23
|
ButtonGroup
|
|
24
24
|
WebsyUtils
|
|
25
|
+
<<<<<<< HEAD
|
|
26
|
+
WebsyCarousel
|
|
27
|
+
=======
|
|
25
28
|
Pager
|
|
29
|
+
>>>>>>> master
|
|
26
30
|
*/
|
|
27
31
|
|
|
28
32
|
/* global XMLHttpRequest fetch ENV */
|
|
@@ -197,6 +201,189 @@ class ButtonGroup {
|
|
|
197
201
|
}
|
|
198
202
|
}
|
|
199
203
|
|
|
204
|
+
/* global */
|
|
205
|
+
|
|
206
|
+
class WebsyCarousel {
|
|
207
|
+
constructor (elementId, options) {
|
|
208
|
+
const DEFAULTS = {
|
|
209
|
+
currentFrame: 0,
|
|
210
|
+
frameDuration: 4000,
|
|
211
|
+
showFrameSelector: true,
|
|
212
|
+
showPrevNext: true
|
|
213
|
+
}
|
|
214
|
+
this.playTimeoutFn = null
|
|
215
|
+
this.options = Object.assign({}, DEFAULTS, options)
|
|
216
|
+
if (!elementId) {
|
|
217
|
+
console.log('No element Id provided')
|
|
218
|
+
}
|
|
219
|
+
const el = document.getElementById(elementId)
|
|
220
|
+
if (el) {
|
|
221
|
+
this.elementId = elementId
|
|
222
|
+
el.addEventListener('click', this.handleClick.bind(this))
|
|
223
|
+
this.render()
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
handleClick (event) {
|
|
227
|
+
if (event.target.classList.contains('websy-next-arrow')) {
|
|
228
|
+
this.next()
|
|
229
|
+
}
|
|
230
|
+
if (event.target.classList.contains('websy-prev-arrow')) {
|
|
231
|
+
this.prev()
|
|
232
|
+
}
|
|
233
|
+
if (event.target.classList.contains('websy-progress-btn' || 'websy-progress-btn-active')) {
|
|
234
|
+
const index = +event.target.getAttribute('data-index')
|
|
235
|
+
let prevFrameIndex = this.options.currentFrame
|
|
236
|
+
this.options.currentFrame = index
|
|
237
|
+
this.showFrame(prevFrameIndex, index)
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
next () {
|
|
241
|
+
this.pause()
|
|
242
|
+
let prevFrameIndex = this.options.currentFrame
|
|
243
|
+
if (this.options.currentFrame === this.options.frames.length - 1) {
|
|
244
|
+
this.options.currentFrame = 0
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
this.options.currentFrame++
|
|
248
|
+
}
|
|
249
|
+
this.showFrame(prevFrameIndex, this.options.currentFrame)
|
|
250
|
+
// this.play()
|
|
251
|
+
// document.getElementById(`${this.elementId}_frame_${this.options.currentFrame}`)
|
|
252
|
+
// .style.transform = `translateX(-100%)`
|
|
253
|
+
// if (`${this.options.currentFrame === this.options.frames.length - 1}`) {
|
|
254
|
+
// document.getElementById`${this.elementId}_frame_${this.options.currentFrame}`.style.transform = `translateX('-100%')`
|
|
255
|
+
// }
|
|
256
|
+
}
|
|
257
|
+
pause () {
|
|
258
|
+
if (this.playTimeoutFn) {
|
|
259
|
+
clearTimeout(this.playTimeoutFn)
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
play () {
|
|
263
|
+
this.playTimeoutFn = setTimeout(() => {
|
|
264
|
+
let prevFrameIndex = this.options.currentFrame
|
|
265
|
+
if (this.options.currentFrame === this.options.frames.length - 1) {
|
|
266
|
+
this.options.currentFrame = 0
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
this.options.currentFrame++
|
|
270
|
+
}
|
|
271
|
+
this.showFrame(prevFrameIndex, this.options.currentFrame)
|
|
272
|
+
this.play()
|
|
273
|
+
}, this.options.frameDuration)
|
|
274
|
+
}
|
|
275
|
+
prev () {
|
|
276
|
+
this.pause()
|
|
277
|
+
let prevFrameIndex = this.options.currentFrame
|
|
278
|
+
if (this.options.currentFrame === 0) {
|
|
279
|
+
this.options.currentFrame = this.options.frames.length - 1
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
this.options.currentFrame--
|
|
283
|
+
}
|
|
284
|
+
this.showFrame(prevFrameIndex, this.options.currentFrame)
|
|
285
|
+
// this.play()
|
|
286
|
+
// document.getElementById(`${this.elementId}_frame_${this.options.currentFrame}`)
|
|
287
|
+
// .style.transform = `translateX(100%)`
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
render (options) {
|
|
291
|
+
this.options = Object.assign({}, this.options, options)
|
|
292
|
+
this.resize()
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
resize () {
|
|
296
|
+
const el = document.getElementById(this.elementId)
|
|
297
|
+
if (el) {
|
|
298
|
+
let html = `
|
|
299
|
+
<div class="websy-carousel">
|
|
300
|
+
`
|
|
301
|
+
this.options.frames.forEach((frame, frameIndex) => {
|
|
302
|
+
html += `
|
|
303
|
+
<div id="${this.elementId}_frame_${frameIndex}" class="websy-frame-container animate" style="transform: translateX(${frameIndex === 0 ? '0' : '100%'})">
|
|
304
|
+
`
|
|
305
|
+
frame.images.forEach(image => {
|
|
306
|
+
html += `
|
|
307
|
+
<div style="${image.style || 'position: absolute; width: 100%; height: 100%; top: 0; left: 0;'} background-image: url('${image.url}')" class="${image.classes || ''} websy-carousel-image">
|
|
308
|
+
</div>
|
|
309
|
+
`
|
|
310
|
+
})
|
|
311
|
+
frame.text && frame.text.forEach(text => {
|
|
312
|
+
html += `
|
|
313
|
+
<div style="${text.style || 'position: absolute; width: 100%; height: 100%; top: 0; left: 0;'}" class="${text.classes || ''} websy-carousel-image">
|
|
314
|
+
${text.html}
|
|
315
|
+
</div>
|
|
316
|
+
`
|
|
317
|
+
})
|
|
318
|
+
html += `</div>`
|
|
319
|
+
})
|
|
320
|
+
if (this.options.showFrameSelector === true) {
|
|
321
|
+
html += `<div class="websy-btn-parent">`
|
|
322
|
+
this.options.frames.forEach((frame, frameIndex) => {
|
|
323
|
+
html += `
|
|
324
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" data-index="${frameIndex}" id="${this.elementId}_selector_${frameIndex}"
|
|
325
|
+
class="websy-progress-btn ${this.options.currentFrame === frameIndex ? 'websy-progress-btn-active' : ''}">
|
|
326
|
+
<title>Ellipse</title><circle cx="256" cy="256" r="192" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32"/>
|
|
327
|
+
</svg>
|
|
328
|
+
`
|
|
329
|
+
})
|
|
330
|
+
html += `</div>`
|
|
331
|
+
}
|
|
332
|
+
if (this.options.showPrevNext === true) {
|
|
333
|
+
html += `
|
|
334
|
+
<svg xmlns="http://www.w3.org/2000/svg" class="websy-prev-arrow"
|
|
335
|
+
viewBox="0 0 512 512">
|
|
336
|
+
<title>Caret Back</title>
|
|
337
|
+
<path d="M321.94 98L158.82 237.78a24 24 0 000 36.44L321.94 414c15.57 13.34 39.62 2.28 39.62-18.22v-279.6c0-20.5-24.05-31.56-39.62-18.18z"/>
|
|
338
|
+
</svg>
|
|
339
|
+
</div>
|
|
340
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" class="websy-next-arrow">
|
|
341
|
+
<title>Caret Forward</title>
|
|
342
|
+
<path d="M190.06 414l163.12-139.78a24 24 0 000-36.44L190.06 98c-15.57-13.34-39.62-2.28-39.62 18.22v279.6c0 20.5 24.05 31.56 39.62 18.18z"/>
|
|
343
|
+
</svg>
|
|
344
|
+
`
|
|
345
|
+
}
|
|
346
|
+
html += `
|
|
347
|
+
</div>
|
|
348
|
+
`
|
|
349
|
+
el.innerHTML = html
|
|
350
|
+
}
|
|
351
|
+
// this.play()
|
|
352
|
+
// this.showFrameSelector()
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
showFrame (prevFrameIndex, currFrameIndex) {
|
|
356
|
+
let prevTranslateX = prevFrameIndex > currFrameIndex ? '100%' : '-100%'
|
|
357
|
+
let nextTranslateX = prevFrameIndex < currFrameIndex ? '100%' : '-100%'
|
|
358
|
+
if (currFrameIndex === 0 && prevFrameIndex === this.options.frames.length - 1) {
|
|
359
|
+
prevTranslateX = '-100%'
|
|
360
|
+
nextTranslateX = '100%'
|
|
361
|
+
}
|
|
362
|
+
else if (prevFrameIndex === 0 && currFrameIndex === this.options.frames.length - 1) {
|
|
363
|
+
prevTranslateX = '100%'
|
|
364
|
+
nextTranslateX = '-100%'
|
|
365
|
+
}
|
|
366
|
+
const prevF = document.getElementById(
|
|
367
|
+
`${this.elementId}_frame_${prevFrameIndex}`)
|
|
368
|
+
prevF.style.transform = `translateX(${prevTranslateX})`
|
|
369
|
+
const btnInactive = document.getElementById(`${this.elementId}_selector_${prevFrameIndex}`)
|
|
370
|
+
btnInactive.classList.remove('websy-progress-btn-active')
|
|
371
|
+
const newF = document.getElementById(`${this.elementId}_frame_${currFrameIndex}`)
|
|
372
|
+
newF.classList.remove('animate')
|
|
373
|
+
newF.style.transform = `translateX(${nextTranslateX})`
|
|
374
|
+
setTimeout(() => {
|
|
375
|
+
newF.classList.add('animate')
|
|
376
|
+
newF.style.transform = 'translateX(0%)'
|
|
377
|
+
}, 100)
|
|
378
|
+
|
|
379
|
+
const btnActive = document.getElementById(`${this.elementId}_selector_${currFrameIndex}`)
|
|
380
|
+
btnActive.classList.add('websy-progress-btn-active')
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// showFrameSelector () {
|
|
384
|
+
// }
|
|
385
|
+
}
|
|
386
|
+
|
|
200
387
|
class WebsyDatePicker {
|
|
201
388
|
constructor (elementId, options) {
|
|
202
389
|
this.oneDay = 1000 * 60 * 60 * 24
|