var popped = false; var animated = false; var submenu_animated = false; var current_submenu = ""; $submenu_opacity_target = 0; $show_submenu = 1; $mainContent = $("article"); $submenu = $("aside"); $to_open = ""; $open = 7, $prev = $open; $dropped_hamburger = 0; $.extend($.expr[":"], { neq: function(elem, i, match) { return i !== (match[3] - 0); } }); function setCookie(name, value) { var date = new Date(); date.setTime(date.getTime() + (365*24*60*60*1000)); var expires = "expires=" + date.toUTCString(); document.cookie = name + "=" + value + ";" + expires + ";path=/"; } function getCookie(name){ var name = name + "="; var decoded = decodeURIComponent(document.cookie); var array = decoded.split(';'); for (var i=0; i 0){ $("body").waitForImages(function(){ $('html, body').animate( { scrollTop: $(h).offset().top - 45 }, 1500, 'easeInOutSine' ); }); } } function ucwords(str) { // via http://phpjs.org/functions/ucwords/ return (str + '').replace( /^([a-z\u00E0-\u00FC])|\s+([a-z\u00E0-\u00FC])/g, function($1) { return $1.toUpperCase(); } ); } function stripslashes(str) { // via http://phpjs.org/functions/stripslashes/ return (str + '').replace( /\\(.?)/g, function(s, n1) { switch (n1) { case '\\': return '\\'; case '0': return '\u0000'; case '': return ''; default: return n1; } } ); } function str_replace(search, replace, subject, count) { // via http://phpjs.org/functions/str_replace/ var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0, f = [].concat(search), r = [].concat(replace), s = subject, ra = Object.prototype.toString.call(r) === '[object Array]', sa = Object.prototype.toString.call(s) === '[object Array]'; s = [].concat(s); if (count) { this.window[count] = 0; } for (i = 0, sl = s.length; i < sl; i++) { if (s[i] === '') { continue; } for (j = 0, fl = f.length; j < fl; j++) { temp = s[i] + ''; repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0]; s[i] = (temp) .split(f[j]) .join(repl); if (count && s[i] !== temp) { this.window[count] += (temp.length - s[i].length) / f[j].length; } } } return sa ? s : s[0]; } $(function() { if(Modernizr.history){ var newHash = "", $page_title = "", $month = "", $month_names = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; $("nav").delegate("a", "click", function() { _link = $(this).attr("href"); history.pushState(null, null, _link); $open = 0; loadContent(_link, 0); if (_link == "/"){ _link = "/news/"; } fixMenu("#".concat(_link.substring(1,_link.length - 1))); return false; }); $("footer").delegate("a", "click", function() { _link = $(this).attr("href"); if (_link.search("#") == 0){ $('html, body').animate( { scrollTop: $("#top").offset().top }, 1500, 'easeInOutSine' ); return false; } else { history.pushState(null, null, _link); $open = 0; loadContent(_link, 1); return false; } }); $("article").delegate("a", "click", function() { _link = $(this).attr("href"); if (_link.search("/download") == 0){ return !window.open(href); } else { history.pushState(null, null, _link); $open = 0; loadContent(_link, 1); fixMenu("#".concat( _link.split("/")[1] )); return false; } }); function fixMenu(href){ var menus = ["#news", "#work", "#about", "#contact", "#shop"]; for (var i=0; i < menus.length; i++) { $("nav").find(menus[i]).removeClass("selected"); } $("nav").find(href).addClass("selected"); }; function loadContent(href, submenu_opacity_target){ $submenu_opacity_target = submenu_opacity_target; if ( (href == "/cv") || (href == "/cv/") || (href == "/cv/min") || (href == "/cv/min/") ){ return !window.open(href); } else { if ( (href == "/") || (href == "/news") || (href == "/news/") ){ $.getJSON("/includes/t/news", function(data){ href = data[0].href; loadContent(href, submenu_opacity_target); }); } else if ( (href == "/work") || (href == "/work/") ){ $.getJSON("/includes/t/work", function(data){ href = data[0].href; loadContent(href, submenu_opacity_target); }); } else { $to_open = href.split("/")[2]; if (typeof $to_open === "undefined") { $("#first > ul").slideDown(10, 'easeInSine'); } else { if (current_submenu == $to_open){ // $('#' + $to_open).slideDown(2500, 'easeInSine'); // $('#accordion li div ul').delay(1500).slideDown(2500, 'easeInSine'); // $('#accordion ul:eq(0)').slideDown(2500, 'easeInSine'); } else { // $('#' + $to_open).slideDown(2500, 'easeInSine'); // $("footer").css('opacity',0).css('visibility', 'hidden').hide(); // $mainContent.css('opacity',0).css('visibility', 'hidden').hide(); } } $page_title = href; $page_title = $page_title.substring(1, $page_title.length); if ($page_title.substring($page_title.length - 1, $page_title.length) == "/"){ $page_title = $page_title.substring(0, $page_title.length - 1); } if ($page_title.substring(0, 4) == "news"){ $year = $page_title.split("/")[1]; $month = $page_title.split("/")[2]; if (($year == undefined) && ($month == undefined)){ $page_title = "News"; } else if ($month == undefined) { $page_title = "News | ".concat(" ").concat($year); } else { $page_title = "News | ".concat($month_names[Number($month) - 1]).concat(" ").concat($year); } } else if ($page_title.substring(0, 4) == "work"){ $category = $page_title.split("/")[1]; $piece = $page_title.split("/")[2]; if (($category == undefined) && ($piece == undefined)){ $page_title = "Work"; } else if ($piece == undefined) { $page_title = "Work | ".concat(" ").concat($category); } else { $page_title = "Work | ".concat($category).concat(" | ").concat($piece); } $page_title = ucwords(str_replace(['-'], [' '], $page_title)); } else if ($page_title.substring(0, 5) == "about"){ $category = $page_title.split("/")[1]; $artist = $page_title.split("/")[2]; $album = $page_title.split("/")[3]; if (($category == undefined) && ($artist == undefined)){ $page_title = "About"; } else if ($artist == undefined) { $page_title = "About | ".concat($category); } else if ($album == undefined) { $page_title = "About | ".concat($category).concat(" | ").concat($artist); } else { if ($album == "1"){ $album = "+1"; } $page_title = "About | ".concat($category).concat(" | ").concat($artist).concat(" | ").concat($album); } $page_title = ucwords(str_replace(['/','-'], [' | ',' '], $page_title)); } else { if ($page_title == ""){ $page_title = "News"; } $page_title = ucwords(str_replace(['/','-'], [' | ',' '], $page_title)); } document.title = "Mark Cetilia | ".concat($page_title); if (($show_submenu == 1) && (submenu_animated)){ if ($submenu_opacity_target == 0) { $submenu.delay(501).css('visibility', 'visible').show().animate( { 'opacity': 0 }, 500, 'easeInSine', function(){ $submenu.hide(); } ); } } $submenu.delay(1001 * (1 - $submenu_opacity_target)).queue(function(run_submenu_animation){ if ( (href.split("/")[1] == "shop") && ( (href.split("/")[2] == "add") || (href.split("/")[2] == "remove") ) ){ if (href.split("/")[2] == "add"){ add(href.split("/")[3]); } if (href.split("/")[2] == "remove"){ remove(href.split("/")[3]); } $submenu.load("/shop/shopping-cart/" + " #submenu", function() { animate_submenu(); }); } else { $submenu.load(href + " #submenu", function() { animate_submenu(); }); } run_submenu_animation(); }); $("footer").animate( { 'opacity': 0 }, 500, 'easeInSine', function(){ $("footer").hide(); } ); $mainContent.delay(251).animate( { 'opacity': 0 }, 500, 'easeInSine', function(){ $mainContent.hide(); } ); $mainContent.delay(751 + (500 * (1 - $submenu_opacity_target))).queue(function(run_main_content_animation){ $mainContent.load(href + " #content", function() { animate_main_content(href); }); run_main_content_animation(); }); }; }; }; $(window).load(function(){ _link = location.pathname; //get filename only auto_submenu(); loadContent(_link, 0); if (_link == "/"){ _link = "/news/"; } fixMenu("#".concat( _link.split("/")[1] )); }); $(document).ready(function(){ $(".hamburger").click(function(){ toggle_submenu(); }); auto_submenu(); }); $(window).resize(function(){ auto_submenu(); }); $(window).bind('resize', function(){ auto_submenu(); }); $(window).bind('popstate', function(){ auto_submenu(); // Ignore inital popstate that some browsers fire on page load var initialPop = (!popped); popped = true; if (!initialPop){ _link = location.pathname; //get filename only loadContent(_link, 1); if (_link == "/"){ _link = "/news/"; } fixMenu("#".concat( _link.split("/")[1] )); } }); function animate_submenu(){ if (($show_submenu == 1) && (submenu_animated)){ $submenu.css('visibility', 'visible').show().animate( { 'opacity': 1 }, 500, 'easeInSine' ); } // Allow animation.js to take care of animation on page load var initial_submenu_animation = (!submenu_animated); submenu_animated = true; if (initial_submenu_animation){ if ($show_submenu == 1){ $("aside #submenu ul li").delay(2001).each(function(index) { if ($aside_hidden){ $("aside").css("opacity", 1).show(); $aside_hidden = false; } $(this).css("opacity", 0).delay((50*index)).css("visibility", "visible").show().animate( { opacity: 1 }, 500, "easeInSine", function(){ reveal_article(); } ); }); } else { reveal_article(); } } else { $submenu.find("#submenu").css("opacity", 1).show(); if (current_submenu != $to_open){ $submenu.find("#submenu ul li").each(function(index) { $(this).css("opacity", $submenu_opacity_target).delay((50*index)).show().animate( { opacity: 1 }, 500, "easeInSine", function(){ reveal_article(); } ); }); } else { $submenu.find("#submenu ul li").each(function(index) { $(this).css("opacity", 1).show(); }); } } $submenu.find("#submenu").each(function(index) { if ($(this).has("#accordion").length){ $('#accordion > li > div > ul > li').delegate("a", "click", function(){ _link = $(this).attr("href"); history.pushState(null, null, _link); $(this).removeClass('selected'); $(this).addClass('selected'); loadContent(_link, 1); if (_link == "/"){ _link = "/news/"; } fixMenu("#".concat( _link.split("/")[1] )); return false; }); $('#accordion > li > span > ul > li').delegate("a", "click", function(){ // only shows up on cv pages if (($(this).attr("href") != "/about/curriculum-vitae") && ($(this).attr("href") != "/about/curriculum-vitae/")){ $(this).css({ opacity: 0.5 }); } _link = $(this).attr("href"); $('#accordion > li > div > span > ul > li').removeClass('selected'); $(this).addClass('selected'); loadContent(_link, 1); return false; }); $('#accordion > li > span').delegate("a", "click", function(){ _link = $(this).attr("href"); history.pushState(null, null, _link); $prev = $open; $open = $(this).parent().parent().index(); if ($to_open==current_submenu){ if (false == $('#accordion span:eq(' + $prev + ')').hasClass("null")){ if(false == $(this).next().is(':visible')) { $('#accordion ul').slideUp(2500, 'easeInSine'); } } } $(this).removeClass('selected'); $(this).addClass('selected'); loadContent(_link, 1); if (_link == "/"){ _link = "/news/"; } fixMenu("#".concat( _link.split("/")[1] )); return false; }); if (current_submenu != $to_open){ $('#' + $to_open).slideDown(2500, 'easeInSine'); } else { $('#' + $to_open).slideDown(0); } current_submenu = $to_open; } else { // if ($show_submenu == 1){ $(this).delay(150*index).animate( { opacity: 1 }, 500, 'easeInSine' ); // } $(this).delegate("a", "click", function(){ _link = $(this).attr("href"); history.pushState(null, null, _link); loadContent(_link, 1); if (_link == "/"){ _link = "/news/"; } fixMenu("#".concat( _link.split("/")[1] )); return false; }); } }); } function animate_main_content(href){ // Allow animation.js to take care of animation on page load var initialAnimation = (!animated); animated = true; if (!initialAnimation){ $mainContent.css('opacity', 0).css('visibility','visible').show().animate( { opacity: 1 }, 500, 'easeInSine' ); $("footer").delay(251).css('opacity', 0).css('visibility','visible').show().animate( { opacity: 1 }, 500, 'easeInSine', scrollWin() ); } $(".email").replaceWith("mark@cetilia.org"); $("#l_button").load('/includes/l/' + href); $("#c_button").load('/includes/c/' + href); $("#r_button").load('/includes/r/' + href); } } // otherwise, history is not supported, so nothing fancy here. }); function validateForm(){ var name = document.forms["form"]["name"].value; if (name == null || name == ""){ alert("Please enter your name."); return false; } var email = document.forms["form"]["email"].value; var atpos = email.indexOf("@"); var dotpos = email.lastIndexOf("."); if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= email.length){ alert("Please enter a valid email address."); return false; } event.preventDefault(); var url = $("#form").attr("action"); var snd = $("#form").serialize() + "&js=1"; $("footer").animate( { 'opacity': 0 }, 500, 'easeInSine', function(){ $("footer").hide(); } ); $("article").delay(251).animate( { 'opacity': 0 }, 500, 'easeInSine', function(){ $("article").hide(); $.post(url, snd, function(rcv) { $("article").css('opacity', 0).css('visibility','hidden').hide(); $("footer").css('opacity', 0).css('visibility','hidden').hide(); $("article").html(rcv); $("article").css('opacity', 0).css('visibility','visible').show().animate( { opacity: 1 }, 500, 'easeInSine' ); $("footer").css('opacity', 0).css('visibility','visible').show().delay(251).animate( { opacity: 1 }, 500, 'easeInSine' ); }); } ); } function selectShipping(){ event.preventDefault(); var url = $("#form").attr("action"); var snd = $("#form").serialize() + "&js=1"; $("footer").animate( { 'opacity': 0 }, 500, 'easeInSine', function(){ $("footer").hide(); } ); $("article").delay(251).animate( { 'opacity': 0 }, 500, 'easeInSine', function(){ $("article").hide(); $.post(url, snd, function(rcv) { $("article").css('opacity', 0).css('visibility','hidden').hide(); $("footer").css('opacity', 0).css('visibility','hidden').hide(); $("article").html(rcv); $("article").css('opacity', 0).css('visibility','visible').show().animate( { opacity: 1 }, 500, 'easeInSine' ); $("footer").css('opacity', 0).css('visibility','visible').show().delay(251).animate( { opacity: 1 }, 500, 'easeInSine' ); }); } ); } function go_to_checkout(){ event.preventDefault(); var url = $("#form").attr("action"); var snd = $("#form").serialize(); history.pushState(null, null, url); $("footer").animate( { 'opacity': 0 }, 500, 'easeInSine', function(){ $("footer").hide(); } ); $("article").delay(251).animate( { 'opacity': 0 }, 500, 'easeInSine', function(){ $("article").hide(); $.post(url, snd, function(rcv) { $("#shopping-cart").removeClass("selected"); $("#checkout").addClass("selected"); $("article").css('opacity', 0).css('visibility','hidden').hide(); $("footer").css('opacity', 0).css('visibility','hidden').hide(); $("article").html(rcv); $("article").css('opacity', 0).css('visibility','visible').show().animate( { opacity: 1 }, 500, 'easeInSine' ); $("footer").css('opacity', 0).css('visibility','visible').show().delay(251).animate( { opacity: 1 }, 500, 'easeInSine' ); }); } ); } function thanks(){ var url = $("#form").attr("action"); var snd = $("#form").serialize(); history.pushState(null, null, url); $("footer").animate( { 'opacity': 0 }, 500, 'easeInSine', function(){ $("footer").hide(); } ); $("article").delay(251).animate( { 'opacity': 0 }, 500, 'easeInSine', function(){ $("article").hide(); $.post("/shop/checkout/", "form=thanks", function(rcv) { $("#shopping-cart").removeClass("selected"); $("#checkout").addClass("selected"); $("article").css('opacity', 0).css('visibility','hidden').hide(); $("footer").css('opacity', 0).css('visibility','hidden').hide(); $("article").html(rcv); $("article").css('opacity', 0).css('visibility','visible').show().animate( { opacity: 1 }, 500, 'easeInSine' ); $("footer").css('opacity', 0).css('visibility','visible').show().delay(251).animate( { opacity: 1 }, 500, 'easeInSine' ); }); } ); }