Created
December 21, 2017 13:35
-
-
Save mdesantis/2c737cbd738c9acf3828618b3f3b4304 to your computer and use it in GitHub Desktop.
Sir Trevor initializer for Rails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).on 'ready turbolinks:load', -> | |
SirTrevor.config.language = 'it' | |
SirTrevor.setDefaults( | |
language: 'it' | |
focusOnInit: false | |
blockTypes: ['Text', 'Image', 'List', 'Heading', 'Quote', 'Video'] | |
defaultType: 'Text' | |
iconUrl: "<%= asset_path('sir-trevor/build/sir-trevor-icons.svg') %>" | |
uploadUrl: "/admin/uploads/images" | |
ajaxOptions: { | |
headers: { | |
'X-Requested-With': 'XMLHttpRequest' | |
'X-CSRF-Token': Rails.csrfToken() | |
} | |
credentials: 'same-origin' | |
} | |
) | |
for el in $('.js-sir-trevor-editor') | |
$el = $ el | |
elConfig = $(el).data('sir-trevor-editor-config') ? {} | |
config = { el: el } | |
instance = new (SirTrevor.Editor)($.extend({}, config, elConfig)) | |
$el.data 'sir-trevor-editor-instance', instance | |
$(document).on 'turbolinks:before-cache', -> | |
for el in $('.js-sir-trevor-editor') | |
$el = $ el | |
instance = $el.data 'sir-trevor-editor-instance' | |
if instance? | |
instance.destroy() | |
$el.removeData 'sir-trevor-editor-instance' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment