diff --git a/functions.php b/functions.php index 230bcef..84bed8c 100644 --- a/functions.php +++ b/functions.php @@ -7,10 +7,19 @@ February 2014 by UITS Web Lab brian.dunnigan@uconn.edu ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ */ +function new_excerpt_more( $more ) { + return ' Read More'; +} +add_filter( 'excerpt_more', 'new_excerpt_more' ); + +function custom_excerpt_length( $length ) { + return 200; +} +add_filter( 'excerpt_length', 'custom_excerpt_length', 999 ); -add_theme_support( 'post-thumbnails' ); +add_theme_support( 'post-thumbnails' ); // If no Menu is created, displays a home link, and starts listing pages across the top. @@ -204,10 +213,6 @@ function my_cpt_post_types( $post_types ) { add_filter( 'cpt_post_types', 'my_cpt_post_types' ); - - - - /* Disabled until theme supports these types... (AB June 26, 2013) add_theme_support( 'post-formats', array( 'aside', 'image', 'link', 'quote', 'status' ) ); @@ -306,9 +311,9 @@ function hale_enqueue_scripts() { } add_action('wp_enqueue_scripts', 'hale_enqueue_scripts'); -add_action( 'wp_ajax_clas_post_content', 'prefix_ajax_clas_post_content' ); -add_action('wp_ajax_nopriv_clas_post_content', 'prefix_ajax_clas_post_content'); -function prefix_ajax_clas_post_content() { //Retrieves post info and content for ajax on News-Archive +add_action( 'wp_ajax_clas_post_content', 'ajax_clas_post_content' ); +add_action('wp_ajax_nopriv_clas_post_content', 'ajax_clas_post_content'); +function ajax_clas_post_content() { //Retrieves post info and content for ajax on News-Archive $id = $_POST['postID']; global $post; $content_post = get_post($id); @@ -331,100 +336,185 @@ function prefix_ajax_clas_post_content() { //Retrieves post info and content for echo wp_json_encode($object); die(); } -add_action( 'wp_ajax_clas_tag_posts', 'prefix_ajax_clas_tag_posts' ); -add_action('wp_ajax_nopriv_clas_tag_posts', 'prefix_ajax_clas_tag_posts'); -function prefix_ajax_clas_tag_posts() { //Retieves posts of a specific tag, using class name - $tag = $_POST['val']; - $args = "tag='".$tag."'&orderby=post-date&field=ids&numberposts=-1"; - $ids = get_posts( $args ); - if( $tag == 'All News' ){ - $ids = get_posts( 'orderby=post-date&field=ids&numberposts=-1' ); + +function getPostExcerpt( $id ){ + $content = get_post($id)->post_content; + $excerpt = strip_tags( strip_shortcodes( $content ) ); + $words = explode(' ', $excerpt, 201); + + if(count($words) > 200){ + array_pop($words); + array_push($words, '…'); + $excerpt = implode(' ', $words); + } + + $excerpt = '

'.$excerpt.'

