Skip to content

Instantly share code, notes, and snippets.

@gaybro8777
Forked from wren-hearn/hallo-mirrorstage.coffee
Created January 30, 2019 06:20
Show Gist options
  • Save gaybro8777/fa2981c0bc4002e3c13d158e95bf4669 to your computer and use it in GitHub Desktop.
Save gaybro8777/fa2981c0bc4002e3c13d158e95bf4669 to your computer and use it in GitHub Desktop.
Extending hallo.js using Wagtail hooks
((jQuery) ->
jQuery.widget "IKS.mirrorstageeditor",
boldElement: null
options:
uuid: ''
editable: null
_create: ->
# Add any actions you want to run on plugin initialization
# here
populateToolbar: (toolbar) ->
# Create an element for holding the button
@boldElement = jQuery '<span></span>'
# Use Hallo Button
@boldElement.hallobutton
uuid: @options.uuid
editable: @options.editable
label: 'Bold'
# Icons come from Font Awesome
icon: 'fa fa-space-shuttle'
# Commands are used for execCommand and queryCommandState
command: 'bold'
# Append the button to toolbar
toolbar.append @boldElement
)(jQuery)
from django.utils.html import format_html, format_html_join
from django.conf import settings
from wagtail.wagtailadmin import hooks
def editor_js():
js_files = [
'mirrorstage/js/hallo-plugins/hallo-mirrorstage.js',
]
js_includes = format_html_join('\n', '<script src="{0}{1}"></script>',
((settings.STATIC_URL, filename) for filename in js_files)
)
return js_includes + format_html(
"""
<script>
console.log('Mirrorstage Editor JS Loaded!');
registerHalloPlugin('mirrorstageeditor');
</script>
"""
)
hooks.register('insert_editor_js', editor_js)
def editor_css():
return format_html('<link rel="stylesheet" href="'+ settings.STATIC_URL + 'mirrorstage/css/vendor/font-awesome/css/font-awesome.min.css">')
hooks.register('insert_editor_css', editor_css)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment