diff options
| author | David Baumgold | 2013-11-05 11:00:07 -0500 |
|---|---|---|
| committer | David Baumgold | 2013-11-05 11:00:07 -0500 |
| commit | acc0f8434b37ccce048b7b7dc4364475cec44edd (patch) | |
| tree | c603bc6c3b69bb2ce12ced7c7c034610b01fc2bb | |
| parent | 0016356400822c452250d3fd8d84bc38e1e9d48c (diff) | |
| download | django-debug-toolbar-acc0f8434b37ccce048b7b7dc4364475cec44edd.tar.bz2 | |
Wrap toolbar.js in AMD define() if it exists
| -rw-r--r-- | debug_toolbar/static/debug_toolbar/js/toolbar.js | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.js b/debug_toolbar/static/debug_toolbar/js/toolbar.js index 89fe64e..f4f4f5b 100644 --- a/debug_toolbar/static/debug_toolbar/js/toolbar.js +++ b/debug_toolbar/static/debug_toolbar/js/toolbar.js @@ -1,8 +1,12 @@ -// Grab jQuery for use in any of the below -var $djdtjq = jQuery.noConflict(true); - -window.djdt = (function(window, document, jQuery) { - 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; } }; +(function (factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as anonymous module. + define(['jquery', 'jquery.cookie'], factory); + } else { + // Browser globals. + window.djdt = factory(jQuery); + } +}(function (jQuery) { var $ = jQuery; var COOKIE_NAME = 'djdt'; var djdt = { @@ -232,15 +236,8 @@ window.djdt = (function(window, document, jQuery) { } } }; - $(document).ready(function() { - djdt.init(); - }); - return djdt; -}(window, document, $djdtjq)); - -(function(window, document, $) { - function _renderPerf() { + function renderPerf() { // Browser timing remains hidden unless we can successfully access the performance object var perf = window.performance || window.msPerformance || window.webkitPerformance || window.mozPerformance; @@ -288,10 +285,12 @@ window.djdt = (function(window, document, jQuery) { } } - function renderPerf() { - setTimeout(_renderPerf, 0); - } - - $(window).bind('load', renderPerf); + $(window).bind('load', function() { + setTimeout(renderPerf, 0); + }); + $(document).ready(function() { + djdt.init(); + }); -}(window, document, $djdtjq)); + return djdt; +})); |
