Skip to content

Commit e49340d

Browse files
committed
Merge pull request django-commons#619 from tim-schilling/javascript-api-484
Add a JavaScript API. Fix django-commons#484.
2 parents fbbbc1d + 4b96070 commit e49340d

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

debug_toolbar/static/debug_toolbar/js/toolbar.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(function ($) {
1+
(function ($, publicAPI) {
22
var djdt = {
33
handleDragged: false,
44
events: {
@@ -280,5 +280,11 @@
280280
}
281281
}
282282
};
283+
$.extend(publicAPI, {
284+
show_toolbar: djdt.show_toolbar,
285+
hide_toolbar: djdt.hide_toolbar,
286+
close: djdt.close,
287+
cookie: djdt.cookie
288+
});
283289
$(document).ready(djdt.init);
284-
})(djdt.jQuery);
290+
})(djdt.jQuery, djdt);

docs/panels.rst

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,7 @@ according to the public API described below. Unless noted otherwise, all
240240
methods are optional.
241241

242242
Panels can ship their own templates, static files and views. They're no public
243-
CSS or JavaScript API at this time, but they can assume jQuery is available in
244-
``djdt.jQuery``.
243+
CSS API at this time.
245244

246245
.. autoclass:: debug_toolbar.panels.Panel(*args, **kwargs)
247246

@@ -272,3 +271,42 @@ CSS or JavaScript API at this time, but they can assume jQuery is available in
272271
.. automethod:: debug_toolbar.panels.Panel.process_view
273272

274273
.. automethod:: debug_toolbar.panels.Panel.process_response
274+
275+
JavaScript API
276+
~~~~~~~~~~~~~~
277+
278+
Panel templates should include any JavaScript files they need. There are a few
279+
common methods available, as well as the toolbar's version of jQuery.
280+
281+
.. js:function:: djdt.close
282+
283+
Triggers the event to close any active panels.
284+
285+
.. js:function:: djdt.cookie.get
286+
287+
This is a helper function to fetch values stored in the cookies.
288+
289+
:param string key: The key for the value to be fetched.
290+
291+
.. js:function:: djdt.cookie.set
292+
293+
This is a helper function to set a value stored in the cookies.
294+
295+
:param string key: The key to be used.
296+
297+
:param string value: The value to be set.
298+
299+
:param Object options: The options for the value to be set. It should contain
300+
the properties ``expires`` and ``path``.
301+
302+
.. js:function:: djdt.hide_toolbar
303+
304+
Closes any panels and hides the toolbar.
305+
306+
.. js:function:: djdt.jQuery
307+
308+
This is the toolbar's version of jQuery.
309+
310+
.. js:function:: djdt.show_toolbar
311+
312+
Shows the toolbar.

0 commit comments

Comments
 (0)