Adapters Javascript

We now need to create the javascript function to actually apply the color to the styles of the element.
This function will be called myColorizerJavascriptFunction, as defined in the adapter's __init__ method.

1// myapp/static/myapp/js/custom.js
2function myColorizerJavascriptFunction(element, response) {
3    element.style.color = response.color;
4}

We must then register this javascript file to be included in the frontend editing interface.

This should be done in a wagtail_hooks.py file.

 1# myapp/wagtail_hooks.py
 2
 3from django.utils.html import format_html
 4from django.templatetags.static import static
 5from wagtail_fedit.hooks import REGISTER_JS
 6from wagtail import hooks
 7
 8@hooks.register(REGISTER_JS)
 9def register_js(request):
10    return [
11        format_html(
12            '<script src="{0}"></script>',
13            static('myapp/js/custom.js')
14        ),
15    ]

View the custom Python adapter in the Adapters Python page.