Skip to content

Commit 1339fba

Browse files
committed
Merge pull request #3989 from wlanslovenija/delay-javascript
Run JavaScript only when DOM is ready
2 parents f1a4e9a + 2f49df8 commit 1339fba

File tree

1 file changed

+37
-35
lines changed

1 file changed

+37
-35
lines changed

rest_framework/static/rest_framework/js/default.js

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,47 +19,49 @@ function getCookie(c_name)
1919
return c_value;
2020
}
2121

22-
// JSON highlighting.
23-
prettyPrint();
22+
$(document).ready(function () {
23+
// JSON highlighting.
24+
prettyPrint();
2425

25-
// Bootstrap tooltips.
26-
$('.js-tooltip').tooltip({
27-
delay: 1000,
28-
container: 'body'
29-
});
26+
// Bootstrap tooltips.
27+
$('.js-tooltip').tooltip({
28+
delay: 1000,
29+
container: 'body'
30+
});
3031

31-
// Deal with rounded tab styling after tab clicks.
32-
$('a[data-toggle="tab"]:first').on('shown', function (e) {
33-
$(e.target).parents('.tabbable').addClass('first-tab-active');
34-
});
35-
$('a[data-toggle="tab"]:not(:first)').on('shown', function (e) {
36-
$(e.target).parents('.tabbable').removeClass('first-tab-active');
37-
});
32+
// Deal with rounded tab styling after tab clicks.
33+
$('a[data-toggle="tab"]:first').on('shown', function (e) {
34+
$(e.target).parents('.tabbable').addClass('first-tab-active');
35+
});
36+
$('a[data-toggle="tab"]:not(:first)').on('shown', function (e) {
37+
$(e.target).parents('.tabbable').removeClass('first-tab-active');
38+
});
3839

39-
$('a[data-toggle="tab"]').click(function(){
40-
document.cookie="tabstyle=" + this.name + "; path=/";
41-
});
40+
$('a[data-toggle="tab"]').click(function(){
41+
document.cookie="tabstyle=" + this.name + "; path=/";
42+
});
4243

43-
// Store tab preference in cookies & display appropriate tab on load.
44-
var selectedTab = null;
45-
var selectedTabName = getCookie('tabstyle');
44+
// Store tab preference in cookies & display appropriate tab on load.
45+
var selectedTab = null;
46+
var selectedTabName = getCookie('tabstyle');
4647

47-
if (selectedTabName) {
48-
selectedTabName = selectedTabName.replace(/[^a-z-]/g, '');
49-
}
48+
if (selectedTabName) {
49+
selectedTabName = selectedTabName.replace(/[^a-z-]/g, '');
50+
}
5051

51-
if (selectedTabName) {
52-
selectedTab = $('.form-switcher a[name=' + selectedTabName + ']');
53-
}
52+
if (selectedTabName) {
53+
selectedTab = $('.form-switcher a[name=' + selectedTabName + ']');
54+
}
5455

55-
if (selectedTab && selectedTab.length > 0) {
56-
// Display whichever tab is selected.
57-
selectedTab.tab('show');
58-
} else {
59-
// If no tab selected, display rightmost tab.
60-
$('.form-switcher a:first').tab('show');
61-
}
56+
if (selectedTab && selectedTab.length > 0) {
57+
// Display whichever tab is selected.
58+
selectedTab.tab('show');
59+
} else {
60+
// If no tab selected, display rightmost tab.
61+
$('.form-switcher a:first').tab('show');
62+
}
6263

63-
$(window).load(function(){
64-
$('#errorModal').modal('show');
64+
$(window).load(function(){
65+
$('#errorModal').modal('show');
66+
});
6567
});

0 commit comments

Comments
 (0)