summaryrefslogtreecommitdiffstats
path: root/source/javascripts/slash.js
diff options
context:
space:
mode:
Diffstat (limited to 'source/javascripts/slash.js')
-rw-r--r--source/javascripts/slash.js106
1 files changed, 66 insertions, 40 deletions
diff --git a/source/javascripts/slash.js b/source/javascripts/slash.js
index c23a4a2..6433ba0 100644
--- a/source/javascripts/slash.js
+++ b/source/javascripts/slash.js
@@ -1,45 +1,71 @@
(function($){
- /* external.js */
- var host = location.host;
-
- $('a').on('click', function(e){
- var href = $(this).attr('href'),
- link = href.replace(/(https?:\/\/)(.*)\/(.*)/, '$2');
-
- 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>';
+ // Open external links in new window
+ var externalLinks = function(){
+ var host = location.host;
+
+ $('body').on('click', 'a', function(e){
+ var href = this.href,
+ link = href.replace(/https?:\/\/([^\/]+)(.*)/, '$1');
+
+ 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();
- });
-
- /* caption.js */
- $('.entry').each(function(i){
- var _i = i;
- $(this).find('img').each(function(){
- var alt = $(this).attr('alt');
-
- 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+'" />');
+ };
+
+ // Append menu for mobile device
+ var navigationMenu = function(){
+ var appends = '<option>Menu</option>';
+
+ var search = function(obj, level){
+ var children = obj.children(),
+ link = children.eq(0),
+ _level = level + 1;
+
+ appends += '<option value="'+link.attr('href')+'">';
+
+ if (level > 0) appends += '|';
+
+ for (var i=0; i<level; i++){
+ appends += '—';
}
+
+ appends += link.text()+'</option>';
+
+ if (children.length > 1){
+ children.eq(1).children('li').each(function(){
+ search($(this), _level);
+ });
+ }
+ };
+
+ $('#header .menu .main').children('li').each(function(){
+ search($(this), 0);
});
- });
- $('.fancybox').fancybox();
+
+ $('#header .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;
+
+ if (alt != ''){
+ $(this).after('<span class="caption">'+alt+'</span>');
+ }
+
+ $(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
+ navigationMenu(); // Delete or comment this line to disable menu for mobile device
+ appendCaption(); // Delete or comment this line to disable caption
})(jQuery); \ No newline at end of file