1/* 2 * faded 0.3.2 - jQuery plugin 3 * written by Nathan Searles 4 * http://nathansearles.com/faded/ 5 * 6 * Copyright (c) 2010 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 return false; 90 }); 91 } 92 if (o.loading&&$c.children()[0].tagName=="IMG") { 93 $c.css({background:"url("+o.loadingimg+") no-repeat 50% 50%"}); 94 imgSrc = $("img:eq(0)",$c).attr("src") + "?" + (new Date()).getTime(); 95 $("img:eq(0)",$c).attr("src", imgSrc).load(function() { 96 $(this).fadeIn(o.speed,function(){ 97 loaded = true; 98 }); 99 }); 100 } else { 101 $c.find(":eq(0)").fadeIn(o.speed,function(){ 102 loaded = true; 103 }); 104 } 105 if (o.bigtarget) { 106 $c.css({"cursor":"pointer"}); 107 $c.click(function(){ 108 animate("next"); 109 if(o.autoplay){ 110 if (o.autorestart) { 111 pause(); 112 } else { 113 clearInterval(autoplay); 114 } 115 } 116 return false; 117 }); 118 } 119 if (o.autoplay) { 120 autoplay = setInterval(function(){ 121 animate("next"); 122 },o.autoplay); 123 pause(); 124 } 125 $("."+o.nextbtn,$t).click(function(){ 126 animate("next"); 127 if(o.autoplay){ 128 if (o.autorestart) { 129 pause(); 130 } else { 131 clearInterval(autoplay); 132 } 133 } 134 return false;
135 }); 136 $("."+o.prevbtn,$t).click(function(){ 137 animate("prev"); 138 if(o.autoplay){ 139 if (o.autorestart) { 140 pause(); 141 } else { 142 clearInterval(autoplay); 143 } 144 } 145 return false; 146 }); 147 function animate(dir,clicked,current){ 148 if (!active&&loaded) { 149 active=true; 150 switch(dir) { 151 case "next": 152 prev = next; 153 next = currentitem*1+1; 154 if (total === next) { next = 0; } 155 break; 156 case "prev": 157 prev = next; 158 next = currentitem*1-1; 159 if (next === -1) { next = total-1; } 160 break; 161 case "pagination": 162 next = clicked; 163 prev = current; 164 break; 165 } 166 if (o.pagination) { 167 $(".pagination li.current",$t).removeClass("current"); 168 $(".pagination li a:eq("+next+")",$t).parent().addClass("current"); 169 } 170 if (o.crossfade) { 171 $c.children(":eq("+next+")").css({zIndex:10}).fadeIn(o.speed,function(){ 172 $c.children(":eq("+prev+")").css({display:"none",zIndex:0}); 173 $(this).css({zIndex:0}); 174 currentitem = next; 175 active = false; 176 }); 177 } else { 178 $c.children(":eq("+prev+")").fadeOut(o.speed,function(){ 179 if (o.autoheight) { 180 $c.animate({height: $c.children(":eq("+next+")").outerHeight()},o.autoheight,function(){ 181 $c.children(":eq("+next+")").fadeIn(o.speed); 182 }); 183 } else { 184 $c.children(":eq("+next+")").fadeIn(o.speed); 185 } 186 currentitem = next; 187 active = false; 188 }); 189 } 190 } 191 } 192 } 193 ); 194 } 195 }); 196 $.fn.faded.defaults = { 197 speed: 300, 198 crossfade: false, 199 bigtarget: false, 200 loading: false, 201 autoheight: false, 202 pagination: "pagination", 203 autopagination: true, 204 nextbtn: "next", 205 prevbtn: "prev", 206 loadingimg: false, 207 autoplay: false, 208 autorestart: false, 209 random: false 210 }; 211 }); 212}
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.