mirror of
https://github.com/TrentSPalmer/fcc-challenges.git
synced 2025-07-04 02:03:15 -07:00
modified: markdown-previewer/markdownPreviewer.css
modified: markdown-previewer/markdownPreviewer.js
This commit is contained in:
@ -1,48 +1,54 @@
|
||||
marked.setOptions({
|
||||
breaks: true,
|
||||
breaks: true
|
||||
});
|
||||
|
||||
$(document).ready(function() {
|
||||
$(document).ready(function () {
|
||||
/* if there is editorText in sessionStorage, load that into
|
||||
* the editor, otherwise load the default text into the editor */
|
||||
if (sessionStorage.hasOwnProperty('editorText')) {
|
||||
$('#editor').val(sessionStorage.editorText);
|
||||
if (sessionStorage.hasOwnProperty("editorText")) {
|
||||
$("#editor").val(sessionStorage.editorText);
|
||||
} else {
|
||||
$('#editor').val(defaultText);
|
||||
};
|
||||
$("#editor").val(defaultText);
|
||||
}
|
||||
|
||||
// render the editor contents to the preview element
|
||||
$('#preview').html(marked($('#editor').val()));
|
||||
$("#preview").html(getMarkUp($("#editor").val()));
|
||||
|
||||
/* on every input event in the editor, store the editor
|
||||
* contents in sessionStorage and also render the contents
|
||||
* of the editor to the preview element */
|
||||
$('#editor').on('input',function() {
|
||||
sessionStorage.setItem('editorText',$(this).val());
|
||||
$('#preview').html(marked($(this).val()));
|
||||
$("#editor").on("input", function () {
|
||||
sessionStorage.setItem("editorText", $(this).val());
|
||||
$("#preview").html(getMarkUp($(this).val()));
|
||||
scrollSync();
|
||||
});
|
||||
|
||||
// handle eraseButton
|
||||
$('#eraseButton').click(function() {
|
||||
$('#editor').val('');
|
||||
sessionStorage.setItem('editorText',$('#editor').val());
|
||||
$('#preview').html(marked($('#editor').val()));
|
||||
$("#eraseButton").click(function () {
|
||||
$("#editor").val("");
|
||||
sessionStorage.setItem("editorText", $("#editor").val());
|
||||
$("#preview").html(getMarkUp($("#editor").val()));
|
||||
});
|
||||
|
||||
// handle reloadButton
|
||||
$('#reloadButton').click(function() {
|
||||
$('#editor').val(defaultText);
|
||||
sessionStorage.setItem('editorText',defaultText);
|
||||
$('#preview').html(marked(defaultText));
|
||||
$("#reloadButton").click(function () {
|
||||
$("#editor").val(defaultText);
|
||||
sessionStorage.setItem("editorText", defaultText);
|
||||
$("#preview").html(getMarkUp(defaultText));
|
||||
});
|
||||
|
||||
$('#editor').on('scroll', scrollSync);
|
||||
$("#editor").on("scroll", scrollSync);
|
||||
});
|
||||
|
||||
const scrollSync = () => {
|
||||
const editorScrollable = document.getElementById('editor').scrollHeight - $('#editor').height();
|
||||
const previewScrollable = document.getElementById('preview').scrollHeight - $('#preview').height();
|
||||
const editorScrollRatio = $('#editor').scrollTop() === 0 ? 0 : $('#editor').scrollTop() / editorScrollable;
|
||||
const editorScrollable = document.getElementById("editor").scrollHeight - $("#editor").height();
|
||||
const previewScrollable = document.getElementById("preview").scrollHeight - $("#preview").height();
|
||||
let editorScrollRatio = $("#editor").scrollTop() === 0 ? 0 : $("#editor").scrollTop() / editorScrollable;
|
||||
if (editorScrollRatio > 0.90) { editorScrollRatio = 1.5; }
|
||||
const previewScrollPosition = previewScrollable * editorScrollRatio;
|
||||
$('#preview').scrollTop(previewScrollPosition);
|
||||
$("#preview").scrollTop(previewScrollPosition);
|
||||
};
|
||||
|
||||
const getMarkUp = (text) => {
|
||||
return marked(text);
|
||||
}
|
||||
|
Reference in New Issue
Block a user