Skip to content

Commit acc0f84

Browse files
Wrap toolbar.js in AMD define() if it exists
1 parent 0016356 commit acc0f84

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

debug_toolbar/static/debug_toolbar/js/toolbar.js

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
// Grab jQuery for use in any of the below
2-
var $djdtjq = jQuery.noConflict(true);
3-
4-
window.djdt = (function(window, document, jQuery) {
5-
jQuery.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; } };
1+
(function (factory) {
2+
if (typeof define === 'function' && define.amd) {
3+
// AMD. Register as anonymous module.
4+
define(['jquery', 'jquery.cookie'], factory);
5+
} else {
6+
// Browser globals.
7+
window.djdt = factory(jQuery);
8+
}
9+
}(function (jQuery) {
610
var $ = jQuery;
711
var COOKIE_NAME = 'djdt';
812
var djdt = {
@@ -232,15 +236,8 @@ window.djdt = (function(window, document, jQuery) {
232236
}
233237
}
234238
};
235-
$(document).ready(function() {
236-
djdt.init();
237-
});
238-
return djdt;
239-
}(window, document, $djdtjq));
240-
241239

242-
(function(window, document, $) {
243-
function _renderPerf() {
240+
function renderPerf() {
244241
// Browser timing remains hidden unless we can successfully access the performance object
245242
var perf = window.performance || window.msPerformance ||
246243
window.webkitPerformance || window.mozPerformance;
@@ -288,10 +285,12 @@ window.djdt = (function(window, document, jQuery) {
288285
}
289286
}
290287

291-
function renderPerf() {
292-
setTimeout(_renderPerf, 0);
293-
}
294-
295-
$(window).bind('load', renderPerf);
288+
$(window).bind('load', function() {
289+
setTimeout(renderPerf, 0);
290+
});
291+
$(document).ready(function() {
292+
djdt.init();
293+
});
296294

297-
}(window, document, $djdtjq));
295+
return djdt;
296+
}));

0 commit comments

Comments
 (0)