|
1 | 1 | $(function() { |
2 | | - $('ul.tab-nav li a.button').click(function(e) { |
3 | | - e.preventDefault(); |
4 | | - activeTab($(this).attr('href')); |
5 | | - return false; |
6 | | - }); |
7 | | - |
8 | | - if (location.hash !== '') { |
9 | | - activeTab(location.hash); |
10 | | - } else { |
11 | | - activeTab('#private'); |
12 | | - } |
| 2 | + setTimeout(() => { |
| 3 | + window.scrollTo(0, 0); |
| 4 | + }, 0); |
| 5 | + $('ul.tab-nav li a.button').click(function(e) { |
| 6 | + e.preventDefault(); |
| 7 | + activeTab($(this).attr('href')); |
| 8 | + return false; |
| 9 | + }); |
13 | 10 |
|
14 | | - function activeTab(tab) { |
| 11 | + if (location.hash !== '') { |
| 12 | + activeTab(location.hash); |
| 13 | + } else { |
| 14 | + activeTab('#private'); |
| 15 | + } |
15 | 16 |
|
16 | | - let button = $('ul.tab-nav li a.button[href="' + tab + '"]'); |
17 | | - let pane = $('div.tab-content div.tab-pane[id="' + tab.slice(1) + '"]'); |
| 17 | + function activeTab(tab) { |
18 | 18 |
|
19 | | - $('ul.tab-nav li a.button.active').removeClass('active'); |
20 | | - button.addClass('active'); |
| 19 | + let button = $('ul.tab-nav li a.button[href="' + tab + '"]'); |
| 20 | + let pane = $('div.tab-content div.tab-pane[id="' + tab.slice(1) + '"]'); |
21 | 21 |
|
22 | | - $('div.tab-content div.tab-pane.active').removeClass('active'); |
23 | | - pane.addClass('active'); |
| 22 | + $('ul.tab-nav li a.button.active').removeClass('active'); |
| 23 | + button.addClass('active'); |
24 | 24 |
|
25 | | - if (history.pushState) { |
26 | | - history.pushState({}, 'RandomAPI :: View Snippets', `view/snippet${tab}`); |
27 | | - } else { |
28 | | - location.hash = tab; |
29 | | - } |
| 25 | + $('div.tab-content div.tab-pane.active').removeClass('active'); |
| 26 | + pane.addClass('active'); |
30 | 27 |
|
31 | | - return false; |
| 28 | + if (history.pushState) { |
| 29 | + history.pushState({}, 'RandomAPI :: View Snippets', `view/snippet${tab}`); |
| 30 | + } else { |
| 31 | + location.hash = tab; |
32 | 32 | } |
33 | 33 |
|
34 | | - $("select[name='revision']").change(updateRevision); |
| 34 | + return false; |
| 35 | + } |
35 | 36 |
|
36 | | - function updateRevision() { |
37 | | - let self = this; |
38 | | - let code = $(this).parent().siblings('td').children('a[name="codeSnippet"]'); |
39 | | - let edit = $(this).parent().siblings('td').children('a[name="editSnippet"]'); |
| 37 | + $("select[name='revision']").change(updateRevision); |
40 | 38 |
|
41 | | - let codeIndex = code.attr('href').lastIndexOf('/'); |
42 | | - let editIndex = edit.attr('href').lastIndexOf('/'); |
| 39 | + function updateRevision() { |
| 40 | + let self = this; |
| 41 | + let code = $(this).parent().siblings('td').children('a[name="codeSnippet"]'); |
| 42 | + let edit = $(this).parent().siblings('td').children('a[name="editSnippet"]'); |
43 | 43 |
|
44 | | - code.attr('href', code.attr('href').slice(0, codeIndex) + '/' + $(this).val()); |
45 | | - edit.attr('href', edit.attr('href').slice(0, editIndex) + '/' + $(this).val()); |
| 44 | + let codeIndex = code.attr('href').lastIndexOf('/'); |
| 45 | + let editIndex = edit.attr('href').lastIndexOf('/'); |
46 | 46 |
|
47 | | - let created = $(this).parent().siblings('td').children('span[name="created"]'); |
48 | | - let modified = $(this).parent().siblings('td').children('span[name="modified"]'); |
| 47 | + code.attr('href', code.attr('href').slice(0, codeIndex) + '/' + $(this).val()); |
| 48 | + edit.attr('href', edit.attr('href').slice(0, editIndex) + '/' + $(this).val()); |
49 | 49 |
|
50 | | - $.when($.ajax(`ajax/snippetLookup/${$(this).closest('tr').data('ref')}/${$(this).val()}`)).then(function(data) { |
51 | | - if (data.published === 1) { |
52 | | - code.html('View Snippet'); |
53 | | - } else { |
54 | | - code.html('Code Snippet'); |
55 | | - } |
56 | | - }); |
57 | | - } |
58 | | - |
59 | | - $('select').each(function () { |
60 | | - var select = $(this); |
61 | | - var selectedValue = select.find('option[selected]').val(); |
| 50 | + let created = $(this).parent().siblings('td').children('span[name="created"]'); |
| 51 | + let modified = $(this).parent().siblings('td').children('span[name="modified"]'); |
62 | 52 |
|
63 | | - if (selectedValue) { |
64 | | - select.val(selectedValue); |
| 53 | + $.when($.ajax(`ajax/snippetLookup/${$(this).closest('tr').data('ref')}/${$(this).val()}`)).then(function(data) { |
| 54 | + if (data.published === 1) { |
| 55 | + code.html('View Snippet'); |
65 | 56 | } else { |
66 | | - select.prop('selectedIndex', 0); |
| 57 | + code.html('Code Snippet'); |
67 | 58 | } |
68 | 59 | }); |
| 60 | + } |
| 61 | + |
| 62 | + $('select').each(function () { |
| 63 | + var select = $(this); |
| 64 | + var selectedValue = select.find('option[selected]').val(); |
| 65 | + |
| 66 | + if (selectedValue) { |
| 67 | + select.val(selectedValue); |
| 68 | + } else { |
| 69 | + select.prop('selectedIndex', 0); |
| 70 | + } |
| 71 | + }); |
69 | 72 | }); |
70 | 73 |
|
71 | 74 | function revisionPublishPrompt(ref, name, rev) { |
|
0 commit comments