diff --git a/assets/assets.qtpl.go b/assets/assets.qtpl.go index 1a8bede..d6fc38c 100644 --- a/assets/assets.qtpl.go +++ b/assets/assets.qtpl.go @@ -177,11 +177,13 @@ header { width: 100%; margin-bottom: 1rem; } main { grid-column: 1 / span 1; grid-row: 1 / span 2; } .relative-hyphae { grid-column: 2 / span 1; grid-row: 1 / span 1; } .layout-card { width: 100%; } + .edit-toolbar { margin: 0 0 0 auto; } + .edit-toolbar__buttons { display: grid; grid-template-columns: 1fr 1fr; } } @media screen and (min-width: 1250px) { .layout { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); } - .layout-card { max-width: 16rem; } + .layout-card { max-width: 18rem; } .main-width { margin: 0 auto; } .backlinks { grid-column: 1 / span 1; margin-right: 0; } main { grid-column: 2 / span 1; } @@ -204,6 +206,7 @@ textarea {font-size:16px; font-family: 'PT Sans', 'Liberation Sans', sans-serif; .edit-form {height:70vh;} .edit-form textarea {width:100%;height:95%;} .edit-form__save { font-weight: bold; } +.edit-toolbar__buttons, .edit-toolbar__ad { margin: .5rem; } .icon {margin-right: .25rem; vertical-align: bottom; } @@ -433,34 +436,19 @@ function getSelectedText(el = editTextarea) { return text.substring(start, end) } -function insertTextAtCursor(text, cursorPosition = null, el = editTextarea) { - const [start, end] = [el.selectionStart, el.selectionEnd] - el.setRangeText(text, start, end, 'select') - el.focus() - if (cursorPosition == null) { - placeCursor(end + text.length) - } else { - placeCursor(end + cursorPosition) +function textInserter(text, cursorPosition = null, el = editTextarea) { + return function() { + const [start, end] = [el.selectionStart, el.selectionEnd] + el.setRangeText(text, start, end, 'select') + el.focus() + if (cursorPosition == null) { + placeCursor(end + text.length) + } else { + placeCursor(end + cursorPosition) + } } } -function wrapSelection(prefix, postfix = null, el = editTextarea) { - const [start, end] = [el.selectionStart, el.selectionEnd] - if (postfix == null) { - postfix = prefix - } - text = getSelectedText(el) - result = prefix + text + postfix - el.setRangeText(result, start, end, 'select') - el.focus() - placeCursor(end + (prefix + postfix).length) -} - -function insertDate() { - let date = new Date().toISOString().split('T')[0] - insertTextAtCursor(date) -} - function selectionWrapper(cursorPosition, prefix, postfix = null, el = editTextarea) { return function() { const [start, end] = [el.selectionStart, el.selectionEnd] @@ -485,14 +473,24 @@ const wrapBold = selectionWrapper(2, '**'), wrapHighlighted = selectionWrapper(2, '!!'), wrapLifted = selectionWrapper(1, '^'), wrapLowered = selectionWrapper(2, ',,'), - wrapStrikethrough = selectionWrapper(2, '~~') + wrapStrikethrough = selectionWrapper(2, '~~'), + wrapLink = selectionWrapper(2, '[[', ']]') -function insertHorizontalBar() { - insertTextAtCursor('----\n') +const insertHorizontalBar = textInserter('----\n'), + insertImgBlock = textInserter('img {\n\t\n}\n', 7), + insertTableBlock = textInserter('table {\n\t\n}\n', 9), + insertRocket = textInserter('=> '), + insertXcl = textInserter('<= ') + +function insertDate() { + let date = new Date().toISOString().split('T')[0] + textInserter(date)() } -function insertImgBlock() { - insertTextAtCursor('img {\n\t\n}\n', 7) +function insertUserlink() { + const userlink = document.querySelector('.header-links__entry_user a') + const userHypha = userlink.getAttribute('href').substring(7) // no /hypha/ + textInserter('[[' + userHypha + ']]')() } `) //line assets/assets.qtpl:14 diff --git a/assets/default.css b/assets/default.css index 4d06d76..84c6fb7 100644 --- a/assets/default.css +++ b/assets/default.css @@ -66,11 +66,13 @@ header { width: 100%; margin-bottom: 1rem; } main { grid-column: 1 / span 1; grid-row: 1 / span 2; } .relative-hyphae { grid-column: 2 / span 1; grid-row: 1 / span 1; } .layout-card { width: 100%; } + .edit-toolbar { margin: 0 0 0 auto; } + .edit-toolbar__buttons { display: grid; grid-template-columns: 1fr 1fr; } } @media screen and (min-width: 1250px) { .layout { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); } - .layout-card { max-width: 16rem; } + .layout-card { max-width: 18rem; } .main-width { margin: 0 auto; } .backlinks { grid-column: 1 / span 1; margin-right: 0; } main { grid-column: 2 / span 1; } @@ -93,6 +95,7 @@ textarea {font-size:16px; font-family: 'PT Sans', 'Liberation Sans', sans-serif; .edit-form {height:70vh;} .edit-form textarea {width:100%;height:95%;} .edit-form__save { font-weight: bold; } +.edit-toolbar__buttons, .edit-toolbar__ad { margin: .5rem; } .icon {margin-right: .25rem; vertical-align: bottom; } diff --git a/assets/toolbar.js b/assets/toolbar.js index fe0629f..ea5c8d4 100644 --- a/assets/toolbar.js +++ b/assets/toolbar.js @@ -11,34 +11,19 @@ function getSelectedText(el = editTextarea) { return text.substring(start, end) } -function insertTextAtCursor(text, cursorPosition = null, el = editTextarea) { - const [start, end] = [el.selectionStart, el.selectionEnd] - el.setRangeText(text, start, end, 'select') - el.focus() - if (cursorPosition == null) { - placeCursor(end + text.length) - } else { - placeCursor(end + cursorPosition) +function textInserter(text, cursorPosition = null, el = editTextarea) { + return function() { + const [start, end] = [el.selectionStart, el.selectionEnd] + el.setRangeText(text, start, end, 'select') + el.focus() + if (cursorPosition == null) { + placeCursor(end + text.length) + } else { + placeCursor(end + cursorPosition) + } } } -function wrapSelection(prefix, postfix = null, el = editTextarea) { - const [start, end] = [el.selectionStart, el.selectionEnd] - if (postfix == null) { - postfix = prefix - } - text = getSelectedText(el) - result = prefix + text + postfix - el.setRangeText(result, start, end, 'select') - el.focus() - placeCursor(end + (prefix + postfix).length) -} - -function insertDate() { - let date = new Date().toISOString().split('T')[0] - insertTextAtCursor(date) -} - function selectionWrapper(cursorPosition, prefix, postfix = null, el = editTextarea) { return function() { const [start, end] = [el.selectionStart, el.selectionEnd] @@ -59,12 +44,22 @@ const wrapBold = selectionWrapper(2, '**'), wrapHighlighted = selectionWrapper(2, '!!'), wrapLifted = selectionWrapper(1, '^'), wrapLowered = selectionWrapper(2, ',,'), - wrapStrikethrough = selectionWrapper(2, '~~') + wrapStrikethrough = selectionWrapper(2, '~~'), + wrapLink = selectionWrapper(2, '[[', ']]') -function insertHorizontalBar() { - insertTextAtCursor('----\n') +const insertHorizontalBar = textInserter('----\n'), + insertImgBlock = textInserter('img {\n\t\n}\n', 7), + insertTableBlock = textInserter('table {\n\t\n}\n', 9), + insertRocket = textInserter('=> '), + insertXcl = textInserter('<= ') + +function insertDate() { + let date = new Date().toISOString().split('T')[0] + textInserter(date)() } -function insertImgBlock() { - insertTextAtCursor('img {\n\t\n}\n', 7) +function insertUserlink() { + const userlink = document.querySelector('.header-links__entry_user a') + const userHypha = userlink.getAttribute('href').substring(7) // no /hypha/ + textInserter('[[' + userHypha + ']]')() } diff --git a/views/mutators.qtpl b/views/mutators.qtpl index 3c01602..904d988 100644 --- a/views/mutators.qtpl +++ b/views/mutators.qtpl @@ -1,14 +1,17 @@ {% import "net/http" %} {% import "github.com/bouncepaw/mycorrhiza/util" %} +{% import "github.com/bouncepaw/mycorrhiza/user" %} -{% func Toolbar() %} +{% func Toolbar(u *user.User) %} {% endfunc %} @@ -45,7 +75,7 @@ Cancel -{%s= Toolbar() %} +{%s= Toolbar(user.FromRequest(rq)) %} {% endfunc %} @@ -66,6 +96,6 @@
Note that the hypha is not saved yet. You can preview the changes ↓
Note that the hypha is not saved yet. You can preview the changes ↓