-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindowPane.min.js
5 lines (5 loc) · 4.5 KB
/
windowPane.min.js
1
2
3
4
5
/******************************************************************************
* windowPane.js
*
* Span images across multiple elements
*****************************************************************************/(function(e){"use strict";e.fn.extend({windowPane:function(t){var n={windowPane:"",insertInto:"",image:"",imageType:"single",bgRepeat:"no-repeat",revealRollovers:!1,slideshowSpeed:5e3,slideSpeed:1e3,autoAdvance:!1,slideDirection:"next",slideStyle:"single",includeNav:!1,navPrev:".nav-prev",navNext:".nav-next",includeNavIcons:!1,navIcon:".nav-icon",activeSlideClass:"current-slide",includeParallax:!1};n.insertInto=t.windowPane;t=e.extend(n,t);var r={};r.self=e(this);r.image=new Image;r.position=[];r.animating=!1;r.currentSlide=1;r.slide=function(n,i){var i=i||1;if(r.animating===!1){var s=e(t.insertInto,r.self);r.stopSlideshow();r.animating=!0;s.each(function(r,s){var o=e(".slide",s).width(),u,a,f,r;s=e(s);if(n==="next")f="-="+o*i+"px";else if(n=="prev"){for(r=0;r<i;r++){u=e(".slide:first",s);a=e(".slide:last",s);u.before(a);s.css("margin-left","-="+o+"px")}f="+="+o*i+"px"}s.animate({"margin-left":f},t.slideSpeed,function(){if(n==="next")for(r=0;r<i;r++){u=e(".slide:first",s);a=e(".slide:last",s);a.after(u);s.css("margin-left","+="+o+"px")}})});for(var o=0;o<i;o++){n==="next"?r.currentSlide===t.image.length?r.currentSlide=1:r.currentSlide+=1:n==="prev"&&(r.currentSlide===1?r.currentSlide=t.image.length:r.currentSlide-=1);e(t.navIcon).removeClass(t.activeSlideClass);e(t.navIcon+":eq("+(r.currentSlide-1)+")").addClass(t.activeSlideClass)}setTimeout(function(){r.animating=!1;t.autoAdvance&&r.startSlideshow();typeof t.onSlide=="function"&&t.onSlide(n,i,r.currentSlide)},t.slideSpeed)}};r.startSlideshow=function(){r.slideshow=setInterval(function(){r.slide(t.slideDirection)},t.slideshowSpeed)};r.stopSlideshow=function(){clearInterval(r.slideshow)};e(t.windowPane,r.self).each(function(){r.position.push(e(this).position())});r.offsetTop=r.position[0].top;r.offsetLeft=r.position[0].left;e.each(r.position,function(){this.top-=r.offsetTop;this.left-=r.offsetLeft});t.imageType==="single"?e(t.insertInto,r.self).each(function(n){e(this).css({width:"100%",height:"100%","background-image":"url("+t.image+")","background-repeat":t.bgRepeat,"background-position":"-"+r.position[n].left+"px -"+r.position[n].top+"px"});n++}):t.imageType==="slideshow"&&e(t.insertInto,r.self).each(function(n){var i=e(this),s=i.width();e.each(t.image,function(s){var o=e('<div class="slide"></div>');i.append(o);t.slideStyle==="separate"?o.css({"float":"left",width:i.css("width"),height:i.css("height"),"background-image":"url("+t.image[s]+")","background-repeat":t.bgRepeat,"background-position":"-"+r.position[n].left+"px -"+r.position[n].top+"px"}):t.slideStyle==="single"&&o.css({"float":"left",width:t.imageWidth,height:t.imageHeight,"background-image":"url("+t.image[s]+")","background-repeat":t.bgRepeat,"background-position":"left top"})});t.slideStyle==="separate"?i.css({width:s*t.image.length+"px"}):t.slideStyle==="single"&&i.css({width:t.imageWidth*t.image.length,"margin-top":"-"+r.position[n].top+"px","margin-left":"-"+r.position[n].left+"px"})});if(t.revealRollovers){e(t.insertInto).show();r.image.src=t.image;r.image.onload=function(){var n=r.image.height;e(t.windowPane,r.self).each(function(i){r.position[i].top>=n&&e(this).children(t.insertInto).hide()})}}t.autoAdvance&&r.startSlideshow();if(t.includeNav){e(t.navPrev,r.self).on("click",function(e){r.slide("prev");e.preventDefault()});e(t.navNext,r.self).on("click",function(e){r.slide("next");e.preventDefault()})}t.includeNavIcons&&e(t.navIcon).on("click",function(t){var n=e(this).index()+1,i=n>r.currentSlide?"next":"prev",s=Math.abs(n-r.currentSlide);r.slide(i,s);t.preventDefault()});e(window).on("mousemove",function(n){if(t.includeParallax&&!r.animating){var i=e(window).width(),s=e(window).height(),o=n.pageX,u=n.pageY,a=o/i,f=u/s,l=Math.abs(t.imageWidth-r.self.width()),c=Math.abs(t.imageHeight-r.self.height());t.imageType==="single"?e(t.insertInto,r.self).each(function(t,n){var i=r.position[t].left+l*a,s=r.position[t].top+c*f;e(n).css({"background-position":"-"+i+"px -"+s+"px"})}):t.imageType==="slideshow"&&(t.slideStyle==="single"?e(t.insertInto,r.self).each(function(t,n){var i=r.position[t].left+l*a,s=r.position[t].top+c*f;e(n).css({"margin-left":"-"+i+"px","margin-top":"-"+s+"px"})}):t.slideStyle==="separate"&&e(t.insertInto,r.self).each(function(t,n){var i=r.position[t].left+l*a,s=r.position[t].top+c*f;e(n).find(".slide:first").css({"background-position":"-"+i+"px -"+s+"px"})}))}})}})})(jQuery);