From 9e5e3c5d2f52b4e67d599717ab4bacc7b6fb73a6 Mon Sep 17 00:00:00 2001 From: Frederic Hemberger Date: Sun, 18 Sep 2011 13:50:23 +0200 Subject: [PATCH] Fixes spacing and global variable leaks, JSHint check octopress.js now almost passes JSHint (http://jshint.com). The only issues left are due to undefined Modernizr and swfobject objects and the compressed swfobject code at the end of the file, but those are neglectable. --- .../classic/source/javascripts/octopress.js | 85 ++++++++++--------- 1 file changed, 44 insertions(+), 41 deletions(-) diff --git a/.themes/classic/source/javascripts/octopress.js b/.themes/classic/source/javascripts/octopress.js index 5266ecb..d944e7e 100644 --- a/.themes/classic/source/javascripts/octopress.js +++ b/.themes/classic/source/javascripts/octopress.js @@ -1,38 +1,40 @@ -function getNav(){ +function getNav() { var mobileNav = $('nav[role=navigation] fieldset[role=site-search]').after('
').next().append(''); mobileNav.children('select').append(''); - $($('ul[role=main-navigation] a')).each(function(link) { - mobileNav.children('select').append('') + $('ul[role=main-navigation] a').each(function(link) { + mobileNav.children('select').append(''); }); - mobileNav.children('select').bind('change', function(event){ + mobileNav.children('select').bind('change', function(event) { if (event.target.value) window.location.href = event.target.value; }); } + function addSidebarToggler() { $('#content').append(''); - $('.toggle-sidebar').bind('click', function(e){ + $('.toggle-sidebar').bind('click', function(e) { e.preventDefault(); - if($('body').hasClass('collapse-sidebar')){ + if ($('body').hasClass('collapse-sidebar')) { $('body').removeClass('collapse-sidebar'); } else { $('body').addClass('collapse-sidebar'); } }); - sections = $('aside[role=sidebar] > section') - if(sections.length > 1){ + var sections = $('aside[role=sidebar] > section'); + if (sections.length > 1) { sections.each(function(section, index){ - if ((sections.length >= 3) && index % 3 == 0) { + if ((sections.length >= 3) && index % 3 === 0) { $(section).addClass("first"); } - count = ((index +1) % 2) ? "odd" : "even"; + var count = ((index +1) % 2) ? "odd" : "even"; $(section).addClass(count); }); } - if(sections.length >= 3){ $('aside[role=sidebar]').addClass('thirds') } + if (sections.length >= 3){ $('aside[role=sidebar]').addClass('thirds'); } } + function testFeatures() { var features = ['maskImage']; - $(features).map(function(feature){ + $(features).map(function(feature) { if (Modernizr.testAllProps(feature)) { $('html').addClass(feature); } else { @@ -46,59 +48,60 @@ function testFeatures() { } } -function addCodeLineNumbers(){ - if (navigator.appName == 'Microsoft Internet Explorer') { return } - $('div.gist-highlight').each(function(code){ - var tableStart = '
'; - var lineNumbers = '
';
-    var tableMiddle = '
'; - var tableEnd = '
'; - var count = $('div.line', code).length; - for (i=1;i<=count; i++){ - lineNumbers += ''+i+'\n'; +function addCodeLineNumbers() { + if (navigator.appName == 'Microsoft Internet Explorer') { return; } + $('div.gist-highlight').each(function(code) { + var tableStart = '
', + lineNumbers = '
',
+        tableMiddle = '
', + tableEnd = '
', + count = $('span.line', code).length; + for (var i=1;i<=count; i++) { + lineNumbers += ''+i+'\n'; } - table = tableStart + lineNumbers + tableMiddle + '
'+$('pre', code).html()+'
' + tableEnd; + var table = tableStart + lineNumbers + tableMiddle + '
'+$('pre', code).html()+'
' + tableEnd; $(code).html(table); }); } function flashVideoFallback(){ var flashplayerlocation = "/assets/jwplayer/player.swf", - flashplayerskin = "/assets/jwplayer/glow/glow.xml"; + flashplayerskin = "/assets/jwplayer/glow/glow.xml"; $('video').each(function(video){ video = $(video); - if(!Modernizr.video.h264 && swfobject.getFlashPlayerVersion() || window.location.hash.indexOf("flash-test") != -1){ - video.children('source[src$=mp4]').first().map(function(source){; + if (!Modernizr.video.h264 && swfobject.getFlashPlayerVersion() || window.location.hash.indexOf("flash-test") != -1){ + video.children('source[src$=mp4]').first().map(function(source){ var src = $(source).attr('src'), - id = 'video_'+Math.round(1 + Math.random()*(100000)), - width = video.attr('width'), - height = parseInt(video.attr('height')) + 30; - video.after('
'); + id = 'video_'+Math.round(1 + Math.random()*(100000)), + width = video.attr('width'), + height = parseInt(video.attr('height'), 10) + 30; + video.after('
'); swfobject.embedSWF(flashplayerlocation, id, width, height + 30, "9.0.0", { file : src, image : video.attr('poster'), skin : flashplayerskin } , - { movie : src, wmode : "opaque", allowfullscreen : "true" }); + { movie : src, wmode : "opaque", allowfullscreen : "true" } + ); }); video.remove(); } }); } -function wrapFlashVideos(){ - $('object').each(function(object){ +function wrapFlashVideos() { + $('object').each(function(object) { object = $(object); - if(object.children('param[name=movie]')){ + if (object.children('param[name=movie]')) { var wrapper = object.before('
').previous(); $(wrapper).children().append(object); } }); - $('iframe[src*=vimeo],iframe[src*=youtube]').each(function(iframe){ + $('iframe[src*=vimeo],iframe[src*=youtube]').each(function(iframe) { iframe = $(iframe); var wrapper = iframe.before('
').previous(); $(wrapper).children().append(iframe); }); } -$.domReady(function(){ +$.domReady(function() { testFeatures(); wrapFlashVideos(); flashVideoFallback(); @@ -113,17 +116,17 @@ $.domReady(function(){ // Source url: https://gist.github.com/901295 (function(doc) { var addEvent = 'addEventListener', - type = 'gesturestart', - qsa = 'querySelectorAll', - scales = [1, 1], - meta = qsa in doc ? doc[qsa]('meta[name=viewport]') : []; + type = 'gesturestart', + qsa = 'querySelectorAll', + scales = [1, 1], + meta = qsa in doc ? doc[qsa]('meta[name=viewport]') : []; function fix() { meta.content = 'width=device-width,minimum-scale=' + scales[0] + ',maximum-scale=' + scales[1]; doc.removeEventListener(type, fix, true); } if ((meta = meta[meta.length - 1]) && addEvent in doc) { fix(); - scales = [.25, 1.6]; + scales = [0.25, 1.6]; doc[addEvent](type, fix, true); } }(document));