Team:UNITN-Trento/JS/Notebook

From 2013.igem.org

(Difference between revisions)
 
(16 intermediate revisions not shown)
Line 5: Line 5:
function useFilters() {
function useFilters() {
-
if ($("#tn-active-filters-F").val() == "" && $("#tn-active-filters-T").val() == "" && $("#tn-active-filters-D").val() == "") {
+
    if ($("#tn-active-filters-F").val() == "" && $("#tn-active-filters-T").val() == "" && $("#tn-active-filters-D").val() == "") {
-
//Scroll through the  posts
+
        //Scroll through the  posts
-
$(".tn-post").each(function() {
+
        $(".tn-post").each(function() {
-
$(this).css("display", "block");
+
            $(this).css("display", "block");
-
});
+
        });
-
} else {
+
    } else {
-
//Get active filters
+
        //Get active filters
-
Ffilters = $("#tn-active-filters-F").val().split("-");
+
        Ffilters = $("#tn-active-filters-F").val().split("-");
-
Tfilter = $("#tn-active-filters-T").val();
+
        Tfilter = $("#tn-active-filters-T").val();
-
Dfilter = $("#tn-active-filters-D").val();
+
        Dfilter = $("#tn-active-filters-D").val();
-
//Scroll through the  posts
+
        //Scroll through the  posts
-
$(".tn-post").each(function() {
+
        $(".tn-post").each(function() {
-
faces = $(this).attr("data-user").split("-");
+
            faces = $(this).attr("data-user").split("-");
-
facesLow = [];
+
            facesLow = [];
-
for (var i = 0; i < faces.length; i++) {
+
            for (var i = 0; i < faces.length; i++) {
-
facesLow.push(faces[i].toLowerCase());
+
                facesLow.push(faces[i].toLowerCase());
-
}
+
            }
-
tags = $(this).attr("data-tag").split("-");
+
            tags = $(this).attr("data-tag").split("-");
-
date = $(this).attr("data-date");
+
            date = $(this).attr("data-date");
-
keepThis1 = true;
+
            keepThis1 = true;
-
if ($("#tn-active-filters-F").val() != "") {
+
            if ($("#tn-active-filters-F").val() != "") {
-
//If one of the active filters is not present, hide the post
+
                //If one of the active filters is not present, hide the post
-
for (var i = 0; i < Ffilters.length; i++) {
+
                for (var i = 0; i < Ffilters.length; i++) {
-
if (facesLow.indexOf(Ffilters[i].toLowerCase()) == -1) {
+
                    if (facesLow.indexOf(Ffilters[i].toLowerCase()) == -1) {
-
keepThis1 = false;
+
                        keepThis1 = false;
-
}
+
                    }
-
}
+
                }
-
}
+
            }
-
keepThis2 = true;
+
            keepThis2 = true;
-
if (Tfilter != "") {
+
            if (Tfilter != "") {
-
keepThis2 = false;
+
                keepThis2 = false;
-
//If the active tag filter is not present, hide the post
+
                //If the active tag filter is not present, hide the post
-
for (var k = 0; k < tags.length; k++) {
+
                for (var k = 0; k < tags.length; k++) {
-
if (tags[k].toLowerCase().trim() === Tfilter && !keepThis2) {
+
                    if (tags[k].toLowerCase().trim() === Tfilter && !keepThis2) {
-
keepThis2 = true;
+
                        keepThis2 = true;
-
}
+
                    }
-
}
+
                }
-
}
+
            }
-
keepThis3 = true;
+
            keepThis3 = true;
-
if (Dfilter != "") {
+
            if (Dfilter != "") {
-
keepThis3 = false;
+
                keepThis3 = false;
-
if (date == Dfilter) {
+
                if (date == Dfilter) {
-
keepThis3 = true;
+
                    keepThis3 = true;
-
}
+
                }
-
}
+
            }
-
keepThis = false;
+
            keepThis = false;
-
//Combine tags and faces filters
+
            //Combine tags and faces filters
-
if (keepThis1 && keepThis2 && keepThis3) {
+
            if (keepThis1 && keepThis2 && keepThis3) {
-
keepThis = true;
+
                keepThis = true;
-
}
+
            }
-
//Act
+
            //Act
-
if (!keepThis) {
+
            if (!keepThis) {
-
$(this).css("display", "none");
+
                $(this).css("display", "none");
-
} else {
+
            } else {
-
$(this).css("display", "block");
+
                $(this).css("display", "block");
-
}
+
            }
-
});
+
        });
-
}
+
    }
}
}
Line 81: Line 81:
function setBorder(parent, color) {
function setBorder(parent, color) {
-
img = parent.children();
+
    img = parent.children();
-
$("img").each(function() {
+
    $("img").each(function() {
-
if ($(this).attr("src") == img.attr("src")) {
+
        if ($(this).attr("src") == img.attr("src")) {
-
$(this).css("border", "2px solid " + color);
+
            $(this).css("border", "2px solid " + color);
-
}
+
        }
-
});
+
    });
}
}
Line 98: Line 98:
function setMonth(yyyy, month, days) {
function setMonth(yyyy, month, days) {
-
//reset
+
    //reset
-
$("#tn-calendar-table td").text("");
+
    $("#tn-calendar-table td").text("");
-
$("#tn-calendar-table td").attr("data-date", "");
+
    $("#tn-calendar-table td").attr("data-date", "");
-
//Start
+
    //Start
-
var days = 0;
+
    var days = 0;
-
//Set  
+
    //Set  
-
switch (month) {
+
    switch (month) {
-
case 1:
+
        case 1:
-
{
+
            {
-
$(".tn-month.tn-name").text("January 2013");
+
                $(".tn-month.tn-name").text("January 2013");
-
days = 31;
+
                days = 31;
-
break;
+
                break;
-
}
+
            }
-
case 2:
+
        case 2:
-
{
+
            {
-
$(".tn-month.tn-name").text("February 2013");
+
                $(".tn-month.tn-name").text("February 2013");
-
days = 30;
+
                days = 30;
-
break;
+
                break;
-
}
+
            }
-
case 3:
+
        case 3:
-
{
+
            {
-
$(".tn-month.tn-name").text("March 2013");
+
                $(".tn-month.tn-name").text("March 2013");
-
days = 31;
+
                days = 31;
-
break;
+
                break;
-
}
+
            }
-
case 4:
+
        case 4:
-
{
+
            {
-
$(".tn-month.tn-name").text("April 2013");
+
                $(".tn-month.tn-name").text("April 2013");
-
days = 30;
+
                days = 30;
-
break;
+
                break;
-
}
+
            }
-
case 5:
+
        case 5:
-
{
+
            {
-
$(".tn-month.tn-name").text("May 2013");
+
                $(".tn-month.tn-name").text("May 2013");
-
days = 31;
+
                days = 31;
-
break;
+
                break;
-
}
+
            }
-
case 6:
+
        case 6:
-
{
+
            {
-
$(".tn-month.tn-name").text("June 2013");
+
                $(".tn-month.tn-name").text("June 2013");
-
days = 30;
+
                days = 30;
-
break;
+
                break;
-
}
+
            }
-
case 7:
+
        case 7:
-
{
+
            {
-
$(".tn-month.tn-name").text("July 2013");
+
                $(".tn-month.tn-name").text("July 2013");
-
days = 31;
+
                days = 31;
-
break;
+
                break;
-
}
+
            }
-
case 8:
+
        case 8:
-
{
+
            {
-
$(".tn-month.tn-name").text("August 2013");
+
                $(".tn-month.tn-name").text("August 2013");
-
days = 31;
+
                days = 31;
-
break;
+
                break;
-
}
+
            }
-
case 9:
+
        case 9:
-
{
+
            {
-
$(".tn-month.tn-name").text("September 2013");
+
                $(".tn-month.tn-name").text("September 2013");
-
days = 30;
+
                days = 30;
-
break;
+
                break;
-
}
+
            }
-
case 10:
+
        case 10:
-
{
+
            {
-
$(".tn-month.tn-name").text("October 2013");
+
                $(".tn-month.tn-name").text("October 2013");
-
days = 31;
+
                days = 31;
-
break;
+
                break;
-
}
+
            }
-
case 11:
+
        case 11:
-
{
+
            {
-
$(".tn-month.tn-name").text("November 2013");
+
                $(".tn-month.tn-name").text("November 2013");
-
days = 30;
+
                days = 30;
-
break;
+
                break;
-
}
+
            }
-
case 12:
+
        case 12:
-
{
+
            {
-
$(".tn-month.tn-name").text("December 2013");
+
                $(".tn-month.tn-name").text("December 2013");
-
days = 31;
+
                days = 31;
-
break;
+
                break;
-
}
+
            }
-
}
+
    }
-
var week = 1;
+
    var week = 1;
-
//$("#week-"+week+" td").get(0).text("Prova");
+
    //$("#week-"+week+" td").get(0).text("Prova");
-
for (var i = 1; i <= days; i++) {
+
    for (var i = 1; i <= days; i++) {
-
pos = new Date(yyyy, month - 1, i, 0, 0, 0, 0).getDay();
+
        pos = new Date(yyyy, month - 1, i, 0, 0, 0, 0).getDay();
-
$("#week-" + week + " td").eq(pos).text(i);
+
        $("#week-" + week + " td").eq(pos).text(i);
-
smonth = "" + month;
+
        smonth = "" + month;
-
si = "" + i;
+
        si = "" + i;
-
if (smonth.length == 1) {
+
        if (smonth.length == 1) {
-
smonth = "0" + smonth;
+
            smonth = "0" + smonth;
-
}
+
        }
-
if (si.length == 1) {
+
        if (si.length == 1) {
-
si = "0" + si;
+
            si = "0" + si;
-
}
+
        }
-
$("#week-" + week + " td").eq(pos).attr("data-date", yyyy + "-" + smonth + "-" + si);
+
        $("#week-" + week + " td").eq(pos).attr("data-date", yyyy + "-" + smonth + "-" + si);
-
if (pos == 6) {
+
        if (pos == 6) {
-
week++;
+
            week++;
-
}
+
        }
-
}
+
    }
-
$("#tn-calendar-table").attr("data-month", month);
+
    $("#tn-calendar-table").attr("data-month", month);
}
}
Line 205: Line 205:
function getJSONstepped(options) {
function getJSONstepped(options) {
-
//Verify options
+
    //Verify options
-
var i, data_list;
+
    var i, data_list;
-
if (undefined === options.a_list) {
+
    if (undefined === options.a_list) {
-
return;
+
        return;
-
} else {
+
    } else {
-
var a_list = options.a_list;
+
        var a_list = options.a_list;
-
}
+
    }
-
if (undefined === options.startingIndex) {
+
    if (undefined === options.startingIndex) {
-
i = 0;
+
        i = 0;
-
} else {
+
    } else {
-
i = options.startingIndex;
+
        i = options.startingIndex;
-
}
+
    }
-
if (undefined === options.data_list) {
+
    if (undefined === options.data_list) {
-
data_list = [];
+
        data_list = [];
-
} else {
+
    } else {
-
data_list = options.data_list;
+
        data_list = options.data_list;
-
}
+
    }
-
if (undefined === options.success) {
+
    if (undefined === options.success) {
-
return;
+
        return;
-
} else {
+
    } else {
-
var success = options.success;
+
        var success = options.success;
-
}
+
    }
 +
    if (undefined === options.errorCounter) {
 +
        var errorCounter = 0;
 +
    } else {
 +
        var errorCounter = options.errorCounter;
 +
    }
 +
    if (undefined === options.errorList) {
 +
        var errorList = [];
 +
    } else {
 +
        var errorList = options.errorList;
 +
    }
-
if ($(a_list).length > i) {
+
    if ($(a_list).length > i) {
-
//Get url
+
        //Get url
-
var href = $(a_list).eq(i).attr('href');
+
        var href = $(a_list).eq(i).attr('href');
-
//Get id
+
        //Get id
-
var id = href.split("/");
+
        var id = href.split("/");
-
id = id[id.length - 1];
+
        id = id[id.length - 1];
-
// alert(id);
+
-
//Make AJAX request
+
        //Make AJAX request
-
$.ajax({
+
        $.ajax({
-
type: 'GET',
+
            type: 'GET',
-
dataType: 'json',
+
            dataType: 'json',
-
url: href + "?action=raw&ctype=text/javascript",
+
            url: href + "?action=raw&ctype=text/javascript",
-
timeout: 500,
+
            //timeout: 3000,
-
success: function(data, textStatus) {
+
            success: function(data, textStatus) {
-
alert(id);
+
                data.id = id;
-
data.id = id;
+
                data_list.push(data);
-
data_list.push(data);
+
-
getJSONstepped({
+
                data.content = data.content.split("{{:Team:UNITN-Trento/Templates/Styles/Spoiler|").join("<div class='tn-spoiler'><a href=''>");
-
'a_list': a_list,
+
                data.content = data.content.split("|").join("</a><div><center>");
-
'startingIndex': i + 1,
+
                data.content = data.content.split("}}").join("</center></div></div>");
-
'data_list': data_list,
+
 
-
'success': function(a) {
+
                div = $('<div></div>').attr('id', 'tn-post-' + data.date + "-" + data.author).addClass('tn-post').attr('data-user', data.author).attr('data-title', data.title).attr('data-date', data.date).attr('data-tag', data.tags).append($("<div></div>").addClass('tn-text').html(data.content)).prepend($("<a href='https://2013.igem.org/Team:UNITN-Trento/Notebook/Labposts/0" + monthn + "/" + data.id + "?action=edit' class='tn-editpost'><img src='https://static.igem.org/mediawiki/2013/0/04/Tn-20130709-edit_button.png' title='Edit' alt='Edit' /></a>"));
-
options.success(a);
+
 
-
}
+
                $("<center></center>").append($(div)).prependTo($("#aj_cont"));
-
});
+
 
-
},
+
                setPost('#tn-post-' + data.date + "-" + data.author);
-
error: function(data, textStatus) {
+
                // alert("p"+post.id);
-
alert(id+" - "+textStatus)
+
 
-
getJSONstepped({
+
                getJSONstepped({
-
'a_list': a_list,
+
                    'a_list': a_list,
-
'startingIndex': i + 1,
+
                    'startingIndex': i + 1,
-
'data_list': data_list,
+
                    'data_list': data_list,
-
'success': function(a) {
+
                    'success': function(a) {
-
options.success(a);
+
                        options.success(a);
-
}
+
                    },
-
});
+
                    'errorCounter' : errorCounter,
-
}
+
                    'errorList' : errorList
-
});
+
                });
-
} else {
+
            },
-
success(data_list);
+
            error: function(data, textStatus) {
-
}
+
                //alert(id + " - " + textStatus);
 +
                if ( "timeout" === textStatus ) {
 +
                    errorCounter += 1;
 +
                }
 +
                errorList.push(textStatus);
 +
                getJSONstepped({
 +
                    'a_list': a_list,
 +
                    'startingIndex': i + 1,
 +
                    'data_list': data_list,
 +
                    'success': function(a) {
 +
                        options.success(a);
 +
                    },
 +
                    'errorCounter' : errorCounter,
 +
                    'errorList' : errorList
 +
                });
 +
            }
 +
        });
 +
 
 +
    } else {
 +
        if ( 0 != errorCounter ) {
 +
            alert(errorCounter + " 'timeout' errors occurred.");
 +
        }
 +
        success(data_list);
 +
    }
}
}
Line 279: Line 310:
  */
  */
