mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
bd6ed8d3c0
Former-commit-id: becceb5fed276d2daa80eca4a41b9fa9d3eae9fd [formerly 4ac3d85f084df155b06e17eea289e34ea60faa50] [formerly 19561726e85e6c133c667d1ee948b0ff2978632d [formerly a3fe621f1947a2cf0b6af4ac6ccb01c3c744fc2e]]
Former-commit-id: 3b7092e62e255f90d4ddcea9a104f5e6db22da2e [formerly 0dd41c8f221df6a21fad9da2ff2287ebb98f3b9a]
Former-commit-id: 62a685d81f08d7b96596cbc236c540141cdd9e42
Former-commit-id: 4b75f66381
406 lines
18 KiB
Cheetah
Executable File
406 lines
18 KiB
Cheetah
Executable File
<!DOCTYPE html>
|
|
<html>
|
|
|
|
<head>
|
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<link rel="apple-touch-icon" sizes="57x57" href=/static/img/cowyo/apple-icon-57x57.png>
|
|
<link rel="apple-touch-icon" sizes="60x60" href=/static/img/cowyo/img/cowyo/apple-icon-60x60.png>
|
|
<link rel="apple-touch-icon" sizes="72x72" href=/static/img/cowyo/apple-icon-72x72.png>
|
|
<link rel="apple-touch-icon" sizes="76x76" href=/static/img/cowyo/apple-icon-76x76.png>
|
|
<link rel="apple-touch-icon" sizes="114x114" href=/static/img/cowyo/apple-icon-114x114.png>
|
|
<link rel="apple-touch-icon" sizes="120x120" href=/static/img/cowyo/apple-icon-120x120.png>
|
|
<link rel="apple-touch-icon" sizes="144x144" href=/static/img/cowyo/apple-icon-144x144.png>
|
|
<link rel="apple-touch-icon" sizes="152x152" href=/static/img/cowyo/apple-icon-152x152.png>
|
|
<link rel="apple-touch-icon" sizes="180x180" href=/static/img/cowyo/apple-icon-180x180.png>
|
|
<link rel="icon" type="image/png" sizes="192x192" href=/static/img/cowyo/android-icon-192x192.png>
|
|
<link rel="icon" type="image/png" sizes="32x32" href=/static/img/cowyo/favicon-32x32.png>
|
|
<link rel="icon" type="image/png" sizes="96x96" href=/static/img/cowyo/favicon-96x96.png>
|
|
<link rel="icon" type="image/png" sizes="16x16" href=/static/img/cowyo/favicon-16x16.png>
|
|
<link rel="manifest" href=/static/img/cowyo/manifest.json>
|
|
<meta name="msapplication-TileColor" content="#fff">
|
|
<meta name="msapplication-TileImage" content="/ms-icon-144x144.png">
|
|
<meta name="theme-color" content="#fff">
|
|
|
|
<script type="text/javascript" src="/static/js/jquery-1.8.3.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="/static/css/github-markdown.css">
|
|
<link rel="stylesheet" type="text/css" href="/static/css/menus-min.css">
|
|
<link rel="stylesheet" type="text/css" href="/static/css/base-min.css">
|
|
<link rel="stylesheet" href="/static/css/highlight.css">
|
|
<script src="/static/js/highlight.min.js"></script>
|
|
<script type="text/javascript" src="/static/js/highlight.pack.js"></script>
|
|
|
|
<style type="text/css">
|
|
{{ if .ListPage }}
|
|
/* Required for lists */
|
|
span { cursor: pointer; }
|
|
{{ end }}
|
|
|
|
|
|
body {
|
|
background: #fff;
|
|
}
|
|
|
|
.success {
|
|
color: #5cb85c;
|
|
}
|
|
|
|
.pure-menu a {
|
|
color: #777;
|
|
}
|
|
|
|
#wrap {
|
|
position: absolute;
|
|
top: 50px;
|
|
left: 2%;
|
|
right: 2%;
|
|
bottom: 2%;
|
|
/* border: 3px double #f99;
|
|
*/
|
|
}
|
|
|
|
textarea {
|
|
width: 100%;
|
|
height: 100%;
|
|
box-sizing: border-box;
|
|
/* For IE and modern versions of Chrome */
|
|
-moz-box-sizing: border-box;
|
|
/* For Firefox */
|
|
-webkit-box-sizing: border-box;
|
|
/* For Safari */
|
|
position: absolute;
|
|
/* padding: 1em 2em;
|
|
*/
|
|
left: 0;
|
|
right: 0;
|
|
bottom: 0;
|
|
top: 0;
|
|
border: 0;
|
|
border: none;
|
|
outline: none;
|
|
-webkit-box-shadow: none;
|
|
-moz-box-shadow: none;
|
|
box-shadow: none;
|
|
resize: none;
|
|
}
|
|
|
|
</style>
|
|
|
|
<title>{{ .Page }}</title>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<script type='text/javascript'>
|
|
//<![CDATA[
|
|
$(window).load(function() {
|
|
// Returns a function, that, as long as it continues to be invoked, will not
|
|
// be triggered. The function will be called after it stops being called for
|
|
// N milliseconds. If `immediate` is passed, trigger the function on the
|
|
// leading edge, instead of the trailing.
|
|
function debounce(func, wait, immediate) {
|
|
var timeout;
|
|
return function() {
|
|
$('#saveEditButton').removeClass()
|
|
$('#saveEditButton').text("Editing");
|
|
var context = this,
|
|
args = arguments;
|
|
var later = function() {
|
|
timeout = null;
|
|
if (!immediate) func.apply(context, args);
|
|
};
|
|
var callNow = immediate && !timeout;
|
|
clearTimeout(timeout);
|
|
timeout = setTimeout(later, wait);
|
|
if (callNow) func.apply(context, args);
|
|
};
|
|
};
|
|
|
|
// This will apply the debounce effect on the keyup event
|
|
// And it only fires 500ms or half a second after the user stopped typing
|
|
$('#userInput').on('keyup', debounce(function() {
|
|
console.log('typing occurred');
|
|
$('#saveEditButton').removeClass()
|
|
$('#saveEditButton').text("Saving")
|
|
upload();
|
|
}, 500));
|
|
|
|
function upload() {
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: '/update',
|
|
data: JSON.stringify({
|
|
new_text: $('#userInput').val(),
|
|
page: "{{ .Page }}"
|
|
}),
|
|
success: function(data) {
|
|
$('#saveEditButton').removeClass()
|
|
if (data.success == true) {
|
|
$('#saveEditButton').addClass("success");
|
|
} else {
|
|
$('#saveEditButton').addClass("failure");
|
|
}
|
|
$('#saveEditButton').text(data.message);
|
|
},
|
|
error: function(xhr, error) {
|
|
$('#saveEditButton').text(error);
|
|
},
|
|
contentType: "application/json",
|
|
dataType: 'json'
|
|
});
|
|
}
|
|
|
|
function primeForSelfDestruct() {
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: '/prime',
|
|
data: JSON.stringify({
|
|
page: "{{ .Page }}"
|
|
}),
|
|
success: function(data) {
|
|
$('#saveEditButton').removeClass()
|
|
if (data.success == true) {
|
|
$('#saveEditButton').addClass("success");
|
|
} else {
|
|
$('#saveEditButton').addClass("failure");
|
|
}
|
|
$('#saveEditButton').text(data.message);
|
|
},
|
|
error: function(xhr, error) {
|
|
$('#saveEditButton').text(error);
|
|
},
|
|
contentType: "application/json",
|
|
dataType: 'json'
|
|
});
|
|
}
|
|
|
|
function lockPage(passphrase) {
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: '/lock',
|
|
data: JSON.stringify({
|
|
page: "{{ .Page }}",
|
|
passphrase: passphrase
|
|
}),
|
|
success: function(data) {
|
|
$('#saveEditButton').removeClass()
|
|
if (data.success == true) {
|
|
$('#saveEditButton').addClass("success");
|
|
} else {
|
|
$('#saveEditButton').addClass("failure");
|
|
}
|
|
$('#saveEditButton').text(data.message);
|
|
if (data.success == true && $('#lockPage').text() == "Lock") {
|
|
window.location = "/{{ .Page }}/view";
|
|
}
|
|
if (data.success == true && $('#lockPage').text() == "Unlock") {
|
|
window.location = "/{{ .Page }}/edit";
|
|
}
|
|
},
|
|
error: function(xhr, error) {
|
|
$('#saveEditButton').removeClass()
|
|
$('#saveEditButton').addClass("failure");
|
|
$('#saveEditButton').text(error);
|
|
},
|
|
contentType: "application/json",
|
|
dataType: 'json'
|
|
});
|
|
}
|
|
|
|
function encryptPage(passphrase) {
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: '/encrypt',
|
|
data: JSON.stringify({
|
|
page: "{{ .Page }}",
|
|
passphrase: passphrase
|
|
}),
|
|
success: function(data) {
|
|
$('#saveEditButton').removeClass()
|
|
if (data.success == true) {
|
|
$('#saveEditButton').addClass("success");
|
|
} else {
|
|
$('#saveEditButton').addClass("failure");
|
|
}
|
|
$('#saveEditButton').text(data.message);
|
|
if (data.success == true && $('#encryptPage').text() == "Encrypt") {
|
|
window.location = "/{{ .Page }}/view";
|
|
}
|
|
if (data.success == true && $('#encryptPage').text() == "Decrypt") {
|
|
window.location = "/{{ .Page }}/edit";
|
|
}
|
|
},
|
|
error: function(xhr, error) {
|
|
$('#saveEditButton').text(error);
|
|
},
|
|
contentType: "application/json",
|
|
dataType: 'json'
|
|
});
|
|
}
|
|
|
|
|
|
$("#encryptPage").click(function(e) {
|
|
e.preventDefault();
|
|
var passphrase = prompt("Please enter a passphrase", "");
|
|
if (passphrase != null) {
|
|
encryptPage(passphrase);
|
|
}
|
|
});
|
|
|
|
|
|
$("#erasePage").click(function(e) {
|
|
e.preventDefault();
|
|
var r = confirm("Are you sure you want to erase?");
|
|
if (r == true) {
|
|
window.location = "/{{ .Page }}/erase";
|
|
} else {
|
|
x = "You pressed Cancel!";
|
|
}
|
|
});
|
|
|
|
|
|
$("#selfDestructPage").click(function(e) {
|
|
e.preventDefault();
|
|
var r = confirm("This will erase the page the next time it is opened, are you sure you want to do that?");
|
|
if (r == true) {
|
|
primeForSelfDestruct();
|
|
} else {
|
|
x = "You pressed Cancel!";
|
|
}
|
|
});
|
|
|
|
|
|
$("#lockPage").click(function(e) {
|
|
e.preventDefault();
|
|
var passphrase = prompt("Please enter a passphrase to lock", "");
|
|
if (passphrase != null) {
|
|
if ($('#lockPage').text() == "Lock") {
|
|
$("#saveEditButton").text("Locking");
|
|
} else {
|
|
$("#saveEditButton").text("Unlocking");
|
|
}
|
|
lockPage(passphrase);
|
|
// POST encrypt page
|
|
// reload page
|
|
}
|
|
});
|
|
|
|
$("textarea").keydown(function(e) {
|
|
if(e.keyCode === 9) { // tab was pressed
|
|
// get caret position/selection
|
|
var start = this.selectionStart;
|
|
var end = this.selectionEnd;
|
|
|
|
var $this = $(this);
|
|
var value = $this.val();
|
|
|
|
// set textarea value to: text before caret + tab + text after caret
|
|
$this.val(value.substring(0, start)
|
|
+ "\t"
|
|
+ value.substring(end));
|
|
|
|
// put caret at right position again (add one for the tab)
|
|
this.selectionStart = this.selectionEnd = start + 1;
|
|
|
|
// prevent the focus lose
|
|
e.preventDefault();
|
|
}
|
|
});
|
|
|
|
$('.deletable').click(function(event) {
|
|
event.preventDefault();
|
|
var lineNum = $(this).attr('id')
|
|
$.ajax({
|
|
url: "/listitem" + '?' + $.param({
|
|
"lineNum": lineNum,
|
|
"page": "{{ .Page }}"
|
|
}),
|
|
type: 'DELETE',
|
|
success: function() {
|
|
window.location.reload(true);
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
}); //]]>
|
|
|
|
</script>
|
|
<script>hljs.initHighlightingOnLoad();</script>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
<article class="markdown-body">
|
|
<div class="pure-menu pure-menu-horizontal">
|
|
<ul class="pure-menu-list">
|
|
<li></li>
|
|
<!-- Required to keep them level? -->
|
|
<li class="pure-menu-item pure-menu-has-children pure-menu-allow-hover">
|
|
<a href="#" id="menuLink1" class="pure-menu-link">CowYo</a>
|
|
<ul class="pure-menu-children">
|
|
<li class="pure-menu-item"><a href="/" class="pure-menu-link">New</a></li>
|
|
<hr>
|
|
{{ if (or (.IsLocked) (.IsEncrypted) )}}
|
|
{{ if .IsLocked }}
|
|
<li class="pure-menu-item"><a href="#" class="pure-menu-link" id="lockPage">{{ if .IsLocked }}Unlock{{ else }}Lock{{end}}</a></li>
|
|
{{ else }}
|
|
<li class="pure-menu-item"><a href="#" class="pure-menu-link" id="encryptPage">{{ if .IsEncrypted }}Decrypt{{ else }}Encrypt{{end}}</a></li>
|
|
{{ end }}
|
|
{{ else }}
|
|
<li class="pure-menu-item"><a href="#" class="pure-menu-link" id="encryptPage">{{ if .IsEncrypted }}Decrypt{{ else }}Encrypt{{end}}</a></li>
|
|
<li class="pure-menu-item"><a href="#" class="pure-menu-link" id="lockPage">{{ if .IsLocked }}Unlock{{ else }}Lock{{end}}</a></li>
|
|
<li class="pure-menu-item"><a href="/{{ .Page }}/history" class="pure-menu-link">History</a></li>
|
|
<hr>
|
|
<li class="pure-menu-item"><a href="#" class="pure-menu-link" id="selfDestructPage">Self-destruct</a></li>
|
|
<li class="pure-menu-item"><a href="#" class="pure-menu-link" id="erasePage">Erase</a></li>
|
|
{{ end }}
|
|
</ul>
|
|
</li>
|
|
<li class="pure-menu-item {{ with .ViewPage }}pure-menu-selected{{ end }}"><a href="/{{ .Page }}/view" class="pure-menu-link">View</a></li>
|
|
{{ if (or (.IsLocked) (.IsEncrypted) )}}
|
|
{{ if .IsLocked }}
|
|
<li class="pure-menu-item"><span id="saveEditButton">Locked</span></li>
|
|
{{ else }}
|
|
<li class="pure-menu-item"><span id="saveEditButton">Encrypted</span></li>
|
|
{{ end }}
|
|
{{else}}<li class="pure-menu-item {{ with .ListPage }}pure-menu-selected{{ end }}"><a href="/{{ .Page }}/list" class="pure-menu-link">List</a></li>
|
|
<li class="pure-menu-item {{ with .EditPage }}pure-menu-selected{{ end }}"><a href="/{{ .Page }}/edit" class="pure-menu-link"><span id="saveEditButton">Edit</span></a></li>
|
|
{{end}}
|
|
|
|
|
|
</ul>
|
|
</div>
|
|
|
|
|
|
<div id="wrap">
|
|
{{ if .DontKnowPage }} <strong><center>{{ .Route }} not understood!</center></strong>{{ end }}
|
|
{{ if .ViewPage }} {{ .RenderedPage }} {{ end }}
|
|
{{ if .EditPage }} <textarea autofocus placeholder="Start typing, it will save automatically." id="userInput">{{ .RawPage }}</textarea>{{ end }}
|
|
{{ if .HistoryPage }}
|
|
<ul>
|
|
{{range $i, $e := .Versions}}
|
|
<li><a href="/{{ $.Page }}/view?version={{$e}}">Version {{index $.VersionsText $i}}</a></li>
|
|
{{end}}
|
|
</ul>
|
|
{{ end }}
|
|
{{ if .ListPage }}
|
|
{{ range $index, $element := .ListItems }}
|
|
{{ $element }}
|
|
{{ end }}
|
|
{{ end }}
|
|
|
|
</div>
|
|
</article>
|
|
|
|
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|