2017-12-27 07:15:29 +08:00
|
|
|
"use strict";
|
|
|
|
|
2018-03-26 01:02:39 +08:00
|
|
|
import noteDetail from '../services/note_detail.js';
|
2017-12-27 07:15:29 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const $showDialogButton = $("#show-source-button");
|
|
|
|
const $dialog = $("#note-source-dialog");
|
|
|
|
const $noteSource = $("#note-source");
|
2017-12-27 07:15:29 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
function showDialog() {
|
|
|
|
glob.activeDialog = $dialog;
|
2017-12-27 07:15:29 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
$dialog.dialog({
|
|
|
|
modal: true,
|
|
|
|
width: 800,
|
|
|
|
height: 500
|
|
|
|
});
|
2017-12-27 07:15:29 +08:00
|
|
|
|
2018-03-26 01:02:39 +08:00
|
|
|
const noteText = noteDetail.getCurrentNote().detail.content;
|
2017-12-27 07:15:29 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
$noteSource.text(formatHtml(noteText));
|
|
|
|
}
|
2017-12-27 07:15:29 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
function formatHtml(str) {
|
|
|
|
const div = document.createElement('div');
|
|
|
|
div.innerHTML = str.trim();
|
2017-12-27 07:15:29 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
return formatNode(div, 0).innerHTML.trim();
|
|
|
|
}
|
2017-12-27 07:15:29 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
function formatNode(node, level) {
|
|
|
|
const indentBefore = new Array(level++ + 1).join(' ');
|
|
|
|
const indentAfter = new Array(level - 1).join(' ');
|
|
|
|
let textNode;
|
2017-12-27 07:15:29 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
for (let i = 0; i < node.children.length; i++) {
|
|
|
|
textNode = document.createTextNode('\n' + indentBefore);
|
|
|
|
node.insertBefore(textNode, node.children[i]);
|
2017-12-27 07:15:29 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
formatNode(node.children[i], level);
|
2017-12-27 07:15:29 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
if (node.lastElementChild === node.children[i]) {
|
|
|
|
textNode = document.createTextNode('\n' + indentAfter);
|
|
|
|
node.appendChild(textNode);
|
|
|
|
}
|
2017-12-27 07:15:29 +08:00
|
|
|
}
|
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
return node;
|
|
|
|
}
|
2017-12-27 07:15:29 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
$(document).bind('keydown', 'ctrl+u', e => {
|
|
|
|
showDialog();
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
2017-12-27 07:15:29 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
$showDialogButton.click(showDialog);
|
2018-03-24 12:54:50 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
export default {
|
|
|
|
showDialog
|
|
|
|
};
|