Mercurial > zeropaste
annotate app/assets/javascripts/init.tabs.js @ 126:bf214f66874d
Reverted customizations to bootstrap.
author | Edho Arief <edho@myconan.net> |
---|---|
date | Mon, 12 Nov 2012 16:36:03 +0700 |
parents | 64f73525503b |
children | 426fb7bb44bb |
rev | line source |
---|---|
59
1833de28583a
Turns out the init file is required.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
1 $(document).ready(function() { |
125
64f73525503b
Use button toolbar instead of nav.
Edho Arief <edho@myconan.net>
parents:
124
diff
changeset
|
2 if ($('#paste-show').length == 1) { |
110
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 |
124
4a8cefa814f1
Options for marked (enabling sanitize).
Edho Arief <edho@myconan.net>
parents:
123
diff
changeset
|
5 marked.setOptions({ |
4a8cefa814f1
Options for marked (enabling sanitize).
Edho Arief <edho@myconan.net>
parents:
123
diff
changeset
|
6 gfm: true, |
4a8cefa814f1
Options for marked (enabling sanitize).
Edho Arief <edho@myconan.net>
parents:
123
diff
changeset
|
7 pedantic: false, |
4a8cefa814f1
Options for marked (enabling sanitize).
Edho Arief <edho@myconan.net>
parents:
123
diff
changeset
|
8 sanitize: true |
4a8cefa814f1
Options for marked (enabling sanitize).
Edho Arief <edho@myconan.net>
parents:
123
diff
changeset
|
9 }); |
120 | 10 $('#markdown div').html(marked(raw)); |
11 $('#markdown div pre').addClass('prettyprint'); | |
121
dd7181c021de
Add rel=nofollow to links in markdown.
Edho Arief <edho@myconan.net>
parents:
120
diff
changeset
|
12 $('#markdown div a').prop('rel', 'nofollow'); |
120 | 13 |
110
e8c632b0eb80
Check if current location is a show paste before triggering tabs js.
Edho Arief <edho@myconan.net>
parents:
109
diff
changeset
|
14 $('#highlight pre').text(raw); |
120 | 15 |
110
e8c632b0eb80
Check if current location is a show paste before triggering tabs js.
Edho Arief <edho@myconan.net>
parents:
109
diff
changeset
|
16 window.prettyPrint && prettyPrint(); |
104 | 17 |
114
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
diff
changeset
|
18 update_state = function() { |
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
diff
changeset
|
19 var paste = $('#paste'), |
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
diff
changeset
|
20 mode = paste.data('mode'), |
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
diff
changeset
|
21 width = paste.data('width'), |
123
5b58b0d6841c
Use hashbang instead of plain hash.
Edho Arief <edho@myconan.net>
parents:
122
diff
changeset
|
22 qstring = '#!' + mode + '.' + width; |
116 | 23 if (width == 'auto') { |
123
5b58b0d6841c
Use hashbang instead of plain hash.
Edho Arief <edho@myconan.net>
parents:
122
diff
changeset
|
24 qstring = '#!'; |
116 | 25 if (mode != 'plain') { |
26 qstring += mode; | |
27 } | |
114
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
diff
changeset
|
28 } |
122
a836cfe4092f
Use hash instead of search because IE can't into replaceState.
Edho Arief <edho@myconan.net>
parents:
121
diff
changeset
|
29 window.location = qstring; |
114
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
diff
changeset
|
30 }; |
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
diff
changeset
|
31 |
112
2b1041e8c35e
Allows parameter-based width passing. Requires switching to .search.
Edho Arief <edho@myconan.net>
parents:
111
diff
changeset
|
32 paste_resize = function(size) { |
2b1041e8c35e
Allows parameter-based width passing. Requires switching to .search.
Edho Arief <edho@myconan.net>
parents:
111
diff
changeset
|
33 var paste = $('#paste'), |
125
64f73525503b
Use button toolbar instead of nav.
Edho Arief <edho@myconan.net>
parents:
124
diff
changeset
|
34 title = $('#paste-resize a.btn'); |
115
546381cf83c2
auto sounds better than full.
Edho Arief <edho@myconan.net>
parents:
114
diff
changeset
|
35 title.html(title.html().replace(/(auto|\d+px)/, size)); |
546381cf83c2
auto sounds better than full.
Edho Arief <edho@myconan.net>
parents:
114
diff
changeset
|
36 if (size == 'auto') { |
112
2b1041e8c35e
Allows parameter-based width passing. Requires switching to .search.
Edho Arief <edho@myconan.net>
parents:
111
diff
changeset
|
37 paste.css('width', ''); |
114
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
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 } else { |
2b1041e8c35e
Allows parameter-based width passing. Requires switching to .search.
Edho Arief <edho@myconan.net>
parents:
111
diff
changeset
|
40 paste.css('width', size); |
2b1041e8c35e
Allows parameter-based width passing. Requires switching to .search.
Edho Arief <edho@myconan.net>
parents:
111
diff
changeset
|
41 paste.data('width', size); |
2b1041e8c35e
Allows parameter-based width passing. Requires switching to .search.
Edho Arief <edho@myconan.net>
parents:
111
diff
changeset
|
42 } |
114
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
diff
changeset
|
43 update_state(); |
112
2b1041e8c35e
Allows parameter-based width passing. Requires switching to .search.
Edho Arief <edho@myconan.net>
parents:
111
diff
changeset
|
44 } |
108
a949b71c9afb
Allows paste content width resize.
Edho Arief <edho@myconan.net>
parents:
104
diff
changeset
|
45 |
125
64f73525503b
Use button toolbar instead of nav.
Edho Arief <edho@myconan.net>
parents:
124
diff
changeset
|
46 $('#paste-mode a').click(function() { |
114
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
diff
changeset
|
47 $('#paste').data('mode', $(this).prop('href').split('#')[1]); |
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
diff
changeset
|
48 update_state(); |
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
diff
changeset
|
49 }); |
125
64f73525503b
Use button toolbar instead of nav.
Edho Arief <edho@myconan.net>
parents:
124
diff
changeset
|
50 $('#paste-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
|
51 paste_resize($(this).data('size')); |
118
e3f3402da5a1
Takeover handling link clicking on dropdown menu.
Edho Arief <edho@myconan.net>
parents:
116
diff
changeset
|
52 $('.open').removeClass('open'); |
e3f3402da5a1
Takeover handling link clicking on dropdown menu.
Edho Arief <edho@myconan.net>
parents:
116
diff
changeset
|
53 return false; |
110
e8c632b0eb80
Check if current location is a show paste before triggering tabs js.
Edho Arief <edho@myconan.net>
parents:
109
diff
changeset
|
54 }); |
112
2b1041e8c35e
Allows parameter-based width passing. Requires switching to .search.
Edho Arief <edho@myconan.net>
parents:
111
diff
changeset
|
55 |
123
5b58b0d6841c
Use hashbang instead of plain hash.
Edho Arief <edho@myconan.net>
parents:
122
diff
changeset
|
56 mode = window.location.hash.substr(2).split('.'); |
114
b72f99d7b8cf
Dynamic url based on options selected.
Edho Arief <edho@myconan.net>
parents:
112
diff
changeset
|
57 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
|
58 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
|
59 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
|
60 |
110
e8c632b0eb80
Check if current location is a show paste before triggering tabs js.
Edho Arief <edho@myconan.net>
parents:
109
diff
changeset
|
61 } |
59
1833de28583a
Turns out the init file is required.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
62 }); |