album-stack.js
870 lines
| 1 | /* Modernizr 2.8.3 (Custom Build) | MIT & BSD |
| 2 | * Build: http://modernizr.com/download/#-csstransitions-prefixed-testprop-testallprops-domprefixes |
| 3 | */ |
| 4 | if (!window.FooGalleryStackAlbumModernizr) { |
| 5 | window.FooGalleryStackAlbumModernizr=function(a,b,c){function w(a){i.cssText=a}function x(a,b){return w(prefixes.join(a+";")+(b||""))}function y(a,b){return typeof a===b}function z(a,b){return!!~(""+a).indexOf(b)}function A(a,b){for(var d in a){var e=a[d];if(!z(e,"-")&&i[e]!==c)return b=="pfx"?e:!0}return!1}function B(a,b,d){for(var e in a){var f=b[a[e]];if(f!==c)return d===!1?a[e]:y(f,"function")?f.bind(d||b):f}return!1}function C(a,b,c){var d=a.charAt(0).toUpperCase()+a.slice(1),e=(a+" "+m.join(d+" ")+d).split(" ");return y(b,"string")||y(b,"undefined")?A(e,b):(e=(a+" "+n.join(d+" ")+d).split(" "),B(e,b,c))}var d="2.8.3",e={},f=b.documentElement,g="modernizr",h=b.createElement(g),i=h.style,j,k={}.toString,l="Webkit Moz O ms",m=l.split(" "),n=l.toLowerCase().split(" "),o={},p={},q={},r=[],s=r.slice,t,u={}.hasOwnProperty,v;!y(u,"undefined")&&!y(u.call,"undefined")?v=function(a,b){return u.call(a,b)}:v=function(a,b){return b in a&&y(a.constructor.prototype[b],"undefined")},Function.prototype.bind||(Function.prototype.bind=function(b){var c=this;if(typeof c!="function")throw new TypeError;var d=s.call(arguments,1),e=function(){if(this instanceof e){var a=function(){};a.prototype=c.prototype;var f=new a,g=c.apply(f,d.concat(s.call(arguments)));return Object(g)===g?g:f}return c.apply(b,d.concat(s.call(arguments)))};return e}),o.csstransitions=function(){return C("transition")};for(var D in o)v(o,D)&&(t=D.toLowerCase(),e[t]=o[D](),r.push((e[t]?"":"no-")+t));return e.addTest=function(a,b){if(typeof a=="object")for(var d in a)v(a,d)&&e.addTest(d,a[d]);else{a=a.toLowerCase();if(e[a]!==c)return e;b=typeof b=="function"?b():b,typeof enableClasses!="undefined"&&enableClasses&&(f.className+=" "+(b?"":"no-")+a),e[a]=b}return e},w(""),h=j=null,e._version=d,e._domPrefixes=n,e._cssomPrefixes=m,e.testProp=function(a){return A([a])},e.testAllProps=C,e.prefixed=function(a,b,c){return b?C(a,b,c):C(a,"pfx")},e}(this,this.document); |
| 6 | } |
| 7 | |
| 8 | /** |
| 9 | * jquery.stapel.js v1.0.0 |
| 10 | * http://www.codrops.com |
| 11 | * |
| 12 | * Licensed under the MIT license. |
| 13 | * http://www.opensource.org/licenses/mit-license.php |
| 14 | * |
| 15 | * Copyright 2012, Codrops |
| 16 | * http://www.codrops.com |
| 17 | */ |
| 18 | ;( function( $, window, undefined ) { |
| 19 | |
| 20 | 'use strict'; |
| 21 | |
| 22 | /* |
| 23 | * debouncedresize: special jQuery event that happens once after a window resize |
| 24 | * |
| 25 | * latest version and complete README available on Github: |
| 26 | * https://github.com/louisremi/jquery-smartresize/blob/master/jquery.debouncedresize.js |
| 27 | * |
| 28 | * Copyright 2011 @louis_remi |
| 29 | * Licensed under the MIT license. |
| 30 | */ |
| 31 | var $event = $.event, |
| 32 | $special, |
| 33 | resizeTimeout; |
| 34 | |
| 35 | $special = $event.special.debouncedresize = { |
| 36 | setup: function() { |
| 37 | $( this ).on( "resize", $special.handler ); |
| 38 | }, |
| 39 | teardown: function() { |
| 40 | $( this ).off( "resize", $special.handler ); |
| 41 | }, |
| 42 | handler: function( event, execAsap ) { |
| 43 | // Save the context |
| 44 | var context = this, |
| 45 | args = arguments, |
| 46 | dispatch = function() { |
| 47 | // set correct event type |
| 48 | event.type = "debouncedresize"; |
| 49 | $event.dispatch.apply( context, args ); |
| 50 | }; |
| 51 | |
| 52 | if ( resizeTimeout ) { |
| 53 | clearTimeout( resizeTimeout ); |
| 54 | } |
| 55 | |
| 56 | execAsap ? |
| 57 | dispatch() : |
| 58 | resizeTimeout = setTimeout( dispatch, $special.threshold ); |
| 59 | }, |
| 60 | threshold: 150 |
| 61 | }; |
| 62 | |
| 63 | // ======================= imagesLoaded Plugin =============================== |
| 64 | // https://github.com/desandro/imagesloaded |
| 65 | |
| 66 | // renamed from imagesLoaded to foogalleryImagesLoaded to avoid conflicts |
| 67 | |
| 68 | // $('#my-container').foogalleryImagesLoaded(myFunction) |
| 69 | // execute a callback when all images have loaded. |
| 70 | // needed because .load() doesn't work on cached images |
| 71 | |
| 72 | // callback function gets image collection as argument |
| 73 | // this is the container |
| 74 | |
| 75 | // original: mit license. paul irish. 2010. |
| 76 | // contributors: Oren Solomianik, David DeSandro, Yiannis Chatzikonstantinou |
| 77 | |
| 78 | // blank image data-uri bypasses webkit log warning (thx doug jones) |
| 79 | var BLANK = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw=='; |
| 80 | |
| 81 | $.fn.foogalleryImagesLoaded = function( callback ) { |
| 82 | var $this = this, |
| 83 | deferred = $.isFunction($.Deferred) ? $.Deferred() : 0, |
| 84 | hasNotify = $.isFunction(deferred.notify), |
| 85 | $images = $this.find('img').add( $this.filter('img') ), |
| 86 | loaded = [], |
| 87 | proper = [], |
| 88 | broken = []; |
| 89 | |
| 90 | // Register deferred callbacks |
| 91 | if ($.isPlainObject(callback)) { |
| 92 | $.each(callback, function (key, value) { |
| 93 | if (key === 'callback') { |
| 94 | callback = value; |
| 95 | } else if (deferred) { |
| 96 | deferred[key](value); |
| 97 | } |
| 98 | }); |
| 99 | } |
| 100 | |
| 101 | function doneLoading() { |
| 102 | var $proper = $(proper), |
| 103 | $broken = $(broken); |
| 104 | |
| 105 | if ( deferred ) { |
| 106 | if ( broken.length ) { |
| 107 | deferred.reject( $images, $proper, $broken ); |
| 108 | } else { |
| 109 | deferred.resolve( $images ); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | if ( $.isFunction( callback ) ) { |
| 114 | callback.call( $this, $images, $proper, $broken ); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | function imgLoaded( img, isBroken ) { |
| 119 | // don't proceed if BLANK image, or image is already loaded |
| 120 | if ( img.src === BLANK || $.inArray( img, loaded ) !== -1 ) { |
| 121 | return; |
| 122 | } |
| 123 | |
| 124 | // store element in loaded images array |
| 125 | loaded.push( img ); |
| 126 | |
| 127 | // keep track of broken and properly loaded images |
| 128 | if ( isBroken ) { |
| 129 | broken.push( img ); |
| 130 | } else { |
| 131 | proper.push( img ); |
| 132 | } |
| 133 | |
| 134 | // cache image and its state for future calls |
| 135 | $.data( img, 'foogalleryImagesLoaded', { isBroken: isBroken, src: img.src } ); |
| 136 | |
| 137 | // trigger deferred progress method if present |
| 138 | if ( hasNotify ) { |
| 139 | deferred.notifyWith( $(img), [ isBroken, $images, $(proper), $(broken) ] ); |
| 140 | } |
| 141 | |
| 142 | // call doneLoading and clean listeners if all images are loaded |
| 143 | if ( $images.length === loaded.length ){ |
| 144 | setTimeout( doneLoading ); |
| 145 | $images.unbind( '.foogalleryImagesLoaded' ); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | // if no images, trigger immediately |
| 150 | if ( !$images.length ) { |
| 151 | doneLoading(); |
| 152 | } else { |
| 153 | $images.bind( 'load.foogalleryImagesLoaded error.foogalleryImagesLoaded', function( event ){ |
| 154 | // trigger imgLoaded |
| 155 | imgLoaded( event.target, event.type === 'error' ); |
| 156 | }).each( function( i, el ) { |
| 157 | var src = el.src; |
| 158 | |
| 159 | // find out if this image has been already checked for status |
| 160 | // if it was, and src has not changed, call imgLoaded on it |
| 161 | var cached = $.data( el, 'foogalleryImagesLoaded' ); |
| 162 | if ( cached && cached.src === src ) { |
| 163 | imgLoaded( el, cached.isBroken ); |
| 164 | return; |
| 165 | } |
| 166 | |
| 167 | // if complete is true and browser supports natural sizes, try |
| 168 | // to check for image status manually |
| 169 | if ( el.complete && el.naturalWidth !== undefined ) { |
| 170 | imgLoaded( el, el.naturalWidth === 0 || el.naturalHeight === 0 ); |
| 171 | return; |
| 172 | } |
| 173 | |
| 174 | // cached images don't fire load sometimes, so we reset src, but only when |
| 175 | // dealing with IE, or image is complete (loaded) and failed manual check |
| 176 | // webkit hack from http://groups.google.com/group/jquery-dev/browse_thread/thread/eee6ab7b2da50e1f |
| 177 | if ( el.readyState || el.complete ) { |
| 178 | el.src = BLANK; |
| 179 | el.src = src; |
| 180 | } |
| 181 | }); |
| 182 | } |
| 183 | |
| 184 | return deferred ? deferred.promise( $this ) : $this; |
| 185 | }; |
| 186 | |
| 187 | // global |
| 188 | var $window = $( window ), |
| 189 | FooGalleryStackAlbumModernizr = window.FooGalleryStackAlbumModernizr; |
| 190 | |
| 191 | $.Stapel = function( options, element ) { |
| 192 | |
| 193 | this.el = $( element ); |
| 194 | this._init( options ); |
| 195 | |
| 196 | }; |
| 197 | |
| 198 | // the options |
| 199 | $.Stapel.defaults = { |
| 200 | // space between the items |
| 201 | gutter : 40, |
| 202 | // the rotations degree for the 2nd and 3rd item |
| 203 | // (to give a more realistic pile effect) |
| 204 | pileAngles : 2, |
| 205 | // animation settings for the clicked pile's items |
| 206 | pileAnimation : { |
| 207 | openSpeed : 400, |
| 208 | openEasing : 'ease-in-out', // try this :) 'cubic-bezier(.47,1.34,.9,1.03)', |
| 209 | closeSpeed : 400, |
| 210 | closeEasing : 'ease-in-out' |
| 211 | }, |
| 212 | // animation settings for the other piles |
| 213 | otherPileAnimation : { |
| 214 | openSpeed : 400, |
| 215 | openEasing : 'ease-in-out', |
| 216 | closeSpeed : 350, |
| 217 | closeEasing : 'ease-in-out' |
| 218 | }, |
| 219 | // delay for each item of the pile |
| 220 | delay : 0, |
| 221 | // random rotation for the items once opened |
| 222 | randomAngle : false, |
| 223 | onLoad : function() { return false; }, |
| 224 | onBeforeOpen : function( pileName ) { return false; }, |
| 225 | onAfterOpen : function( pileName, totalItems ) { return false; }, |
| 226 | onBeforeClose : function( pileName ) { return false; }, |
| 227 | onAfterClose : function( pileName, totalItems ) { return false; } |
| 228 | }; |
| 229 | |
| 230 | $.Stapel.prototype = { |
| 231 | |
| 232 | _init : function( options ) { |
| 233 | |
| 234 | // options |
| 235 | this.options = $.extend( true, {}, $.Stapel.defaults, options ); |
| 236 | |
| 237 | // cache some elements |
| 238 | this._config(); |
| 239 | |
| 240 | // preload images |
| 241 | var self = this; |
| 242 | this.el.foogalleryImagesLoaded( function() { |
| 243 | self.options.onLoad(); |
| 244 | self._layout(); |
| 245 | self._initEvents(); |
| 246 | if (typeof FOOBOX != 'undefined') { |
| 247 | FOOBOX.init(); |
| 248 | } |
| 249 | } ); |
| 250 | |
| 251 | }, |
| 252 | _config : function() { |
| 253 | |
| 254 | // css transitions support |
| 255 | this.support = FooGalleryStackAlbumModernizr.csstransitions; |
| 256 | |
| 257 | var transEndEventNames = { |
| 258 | 'WebkitTransition' : 'webkitTransitionEnd', |
| 259 | 'MozTransition' : 'transitionend', |
| 260 | 'OTransition' : 'oTransitionEnd', |
| 261 | 'msTransition' : 'MSTransitionEnd', |
| 262 | 'transition' : 'transitionend' |
| 263 | }, |
| 264 | transformNames = { |
| 265 | 'WebkitTransform' : '-webkit-transform', |
| 266 | 'MozTransform' : '-moz-transform', |
| 267 | 'OTransform' : '-o-transform', |
| 268 | 'msTransform' : '-ms-transform', |
| 269 | 'transform' : 'transform' |
| 270 | }; |
| 271 | |
| 272 | if( this.support ) { |
| 273 | |
| 274 | this.transEndEventName = transEndEventNames[ FooGalleryStackAlbumModernizr.prefixed( 'transition' ) ] + '.cbpFWSlider'; |
| 275 | this.transformName = transformNames[ FooGalleryStackAlbumModernizr.prefixed( 'transform' ) ]; |
| 276 | |
| 277 | } |
| 278 | |
| 279 | // true if one pile is opened |
| 280 | this.spread = false; |
| 281 | |
| 282 | // the li's |
| 283 | this.items = this.el.children( 'li' ).hide(); |
| 284 | |
| 285 | // close pile |
| 286 | this.close = $( '#tp-close' ); |
| 287 | |
| 288 | }, |
| 289 | _getSize : function() { |
| 290 | |
| 291 | this.elWidth = this.el.outerWidth( true ); |
| 292 | |
| 293 | }, |
| 294 | _initEvents : function() { |
| 295 | |
| 296 | var self = this; |
| 297 | $window.on( 'debouncedresize.stapel', function() { self._resize(); } ); |
| 298 | this.items.on( 'click.stapel', function() { |
| 299 | |
| 300 | var $item = $( this ); |
| 301 | |
| 302 | if( !self.spread && $item.data( 'isPile' ) ) { |
| 303 | |
| 304 | self.spread = true; |
| 305 | self.pileName = $item.data( 'pileName' ); |
| 306 | self.options.onBeforeOpen( self.pileName ); |
| 307 | self._openPile(); |
| 308 | |
| 309 | return false; |
| 310 | |
| 311 | } |
| 312 | |
| 313 | } ); |
| 314 | |
| 315 | }, |
| 316 | _layout : function() { |
| 317 | |
| 318 | /* |
| 319 | piles() : save the items info in a object with the following structure: |
| 320 | |
| 321 | this.piles = { |
| 322 | |
| 323 | pileName : { |
| 324 | |
| 325 | // elements of this pile (note that an element can be also in a different pile) |
| 326 | // for each element, the finalPosition is the position of the element when the pile is opened |
| 327 | elements : [ |
| 328 | { el : HTMLELEMENT, finalPosition : { left : LEFT, top : TOP } }, |
| 329 | {}, |
| 330 | {}, |
| 331 | ... |
| 332 | ], |
| 333 | // this is the position of the pile (all elements of the pile) when the pile is closed |
| 334 | position : { left : LEFT, top : TOP }, |
| 335 | index : INDEX |
| 336 | }, |
| 337 | |
| 338 | // more piles |
| 339 | ... |
| 340 | |
| 341 | } |
| 342 | */ |
| 343 | this._piles(); |
| 344 | |
| 345 | // items width & height |
| 346 | // assuming here that all items have the same width and height |
| 347 | this.itemSize = { width : this.items.outerWidth( true ) , height : this.items.outerHeight( true ) }; |
| 348 | |
| 349 | // remove original elements |
| 350 | this.items.remove(); |
| 351 | |
| 352 | // applies some initial style for the items |
| 353 | this._setInitialStyle(); |
| 354 | |
| 355 | this.el.css( 'min-width', this.itemSize.width + this.options.gutter ); |
| 356 | |
| 357 | // gets the current ul size (needed for the calculation of each item's position) |
| 358 | this._getSize(); |
| 359 | |
| 360 | // calculate and set each Pile's elements position based on the current ul width |
| 361 | // this function will also be called on window resize |
| 362 | this._setItemsPosition(); |
| 363 | |
| 364 | // new items |
| 365 | this.items = this.el.children( 'li' ).show(); |
| 366 | // total items |
| 367 | this.itemsCount = this.items.length; |
| 368 | |
| 369 | }, |
| 370 | _piles : function() { |
| 371 | |
| 372 | var piles = {}; |
| 373 | this.pilesArr = []; |
| 374 | var pile, self = this, idx = 0; |
| 375 | this.items.each( function() { |
| 376 | |
| 377 | var $item = $( this ), |
| 378 | itemPile = $item.attr( 'data-pile' ) || 'nopile-' + $item.index(), |
| 379 | attr = itemPile.split( ',' ); |
| 380 | |
| 381 | for( var i = 0, total = attr.length; i < total; ++i ) { |
| 382 | |
| 383 | var pileName = $.trim( attr[i] ); |
| 384 | pile = piles[ pileName ]; |
| 385 | |
| 386 | if( !pile ) { |
| 387 | |
| 388 | pile = piles[ pileName ] = { |
| 389 | name : pileName, |
| 390 | elements : [], |
| 391 | position : { left : 0, top : 0 }, |
| 392 | index : idx |
| 393 | }; |
| 394 | |
| 395 | self.pilesArr.push(pile); |
| 396 | |
| 397 | ++idx; |
| 398 | |
| 399 | } |
| 400 | |
| 401 | var clone = $item.clone().get(0); |
| 402 | pile.elements.push( { el : clone, finalPosition : { left : 0, top : 0 } } ); |
| 403 | var $clone = $(clone); |
| 404 | $clone.appendTo(self.el); |
| 405 | } |
| 406 | |
| 407 | } ); |
| 408 | |
| 409 | }, |
| 410 | _setInitialStyle : function() { |
| 411 | for (var j =0, pile_len = this.pilesArr.length; j < pile_len; j++){ |
| 412 | |
| 413 | var p = this.pilesArr[j], featured = false, $el, styleCSS; |
| 414 | for (var k = 0, kl = p.elements.length; k < kl; k++){ |
| 415 | if ( $( p.elements[k].el ).data('featured') ){ |
| 416 | featured = true; |
| 417 | break; |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | for( var i = 0, len = p.elements.length; i < len; ++i ) { |
| 422 | |
| 423 | $el = $( p.elements[i].el ); |
| 424 | styleCSS = { transform : 'rotate(0deg)' }; |
| 425 | |
| 426 | this._applyInitialTransition( $el ); |
| 427 | |
| 428 | if ( p.name.substr( 0, 6 ) !== 'nopile' && ( $el.data('featured') || ( !featured && i === 0 ) ) ){ |
| 429 | $el.css({ zIndex: 9999 }).data( 'front', true ).append( '<div class="tp-title-cover"><div class="tp-title"><span>' + p.name + '</span><span>' + len + '</span></div></div>' ); |
| 430 | } |
| 431 | else if( i === len - 2 ) { |
| 432 | styleCSS = { transform : 'rotate(' + this.options.pileAngles + 'deg)' }; |
| 433 | } |
| 434 | else if( i === len - 3 ) { |
| 435 | styleCSS = { transform : 'rotate(-' + this.options.pileAngles + 'deg)' }; |
| 436 | } |
| 437 | else { |
| 438 | var extraStyle = { visibility : 'hidden' }; |
| 439 | $el.css( extraStyle ).data( 'extraStyle', extraStyle ); |
| 440 | } |
| 441 | |
| 442 | $el.css( styleCSS ).data( { |
| 443 | initialStyle : styleCSS, |
| 444 | pileName : p.name, |
| 445 | pileCount : len, |
| 446 | shadow : $el.css( 'box-shadow' ), |
| 447 | isPile : p.name.substr(0, 6) !== 'nopile' |
| 448 | } ); |
| 449 | |
| 450 | } |
| 451 | |
| 452 | } |
| 453 | |
| 454 | }, |
| 455 | _applyInitialTransition : function( $el ) { |
| 456 | |
| 457 | if( this.support ) { |
| 458 | $el.css( 'transition', 'left 400ms ease-in-out, top 400ms ease-in-out' ); |
| 459 | } |
| 460 | |
| 461 | }, |
| 462 | _setItemsPosition : function() { |
| 463 | |
| 464 | var accumL = 0, accumT = 0, |
| 465 | l, t, ml = 0, |
| 466 | lastItemTop = 0; |
| 467 | |
| 468 | for (var j =0, pile_len = this.pilesArr.length; j < pile_len; j++){ |
| 469 | |
| 470 | var p = this.pilesArr[j], |
| 471 | |
| 472 | //for( var pile in this.piles ) { |
| 473 | // |
| 474 | // var p = this.piles[pile], |
| 475 | stepW = this.itemSize.width + this.options.gutter, |
| 476 | |
| 477 | accumIL = 0, accumIT = 0, il, it; |
| 478 | |
| 479 | if( accumL + stepW <= this.elWidth ) { |
| 480 | |
| 481 | l = accumL; |
| 482 | t = accumT; |
| 483 | accumL += stepW; |
| 484 | |
| 485 | } |
| 486 | else { |
| 487 | |
| 488 | if( ml === 0 ) { |
| 489 | ml = Math.ceil( ( this.elWidth - accumL + this.options.gutter ) / 2 ); |
| 490 | } |
| 491 | |
| 492 | accumT += this.itemSize.height + this.options.gutter; |
| 493 | l = 0; |
| 494 | t = accumT; |
| 495 | accumL = stepW; |
| 496 | |
| 497 | } |
| 498 | |
| 499 | p.position.left = l; |
| 500 | p.position.top = t; |
| 501 | |
| 502 | for( var i = 0, len = p.elements.length; i < len; ++i ) { |
| 503 | |
| 504 | var elem = p.elements[i], |
| 505 | fp = elem.finalPosition; |
| 506 | |
| 507 | if( accumIL + stepW <= this.elWidth ) { |
| 508 | |
| 509 | il = accumIL; |
| 510 | it = accumIT; |
| 511 | accumIL += stepW; |
| 512 | |
| 513 | } |
| 514 | else { |
| 515 | |
| 516 | accumIT += this.itemSize.height + this.options.gutter; |
| 517 | il = 0; |
| 518 | it = accumIT; |
| 519 | accumIL = stepW; |
| 520 | |
| 521 | } |
| 522 | |
| 523 | fp.left = il; |
| 524 | fp.top = it; |
| 525 | |
| 526 | var $el = $( elem.el ); |
| 527 | |
| 528 | if(p.name !== this.pileName ) { |
| 529 | |
| 530 | $el.css( { left : p.position.left, top : p.position.top } ); |
| 531 | |
| 532 | } |
| 533 | else { |
| 534 | |
| 535 | lastItemTop = elem.finalPosition.top; |
| 536 | $el.css( { left : elem.finalPosition.left, top : lastItemTop } ); |
| 537 | |
| 538 | } |
| 539 | |
| 540 | } |
| 541 | |
| 542 | } |
| 543 | |
| 544 | if( ml === 0 ) { |
| 545 | ml = Math.ceil( ( this.elWidth - accumL + this.options.gutter ) / 2 ); |
| 546 | } |
| 547 | |
| 548 | // the position of the items will influence the final margin left value and height for the ul |
| 549 | // center the ul |
| 550 | lastItemTop = this.spread ? lastItemTop : accumT; |
| 551 | this.marginLeft = ml; |
| 552 | this.el.css( { |
| 553 | marginLeft : this.marginLeft, |
| 554 | height : lastItemTop + this.itemSize.height |
| 555 | } ); |
| 556 | |
| 557 | }, |
| 558 | _openPile : function() { |
| 559 | |
| 560 | if( !this.spread ) { |
| 561 | return false; |
| 562 | } |
| 563 | |
| 564 | // final style |
| 565 | var fs, rowWidth = 0; |
| 566 | |
| 567 | for (var j =0, pile_len = this.pilesArr.length; j < pile_len; j++){ |
| 568 | |
| 569 | var p = this.pilesArr[j], |
| 570 | cnt = 0; |
| 571 | |
| 572 | for( var i = 0, len = p.elements.length; i < len; ++i ) { |
| 573 | |
| 574 | var elem = p.elements[i], |
| 575 | $item = $( elem.el ), |
| 576 | styleCSS = p.name === this.pileName ? { |
| 577 | zIndex : 9999, |
| 578 | visibility : 'visible', |
| 579 | transition : this.support ? 'left ' + this.options.pileAnimation.openSpeed + 'ms ' + ( ( len - i - 1 ) * this.options.delay ) + 'ms ' + this.options.pileAnimation.openEasing + ', top ' + this.options.pileAnimation.openSpeed + 'ms ' + ( ( len - i - 1 ) * this.options.delay ) + 'ms ' + this.options.pileAnimation.openEasing + ', ' + this.transformName + ' ' + this.options.pileAnimation.openSpeed + 'ms ' + ( ( len - i - 1 ) * this.options.delay ) + 'ms ' + this.options.pileAnimation.openEasing : 'none' |
| 580 | } : { |
| 581 | zIndex : 1, |
| 582 | transition : this.support ? 'opacity ' + this.options.otherPileAnimation.closeSpeed + 'ms ' + this.options.otherPileAnimation.closeEasing : 'none' |
| 583 | }; |
| 584 | |
| 585 | if( p.name === this.pileName ) { |
| 586 | |
| 587 | if (elem.finalPosition.top === 0){ |
| 588 | if (rowWidth > 0) rowWidth += this.options.gutter; |
| 589 | rowWidth += this.itemSize.width; |
| 590 | } |
| 591 | |
| 592 | if( $item.data( 'front' ) ) { |
| 593 | $item.find( 'div.tp-title' ).hide(); |
| 594 | } |
| 595 | |
| 596 | fs = elem.finalPosition; |
| 597 | fs.transform = this.options.randomAngle && i !== p.index ? 'rotate(' + Math.floor( Math.random() * ( 5 + 5 + 1 ) - 5 ) + 'deg)' : 'none'; |
| 598 | |
| 599 | if( !this.support ) { |
| 600 | $item.css( 'transform', 'none' ); |
| 601 | } |
| 602 | |
| 603 | // hack: remove box-shadow while animating to prevent the shadow stack effect |
| 604 | if( i < len - 3 ) { |
| 605 | $item.css( 'box-shadow', 'none' ); |
| 606 | } |
| 607 | |
| 608 | } |
| 609 | |
| 610 | $item.css( styleCSS ); |
| 611 | |
| 612 | var self = this; |
| 613 | |
| 614 | p.name === this.pileName ? |
| 615 | this._applyTransition( $item, fs, this.options.pileAnimation.openSpeed, function( evt ) { |
| 616 | |
| 617 | var target = this.target || this.nodeName; |
| 618 | if( target !== 'LI' ) { |
| 619 | return; |
| 620 | } |
| 621 | |
| 622 | var $el = $( this ); |
| 623 | |
| 624 | // hack: remove box-shadow while animating to prevent the shadow stack effect |
| 625 | $el.css( 'box-shadow', $el.data( 'shadow' ) ); |
| 626 | |
| 627 | if( self.support ) { |
| 628 | $el.off( self.transEndEventName ); |
| 629 | } |
| 630 | |
| 631 | ++cnt; |
| 632 | |
| 633 | if( cnt === $el.data( 'pileCount' ) ) { |
| 634 | |
| 635 | $( document ).one( 'mousemove.stapel', function() { |
| 636 | self.el.addClass( 'tp-open' ); |
| 637 | } ); |
| 638 | self.options.onAfterOpen( self.pileName, cnt ); |
| 639 | |
| 640 | } |
| 641 | |
| 642 | } ) : |
| 643 | this._applyTransition( $item, { visibility: 'hidden', opacity : 0 }, this.options.otherPileAnimation.closeSpeed ); |
| 644 | |
| 645 | } |
| 646 | |
| 647 | } |
| 648 | |
| 649 | //this.el.css( 'height', fs.top + this.itemSize.height ); |
| 650 | this.el.css({ |
| 651 | marginLeft: Math.ceil((this.elWidth - rowWidth) / 2), |
| 652 | height: fs.top + this.itemSize.height |
| 653 | }); |
| 654 | |
| 655 | }, |
| 656 | _closePile : function() { |
| 657 | |
| 658 | var self = this; |
| 659 | |
| 660 | // close.. |
| 661 | if( this.spread ) { |
| 662 | |
| 663 | this.spread = false; |
| 664 | |
| 665 | this.options.onBeforeClose( this.pileName ); |
| 666 | |
| 667 | this.el.removeClass( 'tp-open' ); |
| 668 | |
| 669 | // final style |
| 670 | var fs; |
| 671 | for (var j =0, pile_len = this.pilesArr.length; j < pile_len; j++){ |
| 672 | |
| 673 | var p = this.pilesArr[j], |
| 674 | cnt = 0; |
| 675 | |
| 676 | for( var i = 0, len = p.elements.length; i < len; ++i ) { |
| 677 | |
| 678 | var $item = $( p.elements[i].el ), |
| 679 | styleCSS = p.name === this.pileName ? { |
| 680 | transition : this.support ? 'left ' + this.options.pileAnimation.closeSpeed + 'ms ' + this.options.pileAnimation.closeEasing + ', top ' + this.options.pileAnimation.closeSpeed + 'ms ' + this.options.pileAnimation.closeEasing + ', ' + this.transformName + ' ' + this.options.pileAnimation.closeSpeed + 'ms ' + this.options.pileAnimation.closeEasing : 'none' |
| 681 | } : { |
| 682 | transition : this.support ? 'opacity ' + this.options.otherPileAnimation.openSpeed + 'ms ' + this.options.otherPileAnimation.openEasing : 'none' |
| 683 | }; |
| 684 | |
| 685 | $item.css( styleCSS ); |
| 686 | |
| 687 | fs = p.position; |
| 688 | |
| 689 | if(p.name === this.pileName ) { |
| 690 | |
| 691 | $.extend( fs, $item.data( 'initialStyle' ) ); |
| 692 | |
| 693 | // hack: remove box-shadow while animating to prevent the shadow stack effect |
| 694 | if( i < len - 3 ) { |
| 695 | $item.css( 'box-shadow', 'none' ); |
| 696 | } |
| 697 | |
| 698 | } |
| 699 | |
| 700 | p.name === this.pileName ? this._applyTransition( $item, fs, this.options.pileAnimation.closeSpeed, function( evt ) { |
| 701 | |
| 702 | var target = this.target || this.nodeName; |
| 703 | if( target !== 'LI' ) { |
| 704 | return; |
| 705 | } |
| 706 | |
| 707 | var $el = $( this ), extraStyle = $el.data( 'extraStyle' ), initialStyle = $el.data( 'initialStyle' ); |
| 708 | |
| 709 | // hack: remove box-shadow while animating to prevent the shadow stack effect |
| 710 | $el.css( 'box-shadow', $el.data( 'shadow' ) ); |
| 711 | |
| 712 | if( self.support ) { |
| 713 | $el.off( self.transEndEventName ); |
| 714 | self._applyInitialTransition( $el ); |
| 715 | } |
| 716 | else { |
| 717 | $el.css( initialStyle ); |
| 718 | } |
| 719 | |
| 720 | if( extraStyle ) { |
| 721 | $el.css( extraStyle ); |
| 722 | } |
| 723 | |
| 724 | ++cnt; |
| 725 | |
| 726 | if( $el.data( 'front' ) ) { |
| 727 | $el.css({visibility: 'visible'}).find( 'div.tp-title' ).show(); |
| 728 | } else { |
| 729 | $el.css({visibility: 'hidden', zIndex: 1}); |
| 730 | } |
| 731 | |
| 732 | if( cnt === $el.data( 'pileCount' ) ) { |
| 733 | self.options.onAfterClose( $el.data( 'pileName' ), cnt ); |
| 734 | } |
| 735 | |
| 736 | } ) : this._applyTransition( $item, { opacity : 1 }, this.options.otherPileAnimation.openSpeed, function( evt ) { |
| 737 | |
| 738 | var target = this.target || this.nodeName; |
| 739 | if( target !== 'LI' ) { |
| 740 | return; |
| 741 | } |
| 742 | |
| 743 | var $el = $( this ); |
| 744 | if( $el.data( 'front' ) ) { |
| 745 | $el.css({visibility: 'visible'}).find( 'div.tp-title' ).show(); |
| 746 | } else { |
| 747 | $el.css({visibility: 'hidden', zIndex: 1}); |
| 748 | } |
| 749 | |
| 750 | if( self.support ) { |
| 751 | $el.off( self.transEndEventName ); |
| 752 | self._applyInitialTransition( $el ); |
| 753 | } |
| 754 | |
| 755 | } ); |
| 756 | |
| 757 | } |
| 758 | |
| 759 | } |
| 760 | |
| 761 | // reset pile name |
| 762 | this.pileName = ''; |
| 763 | |
| 764 | // update ul height |
| 765 | //this.el.css( 'height', fs.top + this.itemSize.height ); |
| 766 | this.el.css({ |
| 767 | marginLeft: this.marginLeft, |
| 768 | height: fs.top + this.itemSize.height |
| 769 | }); |
| 770 | |
| 771 | } |
| 772 | |
| 773 | return false; |
| 774 | |
| 775 | }, |
| 776 | _resize : function() { |
| 777 | |
| 778 | // get ul size again |
| 779 | this._getSize(); |
| 780 | // reset items positions |
| 781 | this._setItemsPosition(); |
| 782 | |
| 783 | }, |
| 784 | _applyTransition : function( el, styleCSS, speed, fncomplete ) { |
| 785 | |
| 786 | $.fn.applyStyle = this.support ? $.fn.css : $.fn.animate; |
| 787 | |
| 788 | if( fncomplete && this.support ) { |
| 789 | |
| 790 | el.on( this.transEndEventName, fncomplete ); |
| 791 | |
| 792 | } |
| 793 | |
| 794 | fncomplete = fncomplete || function() { return false; }; |
| 795 | |
| 796 | el.stop().applyStyle( styleCSS, $.extend( true, [], { duration : speed + 'ms', complete : fncomplete } ) ); |
| 797 | |
| 798 | }, |
| 799 | closePile : function() { |
| 800 | |
| 801 | this._closePile(); |
| 802 | |
| 803 | } |
| 804 | |
| 805 | }; |
| 806 | |
| 807 | var logError = function( message ) { |
| 808 | |
| 809 | if ( window.console ) { |
| 810 | |
| 811 | window.console.error( message ); |
| 812 | |
| 813 | } |
| 814 | |
| 815 | }; |
| 816 | |
| 817 | $.fn.stapel = function( options ) { |
| 818 | |
| 819 | var instance = $.data( this, 'stapel' ); |
| 820 | |
| 821 | if ( typeof options === 'string' ) { |
| 822 | |
| 823 | var args = Array.prototype.slice.call( arguments, 1 ); |
| 824 | |
| 825 | this.each(function() { |
| 826 | |
| 827 | if ( !instance ) { |
| 828 | |
| 829 | logError( "cannot call methods on stapel prior to initialization; " + |
| 830 | "attempted to call method '" + options + "'" ); |
| 831 | return; |
| 832 | |
| 833 | } |
| 834 | |
| 835 | if ( !$.isFunction( instance[options] ) || options.charAt(0) === "_" ) { |
| 836 | |
| 837 | logError( "no such method '" + options + "' for stapel instance" ); |
| 838 | return; |
| 839 | |
| 840 | } |
| 841 | |
| 842 | instance[ options ].apply( instance, args ); |
| 843 | |
| 844 | }); |
| 845 | |
| 846 | } |
| 847 | else { |
| 848 | |
| 849 | this.each(function() { |
| 850 | |
| 851 | if ( instance ) { |
| 852 | |
| 853 | instance._init(); |
| 854 | |
| 855 | } |
| 856 | else { |
| 857 | |
| 858 | instance = $.data( this, 'stapel', new $.Stapel( options, this ) ); |
| 859 | |
| 860 | } |
| 861 | |
| 862 | }); |
| 863 | |
| 864 | } |
| 865 | |
| 866 | return instance; |
| 867 | |
| 868 | }; |
| 869 | |
| 870 | } )( jQuery, window ); |