1(function($) { 2 $.fn.extend({ 3 jsCarousel: function(options) { 4 var settings = $.extend({ 5 scrollspeed: 1500, 6 delay: 5000, 7 itemstodisplay: 5, 8 autoscroll: false, 9 circular: false, 10 masked: true, 11 onthumbnailclick: null, 12 orientation: 'h' 13 }, options); 14 return this.each(function() { 15 var oclass = 'horizontal'; 16 if (settings.orientation == 'v') 17 oclass = 'vertical'; 18 var slidercontents = $(this).addClass('jscarousal-contents-' + oclass + ''); 19 var slider = $('<div/>').addClass('jscarousal-' + oclass + '').attr('id', slidercontents.attr('id')); 20 var backbutton = $('<div/>').addClass('jscarousal-' + oclass + '-back'); 21 var forwardbutton = $('<div/>').addClass('jscarousal-' + oclass + '-forward'); 22 slidercontents.removeAttr('id'); 23 slidercontents.before(slider); 24 slider.append(backbutton); 25 slider.append(slidercontents); 26 slider.append(forwardbutton); 27 var total = $('> div', slidercontents).css('display', 'none').length; 28 var index = 0; 29 var start = 0; 30 var current = $('<div/>'); 31 var noOfBlocks; 32 var interval; 33 var display = settings.itemstodisplay; 34 var speed = settings.scrollspeed; 35 var top; 36 var left; 37 var height; 38 var containerHeight; 39 var containerWidth; 40 var direction = "forward"; 41 var scrolling = true; 42 function initialize() { 43 index = -1; 44 noOfBlocks = parseInt(total / display); 45 if (total % display > 0) noOfBlocks++; 46 index = noOfBlocks - 1; 47 var startIndex = 0; 48 var endIndex = display; 49 var copy = false; 50 var allElements = $('> div', slidercontents); 51 $('> div', slidercontents).remove(); 52 if (settings.masked) 53 allElements.addClass('thumbnail-inactive').hover(function() { $(this).removeClass('thumbnail-inactive').addClass('thumbnail-active'); }, function() { $(this).removeClass('thumbnail-active').addClass('thumbnail-inactive'); }) 54 for (var i = 0; i < noOfBlocks; i++) { 55 if (total > display) { 56 startIndex = i * display; 57 endIndex = startIndex + display; 58 if (endIndex > total) { 59 startIndex -= (endIndex - total); 60 endIndex = startIndex + display; 61 copy = true; 62 } 63 } 64 else { 65 startIndex = 0; 66 endIndex = total; 67 } 68 var wrapper = $('<div/>') 69 allElements.slice(startIndex, endIndex).each(function(index, el) { 70 if (!copy) 71 wrapper.append(el); 72 else wrapper.append($(el).clone(true)); 73 }); 74 slidercontents.append(wrapper); 75 } 76 if (settings.onthumbnailclick != null) 77 $('> div > div', slidercontents).css('cursor', 'pointer'); 78 79 $('> div', slidercontents).addClass('hidden'); 80 $('> div > div', slidercontents).css('display', ''); 81 82 /*vertical*/ 83 if (settings.orientation == 'v') { 84 top = $('> div:eq(' + index + ')', slidercontents).css('top'); 85 if (top == 'auto') top = "0px"; 86 containerHeight = slidercontents.height(); 87 height = slidercontents.get(0).offsetHeight; 88 $('> div', slidercontents).css('top', '-' + containerHeight + 'px'); 89 $('> div:eq(' + index + ')', slidercontents).stop(false, true).animate({ 'top': top }, speed, function() { scrolling = false; }); 90 } 91 /*horizontal*/ 92 93 if (settings.orientation == 'h') { 94 left = $('> div:eq(' + index + ')', slidercontents).css('left'); 95 containerWidth = slidercontents.width(); 96 height = slidercontents.get(0).offsetHeight; 97 $('> div', slidercontents).css('left', '-' + containerWidth + 'px'); 98 $('> div:eq(' + index + ')', slidercontents).stop(false, true).animate({ left: 0 }, speed, function() { scrolling = false; }); 99 } 100 $('> div:eq(' + index + ')', slidercontents).addClass('visible').removeClass('hidden'); 101 102 slider.mouseenter(function() { if (settings.autoscroll) stopAnimate(); }).mouseleave(function() { if (settings.autoscroll) animate(); }); 103 if (settings.autoscroll) 104 animate(); 105 forwardbutton.click(function() { 106 if (!scrolling) { 107 direction = "forward"; 108 if (settings.circular) 109 if (index <= 0) index = noOfBlocks; 110 showThumbs(); 111 } 112 }); 113 backbutton.click(function() { 114 if (!scrolling) { 115 direction = "backward"; 116 if (settings.circular) 117 if (index >= noOfBlocks - 1) index = -1; 118 showThumbs(); 119 } 120 }); 121 } 122 initialize(); 123 function stopAnimate() { 124 scrolling = false;
125 clearTimeout(interval); 126 slider.children().clearQueue(); 127 slider.children().stop(false, true); 128 } 129 function animate() { 130 clearTimeout(interval); 131 if (settings.autoscroll) 132 interval = setTimeout(changeSlide, settings.delay); 133 } 134 function changeSlide() { 135 if (direction == "forward") { 136 if (index <= 0) index = noOfBlocks; 137 } else { 138 if (index >= noOfBlocks - 1) { index = -1; } 139 } 140 showThumbs(); 141 interval = setTimeout(changeSlide, settings.delay); 142 } 143 function getDimensions(value) { 144 return value + 'px'; 145 } 146 function showThumbs() { 147 scrolling = true; 148 var current = $('.visible', slidercontents); 149 var scrollSpeed = speed; 150 151 if (direction == "forward") { 152 index--; 153 if (index >= 0) { 154 if (settings.orientation == 'v') { 155 $('>div:eq(' + index + ')', slidercontents).css('top', getDimensions(containerHeight)).removeClass('hidden').addClass('visible').stop(false, true).animate({ 'top': top }, scrollSpeed, function() { scrolling = false; }); 156 current.stop(false, true).animate({ 'top': '-=' + getDimensions(containerHeight) }, scrollSpeed, function() { 157 $(this).removeClass('visible').addClass('hidden'); 158 $(this).css('top', top); 159 scrolling = false; 160 }); 161 } 162 else { 163 $('>div:eq(' + index + ')', slidercontents).css('left', getDimensions(containerWidth)).removeClass('hidden').addClass('visible').stop(false, true).animate({ 'left': '-=' + getDimensions(containerWidth) }, scrollSpeed, function() { scrolling = false; }); 164 current.stop(false, true).animate({ 'left': '-=' + getDimensions(containerWidth) }, scrollSpeed, function() { 165 $(this).removeClass('visible').addClass('hidden'); 166 $(this).css('left', left); 167 scrolling = false; 168 }); 169 } 170 } else index = 0; 171 172 } 173 else if (direction == "backward") { 174 index++; 175 if (index < noOfBlocks) { 176 if (settings.orientation == 'v') { 177 $('>div:eq(' + index + ')', slidercontents).removeClass('hidden').addClass('visible').css({ 178 'top': getDimensions(-containerHeight) 179 }).stop(false, true).animate({ 'top': top }, scrollSpeed, function() { scrolling = false; }); 180 181 current.stop(false, true).animate({ 'top': '+=' + getDimensions(containerHeight) }, scrollSpeed, 182 function() { 183 $(this).removeClass('visible').addClass('hidden'); 184 $(this).css('top', getDimensions(-containerHeight)); 185 scrolling = false; 186 }); 187 } 188 else { 189 $('>div:eq(' + index + ')', slidercontents).removeClass('hidden').addClass('visible').css({ 190 'left': getDimensions(-containerWidth) 191 }).stop(false, true).animate({ 'left': '+=' + getDimensions(containerWidth) }, scrollSpeed, function() { scrolling = false; }); 192 193 current.stop(false, true).animate({ 'left': '+=' + getDimensions(containerWidth) }, scrollSpeed, 194 function() { 195 $(this).removeClass('visible').addClass('hidden'); 196 $(this).css('left', getDimensions(-containerWidth)); 197 scrolling = false;
198 }); 199 } 200 201 } else index = noOfBlocks - 1; 202 } 203 204 } 205 }); 206 } 207 }); 208})(jQuery);
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.