Browse code

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.

Frederic Hemberger authored on 18/09/2011 at 11:50:23
Showing 1 changed files
... ...
@@ -1,38 +1,40 @@
1
-function getNav(){
1
+function getNav() {
2 2
   var mobileNav = $('nav[role=navigation] fieldset[role=site-search]').after('<fieldset role="mobile-nav"></fieldset>').next().append('<select></select>');
3 3
   mobileNav.children('select').append('<option value="">Navigate&hellip;</option>');
4
-  $($('ul[role=main-navigation] a')).each(function(link) {
5
-    mobileNav.children('select').append('<option value="'+link.href+'">&bull; '+link.text+'</option>')
4
+  $('ul[role=main-navigation] a').each(function(link) {
5
+    mobileNav.children('select').append('<option value="'+link.href+'">&bull; '+link.text+'</option>');
6 6
   });
7
-  mobileNav.children('select').bind('change', function(event){
7
+  mobileNav.children('select').bind('change', function(event) {
8 8
     if (event.target.value) window.location.href = event.target.value;
9 9
   });
10 10
 }
11
+
11 12
 function addSidebarToggler() {
12 13
   $('#content').append('<span class="toggle-sidebar"></span>');
13
-  $('.toggle-sidebar').bind('click', function(e){
14
+  $('.toggle-sidebar').bind('click', function(e) {
14 15
     e.preventDefault();
15
-    if($('body').hasClass('collapse-sidebar')){
16
+    if ($('body').hasClass('collapse-sidebar')) {
16 17
       $('body').removeClass('collapse-sidebar');
17 18
     } else {
18 19
       $('body').addClass('collapse-sidebar');
19 20
     }
20 21
   });
21
-  sections = $('aside[role=sidebar] > section')
22
-  if(sections.length > 1){
22
+  var sections = $('aside[role=sidebar] > section');
23
+  if (sections.length > 1) {
23 24
     sections.each(function(section, index){
24
-      if ((sections.length >= 3) && index % 3 == 0) {
25
+      if ((sections.length >= 3) && index % 3 === 0) {
25 26
         $(section).addClass("first");
26 27
       }
27
-      count = ((index +1) % 2) ? "odd" : "even";
28
+      var count = ((index +1) % 2) ? "odd" : "even";
28 29
       $(section).addClass(count);
29 30
     });
30 31
   }
31
-  if(sections.length >= 3){ $('aside[role=sidebar]').addClass('thirds') }
32
+  if (sections.length >= 3){ $('aside[role=sidebar]').addClass('thirds'); }
32 33
 }
34
+
33 35
 function testFeatures() {
34 36
   var features = ['maskImage'];
35
-  $(features).map(function(feature){
37
+  $(features).map(function(feature) {
36 38
     if (Modernizr.testAllProps(feature)) {
37 39
       $('html').addClass(feature);
38 40
     } else {
... ...
@@ -46,59 +48,60 @@ function testFeatures() {
46 46
   }
47 47
 }
48 48
 
49
-function addCodeLineNumbers(){
50
-  if (navigator.appName == 'Microsoft Internet Explorer') { return }
51
-  $('div.gist-highlight').each(function(code){
52
-    var tableStart = '<table cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter">';
53
-    var lineNumbers = '<pre class="line-numbers">';
54
-    var tableMiddle = '</pre></td><td class="code" width="100%">';
55
-    var tableEnd = '</td></tr></tbody></table>';
56
-    var count = $('div.line', code).length;
57
-    for (i=1;i<=count; i++){
58
-      lineNumbers += '<span class="line">'+i+'</span>\n';
49
+function addCodeLineNumbers() {
50
+  if (navigator.appName == 'Microsoft Internet Explorer') { return; }
51
+  $('div.gist-highlight').each(function(code) {
52
+    var tableStart = '<table><tbody><tr><td class="gutter">',
53
+        lineNumbers = '<pre class="line-numbers">',
54
+        tableMiddle = '</pre></td><td class="code">',
55
+        tableEnd = '</td></tr></tbody></table>',
56
+        count = $('span.line', code).length;
57
+    for (var i=1;i<=count; i++) {
58
+      lineNumbers += '<span class="line-number">'+i+'</span>\n';
59 59
     }
60
-    table = tableStart + lineNumbers + tableMiddle + '<pre>'+$('pre', code).html()+'</pre>' + tableEnd;
60
+    var table = tableStart + lineNumbers + tableMiddle + '<pre>'+$('pre', code).html()+'</pre>' + tableEnd;
61 61
     $(code).html(table);
62 62
   });
63 63
 }
64 64
 
65 65
 function flashVideoFallback(){
66 66
   var flashplayerlocation = "/assets/jwplayer/player.swf",
67
-  flashplayerskin = "/assets/jwplayer/glow/glow.xml";
67
+      flashplayerskin = "/assets/jwplayer/glow/glow.xml";
68 68
   $('video').each(function(video){
69 69
     video = $(video);
70
-    if(!Modernizr.video.h264 && swfobject.getFlashPlayerVersion() || window.location.hash.indexOf("flash-test") != -1){
71
-      video.children('source[src$=mp4]').first().map(function(source){;
70
+    if (!Modernizr.video.h264 && swfobject.getFlashPlayerVersion() || window.location.hash.indexOf("flash-test") != -1){
71
+      video.children('source[src$=mp4]').first().map(function(source){
72 72
         var src = $(source).attr('src'),
73
-        id = 'video_'+Math.round(1 + Math.random()*(100000)),
74
-        width = video.attr('width'),
75
-        height = parseInt(video.attr('height')) + 30;
76
-        video.after('<div class="flash-video"><div><div id='+id+'>');
73
+            id = 'video_'+Math.round(1 + Math.random()*(100000)),
74
+            width = video.attr('width'),
75
+            height = parseInt(video.attr('height'), 10) + 30;
76
+            video.after('<div class="flash-video"><div><div id='+id+'>');
77 77
         swfobject.embedSWF(flashplayerlocation, id, width, height + 30, "9.0.0",
78 78
           { file : src, image : video.attr('poster'), skin : flashplayerskin } ,
79
-          { movie : src, wmode : "opaque", allowfullscreen : "true" });
79
+          { movie : src, wmode : "opaque", allowfullscreen : "true" }
80
+        );
80 81
       });
81 82
       video.remove();
82 83
     }
83 84
   });
84 85
 }
85 86
 
86
-function wrapFlashVideos(){
87
-  $('object').each(function(object){
87
+function wrapFlashVideos() {
88
+  $('object').each(function(object) {
88 89
     object = $(object);
89
-    if(object.children('param[name=movie]')){
90
+    if (object.children('param[name=movie]')) {
90 91
       var wrapper = object.before('<div class="flash-video"><div>').previous();
91 92
       $(wrapper).children().append(object);
92 93
     }
93 94
   });
94
-  $('iframe[src*=vimeo],iframe[src*=youtube]').each(function(iframe){
95
+  $('iframe[src*=vimeo],iframe[src*=youtube]').each(function(iframe) {
95 96
     iframe = $(iframe);
96 97
     var wrapper = iframe.before('<div class="flash-video"><div>').previous();
97 98
     $(wrapper).children().append(iframe);
98 99
   });
99 100
 }
100 101
 
101
-$.domReady(function(){
102
+$.domReady(function() {
102 103
   testFeatures();
103 104
   wrapFlashVideos();
104 105
   flashVideoFallback();
... ...
@@ -113,17 +116,17 @@ $.domReady(function(){
113 113
 // Source url: https://gist.github.com/901295
114 114
 (function(doc) {
115 115
   var addEvent = 'addEventListener',
116
-  type = 'gesturestart',
117
-  qsa = 'querySelectorAll',
118
-  scales = [1, 1],
119
-  meta = qsa in doc ? doc[qsa]('meta[name=viewport]') : [];
116
+      type = 'gesturestart',
117
+      qsa = 'querySelectorAll',
118
+      scales = [1, 1],
119
+      meta = qsa in doc ? doc[qsa]('meta[name=viewport]') : [];
120 120
   function fix() {
121 121
     meta.content = 'width=device-width,minimum-scale=' + scales[0] + ',maximum-scale=' + scales[1];
122 122
     doc.removeEventListener(type, fix, true);
123 123
   }
124 124
   if ((meta = meta[meta.length - 1]) && addEvent in doc) {
125 125
     fix();
126
-    scales = [.25, 1.6];
126
+    scales = [0.25, 1.6];
127 127
     doc[addEvent](type, fix, true);
128 128
   }
129 129
 }(document));