'; + + return $excerpt; +} + +function getPostSlug( $id ){ + return get_post($id)->post_name; +} + +add_action( 'wp_ajax_clas_posts', 'ajax_clas_posts' ); +add_action('wp_ajax_nopriv_clas_posts', 'ajax_clas_posts'); +function ajax_clas_posts(){ + $posts = $_POST['postIDs']; + $postObj = new stdClass(); + if( !empty($posts) ){ + foreach( $posts as $k=>$id ){ + $postObj->$k = new stdClass(); + $postObj->$k->id = $id; + $postObj->$k->link = get_permalink($id); + $postObj->$k->title = get_the_title($id); + $postObj->$k->slug = getPostSlug($id); + $postObj->$k->excerpt = getPostExcerpt($id); + $postObj->$k->date = get_the_time('F j, Y', $id); + $postObj->$k->featuredImage = get_the_post_thumbnail($id, 'medium', $attr); + } + $json = wp_json_encode( $postObj ); } - $object = new stdClass(); - foreach( $ids as $k=>$id ){ - $link = get_permalink($id); - $title = get_the_title($id); - $object->$k->link = $link; - $object->$k->title = $title; - $object->$k->postID = $id; + + echo $json; + wp_die(); +} + +add_action( 'wp_ajax_clas_tag_posts', 'ajax_clas_tag_posts' ); +add_action('wp_ajax_nopriv_clas_tag_posts', 'ajax_clas_tag_posts'); +function ajax_clas_tag_posts() { //Retieves posts of a specific tag, using class name + $tag = $_POST['tag']; + + $args = array( + 'numberposts' => -1, + 'fields' => 'ids' + ); + if( $tag !== 'all-divisions' ){ + $args['tag'] = $tag; } - echo wp_json_encode($object); - die(); + + $posts = get_posts( $args ); + + if( !empty($posts) ){ + $postObj = new stdClass(); + foreach( $posts as $k=>$id ){ + $postObj->$k = new stdClass(); + $postObj->$k->id = $id; + $postObj->$k->slug = getPostSlug($id); + $postObj->$k->link = get_permalink($id); + $postObj->$k->title = get_the_title($id); + } + $json = wp_json_encode( $postObj ); + } + + echo $json; + wp_die(); } -add_action( 'wp_ajax_clas_cat_posts', 'prefix_ajax_clas_cat_posts' ); -add_action('wp_ajax_nopriv_clas_cat_posts', 'prefix_ajax_clas_cat_posts'); -function prefix_ajax_clas_cat_posts() { //Retieves posts of a specific category or tag, using cat/tag id - $json = $_POST['data']; - $tax = $json['taxonomy']; - $val = $json['value']; +add_action( 'wp_ajax_clas_cat_posts', 'ajax_clas_cat_posts' ); +add_action('wp_ajax_nopriv_clas_cat_posts', 'ajax_clas_cat_posts'); +function ajax_clas_cat_posts() { //Retieves posts of a specific category or tag, using cat/tag id + $tax = $_POST['taxonomy']; + $val = $_POST['value']; + + $args = array( + 'field' => 'ids', + 'numberposts' => -1 + ); + if( $tax == 'category' ){ - $args = "category='".$val."'&orderby=post-date&field=ids&numberposts=-1"; - $taxName = get_cat_name($val); + $args['cat'] = $val; + //$taxName = get_cat_name($val); } else if( $tax == 'tag' ) { - $args = "tag_id=".$val."&orderby=post-date&field=ids&numberposts=-1"; - $taxName = get_term_by( 'id', $val, 'post_tag' )->slug; + $args['tag_id'] = $val; + //$taxName = get_tag($val)->name; } - $ids = get_posts( $args ); - if( $val == "0" ){ - $ids = get_posts( 'category=19&orderby=post-date&field=ids&numberposts=-1' ); - } - $object = new stdClass(); - foreach( $ids as $k=>$id ){ - $link = get_permalink($id); - $title = get_the_title($id); - $object->$k->link = $link; - $object->$k->title = $title; - $object->$k->postID = $id; - $object->$k->taxName = $taxName; - + $posts = get_posts( $args ); + + $postObj = new stdClass(); + foreach( $posts as $k=>$id ){ + $postObj->$k = new stdClass(); + $postObj->$k->id = $id->ID; + $postObj->$k->slug = getPostSlug($id); + $postObj->$k->link = get_permalink($id); + $postObj->$k->title = get_the_title($id); } - echo wp_json_encode($object); - die(); + echo wp_json_encode($postObj); + wp_die(); } -add_action( 'wp_ajax_clas_search_archive', 'prefix_ajax_clas_search_archive' ); -add_action('wp_ajax_nopriv_clas_search_archive', 'prefix_ajax_clas_search_archive'); -function prefix_ajax_clas_search_archive() { //Retieves posts of a specific category or tag, using cat/tag id +add_action( 'wp_ajax_clas_search_archive', 'ajax_clas_search_archive' ); +add_action('wp_ajax_nopriv_clas_search_archive', 'ajax_clas_search_archive'); +function ajax_clas_search_archive() { //Retieves posts of a specific category or tag, using cat/tag id $search = $_POST['search']; - $archiveQuery = new WP_Query( 'category_name=archive&fields=ids&s='.$search.'' ); + $args = array( + 's' => $search, + 'fields' => 'ids', + 'category_name' => 'archive' + ); + $archiveQuery = new WP_Query( $args ); $archivePosts = $archiveQuery->get_posts(); - $object = new stdClass(); + + $postObj = new stdClass(); foreach( $archivePosts as $k=>$id ){ if( in_array($id, $archivePosts) ){ - $link = get_permalink($id); - $title = get_the_title($id); - $object->$k->link = $link; - $object->$k->title = $title; - $object->$k->postID->ID = $id; + $postObj->$k = new stdClass(); + $postObj->$k->id = $id; + $postObj->$k->slug = getPostSlug($id); + $postObj->$k->link = get_permalink($id); + $postObj->$k->title = get_the_title($id); } } - echo wp_json_encode($object); - die(); + echo wp_json_encode( $postObj ); + wp_die(); } -add_action( 'wp_ajax_clas_orderby_posts', 'prefix_ajax_clas_orderby_posts' ); -add_action('wp_ajax_nopriv_clas_orderby_posts', 'prefix_ajax_clas_orderby_posts'); -function prefix_ajax_clas_orderby_posts() { //Retrieves and sorts posts by date - $json = $_POST['info']; - $order = $json['order']; - $ids = $json['posts']; - $args = array( 'include' => $ids, 'order'=> $order, 'orderby' => 'post-date', 'field' => 'ids', 'numberposts' => -1 ); - //$args = "order=".$order."&include[]=".$ids."&orderby=post-date&field=ids&numberposts=-1"; +add_action( 'wp_ajax_clas_orderby_posts', 'ajax_clas_orderby_posts' ); +add_action('wp_ajax_nopriv_clas_orderby_posts', 'ajax_clas_orderby_posts'); +function ajax_clas_orderby_posts() { //Retrieves and sorts posts by date + $info = $_POST['info']; + $order = $info['order']; + $ids = $info['posts']; + + $args = array( + 'include' => $ids, + 'order'=> $order, + 'field' => 'ids', + 'numberposts' => -1 + ); $posts = get_posts( $args ); - $object = new stdClass(); + + $postObj = new stdClass(); foreach( $posts as $k=>$id ){ - $link = get_permalink($id); - $title = get_the_title($id); - $object->$k->link = $link; - $object->$k->title = $title; - $object->$k->postID = $id; + $postObj->$k = new stdClass(); + $postObj->$k->id = $id->ID; + $postObj->$k->slug = getPostSlug($id); + $postObj->$k->link = get_permalink($id); + $postObj->$k->title = get_the_title($id); } - echo wp_json_encode($object); - die(); + echo wp_json_encode($postObj); + wp_die(); +} + +add_action( 'wp_ajax_clas_taxid', 'ajax_clas_taxid' ); +add_action('wp_ajax_nopriv_clas_taxid', 'ajax_clas_taxid'); +function ajax_clas_taxid(){ + $taxonomyName = $_POST['taxonomyName']; + $taxonomyType = $_POST['taxonomyType']; + + if( $taxonomyType == 'category' ){ + $idObj = get_category_by_slug($taxonomyName); + $id = $idObj->term_id; + } else if( $taxonomyType == 'tag' ) { + $idObj = get_term_by('slug', $taxonomyName, 'post_tag'); + $id = $idObj->term_id; + } + + echo wp_json_encode( $id ); + wp_die(); } function huskypress_customize_register( $wp_customize ) diff --git a/js/custom-old.js b/js/custom-old.js new file mode 100644 index 0000000..b37791e --- /dev/null +++ b/js/custom-old.js @@ -0,0 +1,446 @@ +jQuery(document).ready(function($) { + +/* +Notes +======= +Components: +Sort by Category/ Tags, Divison, Date +Search +Ajax load posts +History API - Click on link, choose category/tag => push to history +Load posts on direct visit (to specific category/tag/division) + */ + + // News Stories Pagination + function paginateNews(){ + $('#news-stories').css('visibility', 'hidden') + // change the perPage variable to the number of items you want per page. + var perPage = 15 + var stories = $('.news-archive-list li') + var numStories = stories.length + //console.log('numStories'+numStories) + var totalPages = Math.ceil(numStories/perPage) + + + // only run this function if we need to. + if (totalPages > 1) { + $('#news-pagination').show(); + var currentPage = 1 + function assignPageNums(){ + var pageCount = 1 + var storyCount = 1 + stories.each(function() { + $(this).addClass('page'+pageCount) + var x = storyCount / perPage + if(Math.floor(x) == x && $.isNumeric(x)) { + pageCount++ + } + storyCount++ + }) + } + function drawPage() { + // only display items from current page + stories.hide() + $('.news-archive-list li.page'+ currentPage).show() + // insert pagination numbered links + $('.page-link-item').remove() + for (i=1; i<=totalPages; i++){ + var li = $('
  • ') + li.addClass('page-link-item') + var a = $('') + a.attr('href', '#') + a.attr('page', i) + a.addClass('page-link') + a.append(i) + li.append(a) + if (i == currentPage){ + li.addClass('active') + } + $('#news-next').parent('li').before(li) + } + // disable back/next on first/last pages. + if (currentPage == 1){ + $('#news-back').parent('li').addClass('disabled') + } else if (currentPage > 1 && currentPage < totalPages) { + $('#news-next').parent('li').removeClass('disabled') + $('#news-back').parent('li').removeClass('disabled') + } else if (currentPage == totalPages){ + $('#news-next').parent('li').addClass('disabled') + } + // bind click event to new a tags. + $('.page-link').on('click', function(e){ + e.preventDefault() + var page = $(this).attr('page') + currentPage = page + drawPage() + }) + } + + assignPageNums() + drawPage() + + $('#news-next').on('click', function(e){ + e.preventDefault() + if (currentPage < totalPages){ + currentPage++ + drawPage() + } + }) + $('#news-back').on('click', function(e){ + e.preventDefault() + if (currentPage >= 2){ + currentPage-- + drawPage() + } + }) + } else { + // if we don't need pagination, hide the controls. + $('#news-pagination').hide() + } + $('#news-stories').css('visibility', 'visible') + + } + + function updateContent( object ){ + var title = object.title; + $('.clas-entry-content').html('').append(object.content); + $('.clas-entry-title').html('').append(''+title+''); + $('.clas-post-date').html('').append(object.postdate); + $('.clas-entry-thumbnail').html('').append(object.image); + } + + if( $('.news-archive-list').length > 0 ){ + var currentTaxonomy = (function () { + var resetTax = function(){ + $('.clas-taxonomy-type, .clas-taxonomy-name').html(''); + } + + var set = function(taxonomy, taxonomyName){ + $('.clas-taxonomy-type').html(taxonomy+': ').show(); + $('.clas-taxonomy-name').html(taxonomyName).show(); + }; + + return { + set: set, + resetTax: resetTax + }; + })(); + + //Changes right hand side to corresponding post and changes the URL + var ajaxPost = function( list, attr ) { + if (baseURL+'/' == window.location.href){ + paginateNews(); + } + list.click(function(event){ + event.preventDefault(); + var postID = $(this).attr(attr); + var data = { + action: 'clas_post_content', + postID: postID + }; + $.post( + clas_object.ajaxurl, data, function(response){ + var title = response.title; + var slug = response.slug; + var id = response.id; + updateContent( response ); + manualStateChange = false; + History.pushState(response, title, "?post="+slug+"-"+id); + }, "json" + ); + return false; + }); + + } + var decodeHTML = function(html){ + var txt = document.createElement("textarea"); + txt.innerHTML = html; + return txt.value; + }; + //Used for replacing list under "News Stories" + var replaceList = function( response ){ + var array = $.map(response, function(val, key){ + return { post: key, link:val.link, title: val.title, postID: val.postID }; + }); + $('.news-archive-list').empty(); + $(array).each(function(index){ + var postLink = this.link; + var title = decodeHTML(this.title); + var postID = this.postID.ID; + $('.news-archive-list').append( + $('
  • ', { + html: $('', { + title: postID, + href: postLink, + text: title + }) + }) + ); + }); + ajaxPost( $('.news-archive-list li a'), 'title' ); + paginateNews(); + } + + //For getting to post via URL + var baseURL = clas_object.siteurl+'/news-archive'; //base URL + + + if( State.url.indexOf('?post=') !== -1 ){ //Check if URL points to a post + var postURL = baseURL+'/?post='; + var postTitle = State.url.substring( baseURL.length ); + var i = postTitle.lastIndexOf('-'); + var postID = postTitle.substring(i + 1); + ajaxPost( $('.news-archive-list li a'), 'title' ); + var data = { + action: 'clas_post_content', + postID: postID + }; + $.post( + clas_object.ajaxurl, data, function(response){ + var title = response.title; + var slug = response.slug; + var id = response.id; + updateContent( response ); + manualStateChange = false; + History.pushState(response, title, "?post="+slug+"-"+id); + paginateNews(); + }, "json" + ); + } else if( State.url.indexOf('?division=') !== -1 ){ //Check if URL points to a division + var divURL = baseURL+'/?division='; + var divTitle = State.url.substring( divURL.length ); + var data = { action: 'clas_tag_posts', val: divTitle }; + $.post( + clas_object.ajaxurl, data, function(response){ + replaceList( response ); + manualStateChange = false; + var divTitleCap = divTitle.charAt(0).toUpperCase() + divTitle.slice(1); + divTitleCap = divTitleCap.replace(/-/g, ' ').replace(/and/i,'&'); + currentTaxonomy.set("Division", divTitleCap); + History.pushState(response, divTitleCap, "?division="+divTitle); + var postID = $('ul.news-archive-list li a').first().attr('title'); + var data = { + action: 'clas_post_content', + postID: postID + }; + $.post( + clas_object.ajaxurl, data, function(response){ + updateContent(response); + }, "json" + ); + }, "json" + ); + } else if( State.url.indexOf('?category=') !== -1 || State.url.indexOf('?tag=') !== -1 ){ //update content and update list + if( State.url.indexOf('?category=') !== -1 ){ + var taxonomy = 'category'; + } else { + var taxonomy = 'tag'; + } + var URL = baseURL+'/?'+taxonomy; + var value = State.url.substring( URL.length+1 ); + var data = { action: 'clas_cat_posts', data: {value: value, taxonomy: taxonomy} }; + $.post( + clas_object.ajaxurl, data, function(response){ + replaceList( response ); + manualStateChange = false; + if( taxonomy == 'category' ){ + var url = "?category="+value; + } else { + var url = "?tag="+value; + } + var taxCap = response[0].taxName.charAt(0).toUpperCase() + response[0].taxName.slice(1); + var tax = taxonomy.charAt(0).toUpperCase() + taxonomy.slice(1); + currentTaxonomy.set(tax, taxCap); + History.pushState(response, taxCap, url); + var postID = $('ul.news-archive-list li a').first().attr('title'); + var data = { + action: 'clas_post_content', + postID: postID + }; + $.post( + clas_object.ajaxurl, data, function(response){ + updateContent(response); + }, "json" + ); + }, "json" + ); + } + + //Sorting News Stories list by date, uses existing posts under News Stories + if( $('div.date-sort-button').length > 0 ){ + $('div.date-sort-button a').click(function(event){ + event.preventDefault(); + var postIDs = []; + $('.news-archive-list li a').each(function(index){ + var postID = $(this).attr('title'); + postIDs.push(postID); + }); + var data = { + action: 'clas_orderby_posts', + info: {order: $(this).attr('class'), posts: postIDs} + }; + $.post( + clas_object.ajaxurl, data, function(response){ + replaceList( response ); + }, "json" + ); + paginateNews(); + return false; + }); + } + + //Used for the category/tag dropdowns + var postSort = function(){ + var taxonomy = $(this); + if( taxonomy.attr('id') == 'news-sort-cat' ){ + var tax = 'category'; + $('select.tag').find("option:eq(0)").prop("selected", true); + } else if( taxonomy.attr('id') == 'news-sort-tag' ) { + var tax = 'tag'; + $('select.category').find("option:eq(0)").prop("selected", true); + } + var taxName = taxonomy.find(":selected").text(); + var data = { + action: 'clas_cat_posts', + data: {value: taxonomy.val(), taxonomy: tax} + }; + $.post( + clas_object.ajaxurl, data, function(response){ + replaceList( response ); //response is all the posts from the taxonomy + manualStateChange = false; + var taxCap = taxName.charAt(0).toUpperCase() + taxName.slice(1); + var taxType = tax.charAt(0).toUpperCase() + tax.slice(1); + currentTaxonomy.set(taxType, taxCap); + if( tax == 'category' ){ + var url = "?category="+taxonomy.val(); + } else if( tax == 'tag' ){ + var url = "?tag="+taxonomy.val(); + } + History.pushState(response, taxCap, url); //valueCap = tax capitalized + var postID = $('ul.news-archive-list li a').first().attr('title'); + var data = { + action: 'clas_post_content', + postID: postID + }; + $.post( + clas_object.ajaxurl, data, function(response){ + updateContent(response); + }, "json" + ); + }, "json" + ); + return false; + } + $('select.category').change( postSort ); + $('select.tag').change( postSort ); + + //Used for Sort by Division + if( $('.news-tags').length > 0 ){ + var tags = $('.news-tags a'); + tags.click(function(event){ + event.preventDefault(); + var divisionName = $(this).text(); + if( divisionName == 'All Divisions' ){ + window.location.href = baseURL; // baseURL = clas_object.siteurl+'/news-archive' + } else { + var tag = $(this).attr('class'); + var data = { + action: 'clas_tag_posts', + val: tag + }; + $.post( + clas_object.ajaxurl, data, function(response){ + replaceList( response ); + manualStateChange = false; + var tagCap = tag.charAt(0).toUpperCase() + tag.slice(1) + currentTaxonomy.set('Division', divisionName); + History.pushState(response, divisionName, "?division="+tag); + var postID = $('ul.news-archive-list li a').first().attr('title'); + var data = { + action: 'clas_post_content', + postID: postID + }; + $.post( + clas_object.ajaxurl, data, function(response){ + updateContent(response); + }, "json" + ); + }, "json" + ); + return false; + } + paginateNews(); + }); + } + + $('#news-archive-search').keypress(function(event){ + if( this.value && event.keyCode == 13 ){ //If search field isn't empty & "Enter" was pressed, complete the search + currentTaxonomy.resetTax(); + var data = { + action: 'clas_search_archive', + search: this.value + }; + $.post( + clas_object.ajaxurl, data, function(response){ + if( !$.isEmptyObject(response) ){ + replaceList( response ); + var postID = $('ul.news-archive-list li a').first().attr('title'); + var data = { + action: 'clas_post_content', + postID: postID + }; + $.post( + clas_object.ajaxurl, data, function(response){ + updateContent(response); + }, "json" + ); + } else { + $('#news-pagination').hide(); + $('ul.news-archive-list').empty().append('
  • No results found
  • '); + updateContent({ + title: 'No results found', + content: '', + link: '#', + postdate: '', + image: '' + }); + }//endif + }, "json" + ); + return false; + }//endif + }); + + //Used getting post content on right hand side + ajaxPost( $('.news-archive-list li a'), 'title' ); + + }//end if( $('.news-archive-list').length > 0 ) + + //Fix the nav gradient rendering problem in Chrome + $('#uc-nav-mobile').click(function(){ + var className = 'uc-titlebar-gradient'; + $('#uc-titlebar').removeClass('uc-titlebar-gradient'); + var checkHeight = function(height){ + setTimeout(function(){ + var newHeight = $('.nav-collapse').css('height'); + if(newHeight == height){ + $('#uc-titlebar').addClass('uc-titlebar-gradient'); + return; + } + else{ + checkHeight(newHeight); + } + },10); + } + checkHeight(-1); + }); + + var cssua=function(i,l){var m=/\s*([\-\w ]+)[\s\/]([\d_]+\b(?:[\-\._\/]\w+)*)/,n=/([\w\-\.]+[\s\/][v]?[\d_]+\b(?:[\-\._\/]\w+)*)/g,o=/rv[:](\d+(?:\.\w+)*).*?\bgecko[\/]\w+/,p=/\b(?:(blackberry\w*|bb10)|(rim tablet os))(?:\/(\d+\.\d+(?:\.\w+)*))?/,q=/\bsilk-accelerated=true\b/,r=/\bfluidapp\b/,s=/(\bwindows\b|\bmacintosh\b|\blinux\b|\bunix\b)/,t=/(\bandroid\b|\bipad\b|\bipod\b|\bwindows phone\b|\bwpdesktop\b|\bxblwp7\b|\bzunewp7\b|\bwindows ce\b|\bblackberry\w*|\bbb10\b|\brim tablet os\b|\bmeego|\bwebos\b|\bpalm|\bsymbian|\bj2me\b|\bdocomo\b|\bpda\b|\bchtml\b|\bmidp\b|\bcldc\b|\w*?mobile\w*?|\w*?phone\w*?)/, +u=/(\bxbox\b|\bplaystation\b|\bnintendo\s+\w+)/,d={parse:function(c){var a={},c=(""+c).toLowerCase();if(!c)return a;for(var b,g,e=c.split(/[()]/),f=0,d=e.length;f+a.ie?"7.0":10>+a.ie?"7.5":"8.0",delete a.windows_nt}else if(o.exec(c))a.gecko=RegExp.$1;a.version&&delete a.version;return a}, +format:function(c){var a="",b;for(b in c)if(b&&c.hasOwnProperty(b)){var g=b,e=c[b],g=g.split(".").join("-"),f=" ua-"+g;if("string"===typeof e){for(var e=e.split(" ").join("_").split(".").join("-"),d=e.indexOf("-");0'+title+''); - $('.clas-post-date').html('').append(object.postdate); - $('.clas-entry-thumbnail').html('').append(object.image); - } - - var manualStateChange = true; //Tracks if back button was used - - //Manages history & sending to corresponding post based on URL - if( $('.news-archive-list').length > 0 ){ - - var currentTaxonomy = (function () { - var resetTax = function(){ - $('.clas-taxonomy-type, .clas-taxonomy-name').html(''); - } - - var set = function(taxonomy, taxonomyName){ - $('.clas-taxonomy-type').html(taxonomy+': ').show(); - $('.clas-taxonomy-name').html(taxonomyName).show(); - }; - - return { - set: set, - resetTax: resetTax - }; - })(); - - var History = window.History; + + if( $('.news-archive-list').length > 0 ){ + paginateNews(); + + var state = History.getState(); + History.options.initialTitle = 'News Archive'; History.options.disableSuid = true; - var State = History.getState(); - var image = $('.clas-entry-thumbnail').html(); - var title = $('.clas-entry-title a').html(); - var date = $('.clas-post-date').html(); - var content = $('.clas-entry-content').html(); - History.pushState( {image: image, title: title, date: date, content: content}, title, State.url ); - - History.Adapter.bind(window,'statechange',function(){ - if(manualStateChange == true){ - State2 = History.getState(); - var obj = State2.data; - obj.link = State2.url; - obj.postdate = obj.date; - updateContent(obj); + + String.prototype.capitalize = function() { + return this.charAt(0).toUpperCase() + this.slice(1); + }; + + function retrievePreviousIDs(startingElement){ + var postsArray = []; + var currentPost = startingElement; + postsArray.push( currentPost.data("id") ); + for( var i=0; i < 9; i++ ){ + var next = currentPost.prev(); + if( currentPost.data("id") == next.data("id") ){ + break; + } + postsArray.push( next.data("id") ); + currentPost = next; } - manualStateChange = true; - }); - - //Changes right hand side to corresponding post and changes the URL - var ajaxPost = function( list, attr ) { - if (baseURL+'/' == window.location.href){ - paginateNews(); - } - list.click(function(event){ - event.preventDefault(); - var postID = $(this).attr(attr); - var data = { - action: 'clas_post_content', - postID: postID - }; - $.post( - clas_object.ajaxurl, data, function(response){ - var title = response.title; - var slug = response.slug; - var id = response.id; - updateContent( response ); - manualStateChange = false; - History.pushState(response, title, "?post="+slug+"-"+id); - }, "json" - ); - return false; - }); - + return postsArray.reverse(); } - var decodeHTML = function(html){ - var txt = document.createElement("textarea"); - txt.innerHTML = html; - return txt.value; - }; - //Used for replacing list under "News Stories" - var replaceList = function( response ){ - var array = $.map(response, function(val, key){ - return { post: key, link:val.link, title: val.title, postID: val.postID }; - }); - $('.news-archive-list').empty(); - $(array).each(function(index){ - var postLink = this.link; - var title = decodeHTML(this.title); - var postID = this.postID.ID; - $('.news-archive-list').append( - $('
  • ', { - html: $('', { - title: postID, - href: postLink, - text: title - }) - }) - ); + + function retrievePostIDs(startingElement){ + var postsArray = []; + var currentPost = startingElement; + postsArray.push( currentPost.data("id") ); + for( var i=0; i < 9; i++ ){ + var next = currentPost.next(); + if( currentPost.data("id") == next.data("id") ){ + break; + } + postsArray.push( next.data("id") ); + currentPost = next; + } + return postsArray; + } + + function renderPosts(postsArray, taxonomyType, taxonomyName){ + $.ajax({ + type: "POST", + url: clas_object.ajaxurl, + data: { + action: 'clas_posts', + postIDs: postsArray + }, + success: function(response){ + var responseLength = Object.keys(response).length - 1; + $(".span8.follow-hero").html(" "); + var firstID = response[0].id; + var lastID = response[responseLength].id; + if( taxonomyName != undefined && taxonomyType != undefined ){ + var spanTaxType = $('',{ + 'class': 'clas-taxonomy-type', + 'text': taxonomyType + }); + + var spanTaxName = $('',{ + 'class': 'clas-taxonomy-name', + 'text': taxonomyName + }); + $(".span8.follow-hero").append(spanTaxType).append(spanTaxName); + } + for(var post in response){ + var current = response[post]; + var id = current.id; + var title = current.title; + var slug = current.slug; + var link = current.link; + var excerpt = current.excerpt; + var date = current.date; + var image = current.featuredImage; + + if( current.date != false ){ + var article = $('
    ',{ + 'data-id': id, + }); + + var header = $('
    ',{ + 'class': 'entry-header' + }).appendTo(article); + + var h3 = $('

    ',{ + 'class': 'clas-entry-title' + }).appendTo(header); + + var divDate = $('
    ',{ + 'class': 'clas-post-date', + 'html': date + }).appendTo(header); + + if( image.length > 0 ) { + var divImage = $('
    ',{ + 'class': 'archive-thumbnail' + }).append(image); + header.append(divImage); + } + + var aTag = $('',{ + 'href': link, + 'text': title, + 'data-id': id + }).appendTo(h3); + + var divContent = $('
    ',{ + 'class': 'clas-entry-content' + }).appendTo(article); + + if( excerpt.length > 7 ){ // by default excerpt comes with

    , whose lenght is 7 + var readMore = '

    Read More

    '; + excerpt += readMore; + divContent.html(excerpt); + } + + $(".span8.follow-hero").append(article); + } + } + var span = $('
    ',{ + 'class': 'story-navigation', + }).appendTo( $(".span8.follow-hero") ); + $('',{ + 'id': 'newerStories', + 'data-id': firstID, + 'text': 'Newer Stories' + }).appendTo(span); + $('',{ + 'id': 'olderStories', + 'data-id': lastID, + 'text': 'Older Stories' + }).appendTo(span); + storyNavCheck(); + }, + dataType: "json" }); - ajaxPost( $('.news-archive-list li a'), 'title' ); - paginateNews(); } - - //For getting to post via URL - var baseURL = clas_object.siteurl+'/news-archive'; //base URL - - if( State.url.indexOf('?post=') !== -1 ){ //Check if URL points to a post - var postURL = baseURL+'/?post='; - var postTitle = State.url.substring( baseURL.length ); - var i = postTitle.lastIndexOf('-'); - var postID = postTitle.substring(i + 1); - ajaxPost( $('.news-archive-list li a'), 'title' ); - var data = { - action: 'clas_post_content', - postID: postID - }; - $.post( - clas_object.ajaxurl, data, function(response){ - var title = response.title; - var slug = response.slug; - var id = response.id; - updateContent( response ); - manualStateChange = false; - History.pushState(response, title, "?post="+slug+"-"+id); - paginateNews(); - }, "json" - ); - } else if( State.url.indexOf('?division=') !== -1 ){ //Check if URL points to a division - var divURL = baseURL+'/?division='; - var divTitle = State.url.substring( divURL.length ); - var data = { action: 'clas_tag_posts', val: divTitle }; - $.post( - clas_object.ajaxurl, data, function(response){ - replaceList( response ); - manualStateChange = false; - var divTitleCap = divTitle.charAt(0).toUpperCase() + divTitle.slice(1); - divTitleCap = divTitleCap.replace(/-/g, ' ').replace(/and/i,'&'); - currentTaxonomy.set("Division", divTitleCap); - History.pushState(response, divTitleCap, "?division="+divTitle); - var postID = $('ul.news-archive-list li a').first().attr('title'); - var data = { - action: 'clas_post_content', - postID: postID - }; - $.post( - clas_object.ajaxurl, data, function(response){ - updateContent(response); - }, "json" - ); - }, "json" - ); - } else if( State.url.indexOf('?category=') !== -1 || State.url.indexOf('?tag=') !== -1 ){ //update content and update list - if( State.url.indexOf('?category=') !== -1 ){ - var taxonomy = 'category'; - } else { - var taxonomy = 'tag'; + function renderStoriesList(postObj, taxonomyType, taxonomyName){ + $(".news-archive-list").empty(); + var postIDs = []; + var i = 0; + for( var post in postObj ){ + var current = postObj[post]; + var id = current.id; + var slug = current.slug; + var link = current.link; + var title = current.title; + + if( i < 10 ){ + postIDs.push(id); + } + + var li = $('
  • ',{ + 'data-id': id, + 'data-slug': slug + }).appendTo($(".news-archive-list")); + + $('',{ + 'href': link, + 'text': title + }).appendTo(li); + i++; } - var URL = baseURL+'/?'+taxonomy; - var value = State.url.substring( URL.length+1 ); - var data = { action: 'clas_cat_posts', data: {value: value, taxonomy: taxonomy} }; - $.post( - clas_object.ajaxurl, data, function(response){ - replaceList( response ); - manualStateChange = false; - if( taxonomy == 'category' ){ - var url = "?category="+value; - } else { - var url = "?tag="+value; - } - var taxCap = response[0].taxName.charAt(0).toUpperCase() + response[0].taxName.slice(1); - var tax = taxonomy.charAt(0).toUpperCase() + taxonomy.slice(1); - currentTaxonomy.set(tax, taxCap); - History.pushState(response, taxCap, url); - var postID = $('ul.news-archive-list li a').first().attr('title'); - var data = { - action: 'clas_post_content', - postID: postID - }; - $.post( - clas_object.ajaxurl, data, function(response){ - updateContent(response); - }, "json" - ); - }, "json" - ); + renderPosts(postIDs, taxonomyType, taxonomyName); + paginateNews(); + + return postIDs; } - - //Sorting News Stories list by date, uses existing posts under News Stories - if( $('div.date-sort-button').length > 0 ){ - $('div.date-sort-button a').click(function(event){ - event.preventDefault(); - var postIDs = []; - $('.news-archive-list li a').each(function(index){ - var postID = $(this).attr('title'); - postIDs.push(postID); + + History.Adapter.onDomLoad(function(){ + var index; + if( (index = state.url.indexOf('?post/')) !== -1 ){ + var urlQuery = state.url.substring(index); + var postSlug = urlQuery.substring(6); // length of "?post/" is 6 + var postInList = $("ul.news-archive-list").find("[data-slug='" + postSlug + "']"); + + var postIDs = retrievePostIDs(postInList); + renderPosts(postIDs); + } else if( (index = state.url.indexOf('?division') !== -1 ) ){ + var urlQuery = state.url.substring(state.url.indexOf('?division')); + var divisionSlug = urlQuery.substring(10); //length of "?divison/" is 10 + + var divisionTitle = divisionSlug.toLowerCase().replace(/(-)/g, ' ').replace(/\b[a-z]/g, function(letter) { + return letter.toUpperCase(); }); - var data = { - action: 'clas_orderby_posts', - info: {order: $(this).attr('class'), posts: postIDs} - }; - $.post( - clas_object.ajaxurl, data, function(response){ - replaceList( response ); - }, "json" - ); - paginateNews(); + + $.ajax({ + type: "POST", + url: clas_object.ajaxurl, + data: { + action: 'clas_tag_posts', + tag: divisionSlug + }, + success: function(response){ + renderStoriesList(response, 'Division', divisionTitle); + }, + dataType: "json" + }); + } else if( (index = state.url.indexOf('?category/')) !== -1 || (index = state.url.indexOf('?tag/')) !== -1 ) { + var urlQuery = state.url.substring(index+1); + var taxonomyType = urlQuery.substring(0,urlQuery.indexOf('/')); + var taxonomyName = urlQuery.substring(urlQuery.indexOf('/')+1); + + var taxonomyTypeCapitalized = taxonomyType.toLowerCase().replace(/(-)/g, ' ').replace(/\b[a-z]/g, function(letter) { + return letter.toUpperCase(); + }); + var taxonomyNameCapitalized = taxonomyName.capitalize(); + $.ajax({ + type: "POST", + url: clas_object.ajaxurl, + data: { + action: 'clas_taxid', + taxonomyType: taxonomyType, + taxonomyName: taxonomyName + }, + success: function(response){ + var taxonomyID = response; + $.ajax({ + type: "POST", + url: clas_object.ajaxurl, + data: { + action: 'clas_cat_posts', + taxonomy: taxonomyType, + value: taxonomyID + }, + success: function(response){ + renderStoriesList(response, taxonomyTypeCapitalized, taxonomyNameCapitalized); + }, + dataType: "json" + }); + }, + dataType: "json" + }); + } + }); + + History.Adapter.bind(window, 'statechange', function(){ + var state = History.getState(); + if( state.url == clas_object.siteurl+'/news-archive/' ){ + window.location.href = clas_object.siteurl+'/news-archive'; return false; - }); - } - - //Used for the category/tag dropdowns - var postSort = function(){ - var taxonomy = $(this); - if( taxonomy.attr('id') == 'news-sort-cat' ){ - var tax = 'category'; - $('select.tag').find("option:eq(0)").prop("selected", true); - } else if( taxonomy.attr('id') == 'news-sort-tag' ) { - var tax = 'tag'; - $('select.category').find("option:eq(0)").prop("selected", true); - } - var taxName = taxonomy.find(":selected").text(); - var data = { - action: 'clas_cat_posts', - data: {value: taxonomy.val(), taxonomy: tax} - }; - $.post( - clas_object.ajaxurl, data, function(response){ - replaceList( response ); //response is all the posts from the taxonomy - manualStateChange = false; - var taxCap = taxName.charAt(0).toUpperCase() + taxName.slice(1); - var taxType = tax.charAt(0).toUpperCase() + tax.slice(1); - currentTaxonomy.set(taxType, taxCap); - if( tax == 'category' ){ - var url = "?category="+taxonomy.val(); - } else if( tax == 'tag' ){ - var url = "?tag="+taxonomy.val(); - } - History.pushState(response, taxCap, url); //valueCap = tax capitalized - var postID = $('ul.news-archive-list li a').first().attr('title'); - var data = { - action: 'clas_post_content', - postID: postID - }; - $.post( - clas_object.ajaxurl, data, function(response){ - updateContent(response); - }, "json" - ); - }, "json" - ); + } + }); + + $(document.body).on('click', 'ul.news-archive-list li', function(event){ + event.preventDefault(); + + var postIDs = retrievePostIDs( $(this) ); + renderPosts(postIDs); + + var postTitle = $(this).data('slug'); + var postLink = this.children[0].href; + + History.pushState(postIDs, postTitle, "?post/"+postTitle); + }); + + $('div.news-tags a').click(function(event){ + event.preventDefault(); + if( this.className == "all-divisions" ){ + window.location.href = clas_object.siteurl+'/news-archive'; return false; - } - $('select.category').change( postSort ); - $('select.tag').change( postSort ); - - //Used for Sort by Division - if( $('.news-tags').length > 0 ){ - var tags = $('.news-tags a'); - tags.click(function(event){ - event.preventDefault(); - var divisionName = $(this).text(); - if( divisionName == 'All Divisions' ){ - window.location.href = baseURL; // baseURL = clas_object.siteurl+'/news-archive' - } else { - var tag = $(this).attr('class'); - var data = { - action: 'clas_tag_posts', - val: tag - }; - $.post( - clas_object.ajaxurl, data, function(response){ - replaceList( response ); - manualStateChange = false; - var tagCap = tag.charAt(0).toUpperCase() + tag.slice(1) - currentTaxonomy.set('Division', divisionName); - History.pushState(response, divisionName, "?division="+tag); - var postID = $('ul.news-archive-list li a').first().attr('title'); - var data = { - action: 'clas_post_content', - postID: postID - }; - $.post( - clas_object.ajaxurl, data, function(response){ - updateContent(response); - }, "json" - ); - }, "json" - ); - return false; - } - paginateNews(); + } + var tagTitle = this.text; + var tag = this.className; + $.ajax({ + type: "POST", + url: clas_object.ajaxurl, + data: { + action: 'clas_tag_posts', + tag: tag + }, + success: function(response){ + renderStoriesList(response, 'Division', tagTitle); + }, + dataType: "json" }); - } - - $('#news-archive-search').keypress(function(event){ + History.pushState({}, tagTitle, '?division/'+tag); + }); + + $('select.category,select.tag').change(function(event){ + var taxonomyID = $(this).val(); + var taxonomy; + if( this.id == 'news-sort-cat' ){ + taxonomy = 'category'; + $('select.tag').find("option:eq(0)").prop("selected", true); + } else { + taxonomy = 'tag'; + $('select.category').find("option:eq(0)").prop("selected", true); + } + taxonomyName = this.options[this.selectedIndex].text; + var taxonomyTitle = taxonomyName.toLowerCase().replace(/\b[a-z]/g, function(letter) { + return letter.toUpperCase(); + }); + + var taxonomySlug = taxonomyName.toLowerCase().replace(/(\s)/g, '-'); + taxonomyCapitalized = taxonomy.capitalize(); + $.ajax({ + type: "POST", + url: clas_object.ajaxurl, + data: { + action: 'clas_cat_posts', + taxonomy: taxonomy, + value: taxonomyID + }, + success: function(response){ + renderStoriesList(response, taxonomyCapitalized, taxonomyTitle); + }, + dataType: "json" + }); + History.pushState({}, taxonomyTitle, "?"+taxonomy+"/"+taxonomySlug); + }); + + $('div.date-sort-button a').click(function(event){ + event.preventDefault(); + var postIDs = []; + $('.news-archive-list li').each(function(index){ + var postID = $(this).data('id'); + postIDs.push(postID); + }); + $.ajax({ + type: "POST", + url: clas_object.ajaxurl, + data: { + action: 'clas_orderby_posts', + info: {order: $(this).attr('class'), posts: postIDs} + }, + success: function(response){ + renderStoriesList(response); + }, + dataType: "json" + }); + }); + + $('#news-archive-search').keypress(function(event){ if( this.value && event.keyCode == 13 ){ //If search field isn't empty & "Enter" was pressed, complete the search - currentTaxonomy.resetTax(); - var data = { - action: 'clas_search_archive', - search: this.value - }; - $.post( - clas_object.ajaxurl, data, function(response){ - if( !$.isEmptyObject(response) ){ - replaceList( response ); - var postID = $('ul.news-archive-list li a').first().attr('title'); - var data = { - action: 'clas_post_content', - postID: postID - }; - $.post( - clas_object.ajaxurl, data, function(response){ - updateContent(response); - }, "json" - ); - } else { - $('#news-pagination').hide(); - $('ul.news-archive-list').empty().append('
  • No results found
  • '); - updateContent({ - title: 'No results found', - content: '', - link: '#', - postdate: '', - image: '' - }); - }//endif - }, "json" - ); - return false; - }//endif + $.ajax({ + type: "POST", + url: clas_object.ajaxurl, + data: { + action: 'clas_search_archive', + search: this.value + }, + success: function(response){ + renderStoriesList(response); + }, + dataType: "json" + }); + return false; + }//endif }); - - //Used getting post content on right hand side - ajaxPost( $('.news-archive-list li a'), 'title' ); - - }//end if( $('.news-archive-list').length > 0 ){ - + + function storyNavCheck(){ + var firstInList = $("ul.news-archive-list").children().first().data('id'); + var firstPost = $(".span8.follow-hero").children('article').first().data('id'); + + if( firstInList == firstPost ){ + $('a#newerStories').hide(); + } else { + $('a#newerStories').show(); + } + + var lastInList = $("ul.news-archive-list").children().last().data('id'); + var tenthPost = $(".span8.follow-hero").children('article').last().data('id'); + + if( lastInList == tenthPost ){ + $('a#olderStories').hide(); + } else { + $('a#olderStories').show(); + } + } + storyNavCheck(); + + $(document.body).on('click', 'div.story-navigation a', function(event){ + event.preventDefault(); + var element = $("ul.news-archive-list").find( "[data-id='" + $(this).data('id') + "']" ); + + var startingElement; + var postsArray; + if( this.id == 'olderStories' ){ + startingElement = element.next(); + postsArray = retrievePostIDs(startingElement); + $('#news-next').trigger('click'); + } else if( this.id == 'newerStories' ){ + startingElement = element.prev(); + postsArray = retrievePreviousIDs(startingElement); + $('#news-back').trigger('click'); + } + if( postsArray != null ){ + renderPosts( postsArray ); + } + }); + + }//end if( $('.news-archive-list').length > 0 ) + //Fix the nav gradient rendering problem in Chrome $('#uc-nav-mobile').click(function(){ var className = 'uc-titlebar-gradient'; @@ -456,5 +513,4 @@ a.version:{419:"2.0.4",417:"2.0.3",416:"2.0.2",412:"2.0",312:"1.3",125:"1.2",85: format:function(c){var a="",b;for(b in c)if(b&&c.hasOwnProperty(b)){var g=b,e=c[b],g=g.split(".").join("-"),f=" ua-"+g;if("string"===typeof e){for(var e=e.split(" ").join("_").split(".").join("-"),d=e.indexOf("-");0
    -
    +
    1, 'orderby' => 'post-date', 'category_name' => 'archive'); + $args = array( 'numberposts'=> 10, 'orderby' => 'post-date', 'category_name' => 'archive'); $latestpost = get_posts( $args ); + + ?> +