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.
This commit is contained in:
parent
f6bf894387
commit
9e5e3c5d2f
@ -1,13 +1,14 @@
|
|||||||
function getNav() {
|
function getNav() {
|
||||||
var mobileNav = $('nav[role=navigation] fieldset[role=site-search]').after('<fieldset role="mobile-nav"></fieldset>').next().append('<select></select>');
|
var mobileNav = $('nav[role=navigation] fieldset[role=site-search]').after('<fieldset role="mobile-nav"></fieldset>').next().append('<select></select>');
|
||||||
mobileNav.children('select').append('<option value="">Navigate…</option>');
|
mobileNav.children('select').append('<option value="">Navigate…</option>');
|
||||||
$($('ul[role=main-navigation] a')).each(function(link) {
|
$('ul[role=main-navigation] a').each(function(link) {
|
||||||
mobileNav.children('select').append('<option value="'+link.href+'">• '+link.text+'</option>')
|
mobileNav.children('select').append('<option value="'+link.href+'">• '+link.text+'</option>');
|
||||||
});
|
});
|
||||||
mobileNav.children('select').bind('change', function(event) {
|
mobileNav.children('select').bind('change', function(event) {
|
||||||
if (event.target.value) window.location.href = event.target.value;
|
if (event.target.value) window.location.href = event.target.value;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function addSidebarToggler() {
|
function addSidebarToggler() {
|
||||||
$('#content').append('<span class="toggle-sidebar"></span>');
|
$('#content').append('<span class="toggle-sidebar"></span>');
|
||||||
$('.toggle-sidebar').bind('click', function(e) {
|
$('.toggle-sidebar').bind('click', function(e) {
|
||||||
@ -18,18 +19,19 @@ function addSidebarToggler() {
|
|||||||
$('body').addClass('collapse-sidebar');
|
$('body').addClass('collapse-sidebar');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
sections = $('aside[role=sidebar] > section')
|
var sections = $('aside[role=sidebar] > section');
|
||||||
if (sections.length > 1) {
|
if (sections.length > 1) {
|
||||||
sections.each(function(section, index){
|
sections.each(function(section, index){
|
||||||
if ((sections.length >= 3) && index % 3 == 0) {
|
if ((sections.length >= 3) && index % 3 === 0) {
|
||||||
$(section).addClass("first");
|
$(section).addClass("first");
|
||||||
}
|
}
|
||||||
count = ((index +1) % 2) ? "odd" : "even";
|
var count = ((index +1) % 2) ? "odd" : "even";
|
||||||
$(section).addClass(count);
|
$(section).addClass(count);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if(sections.length >= 3){ $('aside[role=sidebar]').addClass('thirds') }
|
if (sections.length >= 3){ $('aside[role=sidebar]').addClass('thirds'); }
|
||||||
}
|
}
|
||||||
|
|
||||||
function testFeatures() {
|
function testFeatures() {
|
||||||
var features = ['maskImage'];
|
var features = ['maskImage'];
|
||||||
$(features).map(function(feature) {
|
$(features).map(function(feature) {
|
||||||
@ -47,17 +49,17 @@ function testFeatures() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addCodeLineNumbers() {
|
function addCodeLineNumbers() {
|
||||||
if (navigator.appName == 'Microsoft Internet Explorer') { return }
|
if (navigator.appName == 'Microsoft Internet Explorer') { return; }
|
||||||
$('div.gist-highlight').each(function(code) {
|
$('div.gist-highlight').each(function(code) {
|
||||||
var tableStart = '<table cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter">';
|
var tableStart = '<table><tbody><tr><td class="gutter">',
|
||||||
var lineNumbers = '<pre class="line-numbers">';
|
lineNumbers = '<pre class="line-numbers">',
|
||||||
var tableMiddle = '</pre></td><td class="code" width="100%">';
|
tableMiddle = '</pre></td><td class="code">',
|
||||||
var tableEnd = '</td></tr></tbody></table>';
|
tableEnd = '</td></tr></tbody></table>',
|
||||||
var count = $('div.line', code).length;
|
count = $('span.line', code).length;
|
||||||
for (i=1;i<=count; i++){
|
for (var i=1;i<=count; i++) {
|
||||||
lineNumbers += '<span class="line">'+i+'</span>\n';
|
lineNumbers += '<span class="line-number">'+i+'</span>\n';
|
||||||
}
|
}
|
||||||
table = tableStart + lineNumbers + tableMiddle + '<pre>'+$('pre', code).html()+'</pre>' + tableEnd;
|
var table = tableStart + lineNumbers + tableMiddle + '<pre>'+$('pre', code).html()+'</pre>' + tableEnd;
|
||||||
$(code).html(table);
|
$(code).html(table);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -68,15 +70,16 @@ function flashVideoFallback(){
|
|||||||
$('video').each(function(video){
|
$('video').each(function(video){
|
||||||
video = $(video);
|
video = $(video);
|
||||||
if (!Modernizr.video.h264 && swfobject.getFlashPlayerVersion() || window.location.hash.indexOf("flash-test") != -1){
|
if (!Modernizr.video.h264 && swfobject.getFlashPlayerVersion() || window.location.hash.indexOf("flash-test") != -1){
|
||||||
video.children('source[src$=mp4]').first().map(function(source){;
|
video.children('source[src$=mp4]').first().map(function(source){
|
||||||
var src = $(source).attr('src'),
|
var src = $(source).attr('src'),
|
||||||
id = 'video_'+Math.round(1 + Math.random()*(100000)),
|
id = 'video_'+Math.round(1 + Math.random()*(100000)),
|
||||||
width = video.attr('width'),
|
width = video.attr('width'),
|
||||||
height = parseInt(video.attr('height')) + 30;
|
height = parseInt(video.attr('height'), 10) + 30;
|
||||||
video.after('<div class="flash-video"><div><div id='+id+'>');
|
video.after('<div class="flash-video"><div><div id='+id+'>');
|
||||||
swfobject.embedSWF(flashplayerlocation, id, width, height + 30, "9.0.0",
|
swfobject.embedSWF(flashplayerlocation, id, width, height + 30, "9.0.0",
|
||||||
{ file : src, image : video.attr('poster'), skin : flashplayerskin } ,
|
{ file : src, image : video.attr('poster'), skin : flashplayerskin } ,
|
||||||
{ movie : src, wmode : "opaque", allowfullscreen : "true" });
|
{ movie : src, wmode : "opaque", allowfullscreen : "true" }
|
||||||
|
);
|
||||||
});
|
});
|
||||||
video.remove();
|
video.remove();
|
||||||
}
|
}
|
||||||
@ -123,7 +126,7 @@ $.domReady(function(){
|
|||||||
}
|
}
|
||||||
if ((meta = meta[meta.length - 1]) && addEvent in doc) {
|
if ((meta = meta[meta.length - 1]) && addEvent in doc) {
|
||||||
fix();
|
fix();
|
||||||
scales = [.25, 1.6];
|
scales = [0.25, 1.6];
|
||||||
doc[addEvent](type, fix, true);
|
doc[addEvent](type, fix, true);
|
||||||
}
|
}
|
||||||
}(document));
|
}(document));
|
||||||
|
Loading…
Reference in New Issue
Block a user