# HG changeset patch # User Edho Arief # Date 1352715936 -25200 # Node ID 0785824a20b92f089d526a62f77f6f3da7f90ccc # Parent 7efe5e87658e43a919510c046054277ad012a2d0 Return immediately if not in pastes#show. diff -r 7efe5e87658e -r 0785824a20b9 app/assets/javascripts/init.tabs.js --- a/app/assets/javascripts/init.tabs.js Mon Nov 12 17:23:35 2012 +0700 +++ b/app/assets/javascripts/init.tabs.js Mon Nov 12 17:25:36 2012 +0700 @@ -1,57 +1,57 @@ $(document).ready(function() { - if ($('#paste-show').length == 1) { - raw = $('#plain pre').text(); + if ($('#paste-show').length !== 1) { + return; + } + raw = $('#plain pre').text(); - $('#markdown div').html(marked(raw)); - $('#markdown div pre').addClass('prettyprint'); - $('#markdown div a').prop('rel', 'nofollow'); + $('#markdown div').html(marked(raw)); + $('#markdown div pre').addClass('prettyprint'); + $('#markdown div a').prop('rel', 'nofollow'); - $('#highlight pre').text(raw); + $('#highlight pre').text(raw); - window.prettyPrint && prettyPrint(); + window.prettyPrint && prettyPrint(); - update_state = function() { - var paste = $('#paste'), - mode = paste.data('mode'), - width = paste.data('width'), - qstring = '#!' + mode + '.' + width; - if (width == 'auto') { - qstring = '#!'; - if (mode != 'plain') { - qstring += mode; - } + update_state = function() { + var paste = $('#paste'), + mode = paste.data('mode'), + width = paste.data('width'), + qstring = '#!' + mode + '.' + width; + if (width == 'auto') { + qstring = '#!'; + if (mode != 'plain') { + qstring += mode; } - window.location = qstring; - }; + } + window.location = qstring; + }; - paste_resize = function(size) { - var paste = $('#paste'), - title = $('#paste-resize a.btn'); - title.html(title.html().replace(/(auto|\d+px)/, size)); - if (size == 'auto') { - paste.css('width', ''); - paste.data('width', size); - } else { - paste.css('width', size); - paste.data('width', size); - } - update_state(); + paste_resize = function(size) { + var paste = $('#paste'), + title = $('#paste-resize a.btn'); + title.html(title.html().replace(/(auto|\d+px)/, size)); + if (size == 'auto') { + paste.css('width', ''); + paste.data('width', size); + } else { + paste.css('width', size); + paste.data('width', size); } + update_state(); + } - $('#paste-mode a').click(function() { - $('#paste').data('mode', $(this).prop('href').split('#')[1]); - update_state(); - }); - $('#paste-resize ul a').click(function() { - paste_resize($(this).data('size')); - $('.open').removeClass('open'); - return false; - }); + $('#paste-mode a').click(function() { + $('#paste').data('mode', $(this).prop('href').split('#')[1]); + update_state(); + }); + $('#paste-resize ul a').click(function() { + paste_resize($(this).data('size')); + $('.open').removeClass('open'); + return false; + }); - mode = window.location.hash.substr(2).split('.'); - if (mode[0] == 'highlight') { $('#paste-mode a:eq(1)').click(); } - else if (mode[0] == 'markdown') { $('#paste-mode a:eq(2)').click(); } - if (mode[1] && mode[1].match(/^\d+px$/)) { paste_resize(mode[1]); } - - } + mode = window.location.hash.substr(2).split('.'); + if (mode[0] == 'highlight') { $('#paste-mode a:eq(1)').click(); } + else if (mode[0] == 'markdown') { $('#paste-mode a:eq(2)').click(); } + if (mode[1] && mode[1].match(/^\d+px$/)) { paste_resize(mode[1]); } });