1/* 2 * faded 0.3.1 - jQuery plugin 3 * written by Nathan Searles 4 * http://nathansearles.com/faded/ 5 * 6 * Copyright (c) 2009 Nathan Searles (http://nathansearles.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 * Compatible with jQuery 1.3.2+ 13 * 14 */ 15if(typeof jQuery != "undefined") { 16 jQuery(function($) { 17 $.fn.extend({ 18 faded: function(options) { 19 var settings = $.extend({}, $.fn.faded.defaults, options); 20 return this.each( 21 function() { 22 if($.fn.jquery < "1.3.1") {return;} 23 var $t = $(this); 24 var $c = $t.children(":nth-child(1)"); 25 var o = $.metadata ? $.extend({}, settings, $t.metadata()) : settings; 26 var total = $c.children().size(); 27 var next = 0, prev = 0, number = 0, currentitem = 0, restart = 0, restartinterval = 0; 28 var loaded,active,imgSrc,clicked,current; 29 if (o.random) { 30 $.fn.reorder = function(callback) { 31 function randOrd() { return(Math.round(Math.random())-0.5); } 32 return($(this).each(function() { 33 var $this = $(this); 34 var $children = $this.children(); 35 var childCount = $children.length; 36 if (childCount > 1) { 37 $children.hide(); 38 var indices = new Array(); 39 for (i=0;i<childCount;i++) { indices[indices.length] = i; } 40 indices = indices.sort(randOrd); 41 $.each(indices,function(j,k) { 42 var $child = $children.eq(k); 43 var $clone = $child.clone(true); 44 $clone.show().appendTo($this); 45 if (callback !== undefined) { 46 callback($child, $clone); 47 } 48 $child.remove(); 49 }); 50 } 51 })); 52 }; 53 $c.reorder(); 54 } 55 function pause() { 56 clearInterval(autoplay); 57 clearTimeout(restart); 58 restart = setTimeout(function() { 59 autoplay = setInterval(function(){ 60 animate("next"); 61 },o.autoplay); 62 },o.autorestart); 63 } 64 $c.css({position:"relative"}); 65 $c.children().css({ 66 position:"absolute", 67 top: 0, 68 left: 0, 69 zIndex: 0, 70 display:"none" 71 }); 72 if (o.autoheight) { 73 $c.animate({height: $c.children(":eq(0)").outerHeight()},o.autoheight); 74 } 75 if (o.pagination) { 76 if (o.autopagination) { 77 $t.append("<ul class="+o.pagination+"></ul>"); 78 $c.children().each(function(){ 79 $("."+o.pagination+"",$t).append("<li><a rel="+number+" href=\"#\" >"+(number+1)+"</a></li>"); 80 number++; 81 }); 82 } 83 $("."+o.pagination+" li a:eq(0)",$t).parent().addClass("current"); 84 $("."+o.pagination+" li a",$t).click(function(){ 85 current = $("."+o.pagination+" li.current a",$t).attr("rel"); 86 clicked = $(this).attr("rel"); 87 if (current != clicked) {animate("pagination",clicked,current);} 88 if(o.autoplay){pause();} 89 90 return false; 91 }); 92 } 93 if (o.sequentialloading&&$c.children()[0].tagName=="IMG") { 94 $c.css({background:"url("+o.loadingimg+") no-repeat 50% 50%"}); 95 imgSrc = $("img:eq(0)",$c).attr("src"); 96 $("img:eq(0)",$c).attr("src", imgSrc).load(function() { 97 $(this).fadeIn(o.speed,function(){ 98 loaded = true; 99 }); 100 }); 101 } else { 102 $c.find(":eq(0)").fadeIn(o.speed,function(){ 103 loaded = true; 104 }); 105 } 106 if (o.bigtarget) { 107 $c.css({"cursor":"pointer"}); 108 $c.click(function(){ 109 animate("next"); 110 if(o.autoplay){ 111 if (o.autorestart) { 112 pause(); 113 } else { 114 clearInterval(autoplay); 115 } 116 } 117 return false; 118 }); 119 } 120 if (o.autoplay) { 121 autoplay = setInterval(function(){ 122 animate("next"); 123 },o.autoplay); 124 pause(); 125 } 126 $("."+o.nextbtn,$t).click(function(){ 127 animate("next"); 128 if(o.autoplay){ 129 if (o.autorestart) { 130 pause(); 131 } else { 132 clearInterval(autoplay); 133 } 134 } 135 return false;
136 }); 137 $("."+o.prevbtn,$t).click(function(){ 138 animate("prev"); 139 if(o.autoplay){ 140 if (o.autorestart) { 141 pause(); 142 } else { 143 clearInterval(autoplay); 144 } 145 } 146 return false; 147 }); 148 function animate(dir,clicked,current){ 149 if (!active&&loaded) { 150 active=true; 151 switch(dir) { 152 case "next": 153 prev = next; 154 next = currentitem*1+1; 155 if (total === next) { next = 0; } 156 break; 157 case "prev": 158 prev = next; 159 next = currentitem*1-1; 160 if (next === -1) { next = total-1; } 161 break; 162 case "pagination": 163 next = clicked; 164 prev = current; 165 break; 166 } 167 if (o.pagination) { 168 $(".pagination li.current",$t).removeClass("current"); 169 $(".pagination li a:eq("+next+")",$t).parent().addClass("current"); 170 } 171 if (o.crossfade) { 172 $c.children(":eq("+next+")").css({zIndex:10}).fadeIn(o.speed,function(){ 173 $c.children(":eq("+prev+")").css({display:"none",zIndex:0}); 174 $(this).css({zIndex:0}); 175 currentitem = next; 176 active = false; 177 }); 178 } else { 179 $c.children(":eq("+prev+")").fadeOut(o.speed,function(){ 180 if (o.autoheight) { 181 $c.animate({height: $c.children(":eq("+next+")").outerHeight()},o.autoheight,function(){ 182 $c.children(":eq("+next+")").fadeIn(o.speed); 183 }); 184 } else { 185 $c.children(":eq("+next+")").fadeIn(o.speed); 186 } 187 currentitem = next; 188 active = false; 189 }); 190 } 191 } 192 } 193 } 194 ); 195 } 196 }); 197 $.fn.faded.defaults = { 198 speed: 300, 199 crossfade: false, 200 bigtarget: false, 201 sequentialloading: false, 202 autoheight: false, 203 pagination: "pagination", 204 autopagination: true, 205 nextbtn: "next", 206 prevbtn: "prev", 207 loadingimg: false, 208 autoplay: false, 209 autorestart: false, 210 random: false 211 }; 212 }); 213}
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.