Skip to content

Instantly share code, notes, and snippets.

@Hampei
Last active May 20, 2017 16:32
Show Gist options
  • Save Hampei/7620806 to your computer and use it in GitHub Desktop.
Save Hampei/7620806 to your computer and use it in GitHub Desktop.
// Turns all textareas into medium-editors
// requires:
// - Medium-Editor
// - jQuery (can be easily rewritten without)
// - find_with_mutations: https://gist.github.com/hampei/7620643
// - sync_node_html_to_form_field: https://gist.github.com/hampei/7620825
window.textareas_to_medium_editor = function() {
find_with_mutations('form', 'textarea', function(el) {
el.style.display = 'none'; // hide the textarea
editor = $('<div />'); // create editor element
editor.html(el.value); // initialize editor with value
$(el).after(editor); // insert the editor
sync_node_html_to_form_field(editor[0], el); // sync editor to the textarea
new MediumEditor(editor);
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment