Skip to content

Commit

Permalink
SAK-44839 - CKEditor 4 preview can't handle apostrophes or HTML (saka…
Browse files Browse the repository at this point in the history
…iproject#8925)

* SAK-44839 - CKEditor 4 preview can't handle apostrophes or HTML

* Update library/src/webapp/editor/ckextraplugins/sakaipreview/plugin.js
  • Loading branch information
jonespm authored Jan 6, 2021
1 parent 0f0398d commit 7aac73b
Showing 1 changed file with 8 additions and 32 deletions.
40 changes: 8 additions & 32 deletions library/src/webapp/editor/ckextraplugins/sakaipreview/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,32 +58,6 @@
baseURL = baseURL + ":" + location.port
}

var highlightedText = false;
function getHighlightedText() {
if (typeof highlightedText == 'string') {
return highlightedText;
}

var selection = editor.getSelection();
if (selection && selection.getType() == CKEDITOR.SELECTION_TEXT) {
if (CKEDITOR.env.ie) {
selection.unlock(true);
highlightedText = selection.getNative().createRange().text;
} else {
highlightedText = selection.getNative().toString();
}
}

return highlightedText;
}

function isHighlight() {
return getHighlightedText().length > 0;
}
// Content to preview: the entire document or just what is highlighted?
var previewHighlightedOnly = isHighlight();


function getPreviewContentHTML(contentToPreview) {
let darkThemeEnabled = document.firstElementChild.classList.contains('sakaiUserTheme-dark') ? 'sakaiUserTheme-dark' : '';

Expand All @@ -103,22 +77,24 @@

function getIframe(html) {
var $iframe = $PBJQ('<iframe>');
$iframe.attr('src', 'data:text/html;charset=utf-8,' + encodeURI(html));
$iframe.attr('srcdoc', html);
$iframe.attr('frameborder', '0');
$iframe.attr('width', '100%');
$iframe.attr('height', $PBJQ(window).height() - 240 + "px");
return $iframe;
}

var previewHighlightedOnly = false;
function getEditorContent() {
var selectedText = "";
var selection = editor.getSelection();
//Available since CKEditor 4.5.0 to get selected Html. True to return html.
var selectedHtml = editor.getSelectedHtml(true);

if (previewHighlightedOnly && isHighlight()) {
return getHighlightedText();
if (selectedHtml) {
previewHighlightedOnly = true;
return selectedHtml;
}

return editor.getData();
return editor.editable().getHtml();
}

sHTML = getPreviewContentHTML(getEditorContent());
Expand Down

0 comments on commit 7aac73b

Please sign in to comment.