Skip to content

Commit b80c922

Browse files
committed
Making a basic javascript API for the toolbar.
1 parent fbbbc1d commit b80c922

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-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: 47 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,49 @@ 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+
282+
.. js:function:: djdt.close
283+
284+
Triggers the event to close any active panels.
285+
286+
.. js:function:: djdt.cookie.get
287+
288+
This is a helper function to fetch values stored in the cookies.
289+
290+
:param string key: The key for the value to be fetched.
291+
292+
.. js:function:: djdt.cookie.set
293+
294+
This is the toolbar's version of jQuery.
295+
296+
:param string key: The key to be used.
297+
298+
:param string value: The value to be set.
299+
300+
:param Object options: The key for the value to be fetched. It should contain
301+
the properties ``expires`` and ``path``.
302+
303+
.. js:function:: djdt.hide_toolbar
304+
305+
Closes any panels and hides the toolbar.
306+
307+
:param boolean setCookie: Whether or not it should set the display cookie for
308+
the toolbar.
309+
310+
.. js:function:: djdt.jQuery
311+
312+
This is the toolbar's version of jQuery.
313+
314+
.. js:function:: djdt.show_toolbar
315+
316+
Shows the toolbar.
317+
318+
:param boolean animate: Whether or not it should use an animation when calling
319+
``show`` on the toolbar.

0 commit comments

Comments
 (0)