$(function() {
category = Array();
function htmlEncode(value){
return $('
').text(value).html();
}
function htmlDecode(value){
return $('').html(value).text();
}
root_site_title = "";
history_counter = 0;
past_href = location.href;
memorize_scrolltop = $(window).scrollTop();
memorize_lastvisit = "root";
memorize_lasturl = location.href;
profile_url = "";
now_viewing = "";
scroll_action_flag = false;
$(window).bind('load', function() {
if( memorize_lastvisit == "entry" ){
scroll_action_flag = false;
$("#entry > article").css({"margin-top": $(window).scrollTop() - $("#container").offset().top + 50});
$("div#entry").fadeIn(400);
memorize_lastindex = "";
memorize_lastvisit_article_type = "";
}else if( memorize_lastvisit == "index" || memorize_lastvisit == "profile" ){
scroll_action_flag = false;
var window_height = $(window).height();
var window_width = $(window).width();
if( window_width < 1600 ){
var slide_margin = window_width*$("div#slide > div").attr("data-ratio");
}else{
var slide_margin = 1600*$("div#slide > div").attr("data-ratio");
}
$("#container").css("margin-top", slide_margin);
var target_nav = $(".class_" + "".replace( "/", "_" ) + " a");
target_nav.removeClass("over");
target_nav.addClass("active");
//article_type(ground・modal)の読み取り
var article_type = $( "article#" + now_viewing ).attr("class");
if( article_type == "ground" ){
var scrollto = $('#' + now_viewing ).offset().top + 20;
$('html,body').animate({
scrollTop: scrollto
}, 1000,
function(){
scroll_action_flag = true;
});
}else if( article_type == "modal" ){
$( "article#" + now_viewing ).css({"margin-top": $(window).scrollTop() - $("#container").offset().top + 50});
$( "article#" + now_viewing ).parent().fadeIn(
400,function(){
if( now_viewing == "schedule" && ! $("#calendar * ").length ){
create_fullcalendar();
}
}
);
}
memorize_lastvisit_article_type = article_type;
}else{
scroll_action_flag = false;
setTimeout(
function(){
scroll_action_flag = true;
}
, 1000);
memorize_lastvisit_article_type = "";
}
});
function PJAX_hrefchange( href, onpop ) {
scroll_action_flag = false;
if( typeof ajax_request != "undefined" ){
ajax_request.abort();
}
if( typeof scroll_action_limiter != "undefined" ){
clearTimeout( scroll_action_limiter );
}
if( href && past_href != href ){
past_href = href;
var id = href.replace( "http://morinote.net/slide/", "" );
var id = id.replace( "?mode=preview", "" );
now_viewing = id;
ajax_request = $.ajax({
url: "http://morinote.net/slide/pjax_readtitle_json.php",
data: "id=" + id + "&type=json" + "",
dataType: "json",
success:
function(data, dataType){
if(!onpop){
PJAX_pushState( href, data.title );
ga('send', 'pageview', {'page': id, 'title': 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 ,"");
if( entry_id != "" && category_filter != "" ){
$("body").append("");
if( memorize_lastvisit == "entry"){
$('html,body').animate({
scrollTop: memorize_scrolltop
}, '200',
function(){
scroll_action_flag = false;
});
}else{
memorize_scrolltop = $(window).scrollTop();
}
ajax_request = $.ajax({
url: "http://morinote.net/slide/ajax_entry.php",
data: "id=" + category_filter + "/" + entry_id + "",
success:
function(data, dataType){
$("div#entry").fadeOut(
400,
function(){
$(this).empty().append(data).fadeIn(
400,function(){
$("#entry > article").css({"margin-top": $(window).scrollTop() - $("#container").offset().top + 50});
$("div#loading").fadeOut(1500).remove();
}
);
}
);
memorize_lastvisit = "entry";
memorize_lastvisit_article_type = "";
memorize_lasturl = href;
memorize_lastindex = category_filter;
},
error:
function(XMLHttpRequest, textStatus, errorThrown){
}
});
}else if( entry_id != "" ){
$("body").append("");
ajax_request = $.ajax({
url: "http://morinote.net/slide/ajax_entry.php",
data: "id=" + entry_id + "",
success:
function(data, dataType){
$("div#entry").fadeOut(
400,
function(){
$(this).empty().append(data).fadeIn(
400,function(){
$("#entry > article").css({"margin-top": $(window).scrollTop() - $("#container").offset().top + 50});
$("div#loading").fadeOut(1500).remove();
}
);
}
);
memorize_lastvisit = "entry";
memorize_lastvisit_article_type = "";
memorize_lasturl = href;
memorize_scrolltop = 0;
memorize_lastindex = "";
},
error:
function(XMLHttpRequest, textStatus, errorThrown){
}
});
}
}
if( typeof entry_id == "undefined" && ( id != "" || id == profile_url ) ){
//article_type(ground・modal)の読み取り
var article_type = $( "article#" + id ).attr("class");
if( memorize_lastvisit == "entry" ){
$('html,body').animate({
scrollTop: memorize_scrolltop
}, 200);
$("div#entry").fadeOut(
400,
function(){
$(this).empty();
scroll_action_flag = true;
memorize_lastvisit = "index";
memorize_lasturl = href;
memorize_scrolltop = 0;
memorize_lastindex = id;
}
);
if( memorize_lastindex != id ){
if( article_type == "ground" ){
var scrollto = $('#' + id).offset().top + 20;
$('html,body').animate({
scrollTop: scrollto
}, 1000,
function(){
scroll_action_flag = true;
});
}else if( article_type == "modal" ){
$( "article#" + id ).css({"margin-top": $(window).scrollTop() - $("#container").offset().top + 50});
$( "article#" + id ).parent().fadeIn(
400,function(){
$("div#loading").fadeOut(1500).remove();
if( id == "schedule" && ! $("#calendar * ").length ){
create_fullcalendar();
}
}
);
}
memorize_lastvisit = "index";
memorize_lastvisit_article_type = article_type;
memorize_lasturl = href;
memorize_scrolltop = $(window).scrollTop();
memorize_lastindex = id;
}
}else{
$( "article.modal" ).parent().fadeOut(400);
if( article_type == "ground" ){
var scrollto = $('#' + id).offset().top + 20;
$('html,body').animate({
scrollTop: scrollto
}, 1000,
function(){
scroll_action_flag = true;
});
}else if( article_type == "modal" ){
$("#slide").attr("data-sign","pause");
$( "article#" + id ).css({"margin-top": $(window).scrollTop() - $("#container").offset().top + 50});
$( "article#" + id ).parent().fadeIn(
400,function(){
$("div#loading").fadeOut(1500).remove();
if( id == "schedule" && ! $("#calendar * ").length ){
create_fullcalendar();
}
}
);
}
memorize_lastvisit = "index";
memorize_lastvisit_article_type = article_type;
memorize_lasturl = href;
memorize_scrolltop = $(window).scrollTop();
memorize_lastindex = id;
}
}
if( id == "" ){
$("#slide").attr("data-sign","play");
$( "article.modal" ).parent().fadeOut(
400,function(){
scroll_action_flag = true;
}
);
$("div#entry").fadeOut(
400,
function(){
$(this).empty();
}
);
if( memorize_lastvisit_article_type != "modal" ){
var scrollto = 0;
$('html,body').animate({
scrollTop: scrollto
}, 1000,
function(){
scroll_action_flag = true;
});
}
memorize_lastvisit = "root";
memorize_lastvisit_article_type = "";
memorize_lasturl = href;
memorize_scrolltop = 0;
}
if( typeof entry_id == "undefined" ){
$("#navi nav li a").removeClass("active");
$("#navi nav li a").css("background-color","rgba(50,50,50,0)");
$("#navi nav li a").addClass("over");
var target_nav = $(".class_" + id.replace( "/", "_" ) + " a");
target_nav.removeClass("over");
target_nav.addClass("active");
}
}else{
if ( href.replace( "http://morinote.net/slide/", "" ) == "" ){
$('html,body').animate({
scrollTop: 0
}, 500);
scroll_action_flag = true;
}
}
}
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 = "http://morinote.net/slide/#!/" + 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( "http://morinote.net/slide/", "" );
var href = "http://morinote.net/slide/#!/" + href.replace( /^.\//, '' );
var past_href = location.href;
if ( href == "http://morinote.net/slide/#!/" && past_href == "http://morinote.net/slide/#!/" ) {
$('html,body').animate({
scrollTop: 0
}, 1000);
memorize_lastvisit_article_type = "";
}
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 = "http://morinote.net/slide/";
}
}
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 );
}
}
});
$(window).scroll(function(){
if( scroll_action_flag === true ){
scroll_action_flag = false;
if( typeof scroll_action_limiter != "undefined" ){
clearTimeout( scroll_action_limiter );
}
scroll_action_limiter = setTimeout(
function(){
var menu_list = [];
var count_i = 0;
$(".ground").each(function(){
if( $(this).attr("id") != null ){
var push_val_id = $(this).attr("id");
var push_val_offset = $("#" + push_val_id).offset().top;
var push_val_height = $("#" + push_val_id).height();
menu_list[count_i] = [];
menu_list[count_i]["id"] = push_val_id;
menu_list[count_i]["offset"] = push_val_offset;
menu_list[count_i]["height"] = push_val_height;
count_i++;
}
});
var scroll_val = $(window).scrollTop();
$.each( menu_list, function(i){
if( scroll_val >= menu_list[i]["offset"] && scroll_val <= menu_list[i]["offset"]+menu_list[i]["height"] ){
if( now_viewing != menu_list[i]["id"] ){
var id = menu_list[i]["id"];
now_viewing = id;
past_href = "http://morinote.net/slide/" + id;
var page_title = category[id][0] + " | " + root_site_title;
PJAX_pushState( "http://morinote.net/slide/" + id, page_title );
document.title = page_title;
$("#navi nav li a").removeClass("active");
$("#navi nav li a").css("background-color","rgba(50,50,50,0)");
$("#navi nav li a").addClass("over");
var target_nav = $(".class_" + id + " a");
target_nav.removeClass("over");
target_nav.addClass("active");
ga('send', 'pageview', {'page': id, 'title': data.title});
}
}else if( scroll_val < menu_list[0]["offset"] ){
if( now_viewing != "" ){
var id = "";
now_viewing = id;
past_href = "http://morinote.net/slide/";
PJAX_pushState( "http://morinote.net/slide/", root_site_title );
document.title = root_site_title;
$("#navi nav li a").removeClass("active");
$("#navi nav li a").css("background-color","rgba(50,50,50,0)");
$("#navi nav li a").addClass("over");
ga('send', 'pageview', {'page': id, 'title': data.title});
}
}
});
scroll_action_flag = true;
}
, 2000);
}
});
});