function fillBook(month) {
function fillBook(month) {
-
//empty book
+
    //empty book
-
$("#aj_cont center").remove();
+
    $("#aj_cont center").remove();
-
//Shows loading message
+
    //Shows loading message
-
$("#aj_load").fadeIn();
+
    $("#aj_load").fadeIn();
-
//Show correct active timeSelect buttons and de-activate all the timeSelect buttons
+
    //Show correct active timeSelect buttons and de-activate all the timeSelect buttons
-
$(".tn-button").removeClass("active");
+
    $(".tn-button").removeClass("active");
-
$(".tn-button."+month).addClass("active");
+
    $(".tn-button."+month).addClass("active");
-
$(".tn-button").removeAttr("href");
+
    $(".tn-button").removeAttr("href");
-
//Remove tags
+
    //Remove tags
-
$("#tn-filter-tags option").remove();
+
    $("#tn-filter-tags option").remove();
-
$("#tn-filter-tags").append("<option value=''></option>")
+
    $("#tn-filter-tags").append("<option value=''></option>")
-
//Set correct month on the calendar
+
    //Set correct month on the calendar
-
switch ( month ) {
+
    switch ( month ) {
-
case 'may': {
+
        case 'may': {
-
monthn = 5;
+
            monthn = 5;
-
break;
+
            break;
-
}
+
        }
-
case 'june': {
+
        case 'june': {
-
monthn = 6;
+
            monthn = 6;
-
break;
+
            break;
-
}
+
        }
-
case 'july': {
+
        case 'july': {
-
monthn = 7;
+
            monthn = 7;
-
break;
+
            break;
-
}
+
        }
-
case 'august': {
+
        case 'august': {
-
monthn = 8;
+
            monthn = 8;
-
break;
+
            break;
-
}
+
        }
-
case 'september': {
+
        case 'september': {
-
monthn = 9;
+
            monthn = 9;
-
break;
+
            break;
-
}
+
        }
-
}
+
    }
-
//Creates the calendar
+
    //Creates the calendar
-
var today = new Date();
+
    var today = new Date();
-
var dd = today.getDate(),
+
    var dd = today.getDate(),
-
wd = today.getDay();
+
        wd = today.getDay();
-
var mm = today.getMonth() + 1;
+
    var mm = today.getMonth() + 1;
-
var yyyy = today.getFullYear();
+
    var yyyy = today.getFullYear();
-
setMonth(yyyy, monthn);
+
    setMonth(yyyy, monthn);
-
/**************************************/
+
    /**************************************/
-
/**GET THE POSTs BACK IN THE TEMPLATE**/
+
    /**GET THE POSTs BACK IN THE TEMPLATE**/
-
/**************************************/
+
    /**************************************/
-
var c = 1;
+
    var c = 1;
-
var calenMap = {};
+
    var calenMap = {};
-
var calenOrdered = [];
+
    var calenOrdered = [];
-
//Get posts from AJAX
+
    //Get posts from AJAX
-
getJSONstepped({
+
    getJSONstepped({
-
'a_list': "#aj_index_" + month + " a",
+
        'a_list': "#aj_index_" + month + " a",
-
'success': function(data_list) {
+
        'success': function(data_list) {
 +
            /*
 +
            var last_id = 0,
 +
                href = "";
-
var last_id = 0,
+
            //Iterate through all posts and order them
-
href = "";
+
            $(data_list).each(function(i, p) {
 +
                // alert("s"+p.id);
 +
                if (last_id < parseInt(p.id)) {
 +
                    last_id = parseInt(p.id);
 +
                }
-
//Iterate through all posts and order them
+
                //Get post date
-
$(data_list).each(function(i, p) {
+
                date = p.date.split("-");
-
// alert("s"+p.id);
+
-
if (last_id < parseInt(p.id)) {
+
-
last_id = parseInt(p.id);
+
-
}
+
-
//Get post date
+
                calenMap[date[0] + ":" + date[1] + ":" + date[2] + ":" + i] = p;
-
date = p.date.split("-");
+
                calenOrdered.push(date[0] + ":" + date[1] + ":" + date[2] + ":" + i);
 +
            });
-
calenMap[date[0] + ":" + date[1] + ":" + date[2] + ":" + i] = p;
+
            //Add posts to the page in an ordered way
-
calenOrdered.push(date[0] + ":" + date[1] + ":" + date[2] + ":" + i);
+
            calenOrdered.sort();
-
});
+
            $("#aj_load").fadeOut();
 +
            for (var key in calenOrdered) {
 +
                post = calenMap[calenOrdered[key]];
-
//Add posts to the page in an ordered way
+
                post.content = post.content.split("{{:Team:UNITN-Trento/Templates/Styles/Spoiler|").join("<div class='tn-spoiler'><a href=''>");
-
calenOrdered.sort();
+
                post.content = post.content.split("|").join("</a><div><center>");
-
$("#aj_load").fadeOut();
+
                post.content = post.content.split("}}").join("</center></div></div>");
-
for (var key in calenOrdered) {
+
-
post = calenMap[calenOrdered[key]];
+
-
post.content = post.content.split("{{:Team:UNITN-Trento/Templates/Styles/Spoiler|").join("<div class='tn-spoiler'><a href=''>");
+
                div = $('<div></div>').attr('id', 'tn-post-' + post.date + "-" + post.author).addClass('tn-post').attr('data-user', post.author).attr('data-title', post.title).attr('data-date', post.date).attr('data-tag', post.tags).append($("<div></div>").addClass('tn-text').html(post.content)).prepend($("<a href='https://2013.igem.org/Team:UNITN-Trento/Notebook/Labposts/0" + monthn + "/" + post.id + "?action=edit' class='tn-editpost'><img src='https://static.igem.org/mediawiki/2013/0/04/Tn-20130709-edit_button.png' title='Edit' alt='Edit' /></a>"));
-
post.content = post.content.split("|").join("</a><div><center>");
+
-
post.content = post.content.split("}}").join("</center></div></div>");
+
-
div = $('<div></div>').attr('id', 'tn-post-' + post.date + "-" + post.author).addClass('tn-post').attr('data-user', post.author).attr('data-title', post.title).attr('data-date', post.date).attr('data-tag', post.tags).append($("<div></div>").addClass('tn-text').html(post.content)).prepend($("<a href='https://2013.igem.org/Team:UNITN-Trento/Notebook/Labposts/0" + monthn + "/" + post.id + "?action=edit' class='tn-editpost'><img src='https://static.igem.org/mediawiki/2013/0/04/Tn-20130709-edit_button.png' title='Edit' alt='Edit' /></a>"));
+
                $("<center></center>").append($(div)).prependTo($("#aj_cont"));
-
$("<center></center>").append($(div)).prependTo($("#aj_cont"));
+
                setPost('#tn-post-' + post.date + "-" + post.author);
 +
                // alert("p"+post.id);
 +
            }
 +
            */
 +
            $("#aj_load").fadeOut();
 +
            /*Spoiler JS*/
 +
            $(".tn-spoiler div").slideUp();
 +
            $(".tn-spoiler a").click(function(e) {
 +
                e.preventDefault();
 +
                $(".tn-spoiler-active").removeClass("tn-spoiler-active");
 +
                $(this).parent().addClass("tn-spoiler-active");
 +
                $(".tn-spoiler").not(".tn-spoiler-active").children("div").slideUp();
 +
                $(".tn-spoiler-active").children("div").slideToggle();
 +
            });
-
setPost('#tn-post-' + post.date + "-" + post.author);
+
            //"Add Post" Buttons
-
// alert("p"+post.id);
+
            // $("#tn-content").prepend("<center><a href='https://2013.igem.org/Team:UNITN-Trento/Notebook/Labposts/" + (parseInt(last_id) + 1) + "?action=edit&preload=Team:UNITN-Trento/Help/Labpost_AJAX'  class='tn-addpost'>Add new labPost</a></center>".replace("amp;", ""));
-
}
+
            // $("#tn-content").append("<center><a href='https://2013.igem.org/Team:UNITN-Trento/Notebook/Labposts/" + (parseInt(last_id) + 1) + "?action=edit&preload=Team:UNITN-Trento/Help/Labpost_AJAX'  class='tn-addpost'>Add new labPost</a></center>".replace("amp;", ""));
-
/*Spoiler JS*/
+
            /*************/
-
$(".tn-spoiler div").slideUp();
+
            /**FILTERS 1**/
-
$(".tn-spoiler a").click(function(e) {
+
            /*************/
-
e.preventDefault();
+
-
$(".tn-spoiler-active").removeClass("tn-spoiler-active");
+
-
$(this).parent().addClass("tn-spoiler-active");
+
-
$(".tn-spoiler").not(".tn-spoiler-active").children("div").slideUp();
+
-
$(".tn-spoiler-active").children("div").slideToggle();
+
-
});
+
-
//"Add Post" Buttons
+
            //Add tags to the select filter option
-
// $("#tn-content").prepend("<center><a href='https://2013.igem.org/Team:UNITN-Trento/Notebook/Labposts/" + (parseInt(last_id) + 1) + "?action=edit&preload=Team:UNITN-Trento/Help/Labpost_AJAX'  class='tn-addpost'>Add new labPost</a></center>".replace("amp;", ""));
+
            var added = [];
-
// $("#tn-content").append("<center><a href='https://2013.igem.org/Team:UNITN-Trento/Notebook/Labposts/" + (parseInt(last_id) + 1) + "?action=edit&preload=Team:UNITN-Trento/Help/Labpost_AJAX'  class='tn-addpost'>Add new labPost</a></center>".replace("amp;", ""));
+
            $(".tag").each(function() {
 +
                if (added.indexOf($(this).text().toLowerCase().trim()) == -1) {
 +
                    added.push($(this).text().toLowerCase().trim());
 +
                    $("#tn-filter-tags").append("<option value='" + $(this).text().toLowerCase().trim() + "'>" + $(this).text().toLowerCase().trim() + "</option>");
 +
                }
 +
            });
 +
           
 +
            //Set TAGS filters
 +
            $("#tn-filter-tags").change(function(e) {
 +
                e.preventDefault();
 +
                $("#tn-active-filters-T").val($("#tn-filter-tags").val());
 +
                //Apply active filters
 +
                useFilters();
 +
            });
-
/*************/
+
            //Reactivate timeSelect buttons
-
/**FILTERS 1**/
+
            $(".tn-button").each(function() {
-
/*************/
+
                $(this).attr("href" , $(this).attr("data-href"));
-
 
+
            });
-
//Add tags to the select filter option
+
        }
-
var added = [];
+
    });
-
$(".tag").each(function() {
+
-
if (added.indexOf($(this).text().toLowerCase().trim()) == -1) {
+
-
added.push($(this).text().toLowerCase().trim());
+
-
$("#tn-filter-tags").append("<option value='" + $(this).text().toLowerCase().trim() + "'>" + $(this).text().toLowerCase().trim() + "</option>");
+
-
}
+
-
});
+
-
+
-
//Set TAGS filters
+
-
$("#tn-filter-tags").change(function(e) {
+
-
e.preventDefault();
+
-
$("#tn-active-filters-T").val($("#tn-filter-tags").val());
+
-
//Apply active filters
+
-
useFilters();
+
-
});
+
-
 
+
-
//Reactivate timeSelect buttons
+
-
$(".tn-button").each(function() {
+
-
$(this).attr("href" , $(this).attr("data-href"));
+
-
});
+
-
}
+
-
});
+
}
}
Line 415: Line 447:
  */
  */
