Learn how to use jQuery at the Blog

Unowhy « visit

  • Added 7 months ago
  • 501 Lines of Code shown
  • 2 Links of Interest
http://unowhy.com
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 Unowhy - http://unowhy.com


/* -------------------------------------------------------------------
   // JS de l'index, ne s'éxécute que pour la navigation full ajax
--------------------------------------------------------------------*/

/* -------------------------------------------------------------------
   // Plugin - Fonction Each asyncrone et temporisée
--------------------------------------------------------------------*/

jQuery.slowEach = function( array, interval, callback ) {
    if(!array.length) return;
    var i = 0;
    next();
    function next() {
        if( callback.call( array[i], i, array[i] ) !== false )
            if( ++i < array.length )
                setTimeout( next, interval );
    }
};

jQuery.fn.slowEach = function( interval, callback ) {
    jQuery.slowEach( this, interval, callback );
};

/* -------------------------------------------------------------------
   // Liste des recettes pour Inspire Me
--------------------------------------------------------------------*/
var allRecettes=new Array('recette_2_tartine_saumon','recette_3_muffins_croustillants_pomme','recette_4_brochettes_saint_jacques','video1_ivideococktail','recette_5_video_empanadas_viande');

$(function() {


/* -------------------------------------------------------------------
   // Adresse et bouton back
--------------------------------------------------------------------*/

	$.data($("body").get(0), "class", 'none');	// Data par défaut du type de lien

	/* -------------------------------------------------------------------
	   // Tout les liens sont mappés sur le gestionnaire d'URL.
	--------------------------------------------------------------------*/

	$('A[href*=.htm][target!=new][target!=blank][href!=#]').live("click", function()
	{
		var contentLink=$(this).attr('href');
		var contentLink=contentLink.replace('http://'+document.domain+'','');
		var thisClass='none';
		if ($(this).parent('div').hasClass('btn-next') || $(this).parent('div').hasClass('arrow-next')) {var thisClass='next'}
		else if ($(this).parent('div').hasClass('btn-prev') || $(this).parent('div').hasClass('arrow-prev')) {var thisClass='prev'}
		$.data($("body").get(0), "class", thisClass);
		$.address.value(contentLink);
		pageTracker._trackPageview(contentLink);
		return false;
	});
	var title = document.title;	// Title par défaut

	/* -------------------------------------------------------------------
	   // Gestionnaire d'URL.
	--------------------------------------------------------------------*/
	$.address.init(function(event) {
		$('#menu').animate({'left':0},500);
	}).change(function(event) {
		/* -------------------------------------------------------------------
		   // Affichage du chemin dans la barre de titre
		--------------------------------------------------------------------*/
		var linkAdress=$.address.value().substr(1);
		var names = $.map(event.pathNames, function(n) {
			return n.substr(0, 1).toUpperCase() + n.substr(1);
		}).concat(event.parameters.id ? event.parameters.id.split('.') : []);
		var links = names.slice();
		var match = links.length ? links.shift() + ' ' + links.join('.') : 'Home';
		$.address.title([title].concat(names).join(' | ').replace('.htm',''));

		/* -------------------------------------------------------------------
		   // Cas particuliers
		--------------------------------------------------------------------*/
		if (linkAdress.length<=3 || linkAdress=='index.htm') {
			return false;		// Arrivée sur le site
		}
		/* -------------------------------------------------------------------
		   // Inspire Me - Index
		--------------------------------------------------------------------*/
		else if (linkAdress=='inspire/index.htm') {
			$('#menu').fadeOut({speed: 500, queue: 'inspire', scope: 'disparition',
				complete : function() {$(this).remove();}
			});
			$('h1.logo, div.item, #header').fadeOut({speed: 500, queue: 'inspire', scope: 'disparition',
				complete : function() {
					$(this).remove();
					$('#content').css({'padding':'0','margin':'0','height':'100%'}).addClass('inspire');
				}
			});
			$('html, body').css('overflow','hidden');
			// Lancement des animations
			if ($.fxqueue("inspire").length > 0){$.fxqueue("inspire").start();}

			$('#content').height('100%');
			var contentHeight=$('#content').height();
			var contentWidth=$('body').width();
			for (var y = 1; y <= parseInt(contentHeight/136); y++)
			{
				$('#content').append('<div class="parts"></div>\n');
			}
			$('div.parts:first').css({'margin':'0','padding-top':'9px'});
			var eachWidth=parseInt(contentWidth/145);	// Anciennement 135, fix IE.
			var pcWidth=parseInt(100/eachWidth);
			$('div.parts').each(function (index, domEle) {
				for (var x = 1; x <= parseInt(contentWidth/145); x++)	// Anciennement 135, fix IE.
				{
					$(domEle).append('<div class="part" STYLE="display:none;"><a href="inspire/recette.htm" class="btn-quest">Question</a></div>');
				}
			});
			$('.parts .part').css('width',pcWidth+'%');
			$('A.btn-quest:last').removeClass('btn-quest').addClass('active').attr('href','http://'+document.domain+'/');
			$('div.part').slowEach( 40, function( i, value ) {
				if ($.browser.msie) {
					if ($.browser.version<8){$(document).pngFix();}
					$(this).show();
				}
				else
				{
					$(this).fadeIn('slow');
				}
			});
		}
		/* -------------------------------------------------------------------
		   // Inspire Me - Recette
		--------------------------------------------------------------------*/
		else if (linkAdress=='inspire/recette.htm') {
			// Nettotage - cas bouton back

			$('#menu, h1.logo, div.item, #header').remove();
			$('#content').css({'padding':'0','margin':'0','height':'100%'}).addClass('inspire');
			$('html, body').css('overflow','hidden');

			$('div.part').slowEach( 40, function( i, value ) {
				if ($.browser.msie) {
					$(this).hide();
				}
				else
				{
					$(this).fadeOut('slow');
				}
			});
			$('#content').removeClass('inspire');
			// Une recette au hasard
			randNbr = Math.floor ( Math.random() * allRecettes.length );
			var maRecette=allRecettes[randNbr];
			allRecettes.splice(randNbr, 1);
			$('body img:first').fadeOut('normal').attr('src','inspire/img/'+maRecette+'.jpg').fadeIn('normal');
			var contentHeight=$('#content').height();
			$('#content').hide().html('<div class="scrollContainer"><div class="boxes-holder"></div></div><div class="btn-up" STYLE="display:none;"><a href="#">Up</a></div><div class="btn-down" STYLE="display:none;"><a href="#">Down</a></div><div class="encore" STYLE="bottom:'+contentHeight+'px"><a href="#">&nbsp;</a></div><div class="revenir" STYLE="bottom:'+contentHeight+'px"><a href="http://'+document.domain+'/">&nbsp;</a></div>');
			if ($.browser.msie) {
				$(document).pngFix();
				$('#content').show();
			}
			else
			{
				$('#content').fadeIn('normal');
			}
			$('div.boxes-holder').load('inspire/'+maRecette+'.php', function (){
				pageTracker._trackPageview('inspire/'+maRecette);
				// Stockage via data
				$.data($("body").get(0), "origineHeight", $('div.boxes-holder').height());
				$('div.boxes-holder,div.scrollContainer').height($('body').height());
				if (maRecette=='video1_ivideococktail' || maRecette=='recette_5_video_empanadas_viande')
				{
					$.getScript('js/jquery.swfobject.min.js', function(){
						$('#maVideo').flash({swf:'/swf/video.swf',height:340,width:480});
					});
				}
				else
				{
					$('div.btn-down').show();
					$.getScript('js/jquery.mousewheel.js', function(){
						$('body').bind('mousewheel', function(event, delta) {
							if (delta >0) {
								$('div.btn-up:visible').click();
							}
							else
							{
								$('div.btn-down:visible').click();
							}
				            return false;
				        });
			        });
				}
				// Descente des badges
				if (allRecettes.length==0) {$('div.encore').remove();}
				else {$('div.encore').animate({bottom:'25px'},{duration: 800, queue: 'badges', postDelay: 250});}
				$('div.revenir').animate({bottom:'109px'},{duration: 800, queue: 'badges'});

			});

		}
		/* -------------------------------------------------------------------
		   // Par défaut - Rubriques / Sous-Rubriques
		--------------------------------------------------------------------*/
		else
		{
			// isolation de la rubrique :
			var urls=linkAdress.split('/');

			var nextInfoBack=$('div.part[rel='+urls[0]+'] div.info-box div.info_back');

			// Switch
			var infoHeight=$('#menu div.info_back:visible').height();
			var infoWidth=$('#menu div.info_back:visible').width();

			switch($.data($("body").get(0), "class")){
				case 'next':
					$('#menu div.info_back:visible').children('div.info').animate({left:'-'+infoWidth},{duration: 500, queue: "global",
						complete : function() {$(this).css('left',infoWidth);}
					});
					break;
				case 'prev':
					$('#menu div.info_back:visible').children('div.info').animate({left:+infoWidth},{duration: 500, queue: "global",
						complete : function() {$(this).css('left',-infoWidth);}
					});
					break;
				default:
					$('#menu div.info_back:visible').children('div.info').animate({top:'-'+infoHeight},{duration: 250, queue: "global"});
					// La rubrique est elle déjà ouverte ?
					if ($('div.part[rel='+urls[0]+'] div.info-box div.info_back:visible').size()==1) {
						if ($('div.part[rel='+urls[0]+'] div.holder div.nav span ul li a[href='+urls[0]+'/'+urls[1]+']').size()==1) {
							$('div.part[rel='+urls[0]+'] div.holder div.nav span ul li a.active').removeClass('active');

							var NewMenu=$('div.part[rel='+urls[0]+'] div.holder div.nav span ul li a[href='+urls[0]+'/'+urls[1]+']');
							var nmWidth=$(NewMenu).width(); var nmOffset=$(NewMenu).offset();var nmLeft=nmOffset.left;
							// Glissement de la nav ouverte
							$('div.part[rel='+urls[0]+'] div.holder div.nav span span.nav_move').animate({width: nmWidth,left: nmLeft},{duration: 1000 , complete : function() {$(NewMenu).addClass('active');}});
						}
					}
					else
					{
						var OldNav=$('#menu div.nav-isOpen').children('span');
						OldNav.hide();
						OldNav.children('ul').hide();
						OldNav.children('div.stitre').show();
						OldNav.show();
						$('#menu div.nav-isOpen').removeClass('nav-isOpen').animate({width:'hide'},{duration: 200, queue: "global"});
						$('#menu div.btn').removeClass('btn-isOpen');

						// Chargement du menu
						var thisNav=$('div.part[rel='+urls[0]+'] div.holder div.nav span');
						thisNav.hide();
						thisNav.children('div.stitre').hide();
						thisNav.children('ul').show();
						thisNav.show();

						// Remove isShow de la nav courrante, le place en isOpen
						$('div.part[rel='+urls[0]+'] div.holder div.nav').removeClass('nav-isShow').addClass('nav-isOpen').animate({width:'show'},{duration: 200, queue: "global"});

						// Selection de la nav en cours
						$('div.part[rel='+urls[0]+'] div.holder div.nav ul li A').removeClass('active');
						$('div.part div.holder div.nav span span.nav_move').hide();
						if (typeof urls[1]!=='undefined' && $('div.part[rel='+urls[0]+'] div.holder div.nav ul li A[href='+urls[0]+'/'+urls[1]+']').size()==0) {
							var mois=new RegExp("(janvier|fevrier|mars|avril|mai|juin|juillet|aout|septembre|octobre|novembre|decembre)", "g");
							var occurence=new RegExp("-(1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20).htm", "g");
							urls[1]=urls[1].replace(mois,'');
							urls[1]=urls[1].replace(occurence,'.htm');
							urls[1]=urls[1].replace('--','-');
							urls[1]=urls[1].replace('-.','.');
						}
						var newNav=$('div.part[rel='+urls[0]+'] div.holder div.nav ul li A[href='+urls[0]+'/'+urls[1]+']');
						$('div.part[rel='+urls[0]+'] div.holder div.nav ul li A[href='+urls[0]+'/'+urls[1]+']').addClass('active');
						$('#menu div.info_back:visible').animate({height:'hide'},{duration: 500, queue: "global"});
						nextInfoBack.animate({height:'show'},{duration: 500, queue: "global"});
					}
			} // switch


			// Chargement du contenu
			contentLink=linkAdress.replace('/','_');
			contentLink='pages/'+contentLink.replace('.htm','.php');
			nextInfoBack.children('div.info').empty().load(contentLink).animate({top: 0,left: 0},{duration: 500, queue: "global", scope: "afterShow", complete : function() {
				var infoHeight=$(this).height();
				var infoHeight=infoHeight+40;
				nextInfoBack.animate({height:infoHeight},{duration:150, queue: "global", scope: "equilibre"});

				// Positionnement de "item".
				var infoOffset=$(this).offset();
				var newPosItem=infoHeight+infoOffset.top-60;
				$('#content .item').animate({top: newPosItem+'px'}, {duration: 500, queue: "global", scope: "equilibre"} );
				var nmWidth=$('div.part[rel='+urls[0]+'] div.holder div.nav ul li A.active').width();
				var nmOffset=$('div.part[rel='+urls[0]+'] div.holder div.nav ul li A.active').offset();var nmLeft=nmOffset.left;
				$('div.part[rel='+urls[0]+'] div.holder div.nav span span.nav_move').css({'width': nmWidth,'left': nmLeft}).show();
			}});
			$('div.part[rel='+urls[0]+'] div.holder div.btn').css('cursor','default').addClass('btn-isOpen');
			// Lancement des animations
			if ($.fxqueue("global").length > 0){$.fxqueue("global").start();}
		}
	});

/* -----------------------------------------------------------------------------
	Bouton Inspire Me
------------------------------------------------------------------------------*/
	$('div.item A').css('cursor','pointer').live("click", function(){
		// Scroll thaut de page
		$('html, body').animate({scrollTop:0}, 'slow').css('overflow','hidden');
		$.address.value('inspire/index.htm');
		return false;
	});

	$('div.encore A').live("click", function(){
		var contentHeight=$('#content').height();
		// Dessendre les badges
		$('div.revenir').animate({bottom:''+contentHeight+'109px'},{duration: 800, queue: 'badges', postDelay: 100});
		$('div.encore').animate({bottom:''+contentHeight+'px'},{duration: 800, queue: 'badges'});
		$('#content').fadeOut('normal').html('').addClass('inspire').fadeIn('normal');
		$.address.value('inspire/index.htm');
		return false;
	});


	/* -----------------------------------------------------------------------------
		Inspire Me / Up & Down
	------------------------------------------------------------------------------*/
	$('div.btn-down').live("click", function()
	{
		$('div.btn-up').show();
		var scrollHeight=parseInt($('body').height())-100;
		var thisMargin=$('div.boxes-holder').css('top');
		if (thisMargin=='auto') {thisMargin=0};
		var newMargin=parseInt(thisMargin)-scrollHeight;
		if (Math.abs(newMargin)+$('div.boxes-holder').height()>$.data($("body").get(0), "origineHeight")) {
			newMargin=0-($.data($("body").get(0), "origineHeight")-$('div.boxes-holder').height());
			$('div.btn-down').hide();
		}
		$('div.boxes-holder').animate({top: newMargin+'px'}, 500 );
		return false;
	});

	$('div.btn-up').live("click", function()
	{
		$('div.btn-down').show();
		var scrollHeight=parseInt($('body').height())-100;
		var thisMargin=$('div.boxes-holder').css('top');
		if (thisMargin=='auto') {thisMargin=0};
		var newMargin=parseInt(thisMargin)+scrollHeight;
		if (newMargin>=0) {
			newMargin=0;
			$('div.btn-up').hide();
		}
		$('div.boxes-holder').animate({top: newMargin+'px'}, 500 );
		return false;
	});




});




