Mercurial > zeropaste
annotate app/assets/javascripts/init.tabs.js @ 136:b327d80c5ff9
Fixed indentation and spaces.
author | Edho Arief <edho@myconan.net> |
---|---|
date | Mon, 12 Nov 2012 17:42:37 +0700 |
parents | 0cd87e69dd65 |
children | 3241fe970c13 |
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; |
134
3c777dbd6b11
Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents:
133
diff
changeset
|
10 if (width == 'auto') { |
3c777dbd6b11
Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents:
133
diff
changeset
|
11 qstring = '#!'; |
3c777dbd6b11
Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents:
133
diff
changeset
|
12 if (mode != 'plain') { |
3c777dbd6b11
Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents:
133
diff
changeset
|
13 qstring += mode; |
3c777dbd6b11
Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents:
133
diff
changeset
|
14 } |
3c777dbd6b11
Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents:
133
diff
changeset
|
15 } |
3c777dbd6b11
Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents:
133
diff
changeset
|
16 window.location = qstring; |
3c777dbd6b11
Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents:
133
diff
changeset
|
17 }, |
3c777dbd6b11
Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents:
133
diff
changeset
|
18 paste_resize = function(size) { |
3c777dbd6b11
Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents:
133
diff
changeset
|
19 var paste = $('#paste'), |
3c777dbd6b11
Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents:
133
diff
changeset
|
20 title = $('#paste-resize a.btn'); |
3c777dbd6b11
Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents:
133
diff
changeset
|
21 title.html(title.html().replace(/(auto|\d+px)/, size)); |
3c777dbd6b11
Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents:
133
diff
changeset
|
22 if (size == 'auto') { |
3c777dbd6b11
Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents:
133
diff
changeset
|
23 paste.css('width', ''); |
3c777dbd6b11
Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents:
133
diff
changeset
|
24 paste.data('width', size); |
3c777dbd6b11
Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents:
133
diff
changeset
|
25 } else { |
3c777dbd6b11
Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents:
133
diff
changeset
|
26 paste.css('width', size); |
3c777dbd6b11
Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents:
133
diff
changeset
|
27 paste.data('width', size); |
3c777dbd6b11
Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents:
133
diff
changeset
|
28 } |
3c777dbd6b11
Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents:
133
diff
changeset
|
29 update_state(); |
135 | 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); | |
134
3c777dbd6b11
Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents:
133
diff
changeset
|
59 }; |
104 | 60 |
135 | 61 init_tabs_base(); |
62 init_tabs_menu(); | |
63 init_state(); | |
64 update_state(); | |
59
1833de28583a
Turns out the init file is required.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
65 }); |