Team:Penn/js/tms-0.3.js
From 2012.igem.org
/* jQuery based image slider /* TMSlider 0.3 */ (function($,undefined){ var _TMS=window._TMS=$.fn._TMS=function(_){ _=_||{} _=$.extend(clone(_TMS),_TMS.presets[_.preset],_) _.init.call(_.me=_.holder=this,_) return _.me.data({opt:_}) }
$.extend(_TMS,{
etal:'',items:'.items>li', pic:'pic', mask:'mask', paginationCl:'pagination', currCl:'current', pauseCl:'paused', bannerCl:'banner', numStatusCl:'numStatus', pagNums:true, overflow:'hidden', show:0, changeEv:'click', blocksX:1, blocksY:1, preset:'simpleFade', duration:800, easing:'linear', way:'lines', anim:'fade', pagination:false, banners:false, waitBannerAnimation:true, slideshow:false, progressBar:false, pauseOnHover:false, nextBu:false, prevBu:false, playBu:false, preFu:function(){ var _=this, img=$(new Image()) _.pic=$(_.etal) .addClass(_.pic) .css({overflow:_.overflow}) .appendTo(_.me) _.mask=$(_.etal) .addClass(_.mask) .appendTo(_.pic)
if(_.me.css('position')=='static') _.me.css({position:'relative'}) if(_.me.css('z-index')=='auto') _.me.css({zIndex:1})
_.me.css({overflow:_.overflow})
if(_.items) _.parseImgFu() img .appendTo(_.me) .load(function(){ _.pic .css({ width:_.width=img.width(), height:_.height=img.height(), background:'url('+_.itms[_.show]+') 0 0 no-repeat' }) img.remove() _.current=_.buff=_.show }) .attr({src:_.itms[_.n=_.show]}) }, sliceFu:function(w,h){ var _=this, w=_.blocksX, h=_.blocksY, eW=parseInt(_.width/w), eH=parseInt(_.height/h), etal=$(_.etal), fW=_.pic.width()-eW*w, fH=_.pic.height()-eH*h, x,y, matrix=_.matrix=[] _.mask .css({ position:'absolute', width:'100%', height:'100%', left:0, top:0, zIndex:1 }) .empty() .appendTo(_.pic)
for(y=0;y<h;y++) for(x=0;x<w;x++) matrix[y]=matrix[y]?matrix[y]:[], matrix[y][x]=$(_.etal).clone() .appendTo(_.mask) .css({ left:x*eW, top:y*eH, position:'absolute', width:x==w-1?eW+fW:eW, height:y==h-1?eH+fH:eH, backgroundPosition:'-'+x*eW+'px -'+y*eH+'px', display:'none' }) _.maskC=_.mask.children()
}, changeFu:function(n){ var _=this if(_.bl) return false if(n==_.n) return false _.n=n _.next=_.itms[n] _.direction=n-_.buff if(_.direction==_.itms.length-1) _.direction=-1 if(_.direction==-1*_.itms.length+1) _.direction=2 _.current=_.buff=n
if(_.numStatus) _.numStatusChFu()
if(_.pagination) _.pags .removeClass(_.currCl) .eq(n) .addClass(_.currCl)
if(_.banners!==false&&_.banner) _.bannerHide(_.banner) if(_.progressBar) clearInterval(_.slShTimer), _.progressBar.stop() if(_.slideshow&&!_.paused&&_.progressBar) _.progressBar.stop().width(0)
var _fu=function(){ if(_.banner) $.when(_.banner).then(function(){_.banner.detach()}) if(_.preset_!=_.preset) _.du=_.duration, _.ea=_.easing, $.extend(_,_TMS.presets[_.preset]), _.duration=_.du, _.easing=_.ea, _.preset_=_.preset _.sliceFu() _.maskC.stop().css({backgroundImage:'url('+_.next+')'}) _.beforeAnimation() _.showFu() } if(_.waitBannerAnimation) $.when(_.banner).then(_fu) else _fu() }, nextFu:function(){ var _=this, n=_.n _.changeFu(++n<_.itms.length?n:0) }, prevFu:function(){ var _=this, n=_.n _.changeFu(--n>=0?n:_.itms.length-1) }, showFu:function(){ var _=this, way, tmp
way=_.ways[_.way].call(_)
if(_.reverseWay) way.reverse() if(_.dirMirror) way=_.dirMirrorFu(way)
if(_.int) clearInterval(_.int) _.int=setInterval(function(){ if(way.length) _.anims[_.anim].apply(_,[way.shift(),!way.length]) else clearInterval(_.int) },_.interval) _.bl=true }, dirMirrorFu:function(way){ var _=this if(_.direction<0) void(0) return way }, afterShow:function(){ var _=this _.pic.css({backgroundImage:'url('+_.next+')'}) _.maskC.hide() if(_.slideshow&&!_.paused) _.startSlShFu(0) if(_.banners!==false) _.banner=_.banners[_.n] if(_.banner) _.banner.appendTo(_.me), _.bannerShow(_.banner) _.afterAnimation() _.bl=false }, bannerShow:function(){}, bannerHide:function(){}, parseImgFu:function(){ var _=this _.itms=[] $(_.items+' img',_.me) .each(function(i){ _.itms[i]=$(this).attr('src') }) }, controlsFu:function(){ var _=this if(_.nextBu) $(_.nextBu).bind(_.changeEv,function(){ _.nextFu() return false }) if(_.prevBu) $(_.prevBu).bind(_.changeEv,function(){ _.prevFu() return false }) }, paginationFu:function(){ var _=this if(_.pagination===false) return false if(_.pagination===true)
_.pags=$('.addClass(_.paginationCl) .appendTo(_.me), $(_.itms).each(function(i){
var li=$('