From fa7ab756946d25771d17755c8cc063197ff0b57c Mon Sep 17 00:00:00 2001 From: Denis Stebunov Date: Fri, 18 Apr 2014 14:50:25 +0400 Subject: [PATCH 1/2] fix RequireJS compatibility --- debug_toolbar/static/debug_toolbar/js/toolbar.js | 6 +++--- debug_toolbar/static/debug_toolbar/js/toolbar.profiling.js | 5 +++-- debug_toolbar/static/debug_toolbar/js/toolbar.sql.js | 5 +++-- debug_toolbar/static/debug_toolbar/js/toolbar.template.js | 5 +++-- debug_toolbar/static/debug_toolbar/js/toolbar.timer.js | 5 +++-- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.js b/debug_toolbar/static/debug_toolbar/js/toolbar.js index cb402055f..fa9d96106 100644 --- a/debug_toolbar/static/debug_toolbar/js/toolbar.js +++ b/debug_toolbar/static/debug_toolbar/js/toolbar.js @@ -1,7 +1,7 @@ (function (factory) { - if (typeof define === 'function' && define.amd) { - // AMD. Register as anonymous module. - define(['jquery'], factory); + if (typeof define === 'function' && define.amd && typeof require === 'function') { + // RequireJS, use jQuery from its config + require(['jquery'], factory); } else { // Browser globals. window.djdt = factory(jQuery); diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.profiling.js b/debug_toolbar/static/debug_toolbar/js/toolbar.profiling.js index 172c2a6a4..5ea3a6afe 100644 --- a/debug_toolbar/static/debug_toolbar/js/toolbar.profiling.js +++ b/debug_toolbar/static/debug_toolbar/js/toolbar.profiling.js @@ -1,6 +1,7 @@ (function (factory) { - if (typeof define === 'function' && define.amd) { - define(['jquery'], factory); + if (typeof define === 'function' && define.amd && typeof require === 'function') { + // RequireJS, use jQuery from its config + require(['jquery'], factory); } else { factory(jQuery); } diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.sql.js b/debug_toolbar/static/debug_toolbar/js/toolbar.sql.js index c554bceea..a0d488feb 100644 --- a/debug_toolbar/static/debug_toolbar/js/toolbar.sql.js +++ b/debug_toolbar/static/debug_toolbar/js/toolbar.sql.js @@ -1,6 +1,7 @@ (function (factory) { - if (typeof define === 'function' && define.amd) { - define(['jquery'], factory); + if (typeof define === 'function' && define.amd && typeof require === 'function') { + // RequireJS, use jQuery from its config + require(['jquery'], factory); } else { factory(jQuery); } diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.template.js b/debug_toolbar/static/debug_toolbar/js/toolbar.template.js index 62408982c..6ec7e737d 100644 --- a/debug_toolbar/static/debug_toolbar/js/toolbar.template.js +++ b/debug_toolbar/static/debug_toolbar/js/toolbar.template.js @@ -1,6 +1,7 @@ (function (factory) { - if (typeof define === 'function' && define.amd) { - define(['jquery'], factory); + if (typeof define === 'function' && define.amd && typeof require === 'function') { + // RequireJS, use jQuery from its config + require(['jquery'], factory); } else { factory(jQuery); } diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.timer.js b/debug_toolbar/static/debug_toolbar/js/toolbar.timer.js index 514fda7ef..cdd76214a 100644 --- a/debug_toolbar/static/debug_toolbar/js/toolbar.timer.js +++ b/debug_toolbar/static/debug_toolbar/js/toolbar.timer.js @@ -1,6 +1,7 @@ (function (factory) { - if (typeof define === 'function' && define.amd) { - define(['jquery'], factory); + if (typeof define === 'function' && define.amd && typeof require === 'function') { + // RequireJS, use jQuery from its config + require(['jquery'], factory); } else { factory(jQuery); } From 4b27834b9d8d500c44eddc411dda13b1bfb65bef Mon Sep 17 00:00:00 2001 From: Denis Stebunov Date: Fri, 18 Apr 2014 15:23:32 +0400 Subject: [PATCH 2/2] more generic solution with support for non-RequireJS environments --- debug_toolbar/static/debug_toolbar/js/toolbar.js | 11 ++++++++--- .../static/debug_toolbar/js/toolbar.profiling.js | 11 ++++++++--- debug_toolbar/static/debug_toolbar/js/toolbar.sql.js | 11 ++++++++--- .../static/debug_toolbar/js/toolbar.template.js | 11 ++++++++--- .../static/debug_toolbar/js/toolbar.timer.js | 11 ++++++++--- 5 files changed, 40 insertions(+), 15 deletions(-) diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.js b/debug_toolbar/static/debug_toolbar/js/toolbar.js index fa9d96106..0641e368e 100644 --- a/debug_toolbar/static/debug_toolbar/js/toolbar.js +++ b/debug_toolbar/static/debug_toolbar/js/toolbar.js @@ -1,7 +1,12 @@ (function (factory) { - if (typeof define === 'function' && define.amd && typeof require === 'function') { - // RequireJS, use jQuery from its config - require(['jquery'], factory); + if (typeof define === 'function' && define.amd) { + if (typeof require === 'function') { + // RequireJS, use jQuery from its config + require(['jquery'], factory); + } else { + // AMD, but not RequireJS. Register as anonymous module. + define(['jquery'], factory); + } } else { // Browser globals. window.djdt = factory(jQuery); diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.profiling.js b/debug_toolbar/static/debug_toolbar/js/toolbar.profiling.js index 5ea3a6afe..908b41c06 100644 --- a/debug_toolbar/static/debug_toolbar/js/toolbar.profiling.js +++ b/debug_toolbar/static/debug_toolbar/js/toolbar.profiling.js @@ -1,7 +1,12 @@ (function (factory) { - if (typeof define === 'function' && define.amd && typeof require === 'function') { - // RequireJS, use jQuery from its config - require(['jquery'], factory); + if (typeof define === 'function' && define.amd) { + if (typeof require === 'function') { + // RequireJS, use jQuery from its config + require(['jquery'], factory); + } else { + // AMD, but not RequireJS. Register as anonymous module. + define(['jquery'], factory); + } } else { factory(jQuery); } diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.sql.js b/debug_toolbar/static/debug_toolbar/js/toolbar.sql.js index a0d488feb..ee2cb1ce4 100644 --- a/debug_toolbar/static/debug_toolbar/js/toolbar.sql.js +++ b/debug_toolbar/static/debug_toolbar/js/toolbar.sql.js @@ -1,7 +1,12 @@ (function (factory) { - if (typeof define === 'function' && define.amd && typeof require === 'function') { - // RequireJS, use jQuery from its config - require(['jquery'], factory); + if (typeof define === 'function' && define.amd) { + if (typeof require === 'function') { + // RequireJS, use jQuery from its config + require(['jquery'], factory); + } else { + // AMD, but not RequireJS. Register as anonymous module. + define(['jquery'], factory); + } } else { factory(jQuery); } diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.template.js b/debug_toolbar/static/debug_toolbar/js/toolbar.template.js index 6ec7e737d..9a9da7307 100644 --- a/debug_toolbar/static/debug_toolbar/js/toolbar.template.js +++ b/debug_toolbar/static/debug_toolbar/js/toolbar.template.js @@ -1,7 +1,12 @@ (function (factory) { - if (typeof define === 'function' && define.amd && typeof require === 'function') { - // RequireJS, use jQuery from its config - require(['jquery'], factory); + if (typeof define === 'function' && define.amd) { + if (typeof require === 'function') { + // RequireJS, use jQuery from its config + require(['jquery'], factory); + } else { + // AMD, but not RequireJS. Register as anonymous module. + define(['jquery'], factory); + } } else { factory(jQuery); } diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.timer.js b/debug_toolbar/static/debug_toolbar/js/toolbar.timer.js index cdd76214a..ce471e29b 100644 --- a/debug_toolbar/static/debug_toolbar/js/toolbar.timer.js +++ b/debug_toolbar/static/debug_toolbar/js/toolbar.timer.js @@ -1,7 +1,12 @@ (function (factory) { - if (typeof define === 'function' && define.amd && typeof require === 'function') { - // RequireJS, use jQuery from its config - require(['jquery'], factory); + if (typeof define === 'function' && define.amd) { + if (typeof require === 'function') { + // RequireJS, use jQuery from its config + require(['jquery'], factory); + } else { + // AMD, but not RequireJS. Register as anonymous module. + define(['jquery'], factory); + } } else { factory(jQuery); }