mirror of https://github.com/JustKato/FreePad.git
Compare commits
No commits in common. "7982d564e87491898c61126409209fc794cb510d" and "1b1fe5987719be906a5bfe87790e4c79f9cb68ca" have entirely different histories.
7982d564e8
...
1b1fe59877
|
@ -4,6 +4,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/JustKato/FreePad/lib/objects"
|
"github.com/JustKato/FreePad/lib/objects"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
@ -33,14 +34,13 @@ func BindSocket(router *gin.RouterGroup) {
|
||||||
// Get the name of the pad to assign to this socket
|
// Get the name of the pad to assign to this socket
|
||||||
padName := ctx.Param("pad")
|
padName := ctx.Param("pad")
|
||||||
// Upgrade the socket connection
|
// Upgrade the socket connection
|
||||||
webSocketUpgrade(ctx, padName)
|
webSocketUpgrade(ctx.Writer, ctx.Request, padName)
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func webSocketUpgrade(ctx *gin.Context, padName string) {
|
func webSocketUpgrade(w http.ResponseWriter, r *http.Request, padName string) {
|
||||||
|
conn, err := wsUpgrader.Upgrade(w, r, nil)
|
||||||
conn, err := wsUpgrader.Upgrade(ctx.Writer, ctx.Request, ctx.Request.Header)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Failed to set websocket upgrade: %v\n", err)
|
fmt.Printf("Failed to set websocket upgrade: %v\n", err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -45,24 +45,6 @@ main#main-card {
|
||||||
tab-size: 2;
|
tab-size: 2;
|
||||||
|
|
||||||
font-family: 'Roboto Mono', monospace !important;
|
font-family: 'Roboto Mono', monospace !important;
|
||||||
|
|
||||||
padding-top: 2rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
#padTitle {
|
|
||||||
padding: .3rem .75rem !important;
|
|
||||||
border-radius: .25rem;
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dark #padTitle {
|
|
||||||
color: #db3384;
|
|
||||||
background-color: rgba(0, 0, 0, 0.10);
|
|
||||||
}
|
|
||||||
|
|
||||||
.light #padTitle {
|
|
||||||
color: #555273;
|
|
||||||
border: 1px solid rgba(0, 0, 0, 0.15);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#pad-content-area {
|
#pad-content-area {
|
||||||
|
@ -72,16 +54,11 @@ main#main-card {
|
||||||
flex-flow: column;
|
flex-flow: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
.light .edit-content-text {
|
|
||||||
color: white !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.edit-content-text {
|
.edit-content-text {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.read-only-content .edit-content-text {
|
.read-only-content .edit-content-text {
|
||||||
margin-top: 1rem;
|
|
||||||
display: block !important;
|
display: block !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,9 +78,6 @@ main#main-card {
|
||||||
max-height: calc(17rem + 30vh);
|
max-height: calc(17rem + 30vh);
|
||||||
min-height: 17rem;
|
min-height: 17rem;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
|
|
||||||
padding-top: 2rem;
|
|
||||||
margin-top: 1rem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
textarea:focus,
|
textarea:focus,
|
||||||
|
|
|
@ -138,10 +138,7 @@ function renderArchivesSelection() {
|
||||||
let resp = confirm("Load contents of pad from memory? This will overwrite the current pad for everyone.");
|
let resp = confirm("Load contents of pad from memory? This will overwrite the current pad for everyone.");
|
||||||
|
|
||||||
if (!!resp) {
|
if (!!resp) {
|
||||||
// Update visually for the client
|
document.getElementById(`pad-content`).value = a.content;
|
||||||
updatePadContent(a.content);
|
|
||||||
// Send the update
|
|
||||||
window.socket.sendPadUpdate();
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -213,8 +210,6 @@ function setTextareaPreview(t = true) {
|
||||||
|
|
||||||
padContentArea.classList.add(`read-only-content`);
|
padContentArea.classList.add(`read-only-content`);
|
||||||
|
|
||||||
prev.scrollTop = prev.scrollHeight;
|
|
||||||
|
|
||||||
textarea.classList.add(`hidden`);
|
textarea.classList.add(`hidden`);
|
||||||
} else {
|
} else {
|
||||||
// Toggle edit mode
|
// Toggle edit mode
|
||||||
|
|
|
@ -31,14 +31,8 @@ class PadSocket {
|
||||||
|
|
||||||
// Check if a connection URL was mentioned
|
// Check if a connection URL was mentioned
|
||||||
if ( connUrl == null ) {
|
if ( connUrl == null ) {
|
||||||
|
|
||||||
let connProtocol = `ws://`;
|
|
||||||
if ( window.location.protocol == `https:` ) {
|
|
||||||
connProtocol = `wss://`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try and connect to the local websocket
|
// Try and connect to the local websocket
|
||||||
connUrl = connProtocol + window.location.host + `/ws/get/${padName}`;
|
connUrl = `ws://` + window.location.host + `/ws/get/${padName}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connect to the websocket
|
// Connect to the websocket
|
||||||
|
@ -51,13 +45,9 @@ class PadSocket {
|
||||||
updateStatus(`Established`, `text-success`);
|
updateStatus(`Established`, `text-success`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onFail() {
|
|
||||||
updateStatus(`Connection Failed`, `text-dangerous`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try and reconnect on failure
|
// Try and reconnect on failure
|
||||||
ws.onclose = onFail;
|
ws.onclose = connectSocket;
|
||||||
ws.onerror = onFail;
|
ws.onerror = connectSocket;
|
||||||
|
|
||||||
// Assign the websocket
|
// Assign the websocket
|
||||||
this.ws = ws;
|
this.ws = ws;
|
||||||
|
@ -186,34 +176,10 @@ class PadSocket {
|
||||||
*/
|
*/
|
||||||
function updatePadContent(newContent, textArea = true) {
|
function updatePadContent(newContent, textArea = true) {
|
||||||
// Update the textarea
|
// Update the textarea
|
||||||
if ( textArea ) {
|
if ( textArea ) document.getElementById(`pad-content`).value = newContent;
|
||||||
document.getElementById(`pad-content`).value = newContent;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the preview
|
// Update the preview
|
||||||
const prev = document.getElementById(`textarea-preview`);
|
document.getElementById(`textarea-preview`).innerHTML = newContent;
|
||||||
const shouldScroll = prev.scrollTop >= (prev.scrollHeight - Number(getComputedStyle(prev).height.replace(/px/g, ''))) * 0.98;
|
// TODO: Re-run the syntax highlight
|
||||||
|
|
||||||
prev.innerHTML = escapeHtml(newContent);
|
|
||||||
|
|
||||||
prev.classList.remove(`language-undefined`);
|
|
||||||
|
|
||||||
prev.classList.forEach( c => {
|
|
||||||
if ( c.indexOf(`language-`) != -1 ) {
|
|
||||||
prev.classList.remove(c);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
try { // highlights
|
|
||||||
hljs.highlightElement(document.getElementById(`textarea-preview`));
|
|
||||||
} catch ( err ) {
|
|
||||||
console.err(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if we should follow the bottom scrolling
|
|
||||||
if (shouldScroll) {
|
|
||||||
prev.scrollTop = prev.scrollHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,16 +212,3 @@ function connectSocket() {
|
||||||
window.addEventListener(`load`, e => {
|
window.addEventListener(`load`, e => {
|
||||||
connectSocket()
|
connectSocket()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
// lol
|
|
||||||
function escapeHtml(html){
|
|
||||||
const text = document.createTextNode(html);
|
|
||||||
const p = document.createElement('p');
|
|
||||||
|
|
||||||
p.appendChild(text);
|
|
||||||
const content = p.innerHTML;
|
|
||||||
p.remove();
|
|
||||||
|
|
||||||
return content;
|
|
||||||
}
|
|
|
@ -35,9 +35,7 @@
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2 class="mb-4" id="padTitle">
|
<h2 class="mb-4">{{.title}}</h2>
|
||||||
{{.title}}
|
|
||||||
</h2>
|
|
||||||
|
|
||||||
<div id="pad-content-area">
|
<div id="pad-content-area">
|
||||||
<div class="btn-sm btn" id="pad-content-toggler" onclick="toggleTextareaPreview()">
|
<div class="btn-sm btn" id="pad-content-toggler" onclick="toggleTextareaPreview()">
|
||||||
|
|
Loading…
Reference in New Issue