$(function() { category = Array(); category['about'] = Array(); category['about'][0] = "ABOUT"; category['about'][1] = "Yuko Takeyama Profile"; category['works'] = Array(); category['works'][0] = "WORKS"; category['works'][1] = "Yuko Takeyama Photography"; category['diary'] = Array(); category['diary'][0] = "DIARY"; category['diary'][1] = "Yuko Takeyama Diary"; category['information'] = Array(); category['information'][0] = "INFORMATION"; category['information'][1] = "Yuko Takeyama Information"; category['instagram'] = Array(); category['instagram'][0] = "INSTAGRAM"; category['instagram'][1] = "Yuko Takeyama Instagram"; history_counter = 0; past_href = location.href; memorize_scrolltop = $(window).scrollTop(); memorize_lastvisit = "root"; if( $("div#index > article").length === 0 ){ memorize_lastindex = ""; }else{ memorize_lastindex = $("div#index > article").attr("class").replace( " ", "/" ); } memorize_lasturl = location.href; profile_url = "about"; function PJAX_hrefchange( href, onpop ) { if( href && past_href != href ){ if( typeof ajax_request != "undefined" ){ ajax_request.abort(); } past_href = href; var id = href.replace( "https://yukotakeyama.com/", "" ); var id = id.replace( "?mode=preview", "" ); _gaq.push(['_trackPageview', '/' + id ]); ajax_request = $.ajax({ url: "https://yukotakeyama.com/pjax_readtitle_json.php", data: "id=" + id + "&type=json" + "", dataType: "json", success: function(data, dataType){ if(!onpop){ PJAX_pushState( href, data.title ); } document.title = data.title; }, error: function(XMLHttpRequest, textStatus, errorThrown){ } }); if (id.match(/\d{4}$/)) { var entry_id = id.match(/\d{4}$/); var category_filter = id.replace("/" + entry_id ,""); $("body").removeClass().addClass("entry").addClass(category_filter); if( entry_id != "" && category_filter != "" ){ $("body").append("
"); if( memorize_lastvisit == "entry"){ $('html,body').animate({ scrollTop: memorize_scrolltop }, '200'); }else{ memorize_scrolltop = $(window).scrollTop(); } ajax_request = $.ajax({ url: "https://yukotakeyama.com/ajax_entry.php", data: "id=" + category_filter + "/" + entry_id + "", success: function(data, dataType){ $("div#entry").empty().append(data); // $("div#entry > article").css("top", memorize_scrolltop + "px"); memorize_lastvisit = "entry"; memorize_lasturl = href; memorize_lastindex = category_filter; $("div#loading").fadeOut(1000).remove(); }, error: function(XMLHttpRequest, textStatus, errorThrown){ } }); if( category_filter != memorize_lastindex ){ ajax_request = $.ajax({ url: "https://yukotakeyama.com/ajax_index.php", data: "id=" + category_filter + "", success: function(data, dataType){ $("div#index").empty().append(data); memorize_lastindex = category_filter; }, error: function(XMLHttpRequest, textStatus, errorThrown){ } }); } }else if( entry_id != "" ){ $("body").append("
"); ajax_request = $.ajax({ url: "https://yukotakeyama.com/ajax_entry.php", data: "id=" + entry_id + "", success: function(data, dataType){ $("div#entry").empty().append(data); // $("div#entry > article").css("top", $(window).scrollTop() + "px"); memorize_lastvisit = "entry"; memorize_lasturl = href; memorize_scrolltop = 0; memorize_lastindex = ""; $("div#loading").fadeOut(1000).remove(); }, error: function(XMLHttpRequest, textStatus, errorThrown){ } }); } } if ( id == profile_url ) { $("body").append("
"); ajax_request = $.ajax({ url: "https://yukotakeyama.com/ajax_profile.php", data: "id=" + id + "", success: function(data, dataType){ $("div#entry").empty().append(data); $("div#entry a.modal_overlay, div#entry a.close").attr("href", memorize_lasturl); // $("div#entry > article").css("top", $(window).scrollTop() + "px"); memorize_lastvisit = "profile"; memorize_lasturl = href; memorize_scrolltop = $(window).scrollTop(); $("div#loading").fadeOut(1000).remove(); }, error: function(XMLHttpRequest, textStatus, errorThrown){ } }); }else if( typeof entry_id == "undefined" && id != "" ){ $("body").removeClass().addClass("index").addClass(id); $('html,body').animate({ scrollTop: memorize_scrolltop }, 200); if( memorize_lastvisit == "entry" || memorize_lastvisit == "profile" ){ $("div#entry").stop().animate({ opacity : 0 },1, function(){ $("div#entry").empty().stop().animate({opacity : 1},200); memorize_lastvisit = "index"; memorize_lasturl = href; memorize_scrolltop = 0; memorize_lastindex = id; } ); if( memorize_lastindex != id ){ $("div#index").stop().animate({ opacity : 0 },1, function(){ var set_class = id.replace( "/", " " ); $("div#index").empty().append('

'+ category[id][0] +'

'+ category[id][1] +'

').stop().animate({opacity : 1},200); $("div#index article header h1").stop().animate({opacity : 1},1000); memorize_lastvisit = "index"; memorize_lasturl = href; memorize_scrolltop = 0; memorize_lastindex = id; ajax_request = $.ajax({ url: "https://yukotakeyama.com/ajax_index.php", data: "id=" + id + "", success: function(data, dataType){ if( $("
").append(data).find("article > ul")[0] ){ var get_html = $("
").append(data).find("ul"); var get_js = $("
").append(data).find("script"); $("div#index > article").append(get_html).append(get_js); }else{ var get_html = $("
").append(data).find("div.body").first(); $("div#index > article").append(get_html); } }, error: function(XMLHttpRequest, textStatus, errorThrown){ } }); } ); } }else{ $("div#index").stop().animate({ opacity : 0 },1, function(){ var set_class = id.replace( "/", " " ); $("div#index").empty().append('

'+ category[id][0] +'

'+ category[id][1] +'

').stop().animate({opacity : 1},200); $("div#index article header h1").stop().animate({opacity : 1},1000); memorize_lastvisit = "index"; memorize_lasturl = href; memorize_scrolltop = 0; memorize_lastindex = id; ajax_request = $.ajax({ url: "https://yukotakeyama.com/ajax_index.php", data: "id=" + id + "", success: function(data, dataType){ if( $("
").append(data).find("article > ul")[0] ){ var get_html = $("
").append(data).find("ul"); var get_js = $("
").append(data).find("script"); $("div#index > article").append(get_html).append(get_js); }else{ var get_html = $("
").append(data).find("div.body").first(); $("div#index > article").append(get_html); } }, error: function(XMLHttpRequest, textStatus, errorThrown){ } }); // if( id == "works" ){ // ajax_request = $.ajax({ // url: "https://yukotakeyama.com/ajax_top_info.php", // data: "", // success: // function(data, dataType){ // $("div#index").append(data); // }, // error: // function(XMLHttpRequest, textStatus, errorThrown){ // } // }); // } } ); } } if( id == "" ){ $("body").removeClass().addClass("root"); // if( memorize_lastvisit == "profile" ){ // $("div#entry").stop().animate({ // opacity : 0 // },1, // function(){ // $("div#entry").empty().stop().animate({opacity : 1},1); // memorize_lastvisit = "root"; // memorize_lasturl = href; // memorize_scrolltop = 0; // } // ); // }else{ $("div#entry").stop().animate({ opacity : 0 },1, function(){ $("div#entry").empty().stop().animate({opacity : 1},1); } ); // console.log(memorize_lastvisit); // if( memorize_lastindex != id || memorize_lastvisit == "entry" || memorize_lastvisit == "profile" ){ $("div#index").stop().animate({ opacity : 0 },500, function(){ $("div#index").empty().stop().animate({opacity : 1},1); } ); $("div#index").stop().animate({ opacity : 0 },1, function(){ var set_class = id.replace( "/", " " ); $("div#index").empty().stop().animate({opacity : 1},1); $("div#index article header h1").stop().animate({opacity : 1},1); memorize_lastvisit = "root"; memorize_lasturl = href; memorize_scrolltop = 0; memorize_lastindex = id; ajax_request = $.ajax({ url: "https://yukotakeyama.com/ajax_top_info.php", data: "", success: function(data, dataType){ $("div#index").append(data); }, error: function(XMLHttpRequest, textStatus, errorThrown){ } }); ajax_request = $.ajax({ url: "https://yukotakeyama.com/ajax_slide.php", data: "", success: function(data, dataType){ $("div#index").append(data); }, error: function(XMLHttpRequest, textStatus, errorThrown){ } }); } ); // } // } } ajax_request = $.ajax({ url: "https://yukotakeyama.com/ajax_social.php", data: "id=" + id + "", success: function(data, dataType){ $("div.social").empty().append(data); }, error: function(XMLHttpRequest, textStatus, errorThrown){ } }); if( typeof entry_id == "undefined" ){ $("#header nav li a").removeClass("active"); $("#header nav li a").addClass("over"); var target_nav = $(".class_" + id.replace( "/", "_" )); target_nav.removeClass("over"); target_nav.addClass("active"); } } } function PJAX_pushState( href, title ) { if ( window.history.pushState ) { window.history.pushState( title, null, href ); } else { } } window.onpopstate = function(event){ var onpop = true; if( history_counter != 0 ){ if (event.state) { } else { } var href = location.href; if ( window.history.pushState ) { PJAX_hrefchange( href, onpop ); history_counter++; } else { var href = "https://yukotakeyama.com/#!/" + href.replace( /^.\//, '' ); window.location = href; history_counter++; } } history_counter++; } $(document).on("click", "a.pjax", function(){ var href = $(this).attr("href"); if ( window.history.pushState ) { PJAX_hrefchange( href ); history_counter++; } else { var href = href.replace( "https://yukotakeyama.com/", "" ); var href = "https://yukotakeyama.com/#!/" + href.replace( /^.\//, '' ); window.location = href; history_counter++; } return false; }); $(window).hashchange( function(){ var hash = location.hash; if( hash.indexOf( "#!/" ) != -1 ){ var href = hash.replace( /^#!\//, '' ); if( href == "" ){ var href = "https://yukotakeyama.com/"; } } PJAX_hrefchange( href ); }) $(window).bind('load', function() { var hash = location.hash; if( hash.indexOf( "#!/" ) != -1 ){ var href = hash.replace( /^#!\//, '' ); if ( window.history.pushState ) { window.location = href; }else{ PJAX_hrefchange( href ); } } }); });