annotate app/assets/javascripts/init.tabs.js @ 130:64523785ad24

Added semicolon.
author Edho Arief <edho@myconan.net>
date Mon, 12 Nov 2012 17:25:47 +0700
parents 0785824a20b9
children 7c7601575358
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 }
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
5 raw = $('#plain pre').text();
104
9825e51ba30f Minor reorganization.
Edho Arief <edho@myconan.net>
parents: 103
diff changeset
6
129
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
7 $('#markdown div').html(marked(raw));
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
8 $('#markdown div pre').addClass('prettyprint');
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
9 $('#markdown div a').prop('rel', 'nofollow');
120
309238f5b7b1 Prettyprint in markdown.
Edho Arief <edho@myconan.net>
parents: 118
diff changeset
10
129
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
11 $('#highlight pre').text(raw);
120
309238f5b7b1 Prettyprint in markdown.
Edho Arief <edho@myconan.net>
parents: 118
diff changeset
12
129
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
13 window.prettyPrint && prettyPrint();
104
9825e51ba30f Minor reorganization.
Edho Arief <edho@myconan.net>
parents: 103
diff changeset
14
129
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
15 update_state = function() {
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
16 var paste = $('#paste'),
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
17 mode = paste.data('mode'),
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
18 width = paste.data('width'),
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
19 qstring = '#!' + mode + '.' + width;
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
20 if (width == 'auto') {
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
21 qstring = '#!';
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
22 if (mode != 'plain') {
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
23 qstring += mode;
114
b72f99d7b8cf Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents: 112
diff changeset
24 }
129
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
25 }
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
26 window.location = qstring;
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
27 };
114
b72f99d7b8cf Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents: 112
diff changeset
28
129
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
29 paste_resize = function(size) {
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
30 var paste = $('#paste'),
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
31 title = $('#paste-resize a.btn');
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
32 title.html(title.html().replace(/(auto|\d+px)/, size));
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
33 if (size == 'auto') {
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
34 paste.css('width', '');
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
35 paste.data('width', size);
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
36 } else {
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
37 paste.css('width', size);
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
38 paste.data('width', size);
112
2b1041e8c35e Allows parameter-based width passing. Requires switching to .search.
Edho Arief <edho@myconan.net>
parents: 111
diff changeset
39 }
129
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
40 update_state();
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
41 }
108
a949b71c9afb Allows paste content width resize.
Edho Arief <edho@myconan.net>
parents: 104
diff changeset
42
129
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
43 $('#paste-mode a').click(function() {
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
44 $('#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
45 update_state();
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
46 });
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
47 $('#paste-resize ul a').click(function() {
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
48 paste_resize($(this).data('size'));
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
49 $('.open').removeClass('open');
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
50 return false;
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
51 });
112
2b1041e8c35e Allows parameter-based width passing. Requires switching to .search.
Edho Arief <edho@myconan.net>
parents: 111
diff changeset
52
129
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
53 mode = window.location.hash.substr(2).split('.');
0785824a20b9 Return immediately if not in pastes#show.
Edho Arief <edho@myconan.net>
parents: 128
diff changeset
54 if (mode[0] == 'highlight') { $('#paste-mode a:eq(1)').click(); }
130
64523785ad24 Added semicolon.
Edho Arief <edho@myconan.net>
parents: 129
diff changeset
55 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
56 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
57 });