vendor/assets/javascripts/vegas/jquery.vegas.js in pcs_vegas-0.0.1.beta vs vendor/assets/javascripts/vegas/jquery.vegas.js in pcs_vegas-0.0.1

- old
+ new

@@ -1,13 +1,13 @@ // ---------------------------------------------------------------------------- // Vegas - jQuery plugin // Add awesome fullscreen backgrounds to your webpages. -// v 1.x +// v 1.3.1 // Dual licensed under the MIT and GPL licenses. // http://vegas.jaysalvat.com/ // ---------------------------------------------------------------------------- -// Copyright (C) 2011 Jay Salvat +// Copyright (C) 2012 Jay Salvat // http://jaysalvat.com/ // ---------------------------------------------------------------------------- // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files ( the "Software" ), to deal // in the Software without restriction, including without limitation the rights @@ -32,12 +32,12 @@ $loading = $( '<div />' ).addClass( 'vegas-loading' ), $current = $(), paused = null, backgrounds = [], step = 0, - delay = 5000, - walk = function() {}, + delay = 5000, + walk = function() {}, timer, methods = { // Init plugin init : function( settings ) { @@ -60,16 +60,16 @@ $new.css( { 'position': 'fixed', 'left': '0px', 'top': '0px' }) - .imagesLoadedForVegas( function() { + .bind('load', function() { if ( $new == $current ) { return; } - $( window ).bind( 'resize.vegas', function( e ) { + $( window ).bind( 'load resize.vegas', function( e ) { resize( $new, options ); }); if ( $current.is( 'img' ) ) { @@ -117,11 +117,11 @@ // Destroy background and/or overlay destroy: function( what ) { if ( !what || what == 'background') { $( '.vegas-background, .vegas-loading' ).remove(); $( window ).unbind( 'resize.vegas' ); - $current = null; + $current = $(); } if ( what == 'overlay') { $( '.vegas-overlay' ).remove(); } @@ -188,13 +188,13 @@ $.vegas( 'preload', options.backgrounds ); } } backgrounds = options.backgrounds; - delay = options.delay; + delay = options.delay; step = options.step; - walk = options.walk; + walk = options.walk; clearInterval( timer ); if ( !backgrounds.length ) { return $.vegas; @@ -210,14 +210,18 @@ } var settings = backgrounds[ step++ ]; settings.walk = options.walk; + if ( typeof( settings.fade ) == 'undefined' ) { + settings.fade = options.fade; + } + if ( settings.fade > options.delay ) { settings.fade = options.delay; } - + $.vegas( settings ); } doSlideshow(); if ( !keepPause ) { @@ -313,13 +317,16 @@ } }, // Preload an array of backgrounds preload: function( backgrounds ) { + var cache = []; for( var i in backgrounds ) { if ( backgrounds[ i ].src ) { - $('<img src="' + backgrounds[ i ].src + '">'); + var cacheImage = document.createElement('img'); + cacheImage.src = backgrounds[ i ].src; + cache.push(cacheImage); } } return $.vegas; } @@ -331,10 +338,18 @@ align: 'center', valign: 'center' } $.extend( options, settings ); + if( $img.height() == 0 ) { + console.log('pecouille'); + $img.load( function(){ + resize( $(this), settings ); + } ); + return; + } + var ww = $( window ).width(), wh = $( window ).height(), iw = $img.width(), ih = $img.height(), rw = wh / ww, @@ -352,14 +367,14 @@ } properties = { 'width': newWidth + 'px', 'height': newHeight + 'px', - 'top': 'auto', - 'bottom': 'auto', - 'left': 'auto', - 'right': 'auto' + 'top': 'auto', + 'bottom': 'auto', + 'left': 'auto', + 'right': 'auto' } if ( !isNaN( parseInt( options.valign ) ) ) { properties[ 'top' ] = ( 0 - ( newHeight - wh ) / 100 * parseInt( options.valign ) ) + 'px'; } else if ( options.valign == 'top' ) { @@ -423,10 +438,11 @@ // loading bool // load: function // complete: function }, slideshow: { + // fade: null // step: int // delay: int // backgrounds: array // preload: bool // walk: function @@ -434,47 +450,6 @@ overlay: { // src: string // opacity: float } } - - /*! - * jQuery imagesLoaded plugin v1.0.3 - * http://github.com/desandro/imagesloaded - * - * MIT License. by Paul Irish et al. - */ - $.fn.imagesLoadedForVegas = function( callback ) { - var $this = this, - $images = $this.find('img').add( $this.filter('img') ), - len = $images.length, - blank = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw=='; - - function triggerCallback() { - callback.call( $this, $images ); - } - - function imgLoaded() { - if ( --len <= 0 && this.src !== blank ){ - setTimeout( triggerCallback ); - $images.unbind( 'load error', imgLoaded ); - } - } - - if ( !len ) { - triggerCallback(); - } - - $images.bind( 'load error', imgLoaded ).each( function() { - // cached images don't fire load sometimes, so we reset src. - if (this.complete || this.complete === undefined){ - var src = this.src; - // webkit hack from http://groups.google.com/group/jquery-dev/browse_thread/thread/eee6ab7b2da50e1f - // data uri bypasses webkit log warning (thx doug jones) - this.src = blank; - this.src = src; - } - }); - - return $this; - }; })( jQuery ); \ No newline at end of file