annotate app/assets/javascripts/init.tabs.js @ 142:113ee07f1871

Added link for donation.
author Edho Arief <edho@myconan.net>
date Tue, 13 Nov 2012 23:50:05 +0700
parents 2104f0c477c0
children b56ad3caed6d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
10 if (width == 'auto') {
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
11 qstring = '#!';
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
12 if (mode != 'plain') {
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
13 qstring += mode;
134
3c777dbd6b11 Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents: 133
diff changeset
14 }
137
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
15 }
141
2104f0c477c0 Use replaceState afterall for browsers supporting it.
Edho Arief <edho@myconan.net>
parents: 140
diff changeset
16 if (history.replaceState) {
2104f0c477c0 Use replaceState afterall for browsers supporting it.
Edho Arief <edho@myconan.net>
parents: 140
diff changeset
17 history.replaceState(null, '', qstring);
2104f0c477c0 Use replaceState afterall for browsers supporting it.
Edho Arief <edho@myconan.net>
parents: 140
diff changeset
18 } else {
2104f0c477c0 Use replaceState afterall for browsers supporting it.
Edho Arief <edho@myconan.net>
parents: 140
diff changeset
19 window.location = qstring;
2104f0c477c0 Use replaceState afterall for browsers supporting it.
Edho Arief <edho@myconan.net>
parents: 140
diff changeset
20 }
140
13ada93ad6a2 Return false on update state.
Edho Arief <edho@myconan.net>
parents: 137
diff changeset
21 return false;
137
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
22 },
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
23 paste_resize = function(size) {
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
24 var paste = $('#paste'),
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
25 title = $('#paste-resize a.btn');
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
26 title.html(title.html().replace(/(auto|\d+px)/, size));
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
27 if (size == 'auto') {
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
28 paste.css('width', '');
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
29 paste.data('width', size);
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
30 } else {
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
31 paste.css('width', size);
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
32 paste.data('width', size);
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
33 }
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
34 update_state();
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
35 },
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
36 paste_resize_menu_handler = function() {
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
37 paste_resize($(this).data('size'));
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
38 $('.open').removeClass('open');
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
39 return false;
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
40 },
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
41 paste_mode_state_handler = function() {
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
42 $('#paste').data('mode', $(this).prop('href').split('#')[1]);
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
43 update_state();
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
44 },
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
45 init_state = function() {
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
46 mode = window.location.hash.substr(2).split('.');
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
47 if (mode[0] == 'highlight') { $('#paste-mode a:eq(1)').click(); }
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
48 else if (mode[0] == 'markdown') { $('#paste-mode a:eq(2)').click(); };
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
49 if (mode[1] && mode[1].match(/^\d+px$/)) { paste_resize(mode[1]); }
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
50 },
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
51 init_tabs_base = function() {
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
52 var raw = $('#plain pre').text(),
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
53 markdown = $('#markdown div');
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
54 markdown.html(marked(raw));
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
55 $('#highlight pre').text(raw);
135
0cd87e69dd65 Reorganize.
Edho Arief <edho@myconan.net>
parents: 134
diff changeset
56
137
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
57 markdown.find('pre').addClass('prettyprint');
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
58 markdown.find('a').prop('rel', 'nofollow');
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
59 prettyPrint();
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
60 },
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
61 init_tabs_menu = function() {
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
62 $('#paste-mode a').click(paste_mode_state_handler);
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
63 $('#paste-resize ul a').click(paste_resize_menu_handler);
3241fe970c13 Yet another indentation fix.
Edho Arief <edho@myconan.net>
parents: 136
diff changeset
64 };
104
9825e51ba30f Minor reorganization.
Edho Arief <edho@myconan.net>
parents: 103
diff changeset
65
135
0cd87e69dd65 Reorganize.
Edho Arief <edho@myconan.net>
parents: 134
diff changeset
66 init_tabs_base();
0cd87e69dd65 Reorganize.
Edho Arief <edho@myconan.net>
parents: 134
diff changeset
67 init_tabs_menu();
0cd87e69dd65 Reorganize.
Edho Arief <edho@myconan.net>
parents: 134
diff changeset
68 init_state();
0cd87e69dd65 Reorganize.
Edho Arief <edho@myconan.net>
parents: 134
diff changeset
69 update_state();
59
1833de28583a Turns out the init file is required.
Edho Arief <edho@myconan.net>
parents:
diff changeset
70 });