annotate app/assets/javascripts/init.tabs.js @ 134:3c777dbd6b11

Moved function declarations to beginning.
author Edho Arief <edho@myconan.net>
date Mon, 12 Nov 2012 17:30:22 +0700
parents 342373709d16
children 0cd87e69dd65
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 }
131
7c7601575358 Moved $('#markdown div') to variable.
Edho Arief <edho@myconan.net>
parents: 130
diff changeset
5 var raw = $('#plain pre').text(),
134
3c777dbd6b11 Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents: 133
diff changeset
6 markdown = $('#markdown div'),
3c777dbd6b11 Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents: 133
diff changeset
7 update_state = function() {
3c777dbd6b11 Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents: 133
diff changeset
8 var paste = $('#paste'),
3c777dbd6b11 Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents: 133
diff changeset
9 mode = paste.data('mode'),
3c777dbd6b11 Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents: 133
diff changeset
10 width = paste.data('width'),
3c777dbd6b11 Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents: 133
diff changeset
11 qstring = '#!' + mode + '.' + width;
3c777dbd6b11 Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents: 133
diff changeset
12 if (width == 'auto') {
3c777dbd6b11 Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents: 133
diff changeset
13 qstring = '#!';
3c777dbd6b11 Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents: 133
diff changeset
14 if (mode != 'plain') {
3c777dbd6b11 Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents: 133
diff changeset
15 qstring += mode;
3c777dbd6b11 Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents: 133
diff changeset
16 }
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 window.location = qstring;
3c777dbd6b11 Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents: 133
diff changeset
19 },
3c777dbd6b11 Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents: 133
diff changeset
20 paste_resize = function(size) {
3c777dbd6b11 Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents: 133
diff changeset
21 var paste = $('#paste'),
3c777dbd6b11 Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents: 133
diff changeset
22 title = $('#paste-resize a.btn');
3c777dbd6b11 Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents: 133
diff changeset
23 title.html(title.html().replace(/(auto|\d+px)/, size));
3c777dbd6b11 Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents: 133
diff changeset
24 if (size == 'auto') {
3c777dbd6b11 Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents: 133
diff changeset
25 paste.css('width', '');
3c777dbd6b11 Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents: 133
diff changeset
26 paste.data('width', size);
3c777dbd6b11 Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents: 133
diff changeset
27 } else {
3c777dbd6b11 Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents: 133
diff changeset
28 paste.css('width', size);
3c777dbd6b11 Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents: 133
diff changeset
29 paste.data('width', size);
3c777dbd6b11 Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents: 133
diff changeset
30 }
3c777dbd6b11 Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents: 133
diff changeset
31 update_state();
3c777dbd6b11 Moved function declarations to beginning.
Edho Arief <edho@myconan.net>
parents: 133
diff changeset
32 };
104
9825e51ba30f Minor reorganization.
Edho Arief <edho@myconan.net>
parents: 103
diff changeset
33
131
7c7601575358 Moved $('#markdown div') to variable.
Edho Arief <edho@myconan.net>
parents: 130
diff changeset
34 markdown.html(marked(raw));
132
e05e47f7d224 Add raw texts first before doing anything with them.
Edho Arief <edho@myconan.net>
parents: 131
diff changeset
35 $('#highlight pre').text(raw);
e05e47f7d224 Add raw texts first before doing anything with them.
Edho Arief <edho@myconan.net>
parents: 131
diff changeset
36
131
7c7601575358 Moved $('#markdown div') to variable.
Edho Arief <edho@myconan.net>
parents: 130
diff changeset
37 markdown.find('pre').addClass('prettyprint');
7c7601575358 Moved $('#markdown div') to variable.
Edho Arief <edho@myconan.net>
parents: 130
diff changeset
38 markdown.find('a').prop('rel', 'nofollow');
133
342373709d16 No need to test window.prettyPrint.
Edho Arief <edho@myconan.net>
parents: 132
diff changeset
39 prettyPrint();
104
9825e51ba30f Minor reorganization.
Edho Arief <edho@myconan.net>
parents: 103
diff changeset
40
129
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
41 $('#paste-mode a').click(function() {
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
42 $('#paste').data('mode', $(this).prop('href').split('#')[1]);
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
43 update_state();
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
44 });
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
45 $('#paste-resize ul a').click(function() {
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
46 paste_resize($(this).data('size'));
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
47 $('.open').removeClass('open');
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
48 return false;
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
49 });
112
2b1041e8c35e Allows parameter-based width passing. Requires switching to .search.
Edho Arief <edho@myconan.net>
parents: 111
diff changeset
50
129
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
51 mode = window.location.hash.substr(2).split('.');
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
52 if (mode[0] == 'highlight') { $('#paste-mode a:eq(1)').click(); }
130
64523785ad24 Added semicolon.
Edho Arief <edho@myconan.net>
parents: 129
diff changeset
53 else if (mode[0] == 'markdown') { $('#paste-mode a:eq(2)').click(); };
129
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
54 if (mode[1] && mode[1].match(/^\d+px$/)) { paste_resize(mode[1]); }
59
1833de28583a Turns out the init file is required.
Edho Arief <edho@myconan.net>
parents:
diff changeset
55 });