comparison app/assets/javascripts/init.tabs.js @ 135:0cd87e69dd65

Reorganize.
author Edho Arief <edho@myconan.net>
date Mon, 12 Nov 2012 17:41:48 +0700
parents 3c777dbd6b11
children b327d80c5ff9
comparison
equal deleted inserted replaced
134:3c777dbd6b11 135:0cd87e69dd65
1 $(document).ready(function() { 1 $(document).ready(function() {
2 if ($('#paste-show').length !== 1) { 2 if ($('#paste-show').length !== 1) {
3 return; 3 return;
4 } 4 }
5 var raw = $('#plain pre').text(), 5 var update_state = function() {
6 markdown = $('#markdown div'),
7 update_state = function() {
8 var paste = $('#paste'), 6 var paste = $('#paste'),
9 mode = paste.data('mode'), 7 mode = paste.data('mode'),
10 width = paste.data('width'), 8 width = paste.data('width'),
11 qstring = '#!' + mode + '.' + width; 9 qstring = '#!' + mode + '.' + width;
12 if (width == 'auto') { 10 if (width == 'auto') {
27 } else { 25 } else {
28 paste.css('width', size); 26 paste.css('width', size);
29 paste.data('width', size); 27 paste.data('width', size);
30 } 28 }
31 update_state(); 29 update_state();
30 },
31 paste_resize_menu_handler = function() {
32 paste_resize($(this).data('size'));
33 $('.open').removeClass('open');
34 return false;
35 },
36 paste_mode_state_handler = function() {
37 $('#paste').data('mode', $(this).prop('href').split('#')[1]);
38 update_state();
39 },
40 init_state = function() {
41 mode = window.location.hash.substr(2).split('.');
42 if (mode[0] == 'highlight') { $('#paste-mode a:eq(1)').click(); }
43 else if (mode[0] == 'markdown') { $('#paste-mode a:eq(2)').click(); };
44 if (mode[1] && mode[1].match(/^\d+px$/)) { paste_resize(mode[1]); }
45 },
46 init_tabs_base = function() {
47 var raw = $('#plain pre').text(),
48 markdown = $('#markdown div');
49 markdown.html(marked(raw));
50 $('#highlight pre').text(raw);
51
52 markdown.find('pre').addClass('prettyprint');
53 markdown.find('a').prop('rel', 'nofollow');
54 prettyPrint();
55 },
56 init_tabs_menu = function() {
57 $('#paste-mode a').click(paste_mode_state_handler);
58 $('#paste-resize ul a').click(paste_resize_menu_handler);
32 }; 59 };
33 60
34 markdown.html(marked(raw)); 61 init_tabs_base();
35 $('#highlight pre').text(raw); 62 init_tabs_menu();
36 63 init_state();
37 markdown.find('pre').addClass('prettyprint'); 64 update_state();
38 markdown.find('a').prop('rel', 'nofollow');
39 prettyPrint();
40
41 $('#paste-mode a').click(function() {
42 $('#paste').data('mode', $(this).prop('href').split('#')[1]);
43 update_state();
44 });
45 $('#paste-resize ul a').click(function() {
46 paste_resize($(this).data('size'));
47 $('.open').removeClass('open');
48 return false;
49 });
50
51 mode = window.location.hash.substr(2).split('.');
52 if (mode[0] == 'highlight') { $('#paste-mode a:eq(1)').click(); }
53 else if (mode[0] == 'markdown') { $('#paste-mode a:eq(2)').click(); };
54 if (mode[1] && mode[1].match(/^\d+px$/)) { paste_resize(mode[1]); }
55 }); 65 });