annotate app/assets/javascripts/init.tabs.js @ 131:7c7601575358

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