Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@
- **Entries with scripts or embeds open as HTML.** If an entry contains
scripts, frames, embedded objects, event-handler attributes or
`javascript:` links, the rich-text editor opens it in the HTML textarea
with a notice, and the stored HTML is kept as is (#331).
with a notice, and the stored HTML is kept as is. Entries with forms, some
Bootstrap data attributes (such as `data-toggle`), a link or URL-like word
containing `<`, as in some code samples, or an iframe or other tag that the
editor's code view removes, even inside an HTML comment, also open in the
textarea (#331).

- **Names are shown as text.** Screen and full names are HTML-escaped where
templates print them and written as plain text in feeds; commenter names
Expand Down
1 change: 1 addition & 0 deletions app/src/main/resources/ApplicationResources.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,7 @@ weblogEdit.draft=Draft
weblogEdit.draftEntries=Recent Drafts
weblogEdit.deleteEntry=Delete Entry
weblogEdit.insertMediaFile=Insert Media File
weblogEdit.richEditorShowsHtml=This entry contains HTML the rich text editor cannot show safely, so it opens as HTML.
weblogEdit.inlineImageInvalid=This entry contains an unsupported or invalid embedded image. Use a PNG, JPEG or GIF image, or insert a media file.
weblogEdit.inlineImageTooLarge=This entry has too much embedded image data. Resize the image or ask an administrator to enable media uploads.
error.postTooLarge=The form is too large to submit, so nothing was saved. Use your browser's Back button to return to it. If it contains pasted images, use smaller images or insert them as media files. An administrator can raise the server's maximum POST size.
Expand Down
73 changes: 57 additions & 16 deletions app/src/main/webapp/WEB-INF/jsps/editor/EntryEditor.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<%-- ********************************************************************* --%>

<%-- content --%>
<s:if test="editor.id != 'editor-text.jsp'">
<div id="edit_content_html_notice" class="alert alert-info" role="status" style="display: none">
<s:text name="weblogEdit.richEditorShowsHtml"/>
</div>
</s:if>
<s:textarea id="edit_content" name="bean.text"
tabindex="5" rows="18" cssClass="col-sm-12" theme="simple"/>

Expand Down Expand Up @@ -88,6 +93,10 @@

</div>

<s:if test="editor.id != 'editor-text.jsp'">
<script src="<s:url value='/roller-ui/scripts/rich-editor-content.js' />"></script>
</s:if>

<script>

<s:if test="editor.id == 'editor-text.jsp'">
Expand Down Expand Up @@ -146,7 +155,19 @@

<%-- Rich text editor functions --%>

// Entries with HTML that Summernote would run or drop open in the textarea
// as HTML; see rich-editor-content.js. Summernote starts the editor on any
// call, so every call checks this first.
var richEditorStarted = false;

$(document).ready(function () {
if (RollerRichEditor.hasActiveHtml(document.getElementById('edit_content').value)) {
$('#edit_content_html_notice').show();
RollerRichEditor.trackCursor(document.getElementById('edit_content'));
armLeaveWarning();
return;
}
richEditorStarted = true;
$('#edit_content').summernote({
toolbar: [
// [groupName, [list of button]]
Expand Down Expand Up @@ -179,26 +200,46 @@
}
}
);
// Added event listener to confirm once the editor content is changed
$('#edit_content').on('summernote.change', function(we, contents, $editable) {
var confirmFunction = function(event) {
// Chrome requires returnValue to be set and original event is found as originalEvent
// see https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload#Example
if (event.originalEvent)
event.originalEvent.returnValue = "Are you sure you want to leave?";
return "Are you sure you want to leave?";
}
$(window).on("beforeunload", confirmFunction);
armLeaveWarning();
});

// Warns before leaving the page once the entry is edited. Input, not
// change, for the textarea: change waits for it to lose focus.
function armLeaveWarning() {
if (richEditorStarted) {
$('#edit_content').one('summernote.change', warnBeforeLeaving);
} else {
$("#edit_content").one("input", warnBeforeLeaving);
}
}

function warnBeforeLeaving() {
var confirmFunction = function(event) {
// Chrome requires returnValue to be set and original event is found as originalEvent
// see https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload#Example
if (event.originalEvent)
event.originalEvent.returnValue = "Are you sure you want to leave?";
return "Are you sure you want to leave?";
}
$(window).on("beforeunload", confirmFunction);

// Remove it if it is form submit
$(this.form).on('submit', function() {
$(window).off("beforeunload", confirmFunction);
});
// Remove it if it is form submit, and warn again on the next edit if
// the page stays, as when the submit is stopped
$(this.form).one('submit', function() {
$(window).off("beforeunload", confirmFunction);
armLeaveWarning();
});
});
}

function insertMediaFile(toInsert) {
$('#edit_content').summernote("pasteHTML", toInsert);
if (richEditorStarted) {
$('#edit_content').summernote("pasteHTML", toInsert);
} else {
// at the cursor, or at the end if the textarea hasn't had one
var textArea = document.getElementById('edit_content');
RollerRichEditor.insertAtCursor(textArea, toInsert);
$(textArea).trigger("input");
}
}

</s:else>
Expand Down
Loading
Loading