PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 4.3.1
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v4.3.1
4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.4.0 4.4.1 4.4.10 4.4.11 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5.0 4.5.1
embedpress / assets / js / glider.js
embedpress / assets / js Last commit date
vendor 7 years ago admin.js 1 year ago ads.js 1 year ago carousel.js 1 year ago carousel.min.js 2 years ago documents-viewer-script.js 3 years ago embed-ui.min.js 11 months ago front.js 1 year ago gallery-justify.js 1 year ago glider.js 1 year ago glider.min.js 2 years ago gutneberg-script.js 1 year ago index.html 7 years ago initCarousel.js 2 years ago initplyr.js 2 years ago instafeed.js 2 years ago license.js 2 years ago pdfobject.js 1 year ago plyr.js 1 year ago plyr.polyfilled.js 3 years ago preview.js 10 months ago remove-round-button.js 11 months ago settings.js 6 years ago vimeo-player.js 2 years ago ytiframeapi.js 2 years ago
glider.js
610 lines
1 /* @preserve
2 _____ __ _ __ _
3 / ___// /(_)___/ /___ ____ (_)___
4 / (_ // // // _ // -_)/ __/_ / /(_-<
5 \___//_//_/ \_,_/ \__//_/ (_)__/ //___/
6 |___/
7
8 Version: 1.7.4
9 Author: Nick Piscitelli (pickykneee)
10 Website: https://nickpiscitelli.com
11 Documentation: http://nickpiscitelli.github.io/Glider.js
12 License: MIT License
13 Release Date: October 25th, 2018
14
15 */
16
17 /* global define */
18
19 (function (factory) {
20 typeof define === 'function' && define.amd
21 ? define(factory)
22 : typeof exports === 'object'
23 ? (module.exports = factory())
24 : factory()
25 })(function () {
26 ('use strict') // eslint-disable-line no-unused-expressions
27
28 /* globals window:true */
29 var _window = typeof window !== 'undefined' ? window : this
30
31 var Glider = (_window.Glider = function (element, settings) {
32 var _ = this
33
34 if (element._glider) return element._glider
35
36 _.ele = element
37 _.ele.classList.add('glider')
38
39 // expose glider object to its DOM element
40 _.ele._glider = _
41
42 // merge user setting with defaults
43 _.opt = Object.assign(
44 {},
45 {
46 slidesToScroll: 1,
47 slidesToShow: 1,
48 resizeLock: true,
49 duration: 0.5,
50 passiveListeners: false,
51 // easeInQuad
52 easing: function (x, t, b, c, d) {
53 return c * (t /= d) * t + b
54 }
55 },
56 settings
57 )
58
59 // set defaults
60 _.animate_id = _.page = _.slide = 0
61 _.arrows = {}
62
63 // preserve original options to
64 // extend breakpoint settings
65 _._opt = _.opt
66
67 if (_.opt.skipTrack) {
68 // first and only child is the track
69 _.track = _.ele.children[0]
70 } else {
71 // create track and wrap slides
72 _.track = document.createElement('div')
73 _.ele.appendChild(_.track)
74 while (_.ele.children.length !== 1) {
75 _.track.appendChild(_.ele.children[0])
76 }
77 }
78
79 _.track.classList.add('glider-track')
80
81 // start glider
82 _.init()
83
84 // set events
85 _.resize = _.init.bind(_, true)
86 _.event(
87 _.ele,
88 'add',
89 {
90 scroll: _.updateControls.bind(_)
91 },
92 { passive: _.opt.passiveListeners }
93 )
94 _.event(_window, 'add', {
95 resize: _.resize
96 })
97 })
98
99 var gliderPrototype = Glider.prototype
100 gliderPrototype.init = function (refresh, paging) {
101 var _ = this
102
103 var width = 0
104
105 var height = 0
106
107 _.slides = _.track.children;
108
109 [].forEach.call(_.slides, function (_, i) {
110 _.classList.add('glider-slide')
111 _.setAttribute('data-gslide', i)
112 })
113
114 _.containerWidth = _.ele.clientWidth
115
116 var breakpointChanged = _.settingsBreakpoint()
117 if (!paging) paging = breakpointChanged
118
119 if (
120 _.opt.slidesToShow === 'auto' ||
121 typeof _.opt._autoSlide !== 'undefined'
122 ) {
123 var slideCount = _.containerWidth / _.opt.itemWidth
124
125 _.opt._autoSlide = _.opt.slidesToShow = _.opt.exactWidth
126 ? slideCount
127 : Math.max(1, Math.floor(slideCount))
128 }
129 if (_.opt.slidesToScroll === 'auto') {
130 _.opt.slidesToScroll = Math.floor(_.opt.slidesToShow)
131 }
132
133 _.itemWidth = _.opt.exactWidth
134 ? _.opt.itemWidth
135 : _.containerWidth / _.opt.slidesToShow;
136
137 // set slide dimensions
138 [].forEach.call(_.slides, function (__) {
139 __.style.height = 'auto'
140 __.style.width = _.itemWidth + 'px'
141 width += _.itemWidth
142 height = Math.max(__.offsetHeight, height)
143 })
144
145 _.track.style.width = width + 'px'
146 _.trackWidth = width
147 _.isDrag = false
148 _.preventClick = false
149 _.move = false
150
151 _.opt.resizeLock && _.scrollTo(_.slide * _.itemWidth, 0)
152
153 if (breakpointChanged || paging) {
154 _.bindArrows()
155 _.buildDots()
156 _.bindDrag()
157 }
158
159 _.updateControls()
160
161 _.emit(refresh ? 'refresh' : 'loaded')
162 }
163
164 gliderPrototype.bindDrag = function () {
165 var _ = this
166 _.mouse = _.mouse || _.handleMouse.bind(_)
167
168 var mouseup = function () {
169 _.mouseDown = undefined
170 _.ele.classList.remove('drag')
171 if (_.isDrag) {
172 _.preventClick = true
173 }
174 _.isDrag = false
175 }
176
177 const move = function () {
178 _.move = true
179 }
180
181 var events = {
182 mouseup: mouseup,
183 mouseleave: mouseup,
184 mousedown: function (e) {
185 e.preventDefault()
186 e.stopPropagation()
187 _.mouseDown = e.clientX
188 _.ele.classList.add('drag')
189 _.move = false
190 setTimeout(move, 300)
191 },
192 touchstart: function (e) {
193 _.ele.classList.add('drag')
194 _.move = false
195 setTimeout(move, 300)
196 },
197 mousemove: _.mouse,
198 click: function (e) {
199 if (_.preventClick && _.move) {
200 e.preventDefault()
201 e.stopPropagation()
202 }
203 _.preventClick = false
204 _.move = false
205 }
206 }
207
208 _.ele.classList.toggle('draggable', _.opt.draggable === true)
209 _.event(_.ele, 'remove', events)
210 if (_.opt.draggable) {
211 _.event(_.ele, 'add', events, {
212 passive: _.opt.passiveListeners
213 })
214 }
215 }
216
217 gliderPrototype.buildDots = function () {
218 var _ = this
219
220 if (!_.opt.dots) {
221 if (_.dots) _.dots.innerHTML = ''
222 return
223 }
224
225 if (typeof _.opt.dots === 'string') {
226 _.dots = document.querySelector(_.opt.dots)
227 } else _.dots = _.opt.dots
228 if (!_.dots) return
229
230 _.dots.innerHTML = ''
231 _.dots.setAttribute('role', 'tablist')
232 _.dots.classList.add('glider-dots')
233
234 for (var i = 0; i < Math.ceil(_.slides.length / _.opt.slidesToShow); ++i) {
235 var dot = document.createElement('button')
236 dot.dataset.index = i
237 dot.setAttribute('aria-label', 'Page ' + (i + 1))
238 dot.setAttribute('role', 'tab')
239 dot.className = 'glider-dot ' + (i ? '' : 'active')
240 _.event(dot, 'add', {
241 click: _.scrollItem.bind(_, i, true)
242 })
243 _.dots.appendChild(dot)
244 }
245 }
246
247 gliderPrototype.bindArrows = function () {
248 var _ = this
249 if (!_.opt.arrows) {
250 Object.keys(_.arrows).forEach(function (direction) {
251 var element = _.arrows[direction]
252 _.event(element, 'remove', { click: element._func })
253 })
254 return
255 }
256 ['prev', 'next'].forEach(function (direction) {
257 var arrow = _.opt.arrows[direction]
258 if (arrow) {
259 if (typeof arrow === 'string') arrow = document.querySelector(arrow)
260 if (arrow) {
261 arrow._func = arrow._func || _.scrollItem.bind(_, direction)
262 _.event(arrow, 'remove', {
263 click: arrow._func
264 })
265 _.event(arrow, 'add', {
266 click: arrow._func
267 })
268 _.arrows[direction] = arrow
269 }
270 }
271 })
272 }
273
274 gliderPrototype.updateControls = function (event) {
275 var _ = this
276
277 if (event && !_.opt.scrollPropagate) {
278 event.stopPropagation()
279 }
280
281 var disableArrows = _.containerWidth >= _.trackWidth
282
283 if (!_.opt.rewind) {
284 if (_.arrows.prev) {
285 _.arrows.prev.classList.toggle(
286 'disabled',
287 _.ele.scrollLeft <= 0 || disableArrows
288 )
289
290 _.arrows.prev.setAttribute(
291 'aria-disabled',
292 _.arrows.prev.classList.contains('disabled')
293 )
294 }
295 if (_.arrows.next) {
296 _.arrows.next.classList.toggle(
297 'disabled',
298 Math.ceil(_.ele.scrollLeft + _.containerWidth) >=
299 Math.floor(_.trackWidth) || disableArrows
300 )
301
302 _.arrows.next.setAttribute(
303 'aria-disabled',
304 _.arrows.next.classList.contains('disabled')
305 )
306 }
307 }
308
309 _.slide = Math.round(_.ele.scrollLeft / _.itemWidth)
310 _.page = Math.round(_.ele.scrollLeft / _.containerWidth)
311
312 var middle = _.slide + Math.floor(Math.floor(_.opt.slidesToShow) / 2)
313
314 var extraMiddle = Math.floor(_.opt.slidesToShow) % 2 ? 0 : middle + 1
315 if (Math.floor(_.opt.slidesToShow) === 1) {
316 extraMiddle = 0
317 }
318
319 // the last page may be less than one half of a normal page width so
320 // the page is rounded down. when at the end, force the page to turn
321 if (_.ele.scrollLeft + _.containerWidth >= Math.floor(_.trackWidth)) {
322 _.page = _.dots ? _.dots.children.length - 1 : 0
323 }
324
325 [].forEach.call(_.slides, function (slide, index) {
326 var slideClasses = slide.classList
327
328 var wasVisible = slideClasses.contains('visible')
329
330 var start = _.ele.scrollLeft
331
332 var end = _.ele.scrollLeft + _.containerWidth
333
334 var itemStart = _.itemWidth * index
335
336 var itemEnd = itemStart + _.itemWidth;
337
338 [].forEach.call(slideClasses, function (className) {
339 /^left|right/.test(className) && slideClasses.remove(className)
340 })
341 slideClasses.toggle('active', _.slide === index)
342 if (middle === index || (extraMiddle && extraMiddle === index)) {
343 slideClasses.add('center')
344 } else {
345 slideClasses.remove('center')
346 slideClasses.add(
347 [
348 index < middle ? 'left' : 'right',
349 Math.abs(index - (index < middle ? middle : extraMiddle || middle))
350 ].join('-')
351 )
352 }
353
354 var isVisible =
355 Math.ceil(itemStart) >= Math.floor(start) &&
356 Math.floor(itemEnd) <= Math.ceil(end)
357 slideClasses.toggle('visible', isVisible)
358 if (isVisible !== wasVisible) {
359 _.emit('slide-' + (isVisible ? 'visible' : 'hidden'), {
360 slide: index
361 })
362 }
363 })
364 if (_.dots) {
365 [].forEach.call(_.dots.children, function (dot, index) {
366 dot.classList.toggle('active', _.page === index)
367 })
368 }
369
370 if (event && _.opt.scrollLock) {
371 clearTimeout(_.scrollLock)
372 _.scrollLock = setTimeout(function () {
373 clearTimeout(_.scrollLock)
374 // dont attempt to scroll less than a pixel fraction - causes looping
375 if (Math.abs(_.ele.scrollLeft / _.itemWidth - _.slide) > 0.02) {
376 if (!_.mouseDown) {
377 // Only scroll if not at the end (#94)
378 if (_.trackWidth > _.containerWidth + _.ele.scrollLeft) {
379 _.scrollItem(_.getCurrentSlide())
380 }
381 }
382 }
383 }, _.opt.scrollLockDelay || 250)
384 }
385 }
386
387 gliderPrototype.getCurrentSlide = function () {
388 var _ = this
389 return _.round(_.ele.scrollLeft / _.itemWidth)
390 }
391
392 gliderPrototype.scrollItem = function (slide, dot, e) {
393 if (e) e.preventDefault()
394
395 var _ = this
396
397 var originalSlide = slide
398 ++_.animate_id
399
400 var prevSlide = _.slide
401 var position
402
403 if (dot === true) {
404 slide = Math.round((slide * _.containerWidth) / _.itemWidth)
405 position = slide * _.itemWidth
406 } else {
407 if (typeof slide === 'string') {
408 var backwards = slide === 'prev'
409
410 // use precise location if fractional slides are on
411 if (_.opt.slidesToScroll % 1 || _.opt.slidesToShow % 1) {
412 slide = _.getCurrentSlide()
413 } else {
414 slide = _.slide
415 }
416
417 if (backwards) slide -= _.opt.slidesToScroll
418 else slide += _.opt.slidesToScroll
419
420 if (_.opt.rewind) {
421 var scrollLeft = _.ele.scrollLeft
422 slide =
423 backwards && !scrollLeft
424 ? _.slides.length
425 : !backwards &&
426 scrollLeft + _.containerWidth >= Math.floor(_.trackWidth)
427 ? 0
428 : slide
429 }
430 }
431
432 slide = Math.max(Math.min(slide, _.slides.length), 0)
433
434 _.slide = slide
435 position = _.itemWidth * slide
436 }
437
438 _.emit('scroll-item', { prevSlide, slide })
439
440 _.scrollTo(
441 position,
442 _.opt.duration * Math.abs(_.ele.scrollLeft - position),
443 function () {
444 _.updateControls()
445 _.emit('animated', {
446 value: originalSlide,
447 type:
448 typeof originalSlide === 'string' ? 'arrow' : dot ? 'dot' : 'slide'
449 })
450 }
451 )
452
453 return false
454 }
455
456 gliderPrototype.settingsBreakpoint = function () {
457 var _ = this
458
459 var resp = _._opt.responsive
460
461 if (resp) {
462 // Sort the breakpoints in mobile first order
463 resp.sort(function (a, b) {
464 return b.breakpoint - a.breakpoint
465 })
466
467 for (var i = 0; i < resp.length; ++i) {
468 var size = resp[i]
469 if (_window.innerWidth >= size.breakpoint) {
470 if (_.breakpoint !== size.breakpoint) {
471 _.opt = Object.assign({}, _._opt, size.settings)
472 _.breakpoint = size.breakpoint
473 return true
474 }
475 return false
476 }
477 }
478 }
479 // set back to defaults in case they were overriden
480 var breakpointChanged = _.breakpoint !== 0
481 _.opt = Object.assign({}, _._opt)
482 _.breakpoint = 0
483 return breakpointChanged
484 }
485
486 gliderPrototype.scrollTo = function (scrollTarget, scrollDuration, callback) {
487 var _ = this
488
489 var start = new Date().getTime()
490
491 var animateIndex = _.animate_id
492
493 var animate = function () {
494 var now = new Date().getTime() - start
495 _.ele.scrollLeft =
496 _.ele.scrollLeft +
497 (scrollTarget - _.ele.scrollLeft) *
498 _.opt.easing(0, now, 0, 1, scrollDuration)
499 if (now < scrollDuration && animateIndex === _.animate_id) {
500 _window.requestAnimationFrame(animate)
501 } else {
502 _.ele.scrollLeft = scrollTarget
503 callback && callback.call(_)
504 }
505 }
506
507 _window.requestAnimationFrame(animate)
508 }
509
510 gliderPrototype.removeItem = function (index) {
511 var _ = this
512
513 if (_.slides.length) {
514 _.track.removeChild(_.slides[index])
515 _.refresh(true)
516 _.emit('remove')
517 }
518 }
519
520 gliderPrototype.addItem = function (ele) {
521 var _ = this
522
523 _.track.appendChild(ele)
524 _.refresh(true)
525 _.emit('add')
526 }
527
528 gliderPrototype.handleMouse = function (e) {
529 var _ = this
530 if (_.mouseDown) {
531 _.isDrag = true
532 _.ele.scrollLeft +=
533 (_.mouseDown - e.clientX) * (_.opt.dragVelocity || 3.3)
534 _.mouseDown = e.clientX
535 }
536 }
537
538 // used to round to the nearest 0.XX fraction
539 gliderPrototype.round = function (double) {
540 var _ = this
541 var step = _.opt.slidesToScroll % 1 || 1
542 var inv = 1.0 / step
543 return Math.round(double * inv) / inv
544 }
545
546 gliderPrototype.refresh = function (paging) {
547 var _ = this
548 _.init(true, paging)
549 }
550
551 gliderPrototype.setOption = function (opt, global) {
552 var _ = this
553
554 if (_.breakpoint && !global) {
555 _._opt.responsive.forEach(function (v) {
556 if (v.breakpoint === _.breakpoint) {
557 v.settings = Object.assign({}, v.settings, opt)
558 }
559 })
560 } else {
561 _._opt = Object.assign({}, _._opt, opt)
562 }
563
564 _.breakpoint = 0
565 _.settingsBreakpoint()
566 }
567
568 gliderPrototype.destroy = function () {
569 var _ = this
570
571 var replace = _.ele.cloneNode(true)
572
573 var clear = function (ele) {
574 ele.removeAttribute('style');
575 [].forEach.call(ele.classList, function (className) {
576 /^glider/.test(className) && ele.classList.remove(className)
577 })
578 }
579 // remove track if it was created by glider
580 if (!_.opt.skipTrack) {
581 replace.children[0].outerHTML = replace.children[0].innerHTML
582 }
583 clear(replace);
584 [].forEach.call(replace.getElementsByTagName('*'), clear)
585 _.ele.parentNode.replaceChild(replace, _.ele)
586 _.event(_window, 'remove', {
587 resize: _.resize
588 })
589 _.emit('destroy')
590 }
591
592 gliderPrototype.emit = function (name, arg) {
593 var _ = this
594
595 var e = new _window.CustomEvent('glider-' + name, {
596 bubbles: !_.opt.eventPropagate,
597 detail: arg
598 })
599 _.ele.dispatchEvent(e)
600 }
601
602 gliderPrototype.event = function (ele, type, args) {
603 var eventHandler = ele[type + 'EventListener'].bind(ele)
604 Object.keys(args).forEach(function (k) {
605 eventHandler(k, args[k])
606 })
607 }
608
609 return Glider
610 })