/* -------------------------------------------------------------------
   // JS du contenu, s'execute partout
--------------------------------------------------------------------*/
$(function() {

/* -------------------------------------------------------------------
   // Hacks
--------------------------------------------------------------------*/

	// Transparence / Pas de fond sous IE 6 et 7 ?

	if ($.browser.msie && $.browser.version<8) {	// Anciens IE trop lents sur transparence

		$.getScript('js/jquery.pngFix.pack.js', function(){
			$(document).pngFix();
		});

		$('div.info-box, div.info_back, div.info').css('background','none').css('background','#F7F6F1');
	}

	// No-Scroll
	$('html, body').css('overflow','hidden');
	// Scroll vertical uniquement sur petits écrans.
	if ($(window).height()<630) {
		$('html, body').css('overflow-y','auto');
	}

	// Hack : sous IE les nav a 100% passent à la ligne qques instants
	// ++ Evite le dépassement des stitres et des menus.
	var bodyWidth=$('body').width();
	$('#menu div.nav').each(function (index, domEle) {
		var prevWidth=$(domEle).prev('div.btn').width();
		$(this).width(bodyWidth-prevWidth-20+'px');
	});

	// resize de la fenêtre
	$(window).bind('resize', function() {
		$('html, body').animate({scrollTop:0}, 'slow').css('overflow','hidden');
		if ($(window).height()<630) {
			$('html, body').css('overflow-y','auto');
		}
		var bodyWidth=$('body').width();
		$('#menu div.nav').each(function (index, domEle) {
			var prevWidth=$(domEle).prev('div.btn').width();
			$(this).width(bodyWidth-prevWidth-20+'px');
		});
		$('div.holder div.nav span span.nav_move:visible').hide();
	})



/* -----------------------------------------------------------------------------
	Fonctions des formulaires
------------------------------------------------------------------------------*/
	/* -----------------------------------------------------------------------------
		Champ "saisissez votre email"
	------------------------------------------------------------------------------*/
	$('INPUT[name=email]').live("click", function()
	{
		if ($(this).val()==$(this).attr('title')) {
			$(this).val('');
		}
	});

	/* -----------------------------------------------------------------------------
		Validation du formulaire
	------------------------------------------------------------------------------*/
	$('#contactsMail INPUT').live("keydown", function(event)
	{
		if (event.keyCode == 13) {
			$('#contactsMail A.submit').click();
			return false;
		}
	});


	$('#contactsMail A.submit').live("click", function()
	{
		var newsEmailOk=false;
		var newsEmail=$('#contactsMail INPUT[name=email]').val();
		var thisPage=$('#contactsMail INPUT[name=page]').val();
		if ((newsEmail.length>7) && (newsEmail.lastIndexOf(".") > 2) && (newsEmail.indexOf("@") > 0) && (newsEmail.lastIndexOf(".") > (newsEmail.indexOf("@")+1)) && (newsEmail.indexOf("@") == newsEmail.lastIndexOf("@") && (newsEmail.lastIndexOf(".")<(newsEmail.length-2))))
		{
			$.post("ajax/actions.php",
			{
				ajaxAction: 'contactsMail'
				,email: newsEmail
				,page: thisPage
			});
			var newsEmailOk=true;
		}
		if (newsEmailOk==true) {
			$('#contactsMail').before("<h2>Merci</h2>").hide();
		}
		else
		{
			$('#contactsMail INPUT[name=email]').css('border','1px solid red');
		}
		return false;
	});

/* -----------------------------------------------------------------------------
	Zooms Produits
------------------------------------------------------------------------------*/
	$('div.product-list div IMG').live("mouseover", function(){
		$(this).parent('div').removeClass('iphone').addClass('iphone-on');
		$(this).attr('height','295').attr('width','168');
	}).live("mouseout", function(){
		$(this).parent('div').removeClass('iphone-on').addClass('iphone');
		$(this).attr('height','215').attr('width','123');
	});


});



$(function() {
/* -------------------------------------------------------------------
   // Accordéon et Sous-Titres
--------------------------------------------------------------------*/
	$('div.btn').css('cursor','pointer').mouseenter(function(){
		// Si fermé
		if (!$(this).hasClass('btn-isOpen')) {
			var thisNav=$(this).next('div.nav').children('span');
				thisNav.hide();
				thisNav.children('div.stitre').show();
				thisNav.children('ul').hide();
				thisNav.show();
			$(this).next('#menu div.nav:not(:animated)').animate({width:'show'},{duration:500, complete : function() {
				if ($(this).width()<900) {
					var bodyWidth=$('body').width();
					var prevWidth=$(this).prev('div.btn').width();
					$(this).width(bodyWidth-prevWidth-20+'px');
				}
			}});
		}
	}).mouseleave(function(){
		$('#menu div.nav:visible').each(function (index, domEle) {
			if (!$(domEle).hasClass('nav-isOpen')) {
				$(this).animate({width:'hide'},500);
			}
		});
	});
});