Template:WUR script.js

From 2012.igem.org

(Difference between revisions)
Line 268: Line 268:
       width: '480',
       width: '480',
       videoId: '19JbFIIyi5c',
       videoId: '19JbFIIyi5c',
 +
      playerVars: {'rel': 0, 'showInfo': 0, 'theme': 'light'},
       events: {
       events: {
         'onReady': onPlayerReady,
         'onReady': onPlayerReady,

Revision as of 14:21, 21 September 2012

/*jshint eqnull:true */ /*!

* jQuery Cookie Plugin v1.2
* https://github.com/carhartl/jquery-cookie
*
* Copyright 2011, Klaus Hartl
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://www.opensource.org/licenses/mit-license.php
* http://www.opensource.org/licenses/GPL-2.0
*/

(function ($, document, undefined) {

var pluses = /\+/g;

function raw(s) { return s; }

function decoded(s) { return decodeURIComponent(s.replace(pluses, ' ')); }

var config = $.cookie = function (key, value, options) {

// write if (value !== undefined) { options = $.extend({}, config.defaults, options);

if (value === null) { options.expires = -1; }

if (typeof options.expires === 'number') { var days = options.expires, t = options.expires = new Date(); t.setDate(t.getDate() + days); }

value = config.json ? JSON.stringify(value) : String(value);

return (document.cookie = [ encodeURIComponent(key), '=', config.raw ? value : encodeURIComponent(value), options.expires ? '; expires=' + options.expires.toUTCString() : , // use expires attribute, max-age is not supported by IE options.path  ? '; path=' + options.path : , options.domain  ? '; domain=' + options.domain : , options.secure  ? '; secure' : ].join()); }

// read var decode = config.raw ? raw : decoded; var cookies = document.cookie.split('; '); for (var i = 0, parts; (parts = cookies[i] && cookies[i].split('=')); i++) { if (decode(parts.shift()) === key) { var cookie = decode(parts.join('=')); return config.json ? JSON.parse(cookie) : cookie; } }

return null; };

config.defaults = {};

$.removeCookie = function (key, options) { if ($.cookie(key) !== null) { $.cookie(key, null, options); return true; } return false; };

})(jQuery, document);

var cssUrl = "https://2012.igem.org/Template:WUR_style.css?action=raw&ctype=text/css"; var nivoJsUrl = 'https://2012.igem.org/Template:WUR_nivo.js?action=raw&ctype=text/javascript'; var nivoCssUrl = "https://2012.igem.org/Template:WUR_nivo.css?action=raw&ctype=text/css"; var prefixfreeUrl = 'https://2012.igem.org/Template:WUR_prefixfree.js?action=raw&ctype=text/javascript';

var headerImgUrl = "";

jQuery(document).ready(function(){

// CSS $("<link/>", { rel: "stylesheet", type: "text/css", href: cssUrl }).appendTo("head");

/* // Slider $("<link/>", { rel: "stylesheet", type: "text/css", href: nivoCssUrl }).appendTo("head"); $.getScript(nivoJsUrl, function(){ //http://nivo.dev7studios.com/support/jquery-plugin-usage/ $('#header_slider').nivoSlider({ effect: 'fade', directionNav: false, controlNav: false, pauseTime: 5500, animSpeed: 1000 }); }); */

// Move menu var menu = $('#navContainer'); $('#navContainer').remove(); $('#content').prepend(menu);

// Move header var header = $('#header_wrapper'); $('#header_wrapper').remove(); $('#content').prepend(header);

// Decorate menu function decorateMenu(el, i) { switch(i) { case 1: el.addClass('ulc1'); i += 1; break;

case 2: el.addClass('ulc2'); i += 1; break;

case 3: i = 1; break;

default: i += 1; } return i; } var i = 0; var ii = 0; menu.find('li').each(function(){ i = decorateMenu($(this),i); ii = $(this).find('ul').find('li').each(function(){decorateMenu($(this),ii);}); });

// Remove title attributes from the menu. // Though this is a bad practice, the design advantage weighted // heavier than the few optically impaired people who visit the // website. menu.find('[title]').removeAttr('title');

// Google Analytics var ga_script = "\ <script type=\"text/javascript\">\ var _gaq = _gaq || [];\ _gaq.push(['_setAccount', 'UA-33423824-1']);\ _gaq.push(['_trackPageview']);\ (function() {\ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\ })();\ </script>"; $('head').append(ga_script);

// Move the Footer $('#contentfooter').appendTo('#content');

$('.bigbutton').hover(function(){ $(this).find('img').animate({ 'margin-top': '-175px' },'fast'); },function(){ $(this).find('img').animate({ 'margin-top': '0px' },'fast'); });

// If an anchor-link was pressed, make sure the scrolling was done correctly. if(location.hash) { var sId = location.hash.substr(1); var sEl = document.getElementById(sId); var sJQ = $(sEl);

setTimeout(function(){ $(document).scrollTop(sJQ.offset().top); }, 250);

}

// Fix prefixes for CSS3 styles $.getScript(prefixfreeUrl, function(){});

// Animate the project overview $('#poPnas, #poVLPs, #poOutside, #poInside, #poApplications').hide(); $('#poPnas').fadeIn(500, function(){ $('#poVLPs').fadeIn(500, function(){ $('#poOutside').fadeIn(500, function(){ $('#poInside').fadeIn(500, function(){ $('#poApplications').fadeIn(500, function(){}); }); }); }); });

// Click actions for the project overview function poLoad(url) { $('#poTextClose').fadeOut(); $('#poText').slideUp().fadeOut('fast', function(){ $('#poLoading').fadeIn('fast'); $('#poText').load(url, function(){ $('#poLoading').fadeOut('fast'); $('#poTextClose').fadeIn(); $(this).fadeIn().slideDown(); }); }); } $('#poTextClose').click(function() { $('#poText').slideUp().fadeOut(); $('#poTextClose').fadeOut(); }); $('#poPnas').click(function(){ poLoad('https://2012.igem.org/Team:Wageningen_UR/Pnas_ProjectOverview?action=render'); }); $('#poVLPs').click(function(){ poLoad('https://2012.igem.org/Team:Wageningen_UR/VLPs_ProjectOverview?action=render'); }); $('#poOutside').click(function(){ poLoad('https://2012.igem.org/Team:Wageningen_UR/OutsideModification_ProjectOverview?action=render'); }); $('#poInside').click(function(){ poLoad('https://2012.igem.org/Team:Wageningen_UR/InsideModification_ProjectOverview?action=render'); }); $('#poApplications').click(function(){ poLoad('https://2012.igem.org/Team:Wageningen_UR/Applications_ProjectOverview?action=render'); });

// Achievements animation $('.achievement').click(function(){ $(this).find('.achievement-desc').slideDown('fast'); }); $('.achievement').hover(function(){ //$(this).find('.achievement-desc').slideDown('fast'); },function(){ $(this).find('.achievement-desc').slideUp('fast'); });

// IE8 column correction if($.browser.msie && parseInt($.browser.version,10) < 9) { $('.col').css('width','296px'); }

// Team photos $('#teamScatter').hover(function(){ $('#teamScatter > div.Hover').fadeIn(); },function(){ $('#teamScatter > div.Hover').fadeOut(); }); $('#teamScatter').mousemove(function(e){ $('#teamScatter > div.Hover').css({ 'left': e.pageX - $(this).offset().left - 100, 'top': e.pageY - $(this).offset().top + 20 }); }); $('#teamScatter area').mouseover(function(){ $('#teamScatter > div.Hover').text($(this).attr('alt')); });

});


//Load YouTube player api asynchronously. var tag = document.createElement('script'); tag.src = "//www.youtube.com/iframe_api"; var firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); var player; function onYouTubeIframeAPIReady() {

   player = new YT.Player('projectVideoPlayer', {
     height: '360',
     width: '480',
     videoId: '19JbFIIyi5c',
     playerVars: {'rel': 0, 'showInfo': 0, 'theme': 'light'},
     events: {
       'onReady': onPlayerReady,
       'onStateChange': onPlayerStateChange
     }
   });

} function onPlayerReady(evt) { if($.cookie('igemWURwatchedVideo') == 'watchedAll') { endVideo(evt); } else {

   evt.target.playVideo();
 }

} function endVideo(evt) { $('#projectVideoPlayerContainer').slideUp('slow', function(){ $('#projectIntro, #projectVideo').animate({'height': '50px'}, 'slow', function(){ $('#projectVideo a').fadeIn(); $('#projectVideo a').click(function(){ $('#projectVideo a').fadeOut(); $('#projectIntro, #projectVideo').animate({'height': '340px'}, 'slow'); $('#projectVideoPlayerContainer').slideDown('slow',function(){ evt.target.playVideo(); }); }); }); }); } function onPlayerStateChange(evt) {

   if(evt.data == YT.PlayerState.PAUSED ) {
   	endVideo(evt);
   }
   if(evt.data == YT.PlayerState.ENDED) {
   	$.cookie('igemWURwatchedVideo', 'watchedAll');
   }

} function stopVideo() {

   player.stopVideo();

}