Mercurial > zeropaste
annotate app/assets/javascripts/init.tabs.js @ 116:9ac24e112ea7
A more compact query string.
author | Edho Arief <edho@myconan.net> |
---|---|
date | Mon, 12 Nov 2012 13:36:38 +0700 |
parents | 546381cf83c2 |
children | e3f3402da5a1 |
rev | line source |
---|---|
59
1833de28583a
Turns out the init file is required.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
1 $(document).ready(function() { |
110
e8c632b0eb80
Check if current location is a show paste before triggering tabs js.
Edho Arief <edho@myconan.net>
parents:
109
diff
changeset
|
2 if ($('#paste-tabs').length == 1) { |
e8c632b0eb80
Check if current location is a show paste before triggering tabs js.
Edho Arief <edho@myconan.net>
parents:
109
diff
changeset
|
3 raw = $('#plain pre').text(); |
104 | 4 |
110
e8c632b0eb80
Check if current location is a show paste before triggering tabs js.
Edho Arief <edho@myconan.net>
parents:
109
diff
changeset
|
5 $('#highlight pre').text(raw); |
e8c632b0eb80
Check if current location is a show paste before triggering tabs js.
Edho Arief <edho@myconan.net>
parents:
109
diff
changeset
|
6 window.prettyPrint && prettyPrint(); |
104 | 7 |
110
e8c632b0eb80
Check if current location is a show paste before triggering tabs js.
Edho Arief <edho@myconan.net>
parents:
109
diff
changeset
|
8 $('#markdown div').html(marked(raw)); |
e8c632b0eb80
Check if current location is a show paste before triggering tabs js.
Edho Arief <edho@myconan.net>
parents:
109
diff
changeset
|
9 |
114
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
diff
changeset
|
10 update_state = function() { |
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
diff
changeset
|
11 var paste = $('#paste'), |
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
diff
changeset
|
12 mode = paste.data('mode'), |
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
diff
changeset
|
13 width = paste.data('width'), |
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
diff
changeset
|
14 qstring = '?' + mode + '.' + width; |
116 | 15 if (width == 'auto') { |
114
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
diff
changeset
|
16 qstring = '?'; |
116 | 17 if (mode != 'plain') { |
18 qstring += mode; | |
19 } | |
114
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
diff
changeset
|
20 } |
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
diff
changeset
|
21 history.replaceState(null, '', qstring); |
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
diff
changeset
|
22 }; |
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
diff
changeset
|
23 |
112
2b1041e8c35e
Allows parameter-based width passing. Requires switching to .search.
Edho Arief <edho@myconan.net>
parents:
111
diff
changeset
|
24 paste_resize = function(size) { |
2b1041e8c35e
Allows parameter-based width passing. Requires switching to .search.
Edho Arief <edho@myconan.net>
parents:
111
diff
changeset
|
25 var paste = $('#paste'), |
2b1041e8c35e
Allows parameter-based width passing. Requires switching to .search.
Edho Arief <edho@myconan.net>
parents:
111
diff
changeset
|
26 title = $('#tab-resize a.btn'); |
115
546381cf83c2
auto sounds better than full.
Edho Arief <edho@myconan.net>
parents:
114
diff
changeset
|
27 title.html(title.html().replace(/(auto|\d+px)/, size)); |
546381cf83c2
auto sounds better than full.
Edho Arief <edho@myconan.net>
parents:
114
diff
changeset
|
28 if (size == 'auto') { |
112
2b1041e8c35e
Allows parameter-based width passing. Requires switching to .search.
Edho Arief <edho@myconan.net>
parents:
111
diff
changeset
|
29 paste.css('width', ''); |
114
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
diff
changeset
|
30 paste.data('width', size); |
112
2b1041e8c35e
Allows parameter-based width passing. Requires switching to .search.
Edho Arief <edho@myconan.net>
parents:
111
diff
changeset
|
31 } else { |
2b1041e8c35e
Allows parameter-based width passing. Requires switching to .search.
Edho Arief <edho@myconan.net>
parents:
111
diff
changeset
|
32 paste.css('width', size); |
2b1041e8c35e
Allows parameter-based width passing. Requires switching to .search.
Edho Arief <edho@myconan.net>
parents:
111
diff
changeset
|
33 paste.data('width', size); |
2b1041e8c35e
Allows parameter-based width passing. Requires switching to .search.
Edho Arief <edho@myconan.net>
parents:
111
diff
changeset
|
34 } |
114
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
diff
changeset
|
35 update_state(); |
112
2b1041e8c35e
Allows parameter-based width passing. Requires switching to .search.
Edho Arief <edho@myconan.net>
parents:
111
diff
changeset
|
36 } |
108
a949b71c9afb
Allows paste content width resize.
Edho Arief <edho@myconan.net>
parents:
104
diff
changeset
|
37 |
114
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
diff
changeset
|
38 $('#paste-tabs > li > a').click(function() { |
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
diff
changeset
|
39 $('#paste').data('mode', $(this).prop('href').split('#')[1]); |
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
diff
changeset
|
40 update_state(); |
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
diff
changeset
|
41 }); |
110
e8c632b0eb80
Check if current location is a show paste before triggering tabs js.
Edho Arief <edho@myconan.net>
parents:
109
diff
changeset
|
42 $('#tab-resize ul a').click(function() { |
112
2b1041e8c35e
Allows parameter-based width passing. Requires switching to .search.
Edho Arief <edho@myconan.net>
parents:
111
diff
changeset
|
43 paste_resize($(this).data('size')); |
110
e8c632b0eb80
Check if current location is a show paste before triggering tabs js.
Edho Arief <edho@myconan.net>
parents:
109
diff
changeset
|
44 }); |
112
2b1041e8c35e
Allows parameter-based width passing. Requires switching to .search.
Edho Arief <edho@myconan.net>
parents:
111
diff
changeset
|
45 |
2b1041e8c35e
Allows parameter-based width passing. Requires switching to .search.
Edho Arief <edho@myconan.net>
parents:
111
diff
changeset
|
46 mode = window.location.search.substr(1).split('.'); |
114
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
diff
changeset
|
47 if (mode[0] == 'highlight') { $('#paste-tabs li:eq(1) a').click(); } |
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
diff
changeset
|
48 else if (mode[0] == 'markdown') { $('#paste-tabs li:eq(2) a').click(); } |
112
2b1041e8c35e
Allows parameter-based width passing. Requires switching to .search.
Edho Arief <edho@myconan.net>
parents:
111
diff
changeset
|
49 if (mode[1] && mode[1].match(/^\d+px$/)) { paste_resize(mode[1]); } |
114
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
diff
changeset
|
50 |
110
e8c632b0eb80
Check if current location is a show paste before triggering tabs js.
Edho Arief <edho@myconan.net>
parents:
109
diff
changeset
|
51 } |
59
1833de28583a
Turns out the init file is required.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
52 }); |