Mercurial > zeropaste
annotate app/assets/javascripts/init.tabs.js @ 183:fc234f8cf3d9
Return on duplicate based on post format.
author | Edho Arief <edho@myconan.net> |
---|---|
date | Tue, 12 Feb 2013 11:32:14 +0900 |
parents | 601c608637e7 |
children | c054f01477c4 |
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') { |
144
b56ad3caed6d
Remove hash on `#!plain.auto`.
Edho Arief <edho@myconan.net>
parents:
141
diff
changeset
|
11 if (mode == 'plain') { |
b56ad3caed6d
Remove hash on `#!plain.auto`.
Edho Arief <edho@myconan.net>
parents:
141
diff
changeset
|
12 qstring = ' '; |
b56ad3caed6d
Remove hash on `#!plain.auto`.
Edho Arief <edho@myconan.net>
parents:
141
diff
changeset
|
13 } else { |
146 | 14 qstring = '#!' + mode; |
134
3c777dbd6b11
Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents:
133
diff
changeset
|
15 } |
137 | 16 } |
141
2104f0c477c0
Use replaceState afterall for browsers supporting it.
Edho Arief <edho@myconan.net>
parents:
140
diff
changeset
|
17 if (history.replaceState) { |
2104f0c477c0
Use replaceState afterall for browsers supporting it.
Edho Arief <edho@myconan.net>
parents:
140
diff
changeset
|
18 history.replaceState(null, '', qstring); |
2104f0c477c0
Use replaceState afterall for browsers supporting it.
Edho Arief <edho@myconan.net>
parents:
140
diff
changeset
|
19 } else { |
2104f0c477c0
Use replaceState afterall for browsers supporting it.
Edho Arief <edho@myconan.net>
parents:
140
diff
changeset
|
20 window.location = qstring; |
2104f0c477c0
Use replaceState afterall for browsers supporting it.
Edho Arief <edho@myconan.net>
parents:
140
diff
changeset
|
21 } |
140
13ada93ad6a2
Return false on update state.
Edho Arief <edho@myconan.net>
parents:
137
diff
changeset
|
22 return false; |
137 | 23 }, |
24 paste_resize = function(size) { | |
25 var paste = $('#paste'), | |
26 title = $('#paste-resize a.btn'); | |
27 title.html(title.html().replace(/(auto|\d+px)/, size)); | |
28 if (size == 'auto') { | |
29 paste.css('width', ''); | |
30 paste.data('width', size); | |
31 } else { | |
32 paste.css('width', size); | |
33 paste.data('width', size); | |
34 } | |
35 update_state(); | |
36 }, | |
37 paste_resize_menu_handler = function() { | |
38 paste_resize($(this).data('size')); | |
39 $('.open').removeClass('open'); | |
40 return false; | |
41 }, | |
42 paste_mode_state_handler = function() { | |
43 $('#paste').data('mode', $(this).prop('href').split('#')[1]); | |
44 update_state(); | |
45 }, | |
46 init_state = function() { | |
47 mode = window.location.hash.substr(2).split('.'); | |
48 if (mode[0] == 'highlight') { $('#paste-mode a:eq(1)').click(); } | |
49 else if (mode[0] == 'markdown') { $('#paste-mode a:eq(2)').click(); }; | |
50 if (mode[1] && mode[1].match(/^\d+px$/)) { paste_resize(mode[1]); } | |
51 }, | |
52 init_tabs_base = function() { | |
53 var raw = $('#plain pre').text(), | |
54 markdown = $('#markdown div'); | |
55 markdown.html(marked(raw)); | |
56 $('#highlight pre').text(raw); | |
135 | 57 |
137 | 58 markdown.find('pre').addClass('prettyprint'); |
59 markdown.find('a').prop('rel', 'nofollow'); | |
60 prettyPrint(); | |
61 }, | |
62 init_tabs_menu = function() { | |
63 $('#paste-mode a').click(paste_mode_state_handler); | |
64 $('#paste-resize ul a').click(paste_resize_menu_handler); | |
65 }; | |
104 | 66 |
135 | 67 init_tabs_base(); |
68 init_tabs_menu(); | |
69 init_state(); | |
70 update_state(); | |
59
1833de28583a
Turns out the init file is required.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
71 }); |