-
Notifications
You must be signed in to change notification settings - Fork 2
/
wonder-slider.min.js
10 lines (10 loc) · 7.69 KB
/
wonder-slider.min.js
1
2
3
4
5
6
7
8
9
10
/*
Name: Wonder Slider
Description: A full screen slider with automatic image positioning.
Tested: FF 16(Windows), Chrome 22(Windows), Opera 12(Windows), Internet Explorer 9(Windows)
Features: Images, Youtube and Vimeo videos, controls and progress bar. Can change images on the fly.
Future: Add thumbnails, slide and random effects
Uses: Weer for absolute image positioning see below the WonderSlider
License: GNU/GPL
*/
(function(){jQuery.wonderslider=function(e,t){return jQuery.wonderSlider(e,t)},jQuery.WonderSlider=function(e,t){return jQuery.wonderSlider(e,t)},jQuery.wonderSlider=function(e,t){var n=jQuery.extend({delay:5e3,speed:400,preload:!0,autoplay:!0,progressBar:!0,progressBarColor:"#000",color:"#000",onBeforeChange:function(){},onAfterChange:function(){},onInit:function(){},onNextClick:function(){},onPrevClick:function(){},onPlayPauseClick:function(){},firstVideoAutoplay:!0,stopAudioTags:!0,youtube:"http://www.youtube-nocookie.com/embed/%v?rel=0&autoplay=%a&controls=0&modestbranding=1&wmode=opaque",vimeo:"http://player.vimeo.com/video/%v/?autoplay=%a",animation:"fade"},t),r={interval:!1,current:!1,progressBar:"",items:"",errors:!0};r.getVideoID=function(e,t){return t.toLowerCase()=="youtube"?e.match(/.*(?:youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#\&\?]*).*/i)[1]:e.match(/\d+/)[0]},r.parseInput=function(e){var t=new Array;if(typeof e=="object")for(i in e)if(typeof e[i]=="string")/https?:\/\/(www\.)?youtube/gi.test(e[i])?t.push({type:"youtube",id:r.getVideoID(e[i],"youtube")}):/https?\:\/\/vimeo\.com/gi.test(e[i])?t.push({type:"vimeo",id:r.getVideoID(e[i],"vimeo")}):t.push({type:"image",src:e[i],caption:!1});else if(typeof e[i]=="object")if(e[i].video===undefined||e[i].video.toLowerCase()==="vimeo"&&e[i].video.toLowerCase()==="youtube"){var s={type:"image"};e[i].src!==undefined&&(s.src=e[i].src,e[i].caption!==undefined?s.caption=e[i].caption:s.caption=!1,t.push(s))}else{var n={};n.type=e[i].video.toLowerCase(),n.caption=e[i].caption,e[i].autoplay==undefined&&(e[i].autoplay=!1),n.autoplay=e[i].autoplay?!1:!0,e[i].id!==undefined?(n.id=e[i].id,t.push(n)):e[i].url!==undefined&&(n.url=e[i].url,t.push(n))}return t},r.run=function(){var t=r.parseInput(e);r.buildHTML(t),r.bindEvents(),r.progressBar=jQuery("#wonder-slider .progress-bar"),r.items=jQuery("#wonder-slider ul li"),r.current=jQuery("#wonder-slider .slides li.slide-0");try{n.onInit.call(r)}catch(i){}jQuery("#wonder-slider").css("backgroundImage","none"),r.current.children("img").length>0?r.current.children("img").attr("src",r.current.children("img")[0].src+"?"+(new Date).getTime()).load(function(){jQuery(this).parent().addClass("active").end().fadeIn(100),n.autoplay&&r.startAnimation()}):n.autoplay&&r.startAnimation()},r.isPlaying=function(){return jQuery("#wonder-slider .controls .play-pause").hasClass("playing")},r.bindEvents=function(){jQuery("#wonder-slider .controls .next").bind("click",function(){try{n.onNextClick.call()}catch(e){}if(r.isPlaying())r.switchSlide("next");else{var t=r.current.next().length>0?r.current.next():r.items.first();r.animate(t)}}),jQuery("#wonder-slider .controls .prev").bind("click",function(){try{n.onNextClick.call()}catch(e){}if(r.isPlaying())r.switchSlide("prev");else{var t=r.current.prev().length>0?r.current.prev():r.items.last();r.animate(t)}}),jQuery("#wonder-slider .controls .play-pause").bind("click",function(){try{n.onPlayPauseClick.call()}catch(e){}jQuery(this).hasClass("paused")?(r.startAnimation(),jQuery(this).removeClass("paused").addClass("playing")):(window.clearInterval(r.interval),r.progressBar.stop().css("width","0"),jQuery(this).removeClass("playing").addClass("paused"))})},r.animateProgressBar=function(){n.progressBar&&r.progressBar.css("width","0").stop().animate({width:"100%"},n.delay+10)},r.startAnimation=function(){r.animateProgressBar(),r.interval=window.setInterval(function(){r.switchSlide()},n.delay)},r.animate=function(e){n.animation=="fade"&&(jQuery("#wonder-slider div.caption").hide(),r.current.stop().animate({opacity:0},n.speed,function(){jQuery(this).removeClass("active")}),e.stop().animate({opacity:1},n.speed).addClass("active"),r.current=e,e.children("div.caption").fadeIn(200),e.hasClass("youtube")&&r.videoFrame(r.current,"youtube"),e.hasClass("vimeo")&&r.videoFrame(r.current,"vimeo"))},r.videoFrame=function(e,t){},r.switchSlide=function(e){try{n.onBeforeChange.call(r)}catch(t){}r.animateProgressBar();if(typeof e=="undefined"){var i=r.current.next().length>0?r.current.next():r.items.first();r.animate(i)}else if(e=="next"){window.clearInterval(r.interval),r.interval=window.setInterval(function(){r.switchSlide("next")},n.delay);var i=r.current.next().length>0?r.current.next():r.items.first();r.animate(i)}else if(e=="prev"){window.clearInterval(r.interval),r.interval=window.setInterval(function(){r.switchSlide("next")},n.delay);var s=r.current.prev().length>0?r.current.prev():r.items.last();r.animate(s)}try{n.onAfterChange.call(r)}catch(t){}},r.buildHTML=function(e){jQuery("#wonder-slider").remove();var t="<div id='wonder-slider'><ul class='slides'>";for(i in e){var s=e[i],o=i%2==0?"odd":"even",u=i==0?" active ":"";t+="<li class='"+s.type+u+" slide-"+i+" "+o+"'>";if(s.type=="youtube"){if(i==0&&n.firstVideoAutoplay==1){r.stopAudioTags();var a=n.youtube.replace("%v",s.id).replace("%a",1)}else var a=n.youtube.replace("%v",s.id).replace("%a",0);s.caption&&(t+="<div class='caption'>"+s.caption+"</div>"),t+="<iframe data-id='"+s.id+"' data-from='youtube' data-autoplay='"+s.autoplay+"' frameborder='0' src='"+a+"'></iframe>"}else if(s.type=="vimeo"){s.caption&&(t+="<div class='caption'>"+s.caption+"</div>");if(i==0&&n.firstVideoAutoplay==1){var a=n.vimeo.replace("%v",s.id).replace("%a",!0);r.stopAudioTags()}else var a=n.vimeo.replace("%v",s.id).replace("%a",!1);t+="<iframe data-id='"+s.id+"' data-from='vimeo' data-autoplay='"+s.autoplay+"' frameborder='0' src='"+a+"'></iframe>"}else n.preload&&r.preloadImage(s.src),s.caption&&(t+="<div class='caption'>"+s.caption+"</div>"),t+="<img src='"+s.src+"' />";t+="</li>"}t+="</ul>",e.length>1&&(t+="<div class='progress-bar'></div><div class='controls'><div class='prev'><span></span></div><div class='play-pause playing'><span></span></div><div class='next'><span></span></div></div>"),jQuery("body").append(t),r.styling();try{jQuery("#wonder-slider ul li img").weer()}catch(f){}},r.styling=function(){jQuery("#wonder-slider .controls div").css({"background-color":n.color,opacity:"0.6"}).hover(function(){jQuery(this).css("opacity",1)},function(){jQuery(this).css("opacity",.6)}),jQuery("#wonder-slider .progress-bar").css({"background-color":n.progressBarColor})},r.stopAudioTags=function(){jQuery("audio").each(function(){this.pause()})},r.preloadImage=function(e){try{var t=new Image;t.src=e}catch(n){r.errors&&console.warn(n)}},r.run()}})(jQuery),function(e){e.extend(e.fn,{weer:function(){var e={init:function(t){jQuery(t).hide();var n=e.getDimensions(t);e.getCenter(t,n.width,n.height),jQuery(t).fadeIn(350),jQuery(window).resize(function(){e.getCenter(t,n.width,n.height)}),jQuery(t).fadeIn(100)},getDimensions:function(e){var t=new Array;return typeof e!="undefined"?(t.width=e.naturalWidth,t.height=e.naturalHeight):(t.width=window.innerWidth,t.height=window.innerHeight),t},getCenter:function(t,n,r){$this=jQuery(t);var i=e.getDimensions(),s=e.getReverse(n,r,i.width,i.height),o=s.height>i.height?-((s.height-i.height)/2):0,u=s.width>i.width?-((s.width-i.width)/2):0;jQuery($this).css({top:o+"px",left:u+"px",width:s.width+"px",height:s.height+"px",position:"fixed"})},getReverse:function(e,t,n,r){var i=new Array;return n>r?(i.width=n,i.height=n*t/e,i.height<r&&(i.height=r,i.width=e*r/t),i):(i.height=r,i.width=e*r/t,i.width<n&&(i.width=n,i.height=n*t/e),i)}};return jQuery(this).each(function(){jQuery(this).load(function(){e.init(this)})})}})}(jQuery)