function addPost() {
function addPost() {
-
//Get month as string
+
    //Get month as string
-
month = $(".tn-button.active").attr('data-href').split("'")[1];
+
    month = $(".tn-button.active").attr('data-href').split("'")[1];
-
//Get month number
+
    //Get month number
-
switch ( month ) {
+
    switch ( month ) {
-
case 'may': {
+
        case 'may': {
-
monthn = "05";
+
            monthn = "05";
-
break;
+
            break;
-
}
+
        }
-
case 'june': {
+
        case 'june': {
-
monthn = "06";
+
            monthn = "06";
-
break;
+
            break;
-
}
+
        }
-
case 'july': {
+
        case 'july': {
-
monthn = "07";
+
            monthn = "07";
-
break;
+
            break;
-
}
+
        }
-
case 'august': {
+
        case 'august': {
-
monthn = "08";
+
            monthn = "08";
-
break;
+
            break;
-
}
+
        }
-
case 'september': {
+
        case 'september': {
-
monthn = "09";
+
            monthn = "09";
-
break;
+
            break;
-
}
+
        }
-
}
+
    }
-
//Get last_id of actve.month's post
+
   
-
var last_id = 0;
+
    //Get last_id of actve.month's post
-
$("#aj_index_"+month+" a").each(function() {
+
    var last_id = 0;
-
lhref = $(this).attr('href').split("/");
+
    $("#aj_index_"+month+" a").each(function() {
-
id = lhref[lhref.length - 1];
+
        lhref = $(this).attr('href').split("/");
-
if ( last_id < parseInt(id) ) { last_id = parseInt(id); }
+
        id = lhref[lhref.length - 1];
-
});
+
        if ( last_id < parseInt(id) ) { last_id = parseInt(id); }
-
//Go to edit of new post
+
    });
-
document.location.href = "https://2013.igem.org/Team:UNITN-Trento/Templates/Notebook/Labposts/"+monthn+"/"+(last_id + 1)+"?action=edit";
+
 
 +
    //Go to edit of new post
 +
    document.location.href = "https://2013.igem.org/Team:UNITN-Trento/Notebook/Labposts/"+monthn+"/"+(last_id + 1)+"?action=edit&preload=Team:UNITN-Trento/Help/Labpost_AJAX";
}
}
Line 454: Line 488:
//Acts when the document is loaded
//Acts when the document is loaded
$(document).ready(function() {
$(document).ready(function() {
-
/***********/
+
    /***********/
-
/**FILTERS**/
+
    /**FILTERS**/
-
/***********/
+
    /***********/
-
//Select all the FACES filters
+
    //Select all the FACES filters
-
$(".faces").each(function() {
+
    $(".faces").each(function() {
-
//Set the click event
+
        //Set the click event
-
$(this).click(function(e) {
+
        $(this).click(function(e) {
-
//Rewrite default
+
            //Rewrite default
-
e.preventDefault();
+
            e.preventDefault();
-
faceBox = $(this);
+
            faceBox = $(this);
-
hidBox = $("#tn-active-filters-F");
+
            hidBox = $("#tn-active-filters-F");
-
name = faceBox.attr("href");
+
            name = faceBox.attr("href");
-
//If there is no filter active
+
            //If there is no filter active
-
if (hidBox.val() == "") {
+
            if (hidBox.val() == "") {
-
//Add the current to the active filters
+
                //Add the current to the active filters
-
hidBox.val(name);
+
                hidBox.val(name);
-
setBorder(faceBox, "rgb(191, 27, 57)");
+
                setBorder(faceBox, "rgb(191, 27, 57)");
-
} else {
+
            } else {
-
//If there are active filters, get them
+
                //If there are active filters, get them
-
arnames = hidBox.val().split("-");
+
                arnames = hidBox.val().split("-");
-
//If the current is not active, activate it
+
                //If the current is not active, activate it
-
if (arnames.indexOf(name) == -1) {
+
                if (arnames.indexOf(name) == -1) {
-
hidBox.val(hidBox.val() + "-" + name);
+
                    hidBox.val(hidBox.val() + "-" + name);
-
setBorder(faceBox, "rgb(191, 27, 57)");
+
                    setBorder(faceBox, "rgb(191, 27, 57)");
-
} else {
+
                } else {
-
//If the current is active, deactivate it
+
                    //If the current is active, deactivate it
-
arnames.splice(arnames.indexOf(name), 1);
+
                    arnames.splice(arnames.indexOf(name), 1);
-
hidBox.val(arnames.join("-"));
+
                    hidBox.val(arnames.join("-"));
-
setBorder(faceBox, "rgb(240, 242, 223)");
+
                    setBorder(faceBox, "rgb(240, 242, 223)");
-
}
+
                }
-
}
+
            }
-
//Apply active filters
+
            //Apply active filters
-
useFilters();
+
            useFilters();
-
});
+
        });
-
});
+
    });
-
/**********/
+
    /**********/
-
/*CALENDAR*/
+
    /*CALENDAR*/
-
/**********/
+
    /**********/
-
//Creates the calendar
+
    //Creates the calendar
-
var today = new Date();
+
    var today = new Date();
-
var dd = today.getDate(),
+
    var dd = today.getDate(),
-
wd = today.getDay();
+
        wd = today.getDay();
-
var mm = today.getMonth() + 1;
+
    var mm = today.getMonth() + 1;
-
var yyyy = today.getFullYear();
+
    var yyyy = today.getFullYear();
-
setMonth(yyyy, mm);
+
    setMonth(yyyy, mm);
-
//Click
+
    //Click
-
$(".tn-month.tn-fw a").click(function(e) {
+
    $(".tn-month.tn-fw a").click(function(e) {
-
e.preventDefault();
+
        e.preventDefault();
-
$("#tn-calendar-table td").css("border", "1px solid rgb(3, 140, 126)");
+
        $("#tn-calendar-table td").css("border", "1px solid rgb(3, 140, 126)");
-
setMonth(yyyy, parseInt($("#tn-calendar-table").attr("data-month")) + 1);
+
        setMonth(yyyy, parseInt($("#tn-calendar-table").attr("data-month")) + 1);
-
});
+
    });
-
$(".tn-month.tn-bw a").click(function(e) {
+
    $(".tn-month.tn-bw a").click(function(e) {
-
e.preventDefault();
+
        e.preventDefault();
-
$("#tn-calendar-table td").css("border", "1px solid rgb(3, 140, 126)");
+
        $("#tn-calendar-table td").css("border", "1px solid rgb(3, 140, 126)");
-
setMonth(yyyy, parseInt($("#tn-calendar-table").attr("data-month")) - 1);
+
        setMonth(yyyy, parseInt($("#tn-calendar-table").attr("data-month")) - 1);
-
});
+
    });
-
//Set link on calendar
+
    //Set link on calendar
-
$("#tn-calendar-table td").each(function() {
+
    $("#tn-calendar-table td").each(function() {
-
$(this).click(function(e) {
+
        $(this).click(function(e) {
-
e.preventDefault();
+
            e.preventDefault();
-
$("#tn-calendar-table td").css("border", "1px solid rgb(3, 140, 126)");
+
            $("#tn-calendar-table td").css("border", "1px solid rgb(3, 140, 126)");
-
if ($("#tn-active-filters-D").val() == $(this).attr("data-date")) {
+
            if ($("#tn-active-filters-D").val() == $(this).attr("data-date")) {
-
$("#tn-active-filters-D").val("");
+
                $("#tn-active-filters-D").val("");
-
} else {
+
            } else {
-
$(this).css("border", "1px solid rgb(191, 27, 57)");
+
                $(this).css("border", "1px solid rgb(191, 27, 57)");
-
$("#tn-active-filters-D").val($(this).attr("data-date"));
+
                $("#tn-active-filters-D").val($(this).attr("data-date"));
-
}
+
            }
-
//Apply active filters
+
            //Apply active filters
-
useFilters();
+
            useFilters();
-
});
+
        });
-
});
+
    });
-
/*FILL BOOK*/
+
    /*FILL BOOK*/
-
fillBook('august');
+
    fillBook('september');
-
/**SCROLL TO POST BASED ON HASH**/
+
    /**SCROLL TO POST BASED ON HASH**/
-
//$("html,body").scrollTo(document.location.hash.replace("#", ""), document.location.hash.replace("#", ""));
+
    //$("html,body").scrollTo(document.location.hash.replace("#", ""), document.location.hash.replace("#", ""));
});
});
// //When hash changes, scroll to correct div
// //When hash changes, scroll to correct div
// oHch(function() {
// oHch(function() {
-
// $("html,body").scrollTo(document.location.hash.replace("#", ""), document.location.hash.replace("#", ""));
+
// $("html,body").scrollTo(document.location.hash.replace("#", ""), document.location.hash.replace("#", ""));
// });
// });

Latest revision as of 15:47, 3 October 2013

/**

* Hides/Shows labposts based on active filter
* @return none
*/

function useFilters() {

   if ($("#tn-active-filters-F").val() == "" && $("#tn-active-filters-T").val() == "" && $("#tn-active-filters-D").val() == "") {
       //Scroll through the  posts
       $(".tn-post").each(function() {
           $(this).css("display", "block");
       });
   } else {
       //Get active filters
       Ffilters = $("#tn-active-filters-F").val().split("-");
       Tfilter = $("#tn-active-filters-T").val();
       Dfilter = $("#tn-active-filters-D").val();
       //Scroll through the  posts
       $(".tn-post").each(function() {
           faces = $(this).attr("data-user").split("-");
           facesLow = [];
           for (var i = 0; i < faces.length; i++) {
               facesLow.push(faces[i].toLowerCase());
           }
           tags = $(this).attr("data-tag").split("-");
           date = $(this).attr("data-date");
           keepThis1 = true;
           if ($("#tn-active-filters-F").val() != "") {
               //If one of the active filters is not present, hide the post
               for (var i = 0; i < Ffilters.length; i++) {
                   if (facesLow.indexOf(Ffilters[i].toLowerCase()) == -1) {
                       keepThis1 = false;
                   }
               }
           }
           keepThis2 = true;
           if (Tfilter != "") {
               keepThis2 = false;
               //If the active tag filter is not present, hide the post
               for (var k = 0; k < tags.length; k++) {
                   if (tags[k].toLowerCase().trim() === Tfilter && !keepThis2) {
                       keepThis2 = true;
                   }
               }
           }
           keepThis3 = true;
           if (Dfilter != "") {
               keepThis3 = false;
               if (date == Dfilter) {
                   keepThis3 = true;
               }
           }
           keepThis = false;
           //Combine tags and faces filters
           if (keepThis1 && keepThis2 && keepThis3) {
               keepThis = true;
           }
           //Act
           if (!keepThis) {
               $(this).css("display", "none");
           } else {
               $(this).css("display", "block");
           }
       });
   }

}

