Mercurial > zeropaste
comparison app/assets/javascripts/init.tabs.js @ 129:0785824a20b9
Return immediately if not in pastes#show.
author | Edho Arief <edho@myconan.net> |
---|---|
date | Mon, 12 Nov 2012 17:25:36 +0700 |
parents | 7efe5e87658e |
children | 64523785ad24 |
comparison
equal
deleted
inserted
replaced
128:7efe5e87658e | 129:0785824a20b9 |
---|---|
1 $(document).ready(function() { | 1 $(document).ready(function() { |
2 if ($('#paste-show').length == 1) { | 2 if ($('#paste-show').length !== 1) { |
3 raw = $('#plain pre').text(); | 3 return; |
4 } | |
5 raw = $('#plain pre').text(); | |
4 | 6 |
5 $('#markdown div').html(marked(raw)); | 7 $('#markdown div').html(marked(raw)); |
6 $('#markdown div pre').addClass('prettyprint'); | 8 $('#markdown div pre').addClass('prettyprint'); |
7 $('#markdown div a').prop('rel', 'nofollow'); | 9 $('#markdown div a').prop('rel', 'nofollow'); |
8 | 10 |
9 $('#highlight pre').text(raw); | 11 $('#highlight pre').text(raw); |
10 | 12 |
11 window.prettyPrint && prettyPrint(); | 13 window.prettyPrint && prettyPrint(); |
12 | 14 |
13 update_state = function() { | 15 update_state = function() { |
14 var paste = $('#paste'), | 16 var paste = $('#paste'), |
15 mode = paste.data('mode'), | 17 mode = paste.data('mode'), |
16 width = paste.data('width'), | 18 width = paste.data('width'), |
17 qstring = '#!' + mode + '.' + width; | 19 qstring = '#!' + mode + '.' + width; |
18 if (width == 'auto') { | 20 if (width == 'auto') { |
19 qstring = '#!'; | 21 qstring = '#!'; |
20 if (mode != 'plain') { | 22 if (mode != 'plain') { |
21 qstring += mode; | 23 qstring += mode; |
22 } | |
23 } | 24 } |
24 window.location = qstring; | 25 } |
25 }; | 26 window.location = qstring; |
27 }; | |
26 | 28 |
27 paste_resize = function(size) { | 29 paste_resize = function(size) { |
28 var paste = $('#paste'), | 30 var paste = $('#paste'), |
29 title = $('#paste-resize a.btn'); | 31 title = $('#paste-resize a.btn'); |
30 title.html(title.html().replace(/(auto|\d+px)/, size)); | 32 title.html(title.html().replace(/(auto|\d+px)/, size)); |
31 if (size == 'auto') { | 33 if (size == 'auto') { |
32 paste.css('width', ''); | 34 paste.css('width', ''); |
33 paste.data('width', size); | 35 paste.data('width', size); |
34 } else { | 36 } else { |
35 paste.css('width', size); | 37 paste.css('width', size); |
36 paste.data('width', size); | 38 paste.data('width', size); |
37 } | |
38 update_state(); | |
39 } | 39 } |
40 update_state(); | |
41 } | |
40 | 42 |
41 $('#paste-mode a').click(function() { | 43 $('#paste-mode a').click(function() { |
42 $('#paste').data('mode', $(this).prop('href').split('#')[1]); | 44 $('#paste').data('mode', $(this).prop('href').split('#')[1]); |
43 update_state(); | 45 update_state(); |
44 }); | 46 }); |
45 $('#paste-resize ul a').click(function() { | 47 $('#paste-resize ul a').click(function() { |
46 paste_resize($(this).data('size')); | 48 paste_resize($(this).data('size')); |
47 $('.open').removeClass('open'); | 49 $('.open').removeClass('open'); |
48 return false; | 50 return false; |
49 }); | 51 }); |
50 | 52 |
51 mode = window.location.hash.substr(2).split('.'); | 53 mode = window.location.hash.substr(2).split('.'); |
52 if (mode[0] == 'highlight') { $('#paste-mode a:eq(1)').click(); } | 54 if (mode[0] == 'highlight') { $('#paste-mode a:eq(1)').click(); } |
53 else if (mode[0] == 'markdown') { $('#paste-mode a:eq(2)').click(); } | 55 else if (mode[0] == 'markdown') { $('#paste-mode a:eq(2)').click(); } |
54 if (mode[1] && mode[1].match(/^\d+px$/)) { paste_resize(mode[1]); } | 56 if (mode[1] && mode[1].match(/^\d+px$/)) { paste_resize(mode[1]); } |
55 | |
56 } | |
57 }); | 57 }); |