start on draggable postform #57

merge-requests/208/head
fatchan 5 years ago
parent 2d65cd4728
commit 236e0ce8d5
  1. 23
      gulp/res/css/style.css
  2. 123
      gulp/res/js/dragable.js
  3. 18
      gulp/res/js/post.js
  4. 1
      gulp/res/js/quote.js
  5. 2
      gulpfile.js
  6. 1380
      style.css
  7. 2
      views/includes/navbar.pug
  8. 2
      views/includes/postform.pug
  9. 2
      views/layout.pug

@ -20,6 +20,7 @@ main {
max-width: 100%;
margin-bottom: 1px;
overflow: hidden;
flex-shrink: 0;
}
.col {
@ -150,7 +151,14 @@ pre {
cursor: pointer;
}
#settings::after {
content: "Settings"
content: "Settings";
}
#dragHandle {
flex-grow: 1;
background: var(--darken);
height: 1.75em;
cursor: move;
}
.statwrap {
@ -794,6 +802,11 @@ input[type="button"], input[type="range"], input[type="number"], input[type="tex
border-radius: 0px;
}
textarea {
max-height: 100%;
max-width: 100%;
}
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
-webkit-appearance: none;
@ -825,8 +838,7 @@ input[type="file"] {
z-index: 2;
box-sizing: border-box;
padding: 5px;
border: 1px solid var(--post-outline-color);
border-top: none;
overflow-y: auto;
}
#postform:target {
@ -954,7 +966,7 @@ table, .boardtable {
text-align: center;
}
/*
@media only screen and (max-height: 400px) {
#postform:target {
display: flex;
@ -962,9 +974,10 @@ table, .boardtable {
z-index: 0;
}
}
*/
@media only screen and (max-width: 600px) {
#settings::after {
content: "\2699"!important;
}

@ -0,0 +1,123 @@
setDefaultLocalStorage('dragtop', null);
setDefaultLocalStorage('dragleft', null);
class Dragable {
constructor(handle, target) {
this.draging = false;
this.xo = 0;
this.yo = 0;
this.handle = document.querySelector(handle);
this.target = document.querySelector(target);
const savedTop = localStorage.getItem('dragtop');
if (savedTop != 'null') {
this.target.style.top = savedTop;
}
const savedLeft = localStorage.getItem('dragleft');
if (savedLeft != 'null') {
this.target.style.left = savedLeft;
}
this.target.style.right = 'unset';
this.target.addEventListener('opened', e => this.updateMaxSizes(e));
this.handle.addEventListener('mousedown', e => this.startDrag(e));
this.handle.addEventListener('touchstart', e => this.startDrag(e));
document.addEventListener('mouseup', e => this.stopDrag(e));
document.addEventListener('touchend', e => this.stopDrag(e));
window.addEventListener('resize', e => this.updateMaxSizes(e));
window.addEventListener('orientationchange', e => this.updateMaxSizes(e));
}
//get a position in bounds
inBounds(pos, offset, size, limit) {
if (pos-offset <= 0) {
return 0;
} else if (pos-offset+size > limit) {
return limit-size;
} else {
return pos-offset;
}
}
updateMaxSizes() {
let rect = this.target.getBoundingClientRect();
if (rect.width === 0) {
return;
}
//reset to top left if resized or rotated and and edge goes off the screen
if (rect.right > document.documentElement.clientWidth) {
this.target.style.left = 0;
}
if (rect.bottom > document.documentElement.clientHeight) {
this.target.style.top = 0;
}
//set max widths, get rect again since it might have changed
rect = this.target.getBoundingClientRect();
this.target.style.maxHeight = `${document.documentElement.clientHeight - rect.top}px`;
this.target.style.maxWidth = `${document.documentElement.clientWidth - rect.left}px`;
}
//start drag and attach appropriate listener for click/drag
startDrag(e) {
this.draging = true;
this.target.style.position = 'fixed';
const rect = this.target.getBoundingClientRect();
switch (e.type) {
case 'mousedown':
this.xo = e.clientX - rect.left;
this.yo = e.clientY - rect.top;
window.addEventListener('mousemove', e => this.doDrag(e));
break;
case 'touchstart':
this.xo = e.targetTouches[0].clientX - rect.left;
this.yo = e.targetTouches[0].clientY - rect.top;
window.addEventListener('touchmove', e => this.doDrag(e));
break;
default:
//user has alien technology
break;
}
return false;
}
//do the actual drag/movement
doDrag(e) {
if (!this.draging) {
return;
}
this.updateMaxSizes();
switch (e.type) {
case 'mousemove':
this.target.style.left = `${this.inBounds(e.clientX, this.xo, this.target.offsetWidth, document.documentElement.clientWidth)}px`;
this.target.style.top = `${this.inBounds(e.clientY, this.yo, this.target.offsetHeight, document.documentElement.clientHeight)}px`;
break;
case 'touchmove':
this.target.style.left = `${this.inBounds(e.targetTouches[0].clientX, this.xo, this.target.offsetWidth, document.documentElement.clientWidth)}px`;
this.target.style.top = `${this.inBounds(e.targetTouches[0].clientY, this.yo, this.target.offsetHeight, document.documentElement.clientHeight)}px`;
break;
default:
break;
}
setLocalStorage('dragtop', this.target.style.top);
setLocalStorage('dragleft', this.target.style.left);
return false;
}
//stopped dragging
stopDrag(e) {
if (this.draging) {
this.draging = false;
window.removeEventListener('mousemove', e => this.doDrag(e));
window.removeEventListener('touchmove', e => this.doDrag(e));
}
}
}
new Dragable('#dragHandle', '#postform');
/*
todo:
-event when resizing to prevent going bigger than screen size
-event when resizing window to prevent going off screen (reset to right side)
-dont show drag handle when mobile and smaller than 400 height (set to middle)
*/

@ -19,7 +19,7 @@ pug_mixins["post"] = pug_interp = function(post, truncate, manage=false, globalm
var block = (this && this.block), attributes = (this && this.attributes) || {};
pug_html = pug_html + "\u003Cdiv" + (" class=\"anchor\""+pug_attr("id", post.postId, true, false)) + "\u003E\u003C\u002Fdiv\u003E\u003Cdiv" + (pug_attr("class", pug_classes([`post-container ${post.thread || ban === true ? '' : 'op'}`], [true]), false, false)+pug_attr("data-board", post.board, true, false)+pug_attr("data-post-id", post.postId, true, false)+pug_attr("data-user-id", post.userId, true, false)) + "\u003E";
const postURL = `/${post.board}/thread/${post.thread || post.postId}.html`;
pug_html = pug_html + "\u003Cdiv class=\"post-info\"\u003E\u003Clabel class=\"noselect\"\u003E";
pug_html = pug_html + "\u003Cdiv class=\"post-info\"\u003E\u003Cspan class=\"noselect\"\u003E\u003Clabel\u003E";
if (globalmanage) {
pug_html = pug_html + "\u003Cinput" + (" class=\"post-check\""+" type=\"checkbox\" name=\"globalcheckedposts\""+pug_attr("value", post._id, true, false)) + "\u002F\u003E ";
ipHashSub = post.ip.hash.slice(-10);
@ -31,17 +31,21 @@ pug_html = pug_html + "\u003Cinput" + (" class=\"post-check\""+" type=\"checkbox
}
pug_html = pug_html + " ";
if (!post.thread) {
if (post.sticky || post.bumplocked || post.locked || post.cyclic) {
pug_html = pug_html + "\u003Cspan class=\"post-icons\"\u003E";
if (post.sticky) {
pug_html = pug_html + "\u003Cimg src=\"\u002Fimg\u002Fsticky.png\" height=\"12\" width=\"12\" title=\"Sticky\"\u002F\u003E ";
pug_html = pug_html + "\u003Cimg src=\"\u002Fimg\u002Fsticky.png\" height=\"14\" width=\"14\" title=\"Sticky\"\u002F\u003E ";
}
if (post.bumplocked) {
pug_html = pug_html + "\u003Cimg src=\"\u002Fimg\u002Fbumplocked.png\" height=\"12\" width=\"12\" title=\"Bumplocked\"\u002F\u003E ";
pug_html = pug_html + "\u003Cimg src=\"\u002Fimg\u002Fbumplock.png\" height=\"14\" width=\"14\" title=\"Bumplocked\"\u002F\u003E ";
}
if (post.locked) {
pug_html = pug_html + "\u003Cimg src=\"\u002Fimg\u002Flocked.png\" height=\"12\" width=\"12\" title=\"Locked\"\u002F\u003E ";
pug_html = pug_html + "\u003Cimg src=\"\u002Fimg\u002Flock.png\" height=\"14\" width=\"14\" title=\"Locked\"\u002F\u003E ";
}
if (post.cyclic) {
pug_html = pug_html + "\u003Cimg src=\"\u002Fimg\u002Fcyclic.png\" height=\"13\" width=\"13\" title=\"Cyclic\"\u002F\u003E ";
pug_html = pug_html + "\u003Cimg src=\"\u002Fimg\u002Fcyclic.png\" height=\"14\" width=\"14\" title=\"Cyclic\"\u002F\u003E ";
}
pug_html = pug_html + "\u003C\u002Fspan\u003E";
}
}
if (post.subject) {
@ -53,7 +57,7 @@ pug_html = pug_html + "\u003Ca" + (pug_attr("href", `mailto:${post.email}`, true
else {
pug_html = pug_html + "\u003Cspan class=\"post-name\"\u003E" + (pug_escape(null == (pug_interp = post.name) ? "" : pug_interp)) + "\u003C\u002Fspan\u003E";
}
pug_html = pug_html + " ";
pug_html = pug_html + " \u003C\u002Flabel\u003E";
if (post.country && post.country.code) {
pug_html = pug_html + "\u003Cspan" + (pug_attr("class", pug_classes([`flag flag-${post.country.code.toLowerCase()}`], [true]), false, false)+pug_attr("title", post.country.name, true, false)+pug_attr("alt", post.country.name, true, false)) + "\u003E\u003C\u002Fspan\u003E ";
}
@ -68,7 +72,7 @@ pug_html = pug_html + "\u003Ctime" + (" class=\"post-date reltime\""+pug_attr("d
if (post.userId) {
pug_html = pug_html + "\u003Cspan" + (" class=\"user-id\""+pug_attr("style", pug_style(`background-color: #${post.userId}`), true, false)) + "\u003E" + (pug_escape(null == (pug_interp = post.userId) ? "" : pug_interp)) + "\u003C\u002Fspan\u003E ";
}
pug_html = pug_html + "\u003C\u002Flabel\u003E\u003Cspan class=\"post-links\"\u003E\u003Ca" + (" class=\"noselect no-decoration\""+pug_attr("href", `${postURL}#${post.postId}`, true, false)) + "\u003ENo.\u003C\u002Fa\u003E\u003Cspan class=\"post-quoters\"\u003E\u003Ca" + (" class=\"no-decoration\""+pug_attr("href", `${postURL}#postform`, true, false)) + "\u003E" + (pug_escape(null == (pug_interp = post.postId) ? "" : pug_interp)) + "\u003C\u002Fa\u003E";
pug_html = pug_html + "\u003C\u002Fspan\u003E\u003Cspan class=\"post-links\"\u003E\u003Ca" + (" class=\"noselect no-decoration\""+pug_attr("href", `${postURL}#${post.postId}`, true, false)) + "\u003ENo.\u003C\u002Fa\u003E\u003Cspan class=\"post-quoters\"\u003E\u003Ca" + (" class=\"no-decoration\""+pug_attr("href", `${postURL}#postform`, true, false)) + "\u003E" + (pug_escape(null == (pug_interp = post.postId) ? "" : pug_interp)) + "\u003C\u002Fa\u003E";
if (!post.thread) {
pug_html = pug_html + " \u003Cspan class=\"noselect\"\u003E\u003Ca" + (pug_attr("href", `${postURL}#postform`, true, false)) + "\u003E[Reply]\u003C\u002Fa\u003E\u003C\u002Fspan\u003E";
}

@ -9,6 +9,7 @@ window.addEventListener('DOMContentLoaded', (event) => {
history.replaceState({}, '', '#postform');
postForm.style.display = 'flex';
newPostButton.style.visibility = 'hidden';
postForm.dispatchEvent(new Event('opened'));
};
const closePostForm = (e) => {
e.preventDefault();

@ -168,6 +168,7 @@ function scripts() {
`${paths.scripts.src}/settings.js`,
`${paths.scripts.src}/live.js`,
`${paths.scripts.src}/*.js`,
`!${paths.scripts.src}/dragable.js`,
`!${paths.scripts.src}/hide.js`,
`!${paths.scripts.src}/time.js`,
])
@ -175,6 +176,7 @@ function scripts() {
.pipe(uglify())
.pipe(gulp.dest(paths.scripts.dest));
return gulp.src([
`${paths.scripts.src}/dragable.js`,
`${paths.scripts.src}/hide.js`,
`${paths.scripts.src}/time.js`,
])

File diff suppressed because it is too large Load Diff

@ -1,4 +1,4 @@
nav.navbar#top
nav.navbar
a.nav-item(href='/index.html') Home
a.nav-item(href='/news.html') News
a.nav-item(href='/boards.html') Boards

@ -5,6 +5,8 @@
section.form-wrapper.flex-center
form.form-post#postform(action=`/forms/board/${board._id}/post`, enctype='multipart/form-data', method='POST')
input(type='hidden' name='thread' value=isThread ? thread.postId : null)
section.row.jsonly
.noselect#dragHandle
unless board.settings.forceAnon
section.row
.label Name

@ -3,7 +3,7 @@ html
head
include includes/head.pug
block head
body
body#top
include includes/navbar.pug
main
.container

Loading…
Cancel
Save