diff options
Diffstat (limited to 'source/javascripts/slash.js')
-rw-r--r-- | source/javascripts/slash.js | 77 |
1 files changed, 42 insertions, 35 deletions
diff --git a/source/javascripts/slash.js b/source/javascripts/slash.js index c23a4a2..c33635a 100644 --- a/source/javascripts/slash.js +++ b/source/javascripts/slash.js @@ -1,45 +1,52 @@ (function($){ - /* external.js */ - var host = location.host; + // Open external links in new window + var externalLinks = function(){ + var host = location.host; - $('a').on('click', function(e){ - var href = $(this).attr('href'), - link = href.replace(/(https?:\/\/)(.*)\/(.*)/, '$2'); + $('body').on('click', 'a', function(e){ + var href = this.href, + link = href.replace(/https?:\/\/([^\/]+)(.*)/, '$1'); - if (href.match('https?') && link != host){ - window.open(href); - e.preventDefault(); - } - }); - - /* navigation.js */ - var appends = '<option>Menu</option>'; - - $('.menu .main > li').each(function(){ - var link = $(this).children('a'); - appends += '<option value="'+link.attr('href')+'">'+link.html()+'</option>'; - $(this).find('li').each(function(){ - var link = $(this).children('a'); - appends += '<option value="'+link.attr('href')+'">- '+link.html()+'</option>'; + if (link != '' && link != host && !$(this).hasClass('fancybox')){ + window.open(href); + e.preventDefault(); + } }); - }); + }; - $('nav.menu').append('<select>'+appends+'</select>').on('change', 'select', function(){ - location.href = $(this).val(); - }); + // Append caption after pictures + var appendCaption = function(){ + $('.entry-content').each(function(i){ + var _i = i; + $(this).find('img').each(function(){ + var alt = this.alt; - /* caption.js */ - $('.entry').each(function(i){ - var _i = i; - $(this).find('img').each(function(){ - var alt = $(this).attr('alt'); + if (alt != ''){ + $(this).after('<span class="caption">'+alt+'</span>'); + } - if (alt == '' || typeof alt == 'undefined'){ - $(this).wrap('<a href="'+$(this).attr('src')+'" class="fancybox" rel="gallery'+_i+'" />'); - } else { - $(this).after('<span class="caption">'+alt+'</span>').wrap('<a href="'+$(this).attr('src')+'" class="fancybox" title="'+alt+'" rel="gallery'+_i+'" />'); - } + $(this).wrap('<a href="'+this.src+'" title="'+alt+'" class="fancybox" rel="gallery'+_i+'" />'); + }); }); + }; + + externalLinks(); // Delete or comment this line to disable opening external links in new window + appendCaption(); // Delete or comment this line to disable caption + + var mobilenav = $('#mobile-nav'); + mobilenav.on('click', '.menu .button', function(){ + if (!$(this).hasClass('on')){ + var width = $(this).width() + 42; + $(this).addClass('on').next().show().css({width: width}); + } else { + $(this).removeClass('on').next().hide(); + } + }).on('click', '.search .button', function(){ + if (!$(this).hasClass('on')){ + var width = mobilenav.width() - 51; + $(this).addClass('on').next().show().css({width: width}).children().children().eq(0).focus(); + } else { + $(this).removeClass('on').next().hide().children().children().eq(0).val(''); + } }); - $('.fancybox').fancybox(); })(jQuery);
\ No newline at end of file |