From 1be3db1453efacb9c6b484d2bcaaf36e5c0e492a Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Wed, 18 Jul 2018 23:01:14 +0100 Subject: [PATCH] Prevent cross-contamination of SimpleMDE auto-saves --- resources/js/text-area-md-support.js | 39 ++++++++++++++++------------ src/adl/to_selmer_templates.clj | 3 ++- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/resources/js/text-area-md-support.js b/resources/js/text-area-md-support.js index 6923b42..f05e241 100644 --- a/resources/js/text-area-md-support.js +++ b/resources/js/text-area-md-support.js @@ -1,17 +1,22 @@ - var simplemde = new SimpleMDE({ - autosave: { - enabled: true, - uniqueId: "adl-generated-{{page}}", - delay: 1000, - }, - indentWithTabs: true, - insertTexts: { - horizontalRule: ["", "\n\n-----\n\n"], - image: ["![](http://", ")"], - link: ["[", "](http://)"], - table: ["", "\n\n| Column 1 | Column 2 | Column 3 |\n| -------- | -------- | -------- |\n| Text | Text | Text |\n\n"], - }, - showIcons: ["code"], //, "table"], - sadly, markdown-clj does not support tables - spellChecker: true, - status: ["autosave", "lines", "words", "cursor"] - }); +/** + * Provide SimpleMDE support for textareas on this page. TODO: this is + * slightly problematic since it assumes (and saves autosave data for) + * only one text area on the page. Perhaps we should disable autosave? + */ +var simplemde = new SimpleMDE({ + autosave: { + enabled: true, + uniqueId: "{{page}}-{{record.id}}", + delay: 1000, + }, + indentWithTabs: true, + insertTexts: { + horizontalRule: ["", "\n\n-----\n\n"], + image: ["![](http://", ")"], + link: ["[", "](http://)"], + table: ["", "\n\n| Column 1 | Column 2 | Column 3 |\n| -------- | -------- | -------- |\n| Text | Text | Text |\n\n"], + }, + showIcons: ["code"], //, "table"], - sadly, markdown-clj does not support tables + spellChecker: true, + status: ["autosave", "lines", "words", "cursor"] +}); diff --git a/src/adl/to_selmer_templates.clj b/src/adl/to_selmer_templates.clj index 0cafd0a..548ddf5 100644 --- a/src/adl/to_selmer_templates.clj +++ b/src/adl/to_selmer_templates.clj @@ -635,7 +635,8 @@ (child-with-tag form :field #(= "text-area" (widget-type (property-for-field % entity) application))) - (embed-script-fragment "resources/js/text-area-md-support.js"))))))}}) + (embed-script-fragment "resources/js/text-area-md-support.js" + [["{{page}}" (-> form :attrs :name)]]))))))}}) (defn form-to-template