/**

* Changes border color of every image with the same source of the clicked one
* @param Object parent the <a> tag containing the image
* @param String color
*/

function setBorder(parent, color) {

   img = parent.children();
   $("img").each(function() {
       if ($(this).attr("src") == img.attr("src")) {
           $(this).css("border", "2px solid " + color);
       }
   });

}

/**

* Rebuilds the calendar changing the month
* @param Integer yyyy
* @param Integer month
* @param Integer days
*/

function setMonth(yyyy, month, days) {

   //reset
   $("#tn-calendar-table td").text("");
   $("#tn-calendar-table td").attr("data-date", "");
   //Start
   var days = 0;
   //Set 
   switch (month) {
       case 1:
           {
               $(".tn-month.tn-name").text("January 2013");
               days = 31;
               break;
           }
       case 2:
           {
               $(".tn-month.tn-name").text("February 2013");
               days = 30;
               break;
           }
       case 3:
           {
               $(".tn-month.tn-name").text("March 2013");
               days = 31;
               break;
           }
       case 4:
           {
               $(".tn-month.tn-name").text("April 2013");
               days = 30;
               break;
           }
       case 5:
           {
               $(".tn-month.tn-name").text("May 2013");
               days = 31;
               break;
           }
       case 6:
           {
               $(".tn-month.tn-name").text("June 2013");
               days = 30;
               break;
           }
       case 7:
           {
               $(".tn-month.tn-name").text("July 2013");
               days = 31;
               break;
           }
       case 8:
           {
               $(".tn-month.tn-name").text("August 2013");
               days = 31;
               break;
           }
       case 9:
           {
               $(".tn-month.tn-name").text("September 2013");
               days = 30;
               break;
           }
       case 10:
           {
               $(".tn-month.tn-name").text("October 2013");
               days = 31;
               break;
           }
       case 11:
           {
               $(".tn-month.tn-name").text("November 2013");
               days = 30;
               break;
           }
       case 12:
           {
               $(".tn-month.tn-name").text("December 2013");
               days = 31;
               break;
           }
   }
   var week = 1;
   //$("#week-"+week+" td").get(0).text("Prova");
   for (var i = 1; i <= days; i++) {
       pos = new Date(yyyy, month - 1, i, 0, 0, 0, 0).getDay();
       $("#week-" + week + " td").eq(pos).text(i);
       smonth = "" + month;
       si = "" + i;
       if (smonth.length == 1) {
           smonth = "0" + smonth;
       }
       if (si.length == 1) {
           si = "0" + si;
       }
       $("#week-" + week + " td").eq(pos).attr("data-date", yyyy + "-" + smonth + "-" + si);
       if (pos == 6) {
           week++;
       }
   }
   $("#tn-calendar-table").attr("data-month", month);

}

