137 lines
		
	
	
		
			4.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
			
		
		
	
	
			137 lines
		
	
	
		
			4.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
/*!
 | 
						|
 * jQuery imagesLoaded plugin v2.0.1
 | 
						|
 * http://github.com/desandro/imagesloaded
 | 
						|
 *
 | 
						|
 * MIT License. by Paul Irish et al.
 | 
						|
 */
 | 
						|
 | 
						|
/*jshint curly: true, eqeqeq: true, noempty: true, strict: true, undef: true, browser: true */
 | 
						|
/*global jQuery: false */
 | 
						|
 | 
						|
;(function($, undefined) {
 | 
						|
'use strict';
 | 
						|
 | 
						|
// blank image data-uri bypasses webkit log warning (thx doug jones)
 | 
						|
var BLANK = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==';
 | 
						|
 | 
						|
$.fn.imagesLoaded = function( callback ) {
 | 
						|
	var $this = this,
 | 
						|
		deferred = $.isFunction($.Deferred) ? $.Deferred() : 0,
 | 
						|
		hasNotify = $.isFunction(deferred.notify),
 | 
						|
		$images = $this.find('img').add( $this.filter('img') ),
 | 
						|
		loaded = [],
 | 
						|
		proper = [],
 | 
						|
		broken = [];
 | 
						|
 | 
						|
	function doneLoading() {
 | 
						|
		var $proper = $(proper),
 | 
						|
			$broken = $(broken);
 | 
						|
 | 
						|
		if ( deferred ) {
 | 
						|
			if ( broken.length ) {
 | 
						|
				deferred.reject( $images, $proper, $broken );
 | 
						|
			} else {
 | 
						|
				deferred.resolve( $images );
 | 
						|
			}
 | 
						|
		}
 | 
						|
 | 
						|
		if ( $.isFunction( callback ) ) {
 | 
						|
			callback.call( $this, $images, $proper, $broken );
 | 
						|
		}
 | 
						|
	}
 | 
						|
 | 
						|
	function imgLoaded( img, isBroken ) {
 | 
						|
		// don't proceed if BLANK image, or image is already loaded
 | 
						|
		if ( img.src === BLANK || $.inArray( img, loaded ) !== -1 ) {
 | 
						|
			return;
 | 
						|
		}
 | 
						|
 | 
						|
		// store element in loaded images array
 | 
						|
		loaded.push( img );
 | 
						|
 | 
						|
		// keep track of broken and properly loaded images
 | 
						|
		if ( isBroken ) {
 | 
						|
			broken.push( img );
 | 
						|
		} else {
 | 
						|
			proper.push( img );
 | 
						|
		}
 | 
						|
 | 
						|
		// cache image and its state for future calls
 | 
						|
		$.data( img, 'imagesLoaded', { isBroken: isBroken, src: img.src } );
 | 
						|
 | 
						|
		// trigger deferred progress method if present
 | 
						|
		if ( hasNotify ) {
 | 
						|
			deferred.notifyWith( $(img), [ isBroken, $images, $(proper), $(broken) ] );
 | 
						|
		}
 | 
						|
 | 
						|
		// call doneLoading and clean listeners if all images are loaded
 | 
						|
		if ( $images.length === loaded.length ){
 | 
						|
			setTimeout( doneLoading );
 | 
						|
			$images.unbind( '.imagesLoaded' );
 | 
						|
		}
 | 
						|
	}
 | 
						|
 | 
						|
	// if no images, trigger immediately
 | 
						|
	if ( !$images.length ) {
 | 
						|
		doneLoading();
 | 
						|
	} else {
 | 
						|
		$images.bind( 'load.imagesLoaded error.imagesLoaded', function( event ){
 | 
						|
			// trigger imgLoaded
 | 
						|
			imgLoaded( event.target, event.type === 'error' );
 | 
						|
		}).each( function( i, el ) {
 | 
						|
			var src = el.src;
 | 
						|
 | 
						|
			// find out if this image has been already checked for status
 | 
						|
			// if it was, and src has not changed, call imgLoaded on it
 | 
						|
			var cached = $.data( el, 'imagesLoaded' );
 | 
						|
			if ( cached && cached.src === src ) {
 | 
						|
				imgLoaded( el, cached.isBroken );
 | 
						|
				return;
 | 
						|
			}
 | 
						|
 | 
						|
			// if complete is true and browser supports natural sizes, try
 | 
						|
			// to check for image status manually
 | 
						|
			if ( el.complete && el.naturalWidth !== undefined ) {
 | 
						|
				imgLoaded( el, el.naturalWidth === 0 || el.naturalHeight === 0 );
 | 
						|
				return;
 | 
						|
			}
 | 
						|
 | 
						|
			// cached images don't fire load sometimes, so we reset src, but only when
 | 
						|
			// dealing with IE, or image is complete (loaded) and failed manual check
 | 
						|
			// webkit hack from http://groups.google.com/group/jquery-dev/browse_thread/thread/eee6ab7b2da50e1f
 | 
						|
			if ( el.readyState || el.complete ) {
 | 
						|
				el.src = BLANK;
 | 
						|
				el.src = src;
 | 
						|
			}
 | 
						|
		});
 | 
						|
	}
 | 
						|
 | 
						|
	return deferred ? deferred.promise( $this ) : $this;
 | 
						|
};
 | 
						|
 | 
						|
})(jQuery);
 | 
						|
 | 
						|
$(document).ready(function() {
 | 
						|
	$('.upload-picture').find('img').imagesLoaded(function(){
 | 
						|
	    var picH = $('.upload-picture').width()/$('.upload-picture').find('img').width()*$('.upload-picture').find('img').height();
 | 
						|
	    var imgMarginTop = ($('.upload-picture').height()-picH)/2;
 | 
						|
	    var d = $('.upload-picture').height();
 | 
						|
	    if(imgMarginTop>0){
 | 
						|
	        imgMarginTop = 0;
 | 
						|
	        d = picH;
 | 
						|
	        $('.upload-picture').css({height:d})
 | 
						|
	    }
 | 
						|
	    $('.upload-picture').find('img').css({marginTop:imgMarginTop})
 | 
						|
	    $('.upload-picture').each(function (i){
 | 
						|
	        $(this).mouseenter(function(){
 | 
						|
	            var h= picH;
 | 
						|
	            $(this).stop().animate({height:h}, 500);
 | 
						|
	            $(this).find('img').stop().animate({marginTop:0}, 500);
 | 
						|
	        });
 | 
						|
	        $(this).mouseleave(function(){
 | 
						|
	            $(this).stop().animate({height:d}, 500);
 | 
						|
	            $(this).find('img').stop().animate({marginTop:imgMarginTop}, 500);
 | 
						|
	        });
 | 
						|
	    });
 | 
						|
	});
 | 
						|
}); |