Adding interactivity
Adding some basic interactivity using Law Widgets.
In this section
Add a searchable Table of Contents using Law Widgets
Add interactivity with Law Widgets for defined terms and internal references
Now that we have a detail page showing the content of the documents, let's add some interactivity using Laws.Africa's Law Widgets.
Table of Contents
A searchable Table of Contents is important to make long legislative documents easier to navigate. There are two widgets you can use for the Table of Contents:
<la-table-of-contents> - this is a basic Table of Contents tree.
<la-table-of-contents-controller> - this is a fully searchable and collapsible Table of Contents tree that builds on top of <la-table-of-contents>.
We'll use la-table-of-contents-controller because it gives us rich functionality right out the box.
Let's divide our content section into two columns to make room for the Table of Contents in a sidebar on the left of the page.
We need to provide the <la-table-of-contents-controller>
with the JSON Table of Contents data in the items attribute. This is the data that is provided by the Laws.Africa Content API.
Update the views.py
to add turn the TOC information into JSON.
The page now has an interactive table of contents.
Popups for defined terms
We're going to use the <la-decorate-terms> Law Widget to add popups for defined terms that occur in a document.
Modify expression_detail.html
to include the new widget anywhere on the page:
This widget will add term definition popups and links in the first <la-akoma-ntoso>
element on the page. If there is more than one, you can target it specifically by providing an akoma-ntoso attribute that uses a CSS selector to identify the target element: <la-decorate-terms akoma-ntoso="#akn-doc">
.
You can control the behaviour by adding or removing these attributes. Try changing them and refreshing the page to see what changes.
popup-definitions
- controls whether definitions of terms are shown in popupslink-terms
- controls whether references to terms are shown as clickable links.
Popups for internal references
We're going to use the <la-decorate-internal-refs> widget to make internal references more interactive. The widget will show a purple bookmark at an internal reference, and show the content of the target element when the user hovers over the reference.
Modify expression_detail.html
to include the new widget:
This widget will add interactivity to internal references in the first <la-akoma-ntoso>
element on the page. Like with <la-decorate-terms>
, you can use the akoma-ntoso attribute to target a specific <la-akoma-ntoso>
element using a CSS selector, such as <la-decorate-internal-refs akoma-ntoso="#akn-doc">
.
You can control the behaviour by adding or removing these attributes. Try changing them and refreshing the page to see what changes.
popups
- controls whether reference target elements are shown in popupsflag
- controls whether internal references are decorated with a purple bookmark icon
Last updated