mirror of
https://github.com/dillonzq/LoveIt.git
synced 2024-12-12 09:51:15 +01:00
7 lines
No EOL
9.1 KiB
JavaScript
7 lines
No EOL
9.1 KiB
JavaScript
/**!
|
|
* lg-thumbnail.js | 1.0.0 | August 8th 2018
|
|
* http://sachinchoolur.github.io/lg-thumbnail.js
|
|
* Copyright (c) 2016 Sachin N;
|
|
* @license GPLv3
|
|
*/
|
|
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.LgThumbnail=t()}}(function(){var t,e,i;return function(){function t(e,i,o){function u(s,l){if(!i[s]){if(!e[s]){var h="function"==typeof require&&require;if(!l&&h)return h(s,!0);if(r)return r(s,!0);var n=new Error("Cannot find module '"+s+"'");throw n.code="MODULE_NOT_FOUND",n}var a=i[s]={exports:{}};e[s][0].call(a.exports,function(t){return u(e[s][1][t]||t)},a,a.exports,t,e,i,o)}return i[s].exports}for(var r="function"==typeof require&&require,s=0;s<o.length;s++)u(o[s]);return u}return t}()({1:[function(e,i,o){!function(e,i){if("function"==typeof t&&t.amd)t([],i);else if(void 0!==o)i();else{var u={exports:{}};i(),e.lgThumbnail=u.exports}}(this,function(){"use strict";var t=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var o in i)Object.prototype.hasOwnProperty.call(i,o)&&(t[o]=i[o])}return t},e={thumbnail:!0,animateThumb:!0,currentPagerPosition:"middle",thumbWidth:100,thumbContHeight:100,thumbMargin:5,exThumbImage:!1,showThumbByDefault:!0,toggleThumb:!0,pullCaptionUp:!0,enableThumbDrag:!0,enableThumbSwipe:!0,swipeThreshold:50,loadYoutubeThumbnail:!0,youtubeThumbSize:1,loadVimeoThumbnail:!0,vimeoThumbSize:"thumbnail_small",loadDailymotionThumbnail:!0},i=function i(o){return this.el=o,this.core=window.lgData[this.el.getAttribute("lg-uid")],this.core.s=t({},e,this.core.s),this.thumbOuter=null,this.thumbOuterWidth=0,this.thumbTotalWidth=this.core.items.length*(this.core.s.thumbWidth+this.core.s.thumbMargin),this.thumbIndex=this.core.index,this.left=0,this.init(),this};i.prototype.init=function(){var t=this;this.core.s.thumbnail&&this.core.items.length>1&&(this.core.s.showThumbByDefault&&setTimeout(function(){utils.addClass(t.core.outer,"lg-thumb-open")},700),this.core.s.pullCaptionUp&&utils.addClass(this.core.outer,"lg-pull-caption-up"),this.build(),this.core.s.animateThumb?(this.core.s.enableThumbDrag&&!this.core.isTouch&&this.core.doCss()&&this.enableThumbDrag(),this.core.s.enableThumbSwipe&&this.core.isTouch&&this.core.doCss()&&this.enableThumbSwipe(),this.thumbClickable=!1):this.thumbClickable=!0,this.toggle(),this.thumbkeyPress())},i.prototype.build=function(){function t(t,u,r){var s=e.core.isVideo(t,r)||{},l,h="";s.youtube||s.vimeo||s.dailymotion?s.youtube?l=e.core.s.loadYoutubeThumbnail?"//img.youtube.com/vi/"+s.youtube[1]+"/"+e.core.s.youtubeThumbSize+".jpg":u:s.vimeo?e.core.s.loadVimeoThumbnail?(l="//i.vimeocdn.com/video/error_"+o+".jpg",h=s.vimeo[1]):l=u:s.dailymotion&&(l=e.core.s.loadDailymotionThumbnail?"//www.dailymotion.com/thumbnail/video/"+s.dailymotion[1]:u):l=u,i+='<div data-vimeo-id="'+h+'" class="lg-thumb-item" style="width:'+e.core.s.thumbWidth+"px; margin-right: "+e.core.s.thumbMargin+'px"><img src="'+l+'" /></div>',h=""}var e=this,i="",o="",u,r='<div class="lg-thumb-outer"><div class="lg-thumb group"></div></div>';switch(this.core.s.vimeoThumbSize){case"thumbnail_large":o="640";break;case"thumbnail_medium":o="200x150";break;case"thumbnail_small":o="100x75"}if(utils.addClass(e.core.outer,"lg-has-thumb"),e.core.outer.querySelector(".lg").insertAdjacentHTML("beforeend",r),e.thumbOuter=e.core.outer.querySelector(".lg-thumb-outer"),e.thumbOuterWidth=e.thumbOuter.offsetWidth,e.core.s.animateThumb&&(e.core.outer.querySelector(".lg-thumb").style.width=e.thumbTotalWidth+"px",e.core.outer.querySelector(".lg-thumb").style.position="relative"),this.core.s.animateThumb&&(e.thumbOuter.style.height=e.core.s.thumbContHeight+"px"),e.core.s.dynamic)for(var s=0;s<e.core.s.dynamicEl.length;s++)t(e.core.s.dynamicEl[s].src,e.core.s.dynamicEl[s].thumb,s);else for(var l=0;l<e.core.items.length;l++)e.core.s.exThumbImage?t(e.core.items[l].getAttribute("href")||e.core.items[l].getAttribute("data-src"),e.core.items[l].getAttribute(e.core.s.exThumbImage),l):t(e.core.items[l].getAttribute("href")||e.core.items[l].getAttribute("data-src"),e.core.items[l].querySelector("img").getAttribute("src"),l);e.core.outer.querySelector(".lg-thumb").innerHTML=i,u=e.core.outer.querySelectorAll(".lg-thumb-item");for(var h=0;h<u.length;h++)!function(t){var i=u[t],o=i.getAttribute("data-vimeo-id");if(o){window["lgJsonP"+e.el.getAttribute("lg-uid")+h]=function(t){i.querySelector("img").setAttribute("src",t[0][e.core.s.vimeoThumbSize])};var r=document.createElement("script");r.className="lg-script",r.src="//www.vimeo.com/api/v2/video/"+o+".json?callback=lgJsonP"+e.el.getAttribute("lg-uid")+h,document.body.appendChild(r)}}(h);utils.addClass(u[e.core.index],"active"),utils.on(e.core.el,"onBeforeSlide.lgtm",function(){for(var t=0;t<u.length;t++)utils.removeClass(u[t],"active");utils.addClass(u[e.core.index],"active")});for(var n=0;n<u.length;n++)!function(t){utils.on(u[t],"click.lg touchend.lg",function(){setTimeout(function(){(e.thumbClickable&&!e.core.lgBusy||!e.core.doCss())&&(e.core.index=t,e.core.slide(e.core.index,!1,!0))},50)})}(n);utils.on(e.core.el,"onBeforeSlide.lgtm",function(){e.animateThumb(e.core.index)}),utils.on(window,"resize.lgthumb orientationchange.lgthumb",function(){setTimeout(function(){e.animateThumb(e.core.index),e.thumbOuterWidth=e.thumbOuter.offsetWidth},200)})},i.prototype.setTranslate=function(t){utils.setVendor(this.core.outer.querySelector(".lg-thumb"),"Transform","translate3d(-"+t+"px, 0px, 0px)")},i.prototype.animateThumb=function(t){var e=this.core.outer.querySelector(".lg-thumb");if(this.core.s.animateThumb){var i;switch(this.core.s.currentPagerPosition){case"left":i=0;break;case"middle":i=this.thumbOuterWidth/2-this.core.s.thumbWidth/2;break;case"right":i=this.thumbOuterWidth-this.core.s.thumbWidth}this.left=(this.core.s.thumbWidth+this.core.s.thumbMargin)*t-1-i,this.left>this.thumbTotalWidth-this.thumbOuterWidth&&(this.left=this.thumbTotalWidth-this.thumbOuterWidth),this.left<0&&(this.left=0),this.core.lGalleryOn?(utils.hasClass(e,"on")||utils.setVendor(this.core.outer.querySelector(".lg-thumb"),"TransitionDuration",this.core.s.speed+"ms"),this.core.doCss()||(e.style.left=-this.left+"px")):this.core.doCss()||(e.style.left=-this.left+"px"),this.setTranslate(this.left)}},i.prototype.enableThumbDrag=function(){var t=this,e=0,i=0,o=!1,u=!1,r=0;utils.addClass(t.thumbOuter,"lg-grab"),utils.on(t.core.outer.querySelector(".lg-thumb"),"mousedown.lgthumb",function(i){t.thumbTotalWidth>t.thumbOuterWidth&&(i.preventDefault(),e=i.pageX,o=!0,t.core.outer.scrollLeft+=1,t.core.outer.scrollLeft-=1,t.thumbClickable=!1,utils.removeClass(t.thumbOuter,"lg-grab"),utils.addClass(t.thumbOuter,"lg-grabbing"))}),utils.on(window,"mousemove.lgthumb",function(s){o&&(r=t.left,u=!0,i=s.pageX,utils.addClass(t.thumbOuter,"lg-dragging"),r-=i-e,r>t.thumbTotalWidth-t.thumbOuterWidth&&(r=t.thumbTotalWidth-t.thumbOuterWidth),r<0&&(r=0),t.setTranslate(r))}),utils.on(window,"mouseup.lgthumb",function(){u?(u=!1,utils.removeClass(t.thumbOuter,"lg-dragging"),t.left=r,Math.abs(i-e)<t.core.s.swipeThreshold&&(t.thumbClickable=!0)):t.thumbClickable=!0,o&&(o=!1,utils.removeClass(t.thumbOuter,"lg-grabbing"),utils.addClass(t.thumbOuter,"lg-grab"))})},i.prototype.enableThumbSwipe=function(){var t=this,e=0,i=0,o=!1,u=0;utils.on(t.core.outer.querySelector(".lg-thumb"),"touchstart.lg",function(i){t.thumbTotalWidth>t.thumbOuterWidth&&(i.preventDefault(),e=i.targetTouches[0].pageX,t.thumbClickable=!1)}),utils.on(t.core.outer.querySelector(".lg-thumb"),"touchmove.lg",function(r){t.thumbTotalWidth>t.thumbOuterWidth&&(r.preventDefault(),i=r.targetTouches[0].pageX,o=!0,utils.addClass(t.thumbOuter,"lg-dragging"),u=t.left,u-=i-e,u>t.thumbTotalWidth-t.thumbOuterWidth&&(u=t.thumbTotalWidth-t.thumbOuterWidth),u<0&&(u=0),t.setTranslate(u))}),utils.on(t.core.outer.querySelector(".lg-thumb"),"touchend.lg",function(){t.thumbTotalWidth>t.thumbOuterWidth&&o?(o=!1,utils.removeClass(t.thumbOuter,"lg-dragging"),Math.abs(i-e)<t.core.s.swipeThreshold&&(t.thumbClickable=!0),t.left=u):t.thumbClickable=!0})},i.prototype.toggle=function(){var t=this;t.core.s.toggleThumb&&(utils.addClass(t.core.outer,"lg-can-toggle"),t.thumbOuter.insertAdjacentHTML("beforeend",'<span class="lg-toggle-thumb lg-icon"></span>'),utils.on(t.core.outer.querySelector(".lg-toggle-thumb"),"click.lg",function(){utils.hasClass(t.core.outer,"lg-thumb-open")?utils.removeClass(t.core.outer,"lg-thumb-open"):utils.addClass(t.core.outer,"lg-thumb-open")}))},i.prototype.thumbkeyPress=function(){var t=this;utils.on(window,"keydown.lgthumb",function(e){38===e.keyCode?(e.preventDefault(),utils.addClass(t.core.outer,"lg-thumb-open")):40===e.keyCode&&(e.preventDefault(),utils.removeClass(t.core.outer,"lg-thumb-open"))})},i.prototype.destroy=function(t){if(this.core.s.thumbnail&&this.core.items.length>1){utils.off(window,".lgthumb"),t||this.thumbOuter.parentNode.removeChild(this.thumbOuter),utils.removeClass(this.core.outer,"lg-has-thumb");for(var e=document.getElementsByClassName("lg-script");e[0];)e[0].parentNode.removeChild(e[0])}},window.lgModules.thumbnail=i})},{}]},{},[1])(1)}); |