Skip to content

Commit

Permalink
Fix for correct showing and saving breakpoints (#4)
Browse files Browse the repository at this point in the history
- Added function for converting br into new line
- Fix for saving data in DB with br instead of new line
  • Loading branch information
slavenstancic authored Feb 17, 2020
1 parent 22e65b7 commit 11c36c7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
18 changes: 5 additions & 13 deletions wcms-admin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
function nl2br(a) {
return (a + "").replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, "$1<br>$2");
}

function fieldSave(id, newContent, dataTarget, dataMenu, dataVisibility, oldContent) {
if (newContent !== oldContent) {
$("#save").show(), $.post("", {
Expand All @@ -18,22 +14,18 @@ function fieldSave(id, newContent, dataTarget, dataMenu, dataVisibility, oldCont
} else {
const target = $('#' + id);
target.removeClass('editTextOpen');
const textarea = target.children('textarea').first();
const content = textarea.val();
target.html(content);
target.html(newContent);
}
}

function editableTextArea(editableTarget, editable) {
function editableTextArea(editableTarget) {
const data = (
target = editableTarget,
isEditable = editable,
content = isEditable ? target.html().replace(/<br>/gi, "\n") : target.html(),
oldContent = target.html(),
content = target.html(),
title = target.attr("title") ? '"' + target.attr("title") + '" ' : '',
targetId = target.attr('id'),
"<textarea " + title + ' id="' + targetId + "_field\" onblur=\"" +
"fieldSave(targetId,(isEditable ? this.value : nl2br(this.value)),target.data('target'),target.data('menu'),target.data('visibility'), oldContent);" +
"fieldSave(targetId,this.value,target.data('target'),target.data('menu'),target.data('visibility'), content);" +
"\">" + content + "</textarea>"
);

Expand All @@ -58,7 +50,7 @@ $(document).ready(function () {
$("body").on("click", "div.editText:not(.editTextOpen)", function () {
const target = $(this);
target.addClass('editTextOpen');
editableTextArea(target, target.hasClass("editable"));
editableTextArea(target);
target.children(':first').focus();
autosize($('textarea'));
});
Expand Down
7 changes: 3 additions & 4 deletions wcms-admin.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 11c36c7

Please sign in to comment.