clean up interface insert
</div>
<script>
$(document).ready(function () {
- var elem = $('#interface_editor');
- var interface = init_codemirror(elem, 400);
- var project = elem.closest('.grid').data("project");
- update_preview();
+ var textarea = $('#interface_editor');
+ var editor = init_codemirror(textarea, 400);
+ var project = textarea.closest('.grid').data("project");
- url = "/ajax/field/render/";
+ update_preview();
$(".card").each(function (index) {
var curr = $(this);
var toml = curr.find(".toml_code").text();
var field = curr.find(".toml_field");
- field.load(url, {toml: toml, project: project}, function (response, status, xhr) {
+ field.load( "/ajax/field/render/", {toml: toml, project: project},
+ function (response, status, xhr) {
});
});
var toml = curr.find(".toml_code").text();
var field = curr.find(".toml_field");
- // Format clicked area value so it inserts correctly.
- var sep = '\n\n';
- if (elem.val().endsWith('\n')) {
- sep = '\n'
- }
- // Remove beginning space from clicked card.
- toml = toml.replace(/^\s+/g, '');
- // Replace all new line followed by spaces by just a newline.
+ // Remove beginning space in first line, replace newline + spaces with newline.
+ toml = toml.replace(/^\s+/g, '\n');
toml = toml.replace(/\n[\s]+/g, '\n');
- // Add clicked field to textarea.
- var new_toml = elem.val() + sep + toml;
-
- // Set new textarea values.
- elem.val(new_toml);
- interface.setValue(elem.val());
+ // Add clicked field to textarea and set values.
+ var new_toml = textarea.val() + toml;
+ editor.setValue(new_toml);
// Add clicked field html to preview;
$("#preview form .preview").append(field.html());
