Mercurial > zeropaste
annotate app/assets/javascripts/init.tabs.js @ 140:13ada93ad6a2
Return false on update state.
author | Edho Arief <edho@myconan.net> |
---|---|
date | Mon, 12 Nov 2012 17:51:53 +0700 |
parents | 3241fe970c13 |
children | 2104f0c477c0 |
rev | line source |
---|---|
59
1833de28583a
Turns out the init file is required.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
1 $(document).ready(function() { |
129
0785824a20b9
Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents:
128
diff
changeset
|
2 if ($('#paste-show').length !== 1) { |
0785824a20b9
Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents:
128
diff
changeset
|
3 return; |
0785824a20b9
Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents:
128
diff
changeset
|
4 } |
136
b327d80c5ff9
Fixed indentation and spaces.
Edho Arief <edho@myconan.net>
parents:
135
diff
changeset
|
5 var update_state = function() { |
b327d80c5ff9
Fixed indentation and spaces.
Edho Arief <edho@myconan.net>
parents:
135
diff
changeset
|
6 var paste = $('#paste'), |
b327d80c5ff9
Fixed indentation and spaces.
Edho Arief <edho@myconan.net>
parents:
135
diff
changeset
|
7 mode = paste.data('mode'), |
b327d80c5ff9
Fixed indentation and spaces.
Edho Arief <edho@myconan.net>
parents:
135
diff
changeset
|
8 width = paste.data('width'), |
b327d80c5ff9
Fixed indentation and spaces.
Edho Arief <edho@myconan.net>
parents:
135
diff
changeset
|
9 qstring = '#!' + mode + '.' + width; |
137 | 10 if (width == 'auto') { |
11 qstring = '#!'; | |
12 if (mode != 'plain') { | |
13 qstring += mode; | |
134
3c777dbd6b11
Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents:
133
diff
changeset
|
14 } |
137 | 15 } |
16 window.location = qstring; | |
140
13ada93ad6a2
Return false on update state.
Edho Arief <edho@myconan.net>
parents:
137
diff
changeset
|
17 return false; |
137 | 18 }, |
19 paste_resize = function(size) { | |
20 var paste = $('#paste'), | |
21 title = $('#paste-resize a.btn'); | |
22 title.html(title.html().replace(/(auto|\d+px)/, size)); | |
23 if (size == 'auto') { | |
24 paste.css('width', ''); | |
25 paste.data('width', size); | |
26 } else { | |
27 paste.css('width', size); | |
28 paste.data('width', size); | |
29 } | |
30 update_state(); | |
31 }, | |
32 paste_resize_menu_handler = function() { | |
33 paste_resize($(this).data('size')); | |
34 $('.open').removeClass('open'); | |
35 return false; | |
36 }, | |
37 paste_mode_state_handler = function() { | |
38 $('#paste').data('mode', $(this).prop('href').split('#')[1]); | |
39 update_state(); | |
40 }, | |
41 init_state = function() { | |
42 mode = window.location.hash.substr(2).split('.'); | |
43 if (mode[0] == 'highlight') { $('#paste-mode a:eq(1)').click(); } | |
44 else if (mode[0] == 'markdown') { $('#paste-mode a:eq(2)').click(); }; | |
45 if (mode[1] && mode[1].match(/^\d+px$/)) { paste_resize(mode[1]); } | |
46 }, | |
47 init_tabs_base = function() { | |
48 var raw = $('#plain pre').text(), | |
49 markdown = $('#markdown div'); | |
50 markdown.html(marked(raw)); | |
51 $('#highlight pre').text(raw); | |
135 | 52 |
137 | 53 markdown.find('pre').addClass('prettyprint'); |
54 markdown.find('a').prop('rel', 'nofollow'); | |
55 prettyPrint(); | |
56 }, | |
57 init_tabs_menu = function() { | |
58 $('#paste-mode a').click(paste_mode_state_handler); | |
59 $('#paste-resize ul a').click(paste_resize_menu_handler); | |
60 }; | |
104 | 61 |
135 | 62 init_tabs_base(); |
63 init_tabs_menu(); | |
64 init_state(); | |
65 update_state(); | |
59
1833de28583a
Turns out the init file is required.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
66 }); |