comparison app/assets/javascripts/init.tabs.js @ 204:c054f01477c4

Use shorter name for the hash magic thing
author Edho Arief <edho@myconan.net>
date Wed, 08 May 2013 01:16:30 +0900
parents 601c608637e7
children
comparison
equal deleted inserted replaced
203:de168fde2df2 204:c054f01477c4
4 } 4 }
5 var update_state = function() { 5 var update_state = function() {
6 var paste = $('#paste'), 6 var paste = $('#paste'),
7 mode = paste.data('mode'), 7 mode = paste.data('mode'),
8 width = paste.data('width'), 8 width = paste.data('width'),
9 qstring = '#!' + mode + '.' + width; 9 short_mode = function(mode) {
10 if (mode == 'highlight') {
11 return 'hl'
12 } else if (mode =='markdown') {
13 return 'md'
14 } else {
15 return 'plain'
16 }
17 },
18 qstring = '#!' + short_mode(mode) + '.' + width;
10 if (width == 'auto') { 19 if (width == 'auto') {
11 if (mode == 'plain') { 20 if (mode == 'plain') {
12 qstring = ' '; 21 qstring = ' ';
13 } else { 22 } else {
14 qstring = '#!' + mode; 23 qstring = '#!' + short_mode(mode);
15 } 24 }
16 } 25 }
17 if (history.replaceState) { 26 if (history.replaceState) {
18 history.replaceState(null, '', qstring); 27 history.replaceState(null, '', qstring);
19 } else { 28 } else {
43 $('#paste').data('mode', $(this).prop('href').split('#')[1]); 52 $('#paste').data('mode', $(this).prop('href').split('#')[1]);
44 update_state(); 53 update_state();
45 }, 54 },
46 init_state = function() { 55 init_state = function() {
47 mode = window.location.hash.substr(2).split('.'); 56 mode = window.location.hash.substr(2).split('.');
48 if (mode[0] == 'highlight') { $('#paste-mode a:eq(1)').click(); } 57 if (mode[0] == 'hl' || mode[0] == 'highlight') { $('#paste-mode a:eq(1)').click(); }
49 else if (mode[0] == 'markdown') { $('#paste-mode a:eq(2)').click(); }; 58 else if (mode[0] == 'md' || mode[0] == 'markdown') { $('#paste-mode a:eq(2)').click(); };
50 if (mode[1] && mode[1].match(/^\d+px$/)) { paste_resize(mode[1]); } 59 if (mode[1] && mode[1].match(/^\d+px$/)) { paste_resize(mode[1]); }
51 }, 60 },
52 init_tabs_base = function() { 61 init_tabs_base = function() {
53 var raw = $('#plain pre').text(), 62 var raw = $('#plain pre').text(),
54 markdown = $('#markdown div'); 63 markdown = $('#markdown div');