Learn how to use jQuery at the Blog

Red Nose Day « visit

  • Added 9 months ago
  • 330 Lines of Code shown
  • 11 Links of Interest
http://rednoseday.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 Red Nose Day - http://rednoseday.com

/*--------------------------------------------------*
 *--------------------------------------------------*
 * rednoseday.com 2009 drupal theme                 *
 * Common javascript library                        *
 * Created by: CR New Media                         *
 *                                                  *
 * depends on jquery: www.jquery.com                *
 *--------------------------------------------------*
 *--------------------------------------------------*/

$(document).ready(initTheme);
$(document).ready(setupBlogs);
$(document).ready(setupInteractiveView);
$(document).ready(setupGallery);
$(document).ready(accordion_nav_rhs);
$(document).ready(setupIconSwitcher);
$(document).ready(gaSetup);


function gaSetup(){
$('.track_btn').click(function(){
		//alert ('buttonHit');
		//alert ($(this).attr('id'));
		$tosend = '/' + $(this).attr('id').replace(/:/g, '/');
		//alert ($temp);
		
		pageTracker._trackPageview($tosend);
	});
}


function setupIconSwitcher(){
  $(".icon_switcher").each(function(i) {
    $(this).children("div.switcher_info").css("display", "none");
    $(this).children("div.switcher_info:first").css("display", "block");
  });
  
  $(".icon_switcher ul:first li a").click(function(){
    clicked_item = $(this).attr("href");
    $(this).parent().parent().siblings("div.switcher_info").css("display", "none");
    $(this).parent().parent().siblings(clicked_item).css("display", "block");
    return false;
  });
  
}

function accordion_nav_rhs(){
  $("ul#accordion_nav_rhs").accordion({ 
    active: true, 
    header: 'h6',
    navigation: true, 
    fillSpace: false, 
    animated: 'easeslide',
    autoHeight: false
  });

}

function initTheme(){

	$(".column .area").each(function(i) {
		$(this).wrapInner( "<div class='area_content'></div>" );
		$(this).append( "<div class='column_bottom'>&nbsp;</div>" );
	});
	
	// Add hasjavascript class to body
	$("body").addClass("hasjavascript");
	
	/* Open links with class link_external in new windows (target="_blank" isn't valid strict HTML)
	*******************************************************************************************************/
	$('a.link_external').click(function(){
        window.open(this.href);
        return false;
    });

$('a.link_download').click(function(){
        window.open(this.href);
        return false;
    });

// Hide join supporters for supporters	
/*
$("body.role_supporter ul.menu li").each(function(){
	if($(this).children("a").html() == "Join the Comic Relief Club"){
		$(this).css("display", "none");
	}
});
*/

	// SETUP CODA PAGE
  $("#coda").parent(".area_content").css("padding", "0");
  if($("body").attr("id") != "winerelief_journey"){
    $("#coda").parent().next().css("display", "none");
  }
  // Wrap a div around all elements before the coda
  $("#coda").siblings().wrapAll("<div class='pre_coda'></div>");
$(".coda_container").css("overflow", "hidden");

// Setup superfish menu
$("ul.sf-menu").superfish();
dropdown_width = $("#myrnd").width();
$("#myrnd ul li").css("width", dropdown_width - 20);
  
  // Fix button rollovers in IE6
  if(!window.XMLHttpRequest){
    $("#search-block-form #edit-submit").hover(function(){$(this).css("background-position", "0 -29px");},function(){$(this).css("background-position", "0 0");});
    $("form#cr-kit-sch-form #edit-submit, form#cr-kit-form #edit-submit, form#cr-kit-order-pack-form #edit-submit, form#cr-kit-mini-form #edit-submit").hover(function(){$(this).css("background-position", "0 -32px");},function(){$(this).css("background-position", "0 0");});
  }
  
 /* Using class toggle_div_next toggle open/close the subsequent element div
**************************************************************************************************/
$(".toggle_div_next").parent().next().toggle(); // Hide all on load
$(".toggle_div_next").click(function() {
	$(this).parent().next().slideToggle("normal");
	$(this).toggleClass("toggle_div_next_selected");
	if ($(this).hasClass("toggle_div_next_selected")){
            $(this).text($(this).text().replace(/More/, "Close"));
        } else {
            $(this).text($(this).text().replace(/Close/, "More"));
        }
	return false;
});
  

  
  /* Paginated Lists
	**************************************************************************************************/
  $("ul.paginated_list").each(function(i){
  	$(this).addClass("paginated_list_" + (i+1));
  	$(this).after("<ul class='paginated_list_no' id='pages_" + (i+1) + "'></ul>");
		total = 0;
		$(this).children().each(function(j){
			if(j > 0){
				$(this).css("display", "none");	
			}
			$(this).addClass("paginated_item_" + (i+1) + "_" + (j+1));
			$("ul#pages_" + (i+1)).append("<li id='pages_" + (i+1) + "_" + (j+1) + "'><a href='#'>" + (j+1) + "</a></li>");
		});
  });
  $(".paginated_list_no li").click(function(){
  	pagination_set = $(this).attr("id").substring(6,7);
  	page_number = $(this).children("a").html();
  	$("ul.paginated_list_" + pagination_set + " li").css("display", "none");
  	$("li.paginated_item_" + pagination_set + "_" + page_number).css("display", "block");
  	return false;
	});

}


