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-deans.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
319 lines (298 sloc)
12.1 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($) { | |
var site = clas_object.siteurl+'/deans-blog/'; | |
var sitelen = site.length; | |
var doc = document.URL; | |
if( doc.substr(0,sitelen) == site ){ | |
// News Stories Pagination | |
function paginateNews(){ | |
$('#dean-posts').css('visibility', 'hidden') | |
// change the perPage variable to the number of items you want per page. | |
var perPage = 15 | |
var stories = $('.deans-blog-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() | |
$('.deans-blog-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() | |
} | |
$('#dean-posts').css('visibility', 'visible') | |
} | |
if( $('.deans-blog-list').length > 0 ){ | |
var ajaxPost = function( list, attr ) { | |
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 content = response.content; | |
var title = response.title; | |
var slug = response.slug; | |
var date = response.date; | |
var image = response.image; | |
var id = response.id; | |
$('.clas-entry-content').html('').append(content); | |
$('.clas-entry-title').html('').append(title); | |
$('.clas-post-date').html('').append(date); | |
$('.clas-entry-thumbnail').html('').append(image); | |
History.pushState(response, title, baseURL+'#'+slug+'-'+id); | |
}, "json" | |
); | |
return false; | |
}); | |
} | |
var History = window.History; | |
History.options.disableSuid = true; | |
if( History.enabled ){ | |
State = History.getState(); | |
var image = $('.clas-entry-thumbnail').html(); | |
var title = $('.clas-entry-title').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 ); | |
var baseURL = clas_object.siteurl+'/deans-blog/'; | |
var postTitle = State.url.substring( baseURL.length ); | |
if( State.url.length > baseURL.length ){ | |
var i = postTitle.lastIndexOf('-'); | |
var postID = postTitle.substring(i + 1); | |
ajaxPost( $('.deans-blog-list li a'), 'title' ); | |
var data = { | |
action: 'clas_post_content', | |
postID: postID | |
}; | |
$.post( | |
clas_object.ajaxurl, data, function(response){ | |
var content = response.content; | |
var title = response.title; | |
var slug = response.slug; | |
var date = response.date; | |
var image = response.image; | |
var id = response.id; | |
$('.clas-entry-content').html('').append(content); | |
$('.clas-entry-title').html('').append(title); | |
$('.clas-post-date').html('').append(date); | |
$('.clas-entry-thumbnail').html('').append(image); | |
History.pushState(response, title, baseURL+'#'+slug+'-'+id); | |
}, "json" | |
); | |
return false; | |
} | |
History.Adapter.bind(window, 'statechange', function(){ | |
State2 = History.getState(); | |
$('.clas-entry-content').html(State2.data.content); | |
$('.clas-entry-title').html(State2.title); | |
$('.clas-post-date').html(State2.data.postdate); | |
$('.clas-entry-thumbnail').html('').append(State2.data.image); | |
}); | |
} | |
if( $('div.date-sort-button').length > 0 ){ | |
$('div.date-sort-button a').click(function(event){ | |
event.preventDefault(); | |
var data = { | |
action: 'clas_orderby_posts', | |
order: $(this).attr('class') | |
}; | |
$.post( | |
clas_object.ajaxurl, data, function(response){ | |
var array = $.map(response, function(val, key){ | |
return { post: key, link:val.link, title: val.title, postID: val.postID }; | |
}); | |
$('.deans-blog-list').empty(); | |
$(array).each(function(index){ | |
var postLink = this.link; | |
var title = this.title; | |
var postID = this.postID.ID; | |
$('.deans-blog-list').append( | |
$('<li/>', { | |
html: $('<a/>', { | |
title: postID, | |
href: postLink, | |
text: title | |
}) | |
}) | |
); | |
}); | |
ajaxPost( $('.deans-blog-list li a'), 'title' ); | |
}, "json" | |
); | |
return false; | |
}); | |
} | |
var postSort = function(){ | |
var taxonomy = $(this); | |
if( taxonomy.attr('id') == 'news-sort-cat' ){ | |
var tax = 'category'; | |
} else if( taxonomy.attr('id') == 'news-sort-tag' ) { | |
var tax = 'tag'; | |
} | |
var data = { | |
action: 'clas_cat_posts', | |
data: {value: taxonomy.val(), taxonomy: tax} | |
}; | |
$.post( | |
clas_object.ajaxurl, data, function(response){ | |
var array = $.map(response, function(val, key){ | |
return { post: key, link:val.link, title: val.title, postID: val.postID }; | |
}); | |
$('.deans-blog-list').empty(); | |
$(array).each(function(index){ | |
var postLink = this.link; | |
var title = this.title; | |
var postID = this.postID.ID; | |
$('.deans-blog-list').append( | |
$('<li/>', { | |
html: $('<a/>', { | |
title: postID, | |
href: postLink, | |
text: title | |
}) | |
}) | |
); | |
}); | |
ajaxPost( $('.deans-blog-list li a'), 'title' ); | |
}, "json" | |
); | |
return false; | |
} | |
$('select.category').change( postSort ); | |
$('select.tag').change( postSort ); | |
if( $('.news-tags').length > 0 ){ | |
var tags = $('.news-tags a'); | |
tags.click(function(event){ | |
event.preventDefault(); | |
var tag = $(this).attr('class'); | |
var data = { | |
action: 'clas_tag_posts', | |
val: tag | |
}; | |
$.post( | |
clas_object.ajaxurl, data, function(response){ | |
var array = $.map(response, function(val, key){ | |
return { post: key, link:val.link, title: val.title, postID: val.postID }; | |
}); | |
$('.deans-blog-list').empty(); | |
$(array).each(function(index){ | |
var postLink = this.link; | |
var title = this.title; | |
var postID = this.postID.ID; | |
$('.deans-blog-list').append( | |
$('<li/>', { | |
html: $('<a/>', { | |
title: postID, | |
href: postLink, | |
text: title | |
}) | |
}) | |
); | |
}); | |
ajaxPost( $('.deans-blog-list li a'), 'title' ); | |
}, "json" | |
); | |
return false; | |
}); | |
} | |
if( $('.deans-blog-list').length > 0 ){ | |
ajaxPost( $('.deans-blog-list li a'), 'title' ); | |
} | |
} | |
} | |
//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); | |
}); |