Learn how to use jQuery at the Blog

Biografy « visit

  • Added 11 months ago
  • 117 Lines of Code shown
  • 0 Links of Interest
http://biografy.cz/en/about-project/
This is my Source Code and I don't want to show it here
View Source Code only (as overlay)
// That code snippet belongs to Biografy - http://biografy.cz/en/about-project/


function deIE(str) {
	/* IE hack - problem s absolutni cestou */
	spl = str.split("/");
	return spl[spl.length-1];
}

function closeGallery() {
	$('div.gallery-gen').fadeOut('fast')
	$('div.gallery-gen').remove();
}

function loaderAnim(srcImg) {
	$('body').append('<div class="loaderAnim" />');	
	obj = $('div.loaderAnim');
	obj.css({top: srcImg.offset()['top'], left: srcImg.offset()['left'], 
			    position: 'absolute',  zIndex:200, visibility: 'visible', width: srcImg.width(), height: srcImg.height() });
	return obj;
}

function animateResize(obj) {
	
	var maxHeight = '800';
	var maxWidth = '900'
	var parentAnchor = $('img',obj).parent();
	var thumbImg = $('img',obj);

    var title = '';
    if( parentAnchor.attr('title').length>0 ) {
        var title = '<p class="galTitle">'+parentAnchor.attr('title')+'</p>';
    }
	$('body').append('<div class="gallery-gen" style="position:absolute;visibility:hidden; display:block;"><div class="gallery-images">'+
            '<img class="middleImg" src="'+parentAnchor.attr('href')+'" />'+title+'</div></div>');	

	var galleryDiv = $('div.gallery-gen');
	var middleImg = $('img.middleImg',galleryDiv);
	var srcImg =  $('img.resizable', obj);
	
//	loader = loaderAnim(srcImg);

	middleImg.one('load', function(){
	
//		loader.remove();
		var orig_width = this.width;
		var orig_height = this.height;

		pomer = thumbImg.width()/thumbImg.height();

		/* pokud se nam z IE6 vrati nulove hodnoty zkusime zrekonstruovat rozmery z nahledu {{ */
		if(orig_width==0 || orig_height==0) {
			alert('fdfs');
			orig_width = Math.round(maxSide*pomer);
			orig_height = maxHeight;
		}
		/* }} */
		
		if(orig_height>maxHeight) {
			orig_height = maxHeight;			
			orig_width = Math.round(orig_height*pomer);
		}
		
		if(orig_width>maxWidth) {
			orig_width = maxWidth;			
			orig_height = Math.round(orig_width*(thumbImg.height()/thumbImg.width()));
		}		
		
		var center_h = ($(window).width()/2)-(orig_width/2);
		var center_v = ($(window).height()/2)-(orig_height/2)+$(window).scrollTop();
		
		middleImg.css({ width: srcImg.width(), height: srcImg.height() });
		galleryDiv.css({top: srcImg.offset()['top'], left: srcImg.offset()['left'], 
				    position: 'absolute',  zIndex:100, visibility: 'visible' });
		galleryDiv.animate({top: center_v, left: center_h});

		middleImg.animate({ width: orig_width+'px', height: orig_height+'px' }, false, false, function() { 
			/*makeSides($(this).attr('src'), true);
			addControls();*/
            $('p.galTitle').slideDown();
		});

	});



	middleImg.click(closeGallery);
	return false;
}

function showGallery(obj) {
	if( $('.gallery-gen').length==0 ) {
		animateResize(obj);
	} else {
		$('.gallery-gen').remove();
	}
}

$(document).ready(
	function() {
		$('img.resizable').parent().click( 
			function() {
				showGallery(this);
				return false;
			}
		);
	}
);

/* special */

$(document).ready( 
	function() {
		$('a.show-map-link').click(function() {
			showGallery($('a.map-href'));
			return false;
		});
	}
)