function setupBlogs() {
  $(".items_share ul").css("display", "none");
  $(".items_share h6").wrapInner("<a></a>");
  $(".items_share h6").css("background", "none");

  $(".items_share h6").click(function(){
    
    if($(this).hasClass("share_open")){
      $(this).removeClass("share_open");
      $(this).next("ul").css("display", "none");
    }else{
      $(this).addClass("share_open");
      $(this).next("ul").css("display", "block");
    }

  });
}


function fbs_click(node_title, full_blog_url)
{
  window.open('http://www.facebook.com/sharer.php?u=http://'+full_blog_url+'&amp;t='+node_title,'sharer','toolbar=0,status=0,width=626,height=436');
  return false;
}


function setupInteractiveView(){
	var categories = new Array();
	
	$("div[class^='cat_']").each(function(i){
		$(this).parent().css("display", "none");
		the_category = $(this).attr("class");
		categories.push(the_category.substring(4));
		
	});

	if(categories[0]){
    $("div[class^='cat_']:first").parent().parent().parent().parent().parent().parent().prepend("<ul id='interactive_view_list'></ul>");
	  
	  // loop through array
	  for ( var i=0, len=categories.length; i<len; ++i ){
	     $("ul#interactive_view_list").prepend("<li class='show_area' id='show_" + categories[i] + "'><a href='#'>" + categories[i].replace("_", " ") + "</a></li>");
	  }
	  $(".cat_" + categories[0]).parent().css("display", "block");
  }
  
  $(".show_area a").click(function(){
        to_show = $(this).parent().attr("id").substring(5);
        $("div[class^='cat_']").each(function(i){$(this).parent().css("display", "none");});
        $("div.cat_" + to_show).parent().css("display", "block");
        return false;
  });
}

function setupGallery(){
	  $('.image_gallery').addClass('gallery_demo'); // adds new class name to maintain degradability
	  $('.image_gallery_auto').addClass('gallery_auto'); // adds new class name to maintain degradability
		$('.nav').css('display','none'); // hides the nav initially
		
		$('ul.gallery_demo').galleria({
  			history   : false, // deactivates the history object for bookmarking, back-button etc.
  			clickNext : true, // helper for making the image clickable. Let's not have that in this example.
  			insert    : '#main_image', // the containing selector for our main image
  			onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes
  				
            				// fade in the image & caption
            				image.css('display','none').fadeIn(1000);
            				caption.css('display','none').fadeIn(1000);
            				
            				// fetch the thumbnail container
            				var _li = thumb.parents('li');
            				
            				// fade out inactive thumbnail
            				_li.siblings().children('img.selected').fadeTo(500,0.3);
            				
            				// fade in active thumbnail
            				thumb.fadeTo('fast',1).addClass('selected');
            				
            				// add a title for the clickable image
            				image.attr('title','Next image &gt;&gt;');
  			},
  			onThumb : function(thumb) { // thumbnail effects goes here
  				
            				// fetch the thumbnail container
            				var _li = thumb.parents('li');
            				
            				// if thumbnail is active, fade all the way.
            				var _fadeTo = _li.is('.active') ? '1' : '0.3';
            				
            				// fade in the thumbnail when finnished loading
            				thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
            				
            				// hover effects
            				thumb.hover(
            					function() { thumb.fadeTo('fast',1); },
            					function() { _li.not('.active').children('img').fadeTo('fast',0.3); } // don't fade out if the parent is active
            				)
  			}
		});
		
		
		// To have a simple slideshow, I have written a seperate script as you cant call 2 gallerias (causes conflicts)
		$('ul.gallery_auto').css("position", "relative").css("height", "340px");
    $('ul.gallery_auto li').css("display", "none").css("position", "absolute").css("background", "none");
		$('ul.gallery_auto li:first').css("display", "block");
		$('ul.gallery_auto li:first').addClass("gallery_auto_current");
		
		if ( $("ul.gallery_auto").length > 0 ) {
      setInterval("changeGalleryImage()", 5000);
    }
}

