Skip to content

Commit f0d34e8

Browse files
author
root
committed
Move JS function to JS file
1 parent d478794 commit f0d34e8

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

Diff for: app/views/repositories/_edit_bottom.html.haml

+1-21
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,5 @@
2020
- if User.current.git_allowed_to?(:view_repository_protected_branches, @repository)
2121
%li{ id: 'tab-repository_protected_branches' }= link_to label_with_icon(l(:label_protected_branches), 'fa-shield'), repository_protected_branches_path(@repository)
2222

23-
2423
:javascript
25-
$(document).ready(function() {
26-
var all_tabs = $("#repository-tabs li");
27-
var active_tab = '';
28-
29-
all_tabs.each(function(){
30-
if ($(this).attr('id').replace('tab-', '') == '#{@tab}') {
31-
active_tab = all_tabs.index(this);
32-
}
33-
});
34-
35-
$("#repository-tabs").tabs({
36-
active: active_tab,
37-
activate: function(event, ui) {
38-
var new_tab_name = $(ui.newTab).attr('id').replace('tab-', '');
39-
if ("replaceState" in window.history) {
40-
window.history.replaceState(null, document.title, 'edit?tab=' + new_tab_name);
41-
}
42-
}
43-
});
44-
});
24+
$(document).ready(function() { setRepositoryActiveTab('#{@tab}'); });

Diff for: assets/javascripts/application.js

+21
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,24 @@ function bindGitUrls(elements) {
6161
});
6262
});
6363
}
64+
65+
function setRepositoryActiveTab(current_tab) {
66+
var all_tabs = $("#repository-tabs li");
67+
var active_tab = '';
68+
69+
all_tabs.each(function(){
70+
if ($(this).attr('id').replace('tab-', '') == current_tab) {
71+
active_tab = all_tabs.index(this);
72+
}
73+
});
74+
75+
$("#repository-tabs").tabs({
76+
active: active_tab,
77+
activate: function(event, ui) {
78+
var new_tab_name = $(ui.newTab).attr('id').replace('tab-', '');
79+
if ("replaceState" in window.history) {
80+
window.history.replaceState(null, document.title, 'edit?tab=' + new_tab_name);
81+
}
82+
}
83+
});
84+
}

0 commit comments

Comments
 (0)