/* --------------------------------------------------- */ /* -------------- DEFAULT AUTHORS SCRIPT-------------- */ /* --------------------------------------------------- */ var AUTH_POSTS_PER_PAGE = 20; var AWAY_MAX = 8; var total_pages_author = 0; var local_author_year_data = []; $(document).ready(function() { initAuthorArchives(); }); function initAuthorArchives(){ //BUILDS DIRECTORY PATH OF CURRENT LOCATION var dir = location.pathname.substring(0,location.pathname.lastIndexOf('/')+1); var archives_dir = dir + "archives/"; //REQUESTS ALL AVAILABLE JSON YEARLY ARCHIVES //AND BUILDS MENU BASED ON THAT FOR CURRENT DIRECTORY/AUTHOR /*$.getJSON("http://dyn.realclearpolitics.com/authors/genAuthorArchiveMenu.php?jsoncallback=?&ldir="+archives_dir, function(data) { $.each(data.items, function(i,item){ //LOOPS THROUGH EACH ITEM //CREATES MENU ITEM'S JSON FILE LOCATION var year_archive_loc = location.hostname+archives_dir+item.year+'.js'; if(i==0){ //PARSES JSON FILE FOR FIRST ITEM loadAuthorJSON_file(year_archive_loc); } //BUILDS OPTION var year_option = ''; $('select#form_year_select').append(year_option); //APPENDS OPTION }); });*/ // LOOP THROUGH CURRENT YEAR ALL THE WAY BACK TO FIRST POSSIBLE YEAR (2008) // LOOKING FOR YEARLY ARCHIVE FILES, THE BUILD MENU var this_year = new Date().getFullYear(); var first_run = true; for(var y = this_year; y >= 2008; y--) { var year_archive_loc = archives_dir+y+'.js'; if(doesFileExist(year_archive_loc)) { var year_option = ''; $('select#form_year_select').append(year_option); if(first_run) { loadAuthorJSON_file(year_archive_loc); first_run = false; } } } } function doesFileExist(file_loc) { var http = new XMLHttpRequest(); http.open('HEAD', file_loc, false); http.send(); return http.status!=404 && http.status!=403; } function loadAuthorJSON_file(file_loc){ $(".author-archive .posts ul").css("opacity","0.3"); $(".processing_div").css("display","block"); $.getJSON(file_loc, function(data) { data.sort(mycomparator); //SORTS JSON RESULTS BY DATE local_author_year_data = data; show_author_posts(data); }); } function show_author_posts(data, active_page) { if(typeof active_page === 'undefined') { active_page = 1; } $('.author-archive .posts ul').html(''); var article_items = []; var total_items = data.length; total_pages_author = Math.ceil(total_items / AUTH_POSTS_PER_PAGE); for(var i = 0; i < total_items; i++) { //BUILDS ITEM REQUESTED CONTAINER if(i >= ((active_page - 1) * AUTH_POSTS_PER_PAGE) + AUTH_POSTS_PER_PAGE ) { // } else if(i >= (active_page - 1) * AUTH_POSTS_PER_PAGE) { article_items.push(buildAuthor_items(data[i])); //BUILDS HTML FOR EACH ITEM } } if(total_items > AUTH_POSTS_PER_PAGE) { create_author_pagination(total_pages_author, active_page); } else { $('.author-archive .pagination_container').remove(); } //INSERTS INTO TO UL LISTING $('.author-archive .posts ul').html(article_items.join('')); //INSERTS INTO HTML $(".author-archive .posts ul").css("opacity","1"); $(".processing_div").css("display","none"); } function create_author_pagination(total_pages, active_page) { if(typeof active_page === 'undefined') { active_page = 1; } else { active_page = parseInt(active_page); } var html = ''; html += '