function changeGalleryImage(){
  total_images = $("ul.gallery_auto li").length;
  $("ul.gallery_auto li").each(function(i){
    if($(this).hasClass("gallery_auto_current")){
      if(i == total_images - 1){
        $("ul.gallery_auto li:first").addClass("gallery_auto_next");
      }else{
        $("ul.gallery_auto li.gallery_auto_current").next("li").addClass("gallery_auto_next");
      }
    }
    
  });
  $("ul.gallery_auto li.gallery_auto_current").fadeOut(1000);
  $("ul.gallery_auto li.gallery_auto_next").fadeIn(2000);  
  $("ul.gallery_auto li.gallery_auto_current").removeClass("gallery_auto_current");  
  $("ul.gallery_auto li.gallery_auto_next").addClass("gallery_auto_current");
  $("ul.gallery_auto li.gallery_auto_next").removeClass("gallery_auto_next");
}

$(document).ready(function() {
	 $("form#cr-verify-teacher-multiform").bind("keypress", function(e) {
		 if (e.keyCode == 13) {
				 return false;
			}
	 });
}); 




$(document).ready(function(){
  	insertPromo();
		$('.show_video').click(function(){
		$('#backstage_tv').hide();
$("#backstage_highlight").append("<p><a href='/backstage'>Go to Backstage</a></p>");
  		insertVideo();
	});
});

function insertPromo() {
  // Flash replacement (using jmedia jquery plugin)
  $("#promo").jmedia(
		{version:"8,0"},
		{src:"http://assets.rednoseday.com/rnd09/swf/preloaders/preloader_660x400.swf",
		  quality:"best",
		  width:660,
		  height:400,
wmode:"transparent",
     	  flashvars: "targetMc=http://assets.rednoseday.com/rnd09/swf/homepage_coda_170309.swf",
		  allowScriptAccess:"always"
    }
  );

  // Alter CSS to cater for flash
  $("#container").css("margin-top", "0");  
}


 
function insertVideo() {
  var flashvars = { "file": "http://www.rednoseday.com/files/rnd09/assets/backstage/video/rednose_ad.flv", "image": "http://www.rednoseday.com/files/rnd09/assets/backstage/video/rednose_ad.jpg", "height": "192", "width": "287", "playlist": "none", "skin": "http://assets.rednoseday.com.s3-external-3.amazonaws.com/rnd09/swf/jw_player/stylishHome.swf", "fullscreen": "true", "autostart": 1, "bufferlength": "1.0", "quality": "true", "repeat": 1, "stretching": "fill", "volume": "50", "allowscriptaccess": "true", "playlistsize": "200" };
  
  
  var params = { "width": "287", "height": "192", "no_flash": "Sorry, you need to install flash to see this content.", "version": "9", "type": "movie", "bg_color": "#FFFFFF", "allowfullscreen": "true", "allowscriptaccess": "always", "express_redirect": "http://assets.rednoseday.com.s3-external-3.amazonaws.com/swf/jw_player/expressinstall.swf" };
  var attributes = null;
  
  swfobject.embedSWF('http://assets.rednoseday.com.s3-external-3.amazonaws.com/rnd09/swf/jw_player/jw_player_4_2.swf', 'backstage_video', '287', '192', '9', 'http://assets.rednoseday.com.s3-external-3.amazonaws.com/rnd09/swf/jw_player/expressinstall.swf', flashvars, params, attributes );
}