/**

*
*/

function getJSONstepped(options) {

   //Verify options
   var i, data_list;
   if (undefined === options.a_list) {
       return;
   } else {
       var a_list = options.a_list;
   }
   if (undefined === options.startingIndex) {
       i = 0;
   } else {
       i = options.startingIndex;
   }
   if (undefined === options.data_list) {
       data_list = [];
   } else {
       data_list = options.data_list;
   }
   if (undefined === options.success) {
       return;
   } else {
       var success = options.success;
   }
   if (undefined === options.errorCounter) {
       var errorCounter = 0;
   } else {
       var errorCounter = options.errorCounter;
   }
   if (undefined === options.errorList) {
       var errorList = [];
   } else {
       var errorList = options.errorList;
   }
   if ($(a_list).length > i) {
       //Get url
       var href = $(a_list).eq(i).attr('href');
       //Get id
       var id = href.split("/");
       id = id[id.length - 1];
       //Make AJAX request
       $.ajax({
           type: 'GET',
           dataType: 'json',
           url: href + "?action=raw&ctype=text/javascript",
           //timeout: 3000,
           success: function(data, textStatus) {
               data.id = id;
               data_list.push(data);
               data.content = data.content.split("
{{{1}}}
{{{2}}}
").join("</center></div></div>");
div = $('
').attr('id', 'tn-post-' + data.date + "-" + data.author).addClass('tn-post').attr('data-user', data.author).attr('data-title', data.title).attr('data-date', data.date).attr('data-tag', data.tags).append($("
").addClass('tn-text').html(data.content)).prepend($("<a href='https://2013.igem.org/Team:UNITN-Trento/Notebook/Labposts/0" + monthn + "/" + data.id + "?action=edit' class='tn-editpost'><img src='https://static.igem.org/mediawiki/2013/0/04/Tn-20130709-edit_button.png' title='Edit' alt='Edit' /></a>")); $("
").append($(div)).prependTo($("#aj_cont"));
               setPost('#tn-post-' + data.date + "-" + data.author);
               // alert("p"+post.id);
               getJSONstepped({
                   'a_list': a_list,
                   'startingIndex': i + 1,
                   'data_list': data_list,
                   'success': function(a) {
                       options.success(a);
                   },
                   'errorCounter' : errorCounter,
                   'errorList' : errorList
               });
           },
           error: function(data, textStatus) {
               //alert(id + " - " + textStatus);
               if ( "timeout" === textStatus ) {
                   errorCounter += 1;
               }
               errorList.push(textStatus);
               getJSONstepped({
                   'a_list': a_list,
                   'startingIndex': i + 1,
                   'data_list': data_list,
                   'success': function(a) {
                       options.success(a);
                   },
                   'errorCounter' : errorCounter,
                   'errorList' : errorList
               });
           }
       });
   } else {
       if ( 0 != errorCounter ) {
           alert(errorCounter + " 'timeout' errors occurred.");
       }
       success(data_list);
   }

}

/**

*
*/

function fillBook(month) {

   //empty book
   $("#aj_cont center").remove();
   //Shows loading message
   $("#aj_load").fadeIn();
   //Show correct active timeSelect buttons and de-activate all the timeSelect buttons
   $(".tn-button").removeClass("active");
   $(".tn-button."+month).addClass("active");
   $(".tn-button").removeAttr("href");
   //Remove tags
   $("#tn-filter-tags option").remove();
   $("#tn-filter-tags").append("<option value=></option>")
   //Set correct month on the calendar
   switch ( month ) {
       case 'may': {
           monthn = 5;
           break;
       }
       case 'june': {
           monthn = 6;
           break;
       }
       case 'july': {
           monthn = 7;
           break;
       }
       case 'august': {
           monthn = 8;
           break;
       }
       case 'september': {
           monthn = 9;
           break;
       }
   }
   //Creates the calendar
   var today = new Date();
   var dd = today.getDate(),
       wd = today.getDay();
   var mm = today.getMonth() + 1;
   var yyyy = today.getFullYear();
   setMonth(yyyy, monthn);
   /**************************************/
   /**GET THE POSTs BACK IN THE TEMPLATE**/
   /**************************************/
   var c = 1;
   var calenMap = {};
   var calenOrdered = [];
   //Get posts from AJAX
   getJSONstepped({
       'a_list': "#aj_index_" + month + " a",
       'success': function(data_list) {
           /*
           var last_id = 0,
               href = "";
           //Iterate through all posts and order them
           $(data_list).each(function(i, p) {
               // alert("s"+p.id);
               if (last_id < parseInt(p.id)) {
                   last_id = parseInt(p.id);
               }
               //Get post date
               date = p.date.split("-");
               calenMap[date[0] + ":" + date[1] + ":" + date[2] + ":" + i] = p;
               calenOrdered.push(date[0] + ":" + date[1] + ":" + date[2] + ":" + i);
           });
           //Add posts to the page in an ordered way
           calenOrdered.sort();
           $("#aj_load").fadeOut();
           for (var key in calenOrdered) {
               post = calenMap[calenOrdered[key]];
               post.content = post.content.split("
{{{1}}}
{{{2}}}
").join("</center></div></div>");
div = $('
').attr('id', 'tn-post-' + post.date + "-" + post.author).addClass('tn-post').attr('data-user', post.author).attr('data-title', post.title).attr('data-date', post.date).attr('data-tag', post.tags).append($("
").addClass('tn-text').html(post.content)).prepend($("<a href='https://2013.igem.org/Team:UNITN-Trento/Notebook/Labposts/0" + monthn + "/" + post.id + "?action=edit' class='tn-editpost'><img src='https://static.igem.org/mediawiki/2013/0/04/Tn-20130709-edit_button.png' title='Edit' alt='Edit' /></a>")); $("
").append($(div)).prependTo($("#aj_cont"));
               setPost('#tn-post-' + post.date + "-" + post.author);
               // alert("p"+post.id);
           }
           */
           $("#aj_load").fadeOut();
           /*Spoiler JS*/
           $(".tn-spoiler div").slideUp();
           $(".tn-spoiler a").click(function(e) {
               e.preventDefault();
               $(".tn-spoiler-active").removeClass("tn-spoiler-active");
               $(this).parent().addClass("tn-spoiler-active");
               $(".tn-spoiler").not(".tn-spoiler-active").children("div").slideUp();
               $(".tn-spoiler-active").children("div").slideToggle();
           });
           //"Add Post" Buttons
// $("#tn-content").prepend("
<a href='https://2013.igem.org/Team:UNITN-Trento/Notebook/Labposts/" + (parseInt(last_id) + 1) + "?action=edit&preload=Team:UNITN-Trento/Help/Labpost_AJAX' class='tn-addpost'>Add new labPost</a>
".replace("amp;", "")); // $("#tn-content").append("
<a href='https://2013.igem.org/Team:UNITN-Trento/Notebook/Labposts/" + (parseInt(last_id) + 1) + "?action=edit&preload=Team:UNITN-Trento/Help/Labpost_AJAX' class='tn-addpost'>Add new labPost</a>
".replace("amp;", ""));
           /*************/
           /**FILTERS 1**/
           /*************/
           //Add tags to the select filter option
           var added = [];
           $(".tag").each(function() {
               if (added.indexOf($(this).text().toLowerCase().trim()) == -1) {
                   added.push($(this).text().toLowerCase().trim());
                   $("#tn-filter-tags").append("<option value='" + $(this).text().toLowerCase().trim() + "'>" + $(this).text().toLowerCase().trim() + "</option>");
               }
           });
           
           //Set TAGS filters
           $("#tn-filter-tags").change(function(e) {
               e.preventDefault();
               $("#tn-active-filters-T").val($("#tn-filter-tags").val());
               //Apply active filters
               useFilters();
           });
           //Reactivate timeSelect buttons
           $(".tn-button").each(function() {
               $(this).attr("href" , $(this).attr("data-href"));
           });
       }
   });

}

/**

*
*/

function addPost() {

   //Get month as string
   month = $(".tn-button.active").attr('data-href').split("'")[1];
   //Get month number
   switch ( month ) {
       case 'may': {
           monthn = "05";
           break;
       }
       case 'june': {
           monthn = "06";
           break;
       }
       case 'july': {
           monthn = "07";
           break;
       }
       case 'august': {
           monthn = "08";
           break;
       }
       case 'september': {
           monthn = "09";
           break;
       }
   }
   
   //Get last_id of actve.month's post
   var last_id = 0;
   $("#aj_index_"+month+" a").each(function() {
       lhref = $(this).attr('href').split("/");
       id = lhref[lhref.length - 1];
       if ( last_id < parseInt(id) ) { last_id = parseInt(id); }
   });
   //Go to edit of new post
   document.location.href = "https://2013.igem.org/Team:UNITN-Trento/Notebook/Labposts/"+monthn+"/"+(last_id + 1)+"?action=edit&preload=Team:UNITN-Trento/Help/Labpost_AJAX";

}


//Acts when the document is loaded $(document).ready(function() {

   /***********/
   /**FILTERS**/
   /***********/
   //Select all the FACES filters
   $(".faces").each(function() {
       //Set the click event
       $(this).click(function(e) {
           //Rewrite default
           e.preventDefault();
           faceBox = $(this);
           hidBox = $("#tn-active-filters-F");
           name = faceBox.attr("href");
           //If there is no filter active
           if (hidBox.val() == "") {
               //Add the current to the active filters
               hidBox.val(name);
               setBorder(faceBox, "rgb(191, 27, 57)");
           } else {
               //If there are active filters, get them
               arnames = hidBox.val().split("-");
               //If the current is not active, activate it
               if (arnames.indexOf(name) == -1) {
                   hidBox.val(hidBox.val() + "-" + name);
                   setBorder(faceBox, "rgb(191, 27, 57)");
               } else {
                   //If the current is active, deactivate it
                   arnames.splice(arnames.indexOf(name), 1);
                   hidBox.val(arnames.join("-"));
                   setBorder(faceBox, "rgb(240, 242, 223)");
               }
           }
           //Apply active filters
           useFilters();
       });
   });
   /**********/
   /*CALENDAR*/
   /**********/
   //Creates the calendar
   var today = new Date();
   var dd = today.getDate(),
       wd = today.getDay();
   var mm = today.getMonth() + 1;
   var yyyy = today.getFullYear();
   setMonth(yyyy, mm);
   //Click
   $(".tn-month.tn-fw a").click(function(e) {
       e.preventDefault();
       $("#tn-calendar-table td").css("border", "1px solid rgb(3, 140, 126)");
       setMonth(yyyy, parseInt($("#tn-calendar-table").attr("data-month")) + 1);
   });
   $(".tn-month.tn-bw a").click(function(e) {
       e.preventDefault();
       $("#tn-calendar-table td").css("border", "1px solid rgb(3, 140, 126)");
       setMonth(yyyy, parseInt($("#tn-calendar-table").attr("data-month")) - 1);
   });
   //Set link on calendar
   $("#tn-calendar-table td").each(function() {
       $(this).click(function(e) {
           e.preventDefault();
           $("#tn-calendar-table td").css("border", "1px solid rgb(3, 140, 126)");
           if ($("#tn-active-filters-D").val() == $(this).attr("data-date")) {
               $("#tn-active-filters-D").val("");
           } else {
               $(this).css("border", "1px solid rgb(191, 27, 57)");
               $("#tn-active-filters-D").val($(this).attr("data-date"));
           }
           //Apply active filters
           useFilters();
       });
   });
   /*FILL BOOK*/
   fillBook('september');
   /**SCROLL TO POST BASED ON HASH**/
   //$("html,body").scrollTo(document.location.hash.replace("#", ""), document.location.hash.replace("#", ""));

});

// //When hash changes, scroll to correct div // oHch(function() { // $("html,body").scrollTo(document.location.hash.replace("#", ""), document.location.hash.replace("#", "")); // });