diff --git a/js/cs.js b/js/cs.js index c46a558..722afdd 100644 --- a/js/cs.js +++ b/js/cs.js @@ -1,248 +1,249 @@ -jQuery(document).ready(function($) { - - /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Link Flags - Scans all the links in the main content area, and adds icons to any links that lead to other websites, or to downloadable documents. - by Andrew Bacon - May 2014 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - var url = location.href - var urlExploded = url.split('/') - var site = urlExploded[2] - var extensions = ['3g2', '3gp', 'avi', 'doc', 'docx', 'dotx', 'gif', 'jpg', 'jpeg', 'm4a', 'mid', 'midi', 'mov', 'mp3', 'mp4', 'mpg', 'odt', 'ogg', 'ogv', 'pdf', 'png', 'ppt', 'pptx', 'xls', 'xlsx', 'wav', 'wmv', 'zip', 'vsd'] - - function scanLinks(){ - var href = $(this).attr('href').toLowerCase() - var img = $(this).children('img').length - var base = null - var last = null - var ext = null - var flag = null - - // if (((href.charAt(0) != '?') || (href.charAt(0) != '#')) && img == 0 ){ - if (href.charAt(0) != '#' && img == 0){ - if (href.charAt(0) != '/'){ - var hrefExploded = href.split('/') - base = hrefExploded[2] - - - - //console.log('checking to see if it might be a file...') - last = hrefExploded[hrefExploded.length-1] || '' - var lastExploded = last.split('.') - - if (lastExploded[1]){ - //console.log('ok, so there was a dot in the last value of the url.') - $.each(extensions, function(index, value){ - - if (value == lastExploded[1]){ - flag = $('') - //console.log('match!') - ext = lastExploded[1] - //console.log('ext:'+ext) - flag.append('.'+ext) - } - }) - } - if (flag != null){ - $(this).append(flag) - } - if (base != site && base != null) { - - //console.log('external link detected, adding icon...') - // is external, and is not a named anchor tag - var icon = '' - $(this).addClass('external').append(icon) - } - } - } - } - - // This will only scan elements in these sections of the site. - - var elementsToScan = [ - '#comments', - '#site-navigation', - 'article.page' - ] - - $.each(elementsToScan, function(index, value){ - $(value+' a').each(scanLinks) - }) - - - /* ----- - - UUP Style Help - - ----- */ - $('.uup-list .has-image').each(function(){ - //console.log('has image...'); - var text = $(this).find('.uup-text'); - var img = $(this).find('img:first'); - //console.log(text); - //console.log(img); - var textHeight = text.height(); - var imgHeight = img.outerHeight(); - //console.log(textHeight); - //console.log(imgHeight); - - if (imgHeight > textHeight){ - var diff = imgHeight - textHeight; - text.css('padding-top', diff/2); - } - }); - $('.uup-index-table .table-has-image').each(function(){ - //console.log('has image...'); - var text = $(this).find('.uup-name'); - var img = $(this).find('.uup-table-thumbnail'); - //console.log(text); - //console.log(img); - var textHeight = text.height(); - var imgHeight = img.outerHeight(); - //console.log(textHeight); - //console.log(imgHeight); - if (imgHeight > textHeight){ - //console.log('img bigger...'); - var diff = imgHeight - textHeight; - text.css('cssText', 'padding-bottom:'+ diff + 'px!important' ); - } - }); - - - - /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Nav: Neverwrap - Keeps navigation items from wrapping to a second line when there are too many. - Emulates browser tabs. - by Andrew Bacon - May 2014 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - /* - function calcNavWidth(){ - var width = 0 - $('#primary-nav > ul > li > a').each(function(){ - console.log('this width: '+$(this).outerWidth()) - width = width + $(this).outerWidth() - }) - console.log('width: '+width) - return width - } - - var containerWidth = $('#site-navigation').outerWidth(); - console.log('containerWidth: '+containerWidth) - - var navWidth = calcNavWidth(); - - if (navWidth > containerWidth) { - var links = $('#primary-nav > ul > li > a').length - console.log('links: '+links) - var width = 100/links - console.log('width: '+width) - $('#primary-nav').addClass('neverwrap') - - - $('#primary-nav > ul > li').each(function(){ - console.log('meep') - $(this).width(width+'%') - }) - - } - /**/ - /* - - Need some kind of a way to... - - when the size of each one gets too low, and is useless... - - actually rewrite the markup, and place the last few categories under a "more" item. Clicking that exposes a second nav bar. - - - */ - - - - /* - - SIMPLE ACCESSIBILITY TESTER - - by Andrew Bacon - This plugin runs simple tests on a site, and adds distinct visual styles to flawed content when they fail. - - */ - function imageWarning(e){ - var block = $('
') - block.addClass('alert alert-danger accessibility-fail-msg') - //console.log(e.width()) - block.width(e.width+'px') - - var icon = $('') - icon.addClass('glyphicon glyphicon-ban-circle') - - var msg = $('') - msg.append(' This image needs a valid Alt tag. ') - - - block.append(icon).append(msg) - $(e).after(block) - } - $('#page img').each(function(){ - alt = $(this).attr('alt') - if (alt){ - alt = alt.toLowerCase() - //console.log('alt='+alt) - if (alt.indexOf('.jpg') >= 0 || alt.indexOf('.png') >= 0 || alt.indexOf('.gif') >= 0 ){ - $(this).addClass('accessibility-fail') - imageWarning(this) - } - } else { - $(this).addClass('accessibility-fail') - imageWarning(this) - } - }) - // adds default bootstrap styles to all tables. - $('#page table').each(function(){ - $(this).addClass('table'); - }) - - /**/ - - -function stickyFoot(){ - /* Andrew's Sticky Footer JS. */ - - if (document.getElementById('page')!=null && document.getElementById('footers') !=null){ - var wrapperH = document.getElementById('page').clientHeight; - var footerH = document.getElementById('footers').clientHeight - var windowH = window.innerHeight; - if(windowH>=wrapperH){ - $('body').addClass('sticky') - } else { - $('body').removeClass('sticky') - } - } - - -} -window.onload = function (){ - placeholderSupport = ("placeholder" in document.createElement("input")); - if(placeholderSupport!=false){ - var d = $('main'); - d.addClass("supports-placeholder"); - } - stickyFoot(); -} - -window.onresize = function() { - - stickyFoot(); - -} - - +jQuery(document).ready(function($) { + + /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + Link Flags + Scans all the links in the main content area, and adds icons to any links that lead to other websites, or to downloadable documents. + by Andrew Bacon + May 2014 + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ + + var url = location.href + var urlExploded = url.split('/') + var site = urlExploded[2] + var extensions = ['3g2', '3gp', 'avi', 'doc', 'docx', 'dotx', 'gif', 'jpg', 'jpeg', 'm4a', 'mid', 'midi', 'mov', 'mp3', 'mp4', 'mpg', 'odt', 'ogg', 'ogv', 'pdf', 'png', 'ppt', 'pptx', 'xls', 'xlsx', 'wav', 'wmv', 'zip', 'vsd'] + + function scanLinks(){ + if(undefined == $(this).attr('href')) return; + var href = $(this).attr('href').toLowerCase() + var img = $(this).children('img').length + var base = null + var last = null + var ext = null + var flag = null + + // if (((href.charAt(0) != '?') || (href.charAt(0) != '#')) && img == 0 ){ + if (href.charAt(0) != '#' && img == 0){ + if (href.charAt(0) != '/'){ + var hrefExploded = href.split('/') + base = hrefExploded[2] + + + + //console.log('checking to see if it might be a file...') + last = hrefExploded[hrefExploded.length-1] || '' + var lastExploded = last.split('.') + + if (lastExploded[1]){ + //console.log('ok, so there was a dot in the last value of the url.') + $.each(extensions, function(index, value){ + + if (value == lastExploded[1]){ + flag = $('') + //console.log('match!') + ext = lastExploded[1] + //console.log('ext:'+ext) + flag.append('.'+ext) + } + }) + } + if (flag != null){ + $(this).append(flag) + } + if (base != site && base != null) { + + //console.log('external link detected, adding icon...') + // is external, and is not a named anchor tag + var icon = '' + $(this).addClass('external').append(icon) + } + } + } + } + + // This will only scan elements in these sections of the site. + + var elementsToScan = [ + '#comments', + '#site-navigation', + 'article.page' + ] + + $.each(elementsToScan, function(index, value){ + $(value+' a').each(scanLinks) + }) + + + /* ----- + + UUP Style Help + + ----- */ + $('.uup-list .has-image').each(function(){ + //console.log('has image...'); + var text = $(this).find('.uup-text'); + var img = $(this).find('img:first'); + //console.log(text); + //console.log(img); + var textHeight = text.height(); + var imgHeight = img.outerHeight(); + //console.log(textHeight); + //console.log(imgHeight); + + if (imgHeight > textHeight){ + var diff = imgHeight - textHeight; + text.css('padding-top', diff/2); + } + }); + $('.uup-index-table .table-has-image').each(function(){ + //console.log('has image...'); + var text = $(this).find('.uup-name'); + var img = $(this).find('.uup-table-thumbnail'); + //console.log(text); + //console.log(img); + var textHeight = text.height(); + var imgHeight = img.outerHeight(); + //console.log(textHeight); + //console.log(imgHeight); + if (imgHeight > textHeight){ + //console.log('img bigger...'); + var diff = imgHeight - textHeight; + text.css('cssText', 'padding-bottom:'+ diff + 'px!important' ); + } + }); + + + + /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + Nav: Neverwrap + Keeps navigation items from wrapping to a second line when there are too many. + Emulates browser tabs. + by Andrew Bacon + May 2014 + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ + /* + function calcNavWidth(){ + var width = 0 + $('#primary-nav > ul > li > a').each(function(){ + console.log('this width: '+$(this).outerWidth()) + width = width + $(this).outerWidth() + }) + console.log('width: '+width) + return width + } + + var containerWidth = $('#site-navigation').outerWidth(); + console.log('containerWidth: '+containerWidth) + + var navWidth = calcNavWidth(); + + if (navWidth > containerWidth) { + var links = $('#primary-nav > ul > li > a').length + console.log('links: '+links) + var width = 100/links + console.log('width: '+width) + $('#primary-nav').addClass('neverwrap') + + + $('#primary-nav > ul > li').each(function(){ + console.log('meep') + $(this).width(width+'%') + }) + + } + /**/ + /* + + Need some kind of a way to... + + when the size of each one gets too low, and is useless... + + actually rewrite the markup, and place the last few categories under a "more" item. Clicking that exposes a second nav bar. + + + */ + + + + /* + + SIMPLE ACCESSIBILITY TESTER + + by Andrew Bacon + This plugin runs simple tests on a site, and adds distinct visual styles to flawed content when they fail. + + */ + function imageWarning(e){ + var block = $('
') + block.addClass('alert alert-danger accessibility-fail-msg') + //console.log(e.width()) + block.width(e.width+'px') + + var icon = $('') + icon.addClass('glyphicon glyphicon-ban-circle') + + var msg = $('') + msg.append(' This image needs a valid Alt tag. ') + + + block.append(icon).append(msg) + $(e).after(block) + } + $('#page img').each(function(){ + alt = $(this).attr('alt') + if (alt){ + alt = alt.toLowerCase() + //console.log('alt='+alt) + if (alt.indexOf('.jpg') >= 0 || alt.indexOf('.png') >= 0 || alt.indexOf('.gif') >= 0 ){ + $(this).addClass('accessibility-fail') + imageWarning(this) + } + } else { + $(this).addClass('accessibility-fail') + imageWarning(this) + } + }) + // adds default bootstrap styles to all tables. + $('#page table').each(function(){ + $(this).addClass('table'); + }) + + /**/ + + +function stickyFoot(){ + /* Andrew's Sticky Footer JS. */ + + if (document.getElementById('page')!=null && document.getElementById('footers') !=null){ + var wrapperH = document.getElementById('page').clientHeight; + var footerH = document.getElementById('footers').clientHeight + var windowH = window.innerHeight; + if(windowH>=wrapperH){ + $('body').addClass('sticky') + } else { + $('body').removeClass('sticky') + } + } + + +} +window.onload = function (){ + placeholderSupport = ("placeholder" in document.createElement("input")); + if(placeholderSupport!=false){ + var d = $('main'); + d.addClass("supports-placeholder"); + } + stickyFoot(); +} + +window.onresize = function() { + + stickyFoot(); + +} + + }) \ No newline at end of file