Skip to content

Commit ed74a1c

Browse files
committed
Updated toolbar Javascript to use a closure.
* Update jQuery to latest version, 1.4.1 * Pulled jquery.cookie.js into toolbar.js so it doesn't depend on jQuery being in the global namespace. * jQuery loading code based on Ben Alman's bookmarklet generator here: http://benalman.com/code/test/jquery-run-code-bookmarklet/
1 parent 83b312e commit ed74a1c

File tree

5 files changed

+235
-124
lines changed

5 files changed

+235
-124
lines changed

debug_toolbar/media/debug_toolbar/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ all: compress_js compress_css
33

44
compress_js:
55
java -jar ~/bin/yuicompressor.jar toolbar.js > toolbar.min.js
6-
java -jar ~/bin/yuicompressor.jar jquery.cookie.js >> toolbar.min.js
76

87
compress_css:
98
java -jar ~/bin/yuicompressor.jar --type css toolbar.css > toolbar.min.css

debug_toolbar/media/debug_toolbar/jquery.js

Lines changed: 149 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 82 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,97 @@
1-
jQuery.noConflict();
2-
jQuery(function($j) {
3-
var COOKIE_NAME = 'dj_debug_panel';
4-
$j.djDebug = function(data, klass) {
5-
$j.djDebug.init();
1+
(function(window, document, version, callback) {
2+
var j, d;
3+
var loaded = false;
4+
if (!(j = window.jQuery) || version > j.fn.jquery || callback(j)) {
5+
var script = document.createElement("script");
6+
script.type = "text/javascript";
7+
script.src = BASEURL + "/__debug__/m/jquery.js";
8+
script.onload = script.onreadystatechange = function() {
9+
if (!loaded && (!(d = this.readyState) || d == "loaded" || d == "complete")) {
10+
callback((j = window.jQuery).noConflict(1), loaded = true);
11+
j(script).remove();
12+
}
13+
};
14+
document.documentElement.childNodes[0].appendChild(script)
615
}
7-
$j.extend($j.djDebug, {
16+
})(window, document, "1.3", function($, jquery_loaded) {
17+
18+
$.cookie = function(name, value, options) { if (typeof value != 'undefined') { options = options || {}; if (value === null) { value = ''; options.expires = -1; } var expires = ''; if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { var date; if (typeof options.expires == 'number') { date = new Date(); date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); } else { date = options.expires; } expires = '; expires=' + date.toUTCString(); } var path = options.path ? '; path=' + (options.path) : ''; var domain = options.domain ? '; domain=' + (options.domain) : ''; var secure = options.secure ? '; secure' : ''; document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); } else { var cookieValue = null; if (document.cookie && document.cookie != '') { var cookies = document.cookie.split(';'); for (var i = 0; i < cookies.length; i++) { var cookie = $.trim(cookies[i]); if (cookie.substring(0, name.length + 1) == (name + '=')) { cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); break; } } } return cookieValue; } };
19+
$('head').append('<link rel="stylesheet" href="'+BASEURL+'/__debug__/m/toolbar.min.css" type="text/css" />');
20+
var COOKIE_NAME = 'djdt';
21+
var djdt = {
822
init: function() {
923
var current = null;
10-
$j('#djDebugPanelList li a').click(function() {
24+
$('#djDebugPanelList li a').click(function() {
1125
if (!this.className) {
1226
return false;
1327
}
14-
current = $j('#djDebug #' + this.className);
28+
current = $('#djDebug #' + this.className);
1529
if (current.is(':visible')) {
16-
$j(document).trigger('close.djDebug');
17-
$j(this).parent().removeClass('active');
30+
$(document).trigger('close.djDebug');
31+
$(this).parent().removeClass('active');
1832
} else {
19-
$j('.panelContent').hide(); // Hide any that are already open
33+
$('.panelContent').hide(); // Hide any that are already open
2034
current.show();
21-
$j.djDebug.open();
22-
$j('#djDebugToolbar li').removeClass('active');
23-
$j(this).parent().addClass('active');
35+
$('#djDebugToolbar li').removeClass('active');
36+
$(this).parent().addClass('active');
2437
}
2538
return false;
2639
});
27-
$j('#djDebug a.djDebugClose').click(function() {
28-
$j(document).trigger('close.djDebug');
29-
$j('#djDebugToolbar li').removeClass('active');
40+
$('#djDebug a.djDebugClose').click(function() {
41+
$(document).trigger('close.djDebug');
42+
$('#djDebugToolbar li').removeClass('active');
3043
return false;
3144
});
32-
$j('#djDebug a.remoteCall').click(function() {
33-
$j('#djDebugWindow').load(this.href, {}, function() {
34-
$j('#djDebugWindow a.djDebugBack').click(function() {
35-
$j(this).parent().parent().hide();
45+
$('#djDebug a.remoteCall').click(function() {
46+
$('#djDebugWindow').load(this.href, {}, function() {
47+
$('#djDebugWindow a.djDebugBack').click(function() {
48+
$(this).parent().parent().hide();
3649
return false;
3750
});
3851
});
39-
$j('#djDebugWindow').show();
52+
$('#djDebugWindow').show();
4053
return false;
4154
});
42-
$j('#djDebugTemplatePanel a.djTemplateShowContext').click(function() {
43-
$j.djDebug.toggle_arrow($j(this).children('.toggleArrow'))
44-
$j.djDebug.toggle_content($j(this).parent().next());
55+
$('#djDebugTemplatePanel a.djTemplateShowContext').click(function() {
56+
djdt.toggle_arrow($(this).children('.toggleArrow'))
57+
djdt.toggle_content($(this).parent().next());
4558
return false;
4659
});
47-
$j('#djDebugSQLPanel a.djSQLShowStacktrace').click(function() {
48-
$j.djDebug.toggle_content($j('.djSQLHideStacktraceDiv', $j(this).parents('tr')));
60+
$('#djDebugSQLPanel a.djSQLShowStacktrace').click(function() {
61+
djdt.toggle_content($('.djSQLHideStacktraceDiv', $(this).parents('tr')));
4962
return false;
5063
});
51-
$j('#djHideToolBarButton').click(function() {
52-
$j.djDebug.hide_toolbar(true);
64+
$('#djHideToolBarButton').click(function() {
65+
djdt.hide_toolbar(true);
5366
return false;
5467
});
55-
$j('#djShowToolBarButton').click(function() {
56-
$j.djDebug.show_toolbar();
68+
$('#djShowToolBarButton').click(function() {
69+
djdt.show_toolbar();
5770
return false;
5871
});
59-
if ($j.cookie(COOKIE_NAME)) {
60-
$j.djDebug.hide_toolbar(false);
72+
$(document).bind('close.djDebug', function() {
73+
// If a sub-panel is open, close that
74+
if ($('#djDebugWindow').is(':visible')) {
75+
$('#djDebugWindow').hide();
76+
return;
77+
}
78+
// If a panel is open, close that
79+
if ($('.panelContent').is(':visible')) {
80+
$('.panelContent').hide();
81+
return;
82+
}
83+
// Otherwise, just minimize the toolbar
84+
if ($('#djDebugToolbar').is(':visible')) {
85+
djdt.hide_toolbar(true);
86+
return;
87+
}
88+
});
89+
if ($.cookie(COOKIE_NAME)) {
90+
djdt.hide_toolbar(false);
6191
} else {
62-
$j.djDebug.show_toolbar(false);
92+
djdt.show_toolbar(false);
6393
}
6494
},
65-
open: function() {
66-
// TODO: Decide if we should remove this
67-
},
6895
toggle_content: function(elem) {
6996
if (elem.is(':visible')) {
7097
elem.hide();
@@ -73,41 +100,41 @@ jQuery(function($j) {
73100
}
74101
},
75102
close: function() {
76-
$j(document).trigger('close.djDebug');
103+
$(document).trigger('close.djDebug');
77104
return false;
78105
},
79106
hide_toolbar: function(setCookie) {
80107
// close any sub panels
81-
$j('#djDebugWindow').hide();
108+
$('#djDebugWindow').hide();
82109
// close all panels
83-
$j('.panelContent').hide();
84-
$j('#djDebugToolbar li').removeClass('active');
110+
$('.panelContent').hide();
111+
$('#djDebugToolbar li').removeClass('active');
85112
// finally close toolbar
86-
$j('#djDebugToolbar').hide('fast');
87-
$j('#djDebugToolbarHandle').show();
113+
$('#djDebugToolbar').hide('fast');
114+
$('#djDebugToolbarHandle').show();
88115
// Unbind keydown
89-
$j(document).unbind('keydown.djDebug');
116+
$(document).unbind('keydown.djDebug');
90117
if (setCookie) {
91-
$j.cookie(COOKIE_NAME, 'hide', {
118+
$.cookie(COOKIE_NAME, 'hide', {
92119
path: '/',
93120
expires: 10
94121
});
95122
}
96123
},
97124
show_toolbar: function(animate) {
98125
// Set up keybindings
99-
$j(document).bind('keydown.djDebug', function(e) {
126+
$(document).bind('keydown.djDebug', function(e) {
100127
if (e.keyCode == 27) {
101-
$j.djDebug.close();
128+
djdt.close();
102129
}
103130
});
104-
$j('#djDebugToolbarHandle').hide();
131+
$('#djDebugToolbarHandle').hide();
105132
if (animate) {
106-
$j('#djDebugToolbar').show('fast');
133+
$('#djDebugToolbar').show('fast');
107134
} else {
108-
$j('#djDebugToolbar').show();
135+
$('#djDebugToolbar').show();
109136
}
110-
$j.cookie(COOKIE_NAME, null, {
137+
$.cookie(COOKIE_NAME, null, {
111138
path: '/',
112139
expires: -1
113140
});
@@ -117,25 +144,9 @@ jQuery(function($j) {
117144
var darr = String.fromCharCode(0x25bc);
118145
elem.html(elem.html() == uarr ? darr : uarr);
119146
}
147+
};
148+
$(document).ready(function() {
149+
djdt.init();
120150
});
121-
$j(document).bind('close.djDebug', function() {
122-
// If a sub-panel is open, close that
123-
if ($j('#djDebugWindow').is(':visible')) {
124-
$j('#djDebugWindow').hide();
125-
return;
126-
}
127-
// If a panel is open, close that
128-
if ($j('.panelContent').is(':visible')) {
129-
$j('.panelContent').hide();
130-
return;
131-
}
132-
// Otherwise, just minimize the toolbar
133-
if ($j('#djDebugToolbar').is(':visible')) {
134-
$j.djDebug.hide_toolbar(true);
135-
return;
136-
}
137-
});
138-
});
139-
jQuery(function() {
140-
jQuery.djDebug();
141151
});
152+

debug_toolbar/media/debug_toolbar/toolbar.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

debug_toolbar/templates/debug_toolbar/base.html

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,10 @@
11
{% load i18n %}
22
<script type="text/javascript" charset="utf-8">
3-
/* <![CDATA[ */
4-
// When jQuery is sourced, it's going to overwrite whatever might be in the
5-
// '$' variable, so store a reference of it in a temporary variable...
6-
var _$ = window.$;
7-
if (typeof jQuery == 'undefined') {
8-
var jquery_url = '{{ BASE_URL }}/__debug__/m/jquery.js';
9-
var head = document.getElementsByTagName("head")[0];
10-
var script = document.createElement('script');
11-
script.type = 'text/javascript';
12-
script.src = jquery_url;
13-
head.appendChild(script);
14-
}
15-
/* ]]> */
3+
// <![CDATA[
4+
var BASEURL = "{{ BASE_URL }}";
5+
// ]]>
166
</script>
177
<script type="text/javascript" src="{{ BASE_URL }}/__debug__/m/toolbar.min.js"></script>
18-
<script type="text/javascript" charset="utf-8">
19-
/* <![CDATA[ */
20-
// Now that jQuery is done loading, put the '$' variable back to what it was...
21-
var $ = _$;
22-
jQuery(document).ready(function() {
23-
jQuery('head').append('<link rel="stylesheet" href="{{ BASE_URL }}/__debug__/m/toolbar.min.css" type="text/css" />');
24-
});
25-
/* ]]> */
26-
</script>
278
<div id="djDebug">
289
<div style="display:none;" id="djDebugToolbar">
2910
<ul id="djDebugPanelList">

0 commit comments

Comments
 (0)