This repository has been archived by the owner. It is now read-only.
Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
clas/js/custom-old.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
446 lines (421 sloc)
16 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>') | |
li.addClass('page-link-item') | |
var a = $('<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('<a href="'+object.link+'">'+title+'</a>'); | |
$('.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( | |
$('<li/>', { | |
html: $('<a/>', { | |
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('<li>No results found</li>'); | |
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<d;f++)if(f%2){var j=e[f].split(";");for(b=0,g=j.length;b<g;b++)if(m.exec(j[b])){var h=RegExp.$1.split(" ").join("_"),i=RegExp.$2;if(!a[h]||parseFloat(a[h])<parseFloat(i))a[h]=i}}else if(j=e[f].match(n))for(b=0,g=j.length;b<g;b++)h=j[b].split(/[\/\s]+/),h.length&&"mozilla"!==h[0]&&(a[h[0].split(" ").join("_")]=h.slice(1).join("-"));if(t.exec(c)){if(a.mobile= | |
RegExp.$1,p.exec(c))if(delete a[a.mobile],a.blackberry=a.version||RegExp.$3||RegExp.$2||RegExp.$1,RegExp.$1)a.mobile="blackberry";else if("0.0.1"===a.version)a.blackberry="7.1.0.0"}else if(s.exec(c))a.desktop=RegExp.$1;else if(u.exec(c)&&(a.game=RegExp.$1,b=a.game.split(" ").join("_"),a.version&&!a[b]))a[b]=a.version;if(a.intel_mac_os_x)a.mac_os_x=a.intel_mac_os_x.split("_").join("."),delete a.intel_mac_os_x;else if(a.cpu_iphone_os)a.ios=a.cpu_iphone_os.split("_").join("."),delete a.cpu_iphone_os; | |
else if(a.cpu_os)a.ios=a.cpu_os.split("_").join("."),delete a.cpu_os;else if("iphone"===a.mobile&&!a.ios)a.ios="1";if(a.opera&&a.version)a.opera=a.version,delete a.blackberry;else if(q.exec(c))a.silk_accelerated=!0;else if(r.exec(c))a.fluidapp=a.version;if(a.applewebkit){a.webkit=a.applewebkit;delete a.applewebkit;if(a.opr)a.opera=a.opr,delete a.opr,delete a.chrome;if(a.safari)a.chrome||a.crios||a.opera||a.silk||a.fluidapp||a.phantomjs||a.mobile&&!a.ios?delete a.safari:a.safari=a.version&&!a.rim_tablet_os? | |
a.version:{419:"2.0.4",417:"2.0.3",416:"2.0.2",412:"2.0",312:"1.3",125:"1.2",85:"1.0"}[parseInt(a.safari,10)]||a.safari}else if(a.msie){if(!a.opera)a.ie=a.msie;delete a.msie;if(a.windows_phone_os)a.windows_phone=a.windows_phone_os,delete a.windows_phone_os;else if("wpdesktop"===a.mobile||"xblwp7"===a.mobile||"zunewp7"===a.mobile)a.mobile="windows desktop",a.windows_phone=9>+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<d;)f+=" ua-"+g+"-"+e.substring(0,d),d=e.indexOf("-",d+1);f+=" ua-"+g+"-"+e}a+=f}return a},encode:function(c){var a="",b;for(b in c)b&&c.hasOwnProperty(b)&&(a&&(a+="&"),a+=encodeURIComponent(b)+"="+encodeURIComponent(c[b]));return a}};d.userAgent=d.ua=d.parse(l);var k=d.format(d.ua)+" js"; | |
i.className=i.className?i.className.replace(/\bno-js\b/g,"")+k:k.substr(1);return d}(document.documentElement,navigator.userAgent); | |
}); |