From b80c9221b48784692a7f454ca173c4a267c9f4c0 Mon Sep 17 00:00:00 2001 From: tschilling Date: Tue, 15 Jul 2014 21:30:25 -0400 Subject: Making a basic javascript API for the toolbar. --- debug_toolbar/static/debug_toolbar/js/toolbar.js | 10 ++++- docs/panels.rst | 49 +++++++++++++++++++++++- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.js b/debug_toolbar/static/debug_toolbar/js/toolbar.js index 2a6df02..9f8523c 100644 --- a/debug_toolbar/static/debug_toolbar/js/toolbar.js +++ b/debug_toolbar/static/debug_toolbar/js/toolbar.js @@ -1,4 +1,4 @@ -(function ($) { +(function ($, publicAPI) { var djdt = { handleDragged: false, events: { @@ -280,5 +280,11 @@ } } }; + $.extend(publicAPI, { + show_toolbar: djdt.show_toolbar, + hide_toolbar: djdt.hide_toolbar, + close: djdt.close, + cookie: djdt.cookie + }); $(document).ready(djdt.init); -})(djdt.jQuery); +})(djdt.jQuery, djdt); diff --git a/docs/panels.rst b/docs/panels.rst index 8941ed2..c639644 100644 --- a/docs/panels.rst +++ b/docs/panels.rst @@ -240,8 +240,7 @@ according to the public API described below. Unless noted otherwise, all methods are optional. Panels can ship their own templates, static files and views. They're no public -CSS or JavaScript API at this time, but they can assume jQuery is available in -``djdt.jQuery``. +CSS API at this time. .. autoclass:: debug_toolbar.panels.Panel(*args, **kwargs) @@ -272,3 +271,49 @@ CSS or JavaScript API at this time, but they can assume jQuery is available in .. automethod:: debug_toolbar.panels.Panel.process_view .. automethod:: debug_toolbar.panels.Panel.process_response + +JavaScript API +~~~~~~~~~~~~~~ + +Panel templates should include any JavaScript files they need. There are a few +common methods available, as well as the toolbar's version of jQuery. + + +.. js:function:: djdt.close + + Triggers the event to close any active panels. + +.. js:function:: djdt.cookie.get + + This is a helper function to fetch values stored in the cookies. + + :param string key: The key for the value to be fetched. + +.. js:function:: djdt.cookie.set + + This is the toolbar's version of jQuery. + + :param string key: The key to be used. + + :param string value: The value to be set. + + :param Object options: The key for the value to be fetched. It should contain + the properties ``expires`` and ``path``. + +.. js:function:: djdt.hide_toolbar + + Closes any panels and hides the toolbar. + + :param boolean setCookie: Whether or not it should set the display cookie for + the toolbar. + +.. js:function:: djdt.jQuery + + This is the toolbar's version of jQuery. + +.. js:function:: djdt.show_toolbar + + Shows the toolbar. + + :param boolean animate: Whether or not it should use an animation when calling + ``show`` on the toolbar. -- cgit v1.2.3 From 4b960709e15455af09d5632f84b463dee268d8a8 Mon Sep 17 00:00:00 2001 From: tschilling Date: Wed, 16 Jul 2014 21:15:39 -0400 Subject: Updating JS api documentation. Removed parameters to show_toolbar and hide_toolbar. Removed extra whitespace and added a tab after a long param description. Fixed copy-paste error for method summary for djdt.cookie.set --- docs/panels.rst | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/docs/panels.rst b/docs/panels.rst index c639644..de6f16a 100644 --- a/docs/panels.rst +++ b/docs/panels.rst @@ -278,7 +278,6 @@ JavaScript API Panel templates should include any JavaScript files they need. There are a few common methods available, as well as the toolbar's version of jQuery. - .. js:function:: djdt.close Triggers the event to close any active panels. @@ -291,22 +290,19 @@ common methods available, as well as the toolbar's version of jQuery. .. js:function:: djdt.cookie.set - This is the toolbar's version of jQuery. + This is a helper function to set a value stored in the cookies. :param string key: The key to be used. :param string value: The value to be set. - :param Object options: The key for the value to be fetched. It should contain - the properties ``expires`` and ``path``. + :param Object options: The options for the value to be set. It should contain + the properties ``expires`` and ``path``. .. js:function:: djdt.hide_toolbar Closes any panels and hides the toolbar. - :param boolean setCookie: Whether or not it should set the display cookie for - the toolbar. - .. js:function:: djdt.jQuery This is the toolbar's version of jQuery. @@ -314,6 +310,3 @@ common methods available, as well as the toolbar's version of jQuery. .. js:function:: djdt.show_toolbar Shows the toolbar. - - :param boolean animate: Whether or not it should use an animation when calling - ``show`` on the toolbar. -- cgit v1.2.3