Mercurial > zeropaste
comparison app/assets/javascripts/init.tabs.js @ 114:b72f99d7b8cf
Dynamic url based on options selected.
Yes, I'm having too much fun.
author | Edho Arief <edho@myconan.net> |
---|---|
date | Mon, 12 Nov 2012 13:31:18 +0700 |
parents | 2b1041e8c35e |
children | 546381cf83c2 |
comparison
equal
deleted
inserted
replaced
113:c24b17044ad1 | 114:b72f99d7b8cf |
---|---|
5 $('#highlight pre').text(raw); | 5 $('#highlight pre').text(raw); |
6 window.prettyPrint && prettyPrint(); | 6 window.prettyPrint && prettyPrint(); |
7 | 7 |
8 $('#markdown div').html(marked(raw)); | 8 $('#markdown div').html(marked(raw)); |
9 | 9 |
10 update_state = function() { | |
11 var paste = $('#paste'), | |
12 mode = paste.data('mode'), | |
13 width = paste.data('width'), | |
14 qstring = '?' + mode + '.' + width; | |
15 if ((mode == 'plain') && (width == 'full')) { | |
16 qstring = '?'; | |
17 } | |
18 history.replaceState(null, '', qstring); | |
19 }; | |
20 | |
10 paste_resize = function(size) { | 21 paste_resize = function(size) { |
11 var paste = $('#paste'), | 22 var paste = $('#paste'), |
12 title = $('#tab-resize a.btn'); | 23 title = $('#tab-resize a.btn'); |
13 title.html(title.html().replace(/(full|\d+px)/, size)); | 24 title.html(title.html().replace(/(full|\d+px)/, size)); |
14 if (size == 'full') { | 25 if (size == 'full') { |
15 paste.css('width', ''); | 26 paste.css('width', ''); |
16 paste.data('width', '0'); | 27 paste.data('width', size); |
17 } else { | 28 } else { |
18 paste.css('width', size); | 29 paste.css('width', size); |
19 paste.data('width', size); | 30 paste.data('width', size); |
20 } | 31 } |
32 update_state(); | |
21 } | 33 } |
22 | 34 |
35 $('#paste-tabs > li > a').click(function() { | |
36 $('#paste').data('mode', $(this).prop('href').split('#')[1]); | |
37 update_state(); | |
38 }); | |
23 $('#tab-resize ul a').click(function() { | 39 $('#tab-resize ul a').click(function() { |
24 paste_resize($(this).data('size')); | 40 paste_resize($(this).data('size')); |
25 }); | 41 }); |
26 | 42 |
27 mode = window.location.search.substr(1).split('.'); | 43 mode = window.location.search.substr(1).split('.'); |
28 if (mode[0] == 'highlight') { $('#paste-tabs li:eq(1) a').tab('show'); } | 44 if (mode[0] == 'highlight') { $('#paste-tabs li:eq(1) a').click(); } |
29 else if (mode[0] == 'markdown') { $('#paste-tabs li:eq(2) a').tab('show'); } | 45 else if (mode[0] == 'markdown') { $('#paste-tabs li:eq(2) a').click(); } |
30 if (mode[1] && mode[1].match(/^\d+px$/)) { paste_resize(mode[1]); } | 46 if (mode[1] && mode[1].match(/^\d+px$/)) { paste_resize(mode[1]); } |
47 | |
31 } | 48 } |
32 }); | 49 }); |