You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
146 lines
4.4 KiB
146 lines
4.4 KiB
function onRead() {
|
|
easyMDE.codemirror.doc.setValue(Android.getValue())
|
|
easyMDE.codemirror.doc.markClean()
|
|
easyMDE.codemirror.focus()
|
|
easyMDE.codemirror.doc.setCursor(JSON.parse(Android.getCursor()))
|
|
pasteText()
|
|
}
|
|
|
|
function saveAs() {
|
|
Android.triggerNewBuffer(easyMDE.value())
|
|
}
|
|
function saveFile() {
|
|
if (!easyMDE.codemirror.doc.isClean()) Android.triggerSaveFile(easyMDE.value())
|
|
easyMDE.codemirror.doc.markClean()
|
|
}
|
|
function blankBuffer() {
|
|
Android.triggerNewBuffer("")
|
|
}
|
|
|
|
function openFile() {
|
|
saveFile()
|
|
Android.triggerOpenFile()
|
|
onRead()
|
|
}
|
|
function dispatchCut() {
|
|
console.log("dispatch cut")
|
|
easyMDE.codemirror.getTextArea().dispatchEvent(new Event("cut"))
|
|
}
|
|
function getValue() {
|
|
return encodeURIComponent(easyMDE.value())
|
|
}
|
|
function myPreview() {
|
|
saveFile()
|
|
easyMDE.togglePreview()
|
|
}
|
|
function refresh() {
|
|
Android.refresh()
|
|
onRead()
|
|
}
|
|
function displayName() {
|
|
if (typeof Android !== 'undefined') return Android.triggerDisplayName()
|
|
else return "NONdroid"
|
|
}
|
|
function shareText() {
|
|
saveFile()
|
|
Android.triggerShare(easyMDE.markdown(easyMDE.codemirror.doc.getValue()))
|
|
}
|
|
|
|
function getHtml() {
|
|
return encodeURIComponent(easyMDE.markdown(easyMDE.codemirror.doc.getValue()))
|
|
}
|
|
|
|
function appendText() {
|
|
if ((appendix = Android.getMdToAppend()) !== "") {
|
|
cursor = easyMDE.codemirror.doc.getCursor()
|
|
easyMDE.codemirror.doc.setValue(easyMDE.codemirror.doc.getValue() + appendix)
|
|
easyMDE.codemirror.doc.setCursor(cursor)
|
|
}
|
|
}
|
|
|
|
function pasteText() {
|
|
data = new DataTransfer()
|
|
data.setData("text/plain", Android.getMdToAppend())
|
|
event = new Event("paste")
|
|
event.clipboardData = data
|
|
easyMDE.codemirror.focus()
|
|
document.getElementsByClassName("CodeMirror-scroll")[0].dispatchEvent(event);
|
|
saveFile()
|
|
}
|
|
|
|
windowHeight = window.innerHeight
|
|
function toggleBar() {
|
|
if (Android.isFullscreen()) {
|
|
easyMDE.codemirror.getScrollerElement().style.height=String(windowHeight-40)+"px"
|
|
} else {
|
|
easyMDE.codemirror.getScrollerElement().style.height=String(windowHeight-120)+"px"
|
|
}
|
|
Android.toggleBar()
|
|
easyMDE.codemirror.focus()
|
|
}
|
|
themes = [ "solarized", "3024-night"]
|
|
i=1
|
|
function toggleTheme() {
|
|
easyMDE.codemirror.setOption("theme",themes[i])
|
|
i++
|
|
if (i>themes.length-1) i=0
|
|
}
|
|
|
|
const easyMDE = new EasyMDE({
|
|
spellChecker: false,
|
|
nativeSpellcheck: false,
|
|
maxHeight: String(windowHeight-120)+"px",
|
|
inputStyle: "textarea",
|
|
autoDownloadFontAwesome: false,
|
|
theme: "solarized",
|
|
status: [
|
|
{
|
|
className: "editor-statusbar-left",
|
|
onUpdate: (el) => {
|
|
el.innerHTML = "<i class=\"fa fa-circle\"></i>"
|
|
}
|
|
},
|
|
{
|
|
className: "displayName",
|
|
defaultValue: "None",
|
|
onUpdate: (el) => {
|
|
el.innerHTML = `${displayName()}`
|
|
},
|
|
}, "lines", "words", "cursor",
|
|
{
|
|
className: "editor-statusbar-right",
|
|
onUpdate: (el) => {
|
|
el.innerHTML = "<i class=\"fa fa-square\"></i>"
|
|
}
|
|
}
|
|
],
|
|
toolbar: [
|
|
{
|
|
name: "toggleTheme",
|
|
action: toggleTheme,
|
|
className: "fa fa-moon",
|
|
title: "Toggle Theme"
|
|
},
|
|
{
|
|
name: "share",
|
|
action: shareText,
|
|
className: "fa fa-share-nodes",
|
|
title: "Share"
|
|
},"strikethrough", "horizontal-rule","undo",
|
|
{
|
|
name: "preview",
|
|
action: myPreview,
|
|
className: "fa fa-eye",
|
|
title: "Preview",
|
|
noDisable: true
|
|
},"redo",
|
|
"bold", "italic","link","code",
|
|
{
|
|
name: "toggle",
|
|
action: toggleBar,
|
|
className: "fa fa-expand",
|
|
title: "Toggle Bar",
|
|
}
|
|
]
|
|
});
|
|
onRead(); |