1 2 3(function($) { 4 5// var div = $('.press ul'); 6//setInterval(function(){ 7// var pos = div.scrollTop(); 8// div.scrollTop(pos + 2); 9//}, 100) 10// 11 12 var aux = { 13 // navigates left / right 14 navigate : function( dir, $el, $wrapper, opts, cache ) { 15 16 var scroll = opts.scroll, 17 factor = 1, 18 idxClicked = 0; 19 20 if( cache.expanded ) { 21 scroll = 1; // scroll is always 1 in full mode 22 factor = 3; // the width of the expanded item will be 3 times bigger than 1 collapsed item 23 idxClicked = cache.idxClicked; // the index of the clicked item 24 } 25 26 // clone the elements on the right / left and append / prepend them according to dir and scroll 27 if( dir === 1 ) { 28 $wrapper.find('div.ca-item:lt(' + scroll + ')').each(function(i) { 29 $(this).clone(true).css( 'left', ( cache.totalItems - idxClicked + i ) * cache.itemW * factor + 'px' ).appendTo( $wrapper ); 30 }); 31 } 32 else { 33 var $first = $wrapper.children().eq(0); 34 35 $wrapper.find('div.ca-item:gt(' + ( cache.totalItems - 1 - scroll ) + ')').each(function(i) { 36 // insert before $first so they stay in the right order 37 $(this).clone(true).css( 'left', - ( scroll - i + idxClicked ) * cache.itemW * factor + 'px' ).insertBefore( $first ); 38 }); 39 } 40 41 // animate the left of each item 42 // the calculations are dependent on dir and on the cache.expanded value 43 $wrapper.find('div.ca-item').each(function(i) { 44 var $item = $(this); 45 $item.stop().animate({ 46 left : ( dir === 1 ) ? '-=' + ( cache.itemW * factor * scroll ) + 'px' : '+=' + ( cache.itemW * factor * scroll ) + 'px' 47 }, opts.sliderSpeed, opts.sliderEasing, function() { 48 if( ( dir === 1 && $item.position().left < - idxClicked * cache.itemW * factor ) || ( dir === -1 && $item.position().left > ( ( cache.totalItems - 1 - idxClicked ) * cache.itemW * factor ) ) ) { 49 // remove the item that was cloned 50 $item.remove(); 51 } 52 cache.isAnimating = false; 53 }); 54 }); 55 56 }, 57 // opens an item (animation) -> opens all the others 58 openItem : function( $wrapper, $item, opts, cache ) { 59 cache.idxClicked = $item.index(); 60 // the item's position (1, 2, or 3) on the viewport (the visible items) 61 cache.winpos = aux.getWinPos( $item.position().left, cache ); 62 $wrapper.find('div.ca-item').not( $item ).hide(); 63 $item.find('div.ca-content-wrapper').css( 'left', cache.itemW + 'px' ).stop().animate({ 64 width : cache.itemW * 2 + 'px', 65 left : cache.itemW + 'px' 66 }, opts.itemSpeed, opts.itemEasing) 67 .end() 68 .stop() 69 .animate({ 70 left : '0px' 71 }, opts.itemSpeed, opts.itemEasing, function() { 72 cache.isAnimating = false; 73 cache.expanded = true; 74 75 aux.openItems( $wrapper, $item, opts, cache ); 76 }); 77 78 }, 79 // opens all the items 80 openItems : function( $wrapper, $openedItem, opts, cache ) { 81 var openedIdx = $openedItem.index(); 82 83 $wrapper.find('div.ca-item').each(function(i) { 84 var $item = $(this), 85 idx = $item.index(); 86 87 if( idx !== openedIdx ) { 88 $item.css( 'left', - ( openedIdx - idx ) * ( cache.itemW * 3 ) + 'px' ).show().find('div.ca-content-wrapper').css({ 89 left : cache.itemW + 'px', 90 width : cache.itemW * 2 + 'px' 91 }); 92 93 // hide more link 94 aux.toggleMore( $item, false ); 95 } 96 }); 97 }, 98 // show / hide the item's more button 99 toggleMore : function( $item, show ) { 100 ( show ) ? $item.find('a.ca-more').show() : $item.find('a.ca-more').hide(); 101 }, 102 // close all the items 103 // the current one is animated 104 closeItems : function( $wrapper, $openedItem, opts, cache ) { 105 var openedIdx = $openedItem.index(); 106 107 $openedItem.find('div.ca-content-wrapper').stop().animate({ 108 width : '0px' 109 }, opts.itemSpeed, opts.itemEasing) 110 .end() 111 .stop() 112 .animate({ 113 left : cache.itemW * ( cache.winpos - 1 ) + 'px' 114 }, opts.itemSpeed, opts.itemEasing, function() { 115 cache.isAnimating = false; 116 cache.expanded = false;
117 }); 118 119 // show more link 120 aux.toggleMore( $openedItem, true ); 121 122 $wrapper.find('div.ca-item').each(function(i) { 123 var $item = $(this), 124 idx = $item.index(); 125 126 if( idx !== openedIdx ) { 127 $item.find('div.ca-content-wrapper').css({ 128 width : '0px' 129 }) 130 .end() 131 .css( 'left', ( ( cache.winpos - 1 ) - ( openedIdx - idx ) ) * cache.itemW + 'px' ) 132 .show(); 133 134 // show more link 135 aux.toggleMore( $item, true ); 136 } 137 }); 138 }, 139 // gets the item's position (1, 2, or 3) on the viewport (the visible items) 140 // val is the left of the item 141 getWinPos : function( val, cache ) { 142 switch( val ) { 143 case 0 : return 1; break; 144 case cache.itemW : return 2; break; 145 case cache.itemW * 2 : return 3; break; 146 } 147 } 148 }, 149 methods = { 150 init : function( options ) { 151 152 if( this.length ) { 153 154 var settings = { 155 sliderSpeed : 500, // speed for the sliding animation 156 sliderEasing : 'easeOutExpo',// easing for the sliding animation 157 itemSpeed : 500, // speed for the item animation (open / close) 158 itemEasing : 'easeOutExpo',// easing for the item animation (open / close) 159 scroll : 1 // number of items to scroll at a time 160 }; 161 162 return this.each(function() { 163 164 // if options exist, lets merge them with our default settings 165 if ( options ) { 166 $.extend( settings, options ); 167 } 168 169 var $el = $(this), 170 $wrapper = $el.find('div.ca-wrapper'), 171 $items = $wrapper.children('div.ca-item'), 172 cache = {}; 173 174 // save the with of one item 175 cache.itemW = $items.width(); 176 // save the number of total items 177 cache.totalItems = $items.length; 178 179 // add navigation buttons 180 if( cache.totalItems > 3 ) 181 $el.prepend('<div class="ca-nav"><span class="ca-nav-prev">Previous</span><span class="ca-nav-next">Next</span></div>') 182 183 // control the scroll value 184 if( settings.scroll < 1 ) 185 settings.scroll = 1; 186 else if( settings.scroll > 3 ) 187 settings.scroll = 3; 188 189 var $navPrev = $el.find('span.ca-nav-prev'), 190 $navNext = $el.find('span.ca-nav-next'); 191 192 // hide the items except the first 3 193 $wrapper.css( 'overflow', 'hidden' ); 194 195 // the items will have position absolute 196 // calculate the left of each item 197 $items.each(function(i) { 198 $(this).css({ 199 position : 'absolute', 200 left : i * cache.itemW + 'px' 201 }); 202 }); 203 204 // click to open the item(s) 205 $el.find('a.ca-more').live('click.contentcarousel', function( event ) { 206 if( cache.isAnimating ) return false; 207 cache.isAnimating = true; 208 $(this).hide(); 209 var $item = $(this).closest('div.ca-item'); 210 aux.openItem( $wrapper, $item, settings, cache ); 211 return false; 212 }); 213 214 // click to close the item(s) 215 $el.find('a.ca-close').live('click.contentcarousel', function( event ) { 216 if( cache.isAnimating ) return false; 217 cache.isAnimating = true; 218 var $item = $(this).closest('div.ca-item'); 219 aux.closeItems( $wrapper, $item, settings, cache ); 220 return false; 221 }); 222 223 // navigate left 224 $navPrev.bind('click.contentcarousel', function( event ) { 225 if( cache.isAnimating ) return false; 226 cache.isAnimating = true; 227 aux.navigate( -1, $el, $wrapper, settings, cache ); 228 }); 229 230 // navigate right 231 $navNext.bind('click.contentcarousel', function( event ) { 232 if( cache.isAnimating ) return false; 233 cache.isAnimating = true; 234 aux.navigate( 1, $el, $wrapper, settings, cache ); 235 }); 236 237 // adds events to the mouse 238 $el.bind('mousewheel.contentcarousel', function(e, delta) { 239 if(delta > 0) { 240 if( cache.isAnimating ) return false; 241 cache.isAnimating = true; 242 aux.navigate( -1, $el, $wrapper, settings, cache ); 243 } 244 else { 245 if( cache.isAnimating ) return false;
246 cache.isAnimating = true; 247 aux.navigate( 1, $el, $wrapper, settings, cache ); 248 } 249 return false; 250 }); 251 252 }); 253 } 254 } 255 }; 256 257 258 $.fn.contentcarousel = function(method) { 259 if ( methods[method] ) { 260 return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 )); 261 } else if ( typeof method === 'object' || ! method ) { 262 return methods.init.apply( this, arguments ); 263 } else { 264 $.error( 'Method ' + method + ' does not exist on jQuery.contentcarousel' ); 265 } 266 }; 267 268 269 270 271})(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.