UNPKG

ng-simple-slideshow

Version:
3 lines (2 loc) 23.6 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/common"),require("@angular/platform-browser")):"function"==typeof define&&define.amd?define(["exports","@angular/core","@angular/common","@angular/platform-browser"],t):t(e["ng-simple-slideshow"]={},e.ng.core,e.ng.common,e.ng.platformBrowser)}(this,function(e,a,o,t){"use strict";var n=function(){function e(){}return e.prototype.swipe=function(e,t){var n=[e.changedTouches[0].pageX,e.changedTouches[0].pageY],i=(new Date).getTime();if("start"===t)this._swipeCoord=n,this._swipeTime=i;else if("end"===t){var s=[n[0]-this._swipeCoord[0],n[1]-this._swipeCoord[1]];if(i-this._swipeTime<1e3&&Math.abs(s[1])<Math.abs(s[0])&&30<Math.abs(s[0]))return s[0]<0?1:-1}return 0},e}();n.decorators=[{type:a.Injectable}],n.ctorParameters=function(){return[]};var r=t.makeStateKey("firstSlide"),i=function(){function e(e,t,n,i,s,o,r){this._swipeService=e,this._renderer=t,this._transferState=n,this._ngZone=i,this.sanitizer=s,this.platform_id=o,this.document=r,this.slideIndex=-1,this.slides=[],this._initial=!0,this._isHidden=!1,this.imageUrls=[],this.height="100%",this.showArrows=!0,this.disableSwiping=!1,this.autoPlay=!1,this.autoPlayInterval=3333,this.stopAutoPlayOnSlide=!0,this.autoPlayWaitForLazyLoad=!1,this.backgroundSize="cover",this.backgroundPosition="center center",this.backgroundRepeat="no-repeat",this.showDots=!1,this.dotColor="#FFF",this.showCaptions=!0,this.captionColor="#FFF",this.captionBackground="rgba(0, 0, 0, .35)",this.lazyLoad=!1,this.hideOnNoSlides=!1,this.fullscreen=!1,this.onSlideLeft=new a.EventEmitter,this.onSlideRight=new a.EventEmitter,this.onSwipeLeft=new a.EventEmitter,this.onSwipeRight=new a.EventEmitter,this.onFullscreenExit=new a.EventEmitter,this.onIndexChanged=new a.EventEmitter}return Object.defineProperty(e.prototype,"safeStyleDotColor",{get:function(){return this.sanitizer.bypassSecurityTrustStyle("--dot-color: "+this.dotColor)},enumerable:!0,configurable:!0}),e.prototype.ngOnInit=function(){this.debug!==undefined&&console.warn("[Deprecation Warning]: The debug input will be removed from ng-simple-slideshow in 1.3.0")},e.prototype.ngDoCheck=function(){this.imageUrls&&0<this.imageUrls.length?(!0===this._initial&&(this._urlCache=Array.from(this.imageUrls)),!0===this._isHidden&&(this._renderer.removeStyle(this.container.nativeElement,"display"),this._isHidden=!1),this.setSlides()):!0===this.hideOnNoSlides&&(this._renderer.setStyle(this.container.nativeElement,"display","none"),this._isHidden=!0),this.setStyles(),this.handleAutoPlay()},e.prototype.onSlide=function(e,t){this.handleAutoPlay(this.stopAutoPlayOnSlide),this.slide(e,t)},e.prototype.onSwipe=function(e,t){if(!0!==this.disableSwiping){var n=this._swipeService.swipe(e,t);0!==n&&this.onSlide(n,!0)}},e.prototype.onClick=function(e){e.preventDefault();var t=0<this.slides.length&&this.slides[this.slideIndex];t&&t.image.clickAction?t.image.clickAction():t&&t.image.href&&(this.document.location.href=t.image.href)},e.prototype.goToSlide=function(e){var t=this.slideIndex;this.slideIndex=e-1,this.setSlideIndex(1),this.slides[this.slideIndex].loaded||this.loadRemainingSlides(),this.handleAutoPlay(this.stopAutoPlayOnSlide),this.slideRight(t),this.slides[t].selected=!1,this.slides[this.slideIndex].selected=!0},e.prototype.getSlideStyle=function(e){var t=this.slides[e];return t.loaded?{"background-image":"url("+t.image.url+")","background-size":t.image.backgroundSize||this.backgroundSize,"background-position":t.image.backgroundPosition||this.backgroundPosition,"background-repeat":t.image.backgroundRepeat||this.backgroundRepeat}:{"background-image":undefined,"background-size":undefined,"background-position":undefined,"background-repeat":undefined}},e.prototype.exitFullScreen=function(e){e.preventDefault(),this.fullscreen=!1,this.onFullscreenExit.emit(!0)},e.prototype.slide=function(e,t){var n=this.slideIndex;this.setSlideIndex(e),this.slides[this.slideIndex].loaded||this.loadRemainingSlides(),1===e?this.slideRight(n,t):this.slideLeft(n,t),this.slides[n].selected=!1,this.slides[this.slideIndex].selected=!0},e.prototype.setSlideIndex=function(e){this.slideIndex+=e,this.slideIndex<0&&(this.slideIndex=this.slides.length-1),this.slideIndex>=this.slides.length&&(this.slideIndex=0),this.onIndexChanged.emit(this.slideIndex)},e.prototype.slideLeft=function(e,t){!0===t?this.onSwipeLeft.emit(this.slideIndex):this.onSlideLeft.emit(this.slideIndex),this.slides[this.getLeftSideIndex(e)].leftSide=!1,this.slides[e].leftSide=!0,this.slides[e].action="slideOutLeft",this.slides[this.slideIndex].rightSide=!1,this.slides[this.getRightSideIndex()].rightSide=!0,this.slides[this.slideIndex].action="slideInRight"},e.prototype.slideRight=function(e,t){!0===t?this.onSwipeRight.emit(this.slideIndex):this.onSlideRight.emit(this.slideIndex),this.slides[this.getRightSideIndex(e)].rightSide=!1,this.slides[e].rightSide=!0,this.slides[e].action="slideOutRight",this.slides[this.slideIndex].leftSide=!1,this.slides[this.getLeftSideIndex()].leftSide=!0,this.slides[this.slideIndex].action="slideInLeft"},e.prototype.setSlides=function(){this.imageUrls&&(this.checkCache()||!0===this._initial)&&(this._initial=!1,this._urlCache=Array.from(this.imageUrls),this.slides=[],!0===this.lazyLoad?this.buildLazyLoadSlideArray():this.buildSlideArray())},e.prototype.buildLazyLoadSlideArray=function(){for(var e=0,t=this.imageUrls;e<t.length;e++){var n=t[e];this.slides.push({image:"string"==typeof n?{url:null}:{url:null,href:n.href||""},action:"",leftSide:!1,rightSide:!1,selected:!1,loaded:!1})}this.slideIndex=0,this.slides[this.slideIndex].selected=!0,this.loadFirstSlide(),this.onIndexChanged.emit(this.slideIndex)},e.prototype.buildSlideArray=function(){for(var e=0,t=this.imageUrls;e<t.length;e++){var n=t[e];this.slides.push({image:"string"==typeof n?{url:n}:n,action:"",leftSide:!1,rightSide:!1,selected:!1,loaded:!0})}this.slideIndex=0,this.slides[this.slideIndex].selected=!0,this.onIndexChanged.emit(this.slideIndex)},e.prototype.loadFirstSlide=function(){var e=this,t=this.slideIndex,n=this.imageUrls[t];if(o.isPlatformServer(this.platform_id))this.slides[t].image="string"==typeof n?{url:n}:n,this.slides[t].loaded=!0,this._transferState.set(r,this.slides[t]);else{var i=this._transferState.get(r,null);if(null===i){var s=new Image;s.src="string"==typeof n?n:n.url,s.addEventListener("load",function(){e.slides[t].image="string"==typeof n?{url:n}:n,e.slides[t].loaded=!0})}else this.slides[t]=i,this._transferState.remove(r)}},e.prototype.loadRemainingSlides=function(){for(var s=this,e=function(i){t.slides[i].loaded||new Promise(function(e){var t=s.imageUrls[i],n=new Image;n.addEventListener("load",function(){s.slides[i].image="string"==typeof t?{url:t}:t,s.slides[i].loaded=!0,e()}),n.src="string"==typeof t?t:t.url})},t=this,n=0;n<this.slides.length;n++)e(n)},e.prototype.handleAutoPlay=function(e){var t=this;o.isPlatformServer(this.platform_id)||(!0===e||!1===this.autoPlay?this._autoplayIntervalId&&(this._ngZone.runOutsideAngular(function(){return clearInterval(t._autoplayIntervalId)}),this._autoplayIntervalId=null):this._autoplayIntervalId||this._ngZone.runOutsideAngular(function(){t._autoplayIntervalId=setInterval(function(){(!t.autoPlayWaitForLazyLoad||t.autoPlayWaitForLazyLoad&&t.slides[t.slideIndex].loaded)&&t._ngZone.run(function(){return t.slide(1)})},t.autoPlayInterval)}))},e.prototype.setStyles=function(){this.fullscreen?(this._renderer.setStyle(this.container.nativeElement,"height","100%"),this._renderer.setStyle(this.container.nativeElement,"background-color","white")):(this._renderer.removeStyle(this.container.nativeElement,"background-color"),this.height&&this._renderer.setStyle(this.container.nativeElement,"height",this.height),this.minHeight&&this._renderer.setStyle(this.container.nativeElement,"min-height",this.minHeight)),this.arrowSize&&(this._renderer.setStyle(this.prevArrow.nativeElement,"height",this.arrowSize),this._renderer.setStyle(this.prevArrow.nativeElement,"width",this.arrowSize),this._renderer.setStyle(this.nextArrow.nativeElement,"height",this.arrowSize),this._renderer.setStyle(this.nextArrow.nativeElement,"width",this.arrowSize))},e.prototype.checkCache=function(){var n=this;return!(this._urlCache.length===this.imageUrls.length&&this._urlCache.every(function(e,t){return e===n.imageUrls[t]}))},e.prototype.getLeftSideIndex=function(e){return e===undefined&&(e=this.slideIndex),--e<0&&(e=this.slides.length-1),e},e.prototype.getRightSideIndex=function(e){return e===undefined&&(e=this.slideIndex),++e>=this.slides.length&&(e=0),e},e.prototype.trackByFn=function(e,t){return t.image},e}();i.decorators=[{type:a.Component,args:[{selector:"slideshow",template:'\n \x3c!-- fullscreen bar --\x3e\n <div [class.display-none]="!fullscreen"\n class="fs-container"\n (click)="exitFullScreen($event)">\n <i title="Back"\n class="arrow-exitfs prev"></i>\n </div>\n <div #container\n (touchstart)="onSwipe($event, \'start\')"\n (touchend)="onSwipe($event, \'end\')"\n class="slideshow-container"\n [class.slideshow-container-fs]="fullscreen">\n \x3c!-- slides --\x3e\n <a *ngFor="let slide of slides; index as i; trackBy: trackByFn"\n class="slides"\n href="{{slide?.image?.clickAction ? \'#\' : slide?.image?.href}}"\n title="{{slide?.image?.title}}"\n [ngStyle]="getSlideStyle(i)"\n [class.selected]="slide?.selected"\n [class.hide-slide]="!slide?.selected && !slide?.leftSide && !slide?.rightSide"\n [class.left-side]="slide?.leftSide"\n [class.right-side]="slide?.rightSide"\n [class.slide-in-left]="slide?.action === \'slideInLeft\'"\n [class.slide-in-right]="slide?.action === \'slideInRight\'"\n [class.slide-out-left]="slide?.action === \'slideOutLeft\'"\n [class.slide-out-right]="slide?.action === \'slideOutRight\'"\n [class.link]="slide?.image?.clickAction || slide?.image?.href"\n (click)="onClick($event)">\n <div class="loader"\n *ngIf="!slide?.loaded"></div>\n <div *ngIf="showCaptions && slide?.image?.caption"\n class="caption"\n [ngStyle]="{\n \'color\': captionColor,\n \'background-color\': captionBackground\n }"\n [innerHTML]="slide?.image?.caption">\n </div>\n </a>\n \x3c!-- left arrow --\x3e\n <div [class.display-none]="!this.showArrows"\n (click)="onSlide(-1)"\n class="arrow-container prev">\n <i #prevArrow\n title="Previous"\n class="arrow prev"></i>\n </div>\n \x3c!-- right arrow --\x3e\n <div [class.display-none]="!this.showArrows"\n (click)="onSlide(1)"\n class="arrow-container next">\n <i #nextArrow\n title="Next"\n class="arrow next"></i>\n </div>\n \x3c!-- dots --\x3e\n <ul class="slick-dots"\n *ngIf="showDots">\n <li *ngFor="let slide of slides; index as i; trackBy: trackByFn"\n (click)="goToSlide(i)"\n [class.slick-active]="slide.selected">\n <button type="button"\n [attr.style]="safeStyleDotColor">\n {{i}}\n </button>\n </li>\n </ul>\n </div>\n ',styles:["\n /*\n styles adapted from https://www.w3schools.com/w3css/4/w3.css\n arrow styles adapted from https://codepen.io/minustalent/pen/Frhaw\n */\n .display-none {\n display: none !important; }\n\n .fs-container {\n display: block;\n cursor: pointer;\n position: fixed;\n z-index: 1;\n top: 16px;\n left: 16px;\n width: 46px;\n height: 46px;\n text-align: center;\n padding: 0;\n background-color: rgba(0, 0, 0, 0.2);\n -webkit-transition: all .2s ease-in-out;\n transition: all .2s ease-in-out; }\n .fs-container:hover {\n background-color: rgba(0, 0, 0, 0.33); }\n .fs-container .arrow-exitfs {\n display: block;\n width: 30px;\n height: 30px;\n background: transparent;\n border-top: 2px solid #f2f2f2;\n -webkit-transition: all .2s ease-in-out;\n transition: all .2s ease-in-out; }\n .fs-container .arrow-exitfs.prev {\n -webkit-transform: rotate(-45deg);\n transform: rotate(-45deg);\n position: relative;\n left: 18px;\n top: 18px; }\n .fs-container .arrow-exitfs:after {\n content: '';\n width: 30px;\n height: 30px;\n background: transparent;\n border-top: 2px solid #f2f2f2;\n -webkit-transform: rotate(90deg);\n transform: rotate(90deg);\n position: absolute;\n left: -15px;\n top: -17px; }\n\n .slideshow-container.slideshow-container-fs {\n position: fixed;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%; }\n\n .slideshow-container {\n position: relative;\n display: block;\n margin: auto;\n height: 100%;\n width: 100%;\n overflow: hidden; }\n .slideshow-container .hide-slide {\n visibility: hidden;\n position: absolute;\n top: -100vw;\n left: -100vw;\n opacity: 0; }\n .slideshow-container .slides {\n position: absolute;\n top: 0;\n height: 100%;\n width: 100%;\n visibility: visible;\n opacity: 1;\n display: block; }\n .slideshow-container .slides.selected {\n left: 0; }\n .slideshow-container .slides.left-slide {\n left: -100%; }\n .slideshow-container .slides.right-slide {\n left: 100%; }\n .slideshow-container .slides.slide-in-left {\n left: 0;\n -webkit-animation: slideInLeft 0.5s cubic-bezier(0.42, 0, 0.58, 1);\n animation: slideInLeft 0.5s cubic-bezier(0.42, 0, 0.58, 1); }\n .slideshow-container .slides.slide-in-right {\n left: 0;\n -webkit-animation: slideInRight 0.5s cubic-bezier(0.42, 0, 0.58, 1);\n animation: slideInRight 0.5s cubic-bezier(0.42, 0, 0.58, 1); }\n .slideshow-container .slides.slide-out-left {\n left: -100%;\n -webkit-animation: slideOutLeft 0.5s cubic-bezier(0.42, 0, 0.58, 1);\n animation: slideOutLeft 0.5s cubic-bezier(0.42, 0, 0.58, 1); }\n .slideshow-container .slides.slide-out-right {\n left: 100%;\n -webkit-animation: slideOutRight 0.5s cubic-bezier(0.42, 0, 0.58, 1);\n animation: slideOutRight 0.5s cubic-bezier(0.42, 0, 0.58, 1); }\n .slideshow-container .slides.link {\n cursor: pointer; }\n .slideshow-container .slides:not(.link) {\n cursor: default; }\n .slideshow-container .caption {\n position: absolute;\n bottom: 0;\n padding: 10px;\n width: 100%; }\n .slideshow-container .arrow-container {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n -webkit-box-pack: center;\n -ms-flex-pack: center;\n justify-content: center;\n position: absolute;\n top: 0;\n height: 100%;\n width: auto;\n cursor: pointer;\n background-size: 100%;\n background-image: -webkit-gradient(linear, left top, left bottom, from(transparent), to(transparent));\n background-image: linear-gradient(transparent, transparent);\n z-index: 100;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none; }\n .slideshow-container .arrow-container:before {\n display: block;\n height: 100%;\n position: absolute;\n top: 0;\n left: 0;\n opacity: 0;\n width: 100%;\n z-index: -100;\n -webkit-transition: opacity 0.45s;\n transition: opacity 0.45s; }\n .slideshow-container .arrow-container.prev {\n left: 0; }\n .slideshow-container .arrow-container.prev:before {\n background-image: -webkit-gradient(linear, right top, left top, from(transparent), to(rgba(0, 0, 0, 0.75)));\n background-image: linear-gradient(to left, transparent, rgba(0, 0, 0, 0.75));\n content: ''; }\n .slideshow-container .arrow-container.next {\n right: 0; }\n .slideshow-container .arrow-container.next:before {\n background-image: -webkit-gradient(linear, left top, right top, from(transparent), to(rgba(0, 0, 0, 0.75)));\n background-image: linear-gradient(to right, transparent, rgba(0, 0, 0, 0.75));\n content: ''; }\n .slideshow-container .arrow-container .arrow {\n display: block;\n margin: auto;\n width: 30px;\n height: 30px;\n background: transparent;\n border-top: 2px solid #f2f2f2;\n border-left: 2px solid #f2f2f2;\n -webkit-transition: all .2s ease-in-out;\n transition: all .2s ease-in-out;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none; }\n .slideshow-container .arrow-container .arrow:before {\n display: block;\n height: 200%;\n width: 200%;\n margin-left: -50%;\n margin-top: -50%;\n content: \"\";\n -webkit-transform: rotate(45deg);\n transform: rotate(45deg); }\n .slideshow-container .arrow-container .arrow.prev {\n -webkit-transform: rotate(-45deg);\n transform: rotate(-45deg);\n position: relative;\n left: 20px;\n margin-right: 10px; }\n .slideshow-container .arrow-container .arrow.next {\n -webkit-transform: rotate(135deg);\n transform: rotate(135deg);\n position: relative;\n right: 20px;\n margin-left: 10px; }\n .slideshow-container .slick-dots {\n display: block;\n bottom: 15px;\n z-index: 1;\n text-align: center;\n position: absolute;\n padding: 0;\n left: 0;\n right: 0;\n margin: 0 auto; }\n .slideshow-container .slick-dots li {\n display: inline;\n margin: 0;\n padding: 0; }\n .slideshow-container .slick-dots li button {\n border: none;\n background: none;\n text-indent: -9999px;\n font-size: 0;\n width: 20px;\n height: 20px;\n outline: none;\n position: relative;\n z-index: 1;\n cursor: pointer; }\n .slideshow-container .slick-dots li button:before {\n content: '';\n width: 4px;\n height: 4px;\n background: var(--dot-color, #FFF);\n border-radius: 4px;\n display: block;\n position: absolute;\n top: 50%;\n left: 50%;\n -webkit-transform: translate(-50%, -50%);\n transform: translate(-50%, -50%);\n opacity: .7;\n -webkit-transition: all .5s ease-out;\n transition: all .5s ease-out; }\n .slideshow-container .slick-dots li.slick-active button:before {\n -webkit-transform: translate(-50%, -50%) scale(1.4);\n transform: translate(-50%, -50%) scale(1.4);\n opacity: 1; }\n\n @media screen and (min-width: 768px) {\n .slideshow-container .arrow-container:hover:before {\n opacity: 1; }\n .slideshow-container .arrow-container:hover .arrow {\n border-width: 4px; }\n .slideshow-container .arrow-container .arrow:hover {\n border-width: 4px; } }\n\n @-webkit-keyframes slideInRight {\n 0% {\n left: -100%; }\n 100% {\n left: 0; } }\n\n @keyframes slideInRight {\n 0% {\n left: -100%; }\n 100% {\n left: 0; } }\n\n @-webkit-keyframes slideInLeft {\n 0% {\n left: 100%; }\n 100% {\n left: 0; } }\n\n @keyframes slideInLeft {\n 0% {\n left: 100%; }\n 100% {\n left: 0; } }\n\n @-webkit-keyframes slideOutRight {\n 0% {\n left: 0; }\n 100% {\n left: -100%; } }\n\n @keyframes slideOutRight {\n 0% {\n left: 0; }\n 100% {\n left: -100%; } }\n\n @-webkit-keyframes slideOutLeft {\n 0% {\n left: 0; }\n 100% {\n left: 100%; } }\n\n @keyframes slideOutLeft {\n 0% {\n left: 0; }\n 100% {\n left: 100%; } }\n\n .loader {\n position: absolute;\n left: 50%;\n margin-left: -20px;\n top: 50%;\n margin-top: -20px;\n border: 5px solid #f3f3f3;\n border-top: 5px solid #555;\n border-radius: 50%;\n width: 50px;\n height: 50px;\n -webkit-animation: spin 1s linear infinite;\n animation: spin 1s linear infinite; }\n\n @-webkit-keyframes spin {\n 0% {\n -webkit-transform: rotate(0deg);\n transform: rotate(0deg); }\n 100% {\n -webkit-transform: rotate(360deg);\n transform: rotate(360deg); } }\n\n @keyframes spin {\n 0% {\n -webkit-transform: rotate(0deg);\n transform: rotate(0deg); }\n 100% {\n -webkit-transform: rotate(360deg);\n transform: rotate(360deg); } }\n "]}]}],i.ctorParameters=function(){return[{type:n},{type:a.Renderer2},{type:t.TransferState},{type:a.NgZone},{type:t.DomSanitizer},{type:undefined,decorators:[{type:a.Inject,args:[a.PLATFORM_ID]}]},{type:undefined,decorators:[{type:a.Inject,args:[o.DOCUMENT]}]}]},i.propDecorators={imageUrls:[{type:a.Input}],height:[{type:a.Input}],minHeight:[{type:a.Input}],arrowSize:[{type:a.Input}],showArrows:[{type:a.Input}],disableSwiping:[{type:a.Input}],autoPlay:[{type:a.Input}],autoPlayInterval:[{type:a.Input}],stopAutoPlayOnSlide:[{type:a.Input}],autoPlayWaitForLazyLoad:[{type:a.Input}],debug:[{type:a.Input}],backgroundSize:[{type:a.Input}],backgroundPosition:[{type:a.Input}],backgroundRepeat:[{type:a.Input}],showDots:[{type:a.Input}],dotColor:[{type:a.Input}],showCaptions:[{type:a.Input}],captionColor:[{type:a.Input}],captionBackground:[{type:a.Input}],lazyLoad:[{type:a.Input}],hideOnNoSlides:[{type:a.Input}],fullscreen:[{type:a.Input}],onSlideLeft:[{type:a.Output}],onSlideRight:[{type:a.Output}],onSwipeLeft:[{type:a.Output}],onSwipeRight:[{type:a.Output}],onFullscreenExit:[{type:a.Output}],onIndexChanged:[{type:a.Output}],container:[{type:a.ViewChild,args:["container"]}],prevArrow:[{type:a.ViewChild,args:["prevArrow"]}],nextArrow:[{type:a.ViewChild,args:["nextArrow"]}]};var s=function l(){};s.decorators=[{type:a.NgModule,args:[{imports:[o.CommonModule,t.BrowserTransferStateModule],declarations:[i],exports:[i],providers:[n]}]}],s.ctorParameters=function(){return[]},e.SlideshowModule=s,e.ɵa=i,e.ɵb=n,Object.defineProperty(e,"__esModule",{value:!0})}); //# sourceMappingURL=ng-simple-slideshow.umd.min.js.map