8 роки тому
1234567891011
  1. // ----------------------------------------------------------------------------
  2. // Vegas - Fullscreen Backgrounds and Slideshows with jQuery.
  3. // v1.3.5 - released 2014-10-13 19:56
  4. // Licensed under the MIT license.
  5. // http://vegas.jaysalvat.com/
  6. // ----------------------------------------------------------------------------
  7. // Copyright (C) 2010-2014 Jay Salvat
  8. // http://jaysalvat.com/
  9. // ----------------------------------------------------------------------------
  10. (function(e){function t(a,n){var o={align:"center",valign:"center"};if(e.extend(o,n),0===a.height())return a.load(function(){t(e(this),n)}),void 0;var i,s,g,d=r(),l=d.width,u=d.height,c=a.width(),v=a.height(),p=u/l,f=v/c;p>f?(i=u/f,s=u):(i=l,s=l*f),g={width:i+"px",height:s+"px",top:"auto",bottom:"auto",left:"auto",right:"auto"},isNaN(parseInt(o.valign,10))?"top"==o.valign?g.top=0:"bottom"==o.valign?g.bottom=0:g.top=(u-s)/2:g.top=0-(s-u)/100*parseInt(o.valign,10)+"px",isNaN(parseInt(o.align,10))?"left"==o.align?g.left=0:"right"==o.align?g.right=0:g.left=(l-i)/2:g.left=0-(i-l)/100*parseInt(o.align,10)+"px",a.css(g)}function a(){d.prependTo("body").fadeIn()}function n(){d.fadeOut("fast",function(){e(this).remove()})}function o(){return e("body").css("backgroundImage")?e("body").css("backgroundImage").replace(/url\("?(.*?)"?\)/i,"$1"):void 0}function r(){var e=window,t="inner";return"innerWidth"in window||(e=document.documentElement||document.body,t="client"),{width:e[t+"Width"],height:e[t+"Height"]}}var i,s=e("<img />").addClass("vegas-background"),g=e("<div />").addClass("vegas-overlay"),d=e("<div />").addClass("vegas-loading"),l=e(),u=null,c=[],v=0,p=5e3,f=function(){},h={init:function(r){var i={src:o(),align:"center",valign:"center",fade:0,loading:!0,load:function(){},complete:function(){}};e.extend(i,e.vegas.defaults.background,r),i.loading&&a();var g=s.clone();return g.css({position:"fixed",left:"0px",top:"0px"}).bind("load",function(){g!=l&&(e(window).bind("load resize.vegas",function(){t(g,i)}),l.is("img")?(l.stop(),g.hide().insertAfter(l).fadeIn(i.fade,function(){e(".vegas-background").not(this).remove(),e("body").trigger("vegascomplete",[this,v-1]),i.complete.apply(g,[v-1])})):g.hide().prependTo("body").fadeIn(i.fade,function(){e("body").trigger("vegascomplete",[this,v-1]),i.complete.apply(this,[v-1])}),l=g,t(l,i),i.loading&&n(),e("body").trigger("vegasload",[l.get(0),v-1]),i.load.apply(l.get(0),[v-1]),v&&(e("body").trigger("vegaswalk",[l.get(0),v-1]),i.walk.apply(l.get(0),[v-1])))}).attr("src",i.src),e.vegas},destroy:function(t){return t&&"background"!=t||(e(".vegas-background, .vegas-loading").remove(),e(window).unbind("*.vegas"),l=e()),t&&"overlay"!=t||e(".vegas-overlay").remove(),clearInterval(i),e.vegas},overlay:function(t){var a={src:null,opacity:null};return e.extend(a,e.vegas.defaults.overlay,t),g.remove(),g.css({margin:"0",padding:"0",position:"fixed",left:"0px",top:"0px",width:"100%",height:"100%"}),a.src===!1&&g.css("backgroundImage","none"),a.src&&g.css("backgroundImage","url("+a.src+")"),a.opacity&&g.css("opacity",a.opacity),g.prependTo("body"),e.vegas},slideshow:function(t,a){var n={step:v,delay:p,preload:!1,loading:!0,backgrounds:c,walk:f};if(e.extend(n,e.vegas.defaults.slideshow,t),n.backgrounds!=c&&(t.step||(n.step=0),t.walk||(n.walk=function(){}),n.preload&&e.vegas("preload",n.backgrounds)),c=n.backgrounds,p=n.delay,v=n.step,f=n.walk,clearInterval(i),!c.length)return e.vegas;var o=function(){0>v&&(v=c.length-1),(v>=c.length||!c[v-1])&&(v=0);var t=c[v++];t.walk=n.walk,t.loading=n.loading,t.fade===void 0&&(t.fade=n.fade),t.fade>n.delay&&(t.fade=n.delay),e.vegas(t)};return o(),a||(u=!1,e("body").trigger("vegasstart",[l.get(0),v-1])),u||(i=setInterval(o,n.delay)),e.vegas},next:function(){var t=v;return v&&(e.vegas("slideshow",{step:v},!0),e("body").trigger("vegasnext",[l.get(0),v-1,t-1])),e.vegas},previous:function(){var t=v;return v&&(e.vegas("slideshow",{step:v-2},!0),e("body").trigger("vegasprevious",[l.get(0),v-1,t-1])),e.vegas},jump:function(t){var a=v;return v&&(e.vegas("slideshow",{step:t},!0),e("body").trigger("vegasjump",[l.get(0),v-1,a-1])),e.vegas},stop:function(){var t=v;return v=0,u=null,clearInterval(i),e("body").trigger("vegasstop",[l.get(0),t-1]),e.vegas},pause:function(){return u=!0,clearInterval(i),e("body").trigger("vegaspause",[l.get(0),v-1]),e.vegas},get:function(e){return null===e||"background"==e?l.get(0):"overlay"==e?g.get(0):"step"==e?v-1:"paused"==e?u:void 0},preload:function(t){var a=[];for(var n in t)if(t[n].src){var o=document.createElement("img");o.src=t[n].src,a.push(o)}return e.vegas}};e.vegas=function(t){return h[t]?h[t].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof t&&t?(e.error("Method "+t+" does not exist"),void 0):h.init.apply(this,arguments)},e.vegas.defaults={background:{},slideshow:{},overlay:{}}})(jQuery);