1/* 2 * Easy Slider 1.7 - jQuery plugin 3 * written by Alen Grakalic 4 * http://cssglobe.com/post/4004/easy-slider-15-the-easiest-jquery-plugin-for-sliding 5 * 6 * Copyright (c) 2009 Alen Grakalic (http://cssglobe.com) 7 * Dual licensed under the MIT (MIT-LICENSE.txt) 8 * and GPL (GPL-LICENSE.txt) licenses. 9 * 10 * Built for jQuery library 11 * http://jquery.com 12 * 13 */ 14 15/* 16 * markup example for $("#slider").easySlider(); 17 * 18 * <div id="slider"> 19 * <ul> 20 * <li><img src="images/01.jpg" alt="" /></li> 21 * <li><img src="images/02.jpg" alt="" /></li> 22 * <li><img src="images/03.jpg" alt="" /></li> 23 * <li><img src="images/04.jpg" alt="" /></li> 24 * <li><img src="images/05.jpg" alt="" /></li> 25 * </ul> 26 * </div> 27 * 28 */ 29 30(function($) { 31 32 $.fn.easySlider = function(options){ 33 34 // default configuration properties 35 var defaults = { 36 prevId: 'prevBtn', 37 prevText: 'Previous', 38 nextId: 'nextBtn', 39 nextText: 'Next', 40 controlsShow: true, 41 controlsBefore: '', 42 controlsAfter: '', 43 controlsFade: true, 44 firstId: 'firstBtn', 45 firstText: 'First', 46 firstShow: false, 47 lastId: 'lastBtn', 48 lastText: 'Last', 49 lastShow: false, 50 vertical: false, 51 speed: 800, 52 auto: false, 53 pause: 2000, 54 clickPause: 4000, 55 continuous: false, 56 numeric: false, 57 numericId: 'controls' 58 }; 59 60 var options = $.extend(defaults, options); 61 62 this.each(function() { 63 var obj = $(this); 64 var s = $("li", obj).length; 65 var w = $("li", obj).width(); 66 var h = $("li", obj).height(); 67 var clickable = true; 68 obj.width(w); 69 obj.height(h); 70 obj.css("overflow","hidden"); 71 var ts = s-1; 72 var t = 0; 73 $("ul", obj).css('width',s*w); 74 75 if(options.continuous){ 76 $("ul", obj).prepend($("ul li:last-child", obj).clone().css("margin-left","-"+ w +"px")); 77 $("ul", obj).append($("ul li:nth-child(2)", obj).clone()); 78 $("ul", obj).css('width',(s+1)*w); 79 }; 80 81 if(!options.vertical) $("li", obj).css('float','left'); 82 83 if(options.controlsShow){ 84 var html = options.controlsBefore; 85 if(options.numeric){ 86 html += '<ol id="'+ options.numericId +'"></ol>'; 87 } else { 88 if(options.firstShow) html += '<span id="'+ options.firstId +'"><a href=\"javascript:void(0);\">'+ options.firstText +'</a></span>'; 89 html += ' <span id="'+ options.prevId +'"><a href=\"javascript:void(0);\">'+ options.prevText +'</a></span>'; 90 html += ' <span id="'+ options.nextId +'"><a href=\"javascript:void(0);\">'+ options.nextText +'</a></span>'; 91 if(options.lastShow) html += ' <span id="'+ options.lastId +'"><a href=\"javascript:void(0);\">'+ options.lastText +'</a></span>'; 92 }; 93 94 html += options.controlsAfter; 95 $(obj).after(html); 96 }; 97 98 if(options.numeric){ 99 for(var i=0;i<s;i++){ 100 $(document.createElement("li")) 101 .attr('id',options.numericId + (i+1)) 102 .html('<a rel='+ i +' href=\"javascript:void(0);\">'+ (i+1) +'</a>') 103 .appendTo($("#"+ options.numericId)) 104 .click(function(){ 105 animate($("a",$(this)).attr('rel'),true); 106 }); 107 }; 108 } else { 109 $("a","#"+options.nextId).click(function(){ 110 animate("next",true); 111 }); 112 $("a","#"+options.prevId).click(function(){ 113 animate("prev",true); 114 }); 115 $("a","#"+options.firstId).click(function(){ 116 animate("first",true); 117 }); 118 $("a","#"+options.lastId).click(function(){ 119 animate("last",true); 120 }); 121 }; 122 123 function setCurrent(i){ 124 i = parseInt(i)+1; 125 $("li", "#" + options.numericId).removeClass("current"); 126 $("li#" + options.numericId + i).addClass("current"); 127 }; 128 129 function adjust(){ 130 if(t>ts) t=0; 131 if(t<0) t=ts; 132 if(!options.vertical) { 133 $("ul",obj).css("margin-left",(t*w*-1)); 134 } else { 135 $("ul",obj).css("margin-left",(t*h*-1)); 136 } 137 clickable = true; 138 if(options.numeric) setCurrent(t); 139 }; 140 141 function animate(dir,clicked){ 142 if (clickable){ 143 clickable = false;
144 var ot = t; 145 switch(dir){ 146 case "next": 147 t = (ot>=ts) ? (options.continuous ? t+1 : ts) : t+1; 148 break; 149 case "prev": 150 t = (t<=0) ? (options.continuous ? t-1 : 0) : t-1; 151 break; 152 case "first": 153 t = 0; 154 break; 155 case "last": 156 t = ts; 157 break; 158 default: 159 t = dir; 160 break; 161 }; 162 var diff = Math.abs(ot-t); 163 var speed = diff*options.speed; 164 if(!options.vertical) { 165 p = (t*w*-1); 166 $("ul",obj).animate( 167 { marginLeft: p }, 168 { queue:false, duration:speed, complete:adjust } 169 ); 170 } else { 171 p = (t*h*-1); 172 $("ul",obj).animate( 173 { marginTop: p }, 174 { queue:false, duration:speed, complete:adjust } 175 ); 176 }; 177 178 if(!options.continuous && options.controlsFade){ 179 if(t==ts){ 180 $("a","#"+options.nextId).hide(); 181 $("a","#"+options.lastId).hide(); 182 } else { 183 $("a","#"+options.nextId).show(); 184 $("a","#"+options.lastId).show(); 185 }; 186 if(t==0){ 187 $("a","#"+options.prevId).hide(); 188 $("a","#"+options.firstId).hide(); 189 } else { 190 $("a","#"+options.prevId).show(); 191 $("a","#"+options.firstId).show(); 192 }; 193 }; 194 195 196 197 if(clicked) { 198 clearTimeout(timeout); 199 timeout = setTimeout(function(){ 200 animate("next",false); 201 },options.clickPause); 202 }; 203 if(options.auto && dir=="next" && !clicked){; 204 timeout = setTimeout(function(){ 205 animate("next",false); 206 },diff*options.speed+options.pause); 207 }; 208 209 }; 210 211 }; 212 213 214 // init 215 var timeout; 216 if(options.auto){ 217 218 timeout = setTimeout(function(){ 219 animate("next",false); 220 },options.pause); 221 222 }; 223 224 if(options.numeric) setCurrent(0); 225 226 if(!options.continuous && options.controlsFade){ 227 $("a","#"+options.prevId).hide(); 228 $("a","#"+options.firstId).hide(); 229 }; 230 231 }); 232 233 }; 234 235})(jQuery); 236 237 238
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.