From 143a015473b37b5028fa71af059d2fd487e97712 Mon Sep 17 00:00:00 2001 From: rr- Date: Fri, 11 Nov 2016 22:35:58 +0100 Subject: [PATCH] client/posts: control over video loops on upload Also loop videos by default --- client/css/post-upload.styl | 4 ++ client/html/post_upload_row.tpl | 30 +++++++++---- .../js/controllers/post_upload_controller.js | 1 + client/js/views/post_upload_view.js | 42 ++++++++++++------- 4 files changed, 52 insertions(+), 25 deletions(-) diff --git a/client/css/post-upload.styl b/client/css/post-upload.styl index 01a215d..f315236 100644 --- a/client/css/post-upload.styl +++ b/client/css/post-upload.styl @@ -59,6 +59,10 @@ $cancel-button-color = tomato display: inline-block margin-right: 1em + .options div + display: inline-block + margin: 0 1em 0 0 + .thumbnail-wrapper float: left width: 12.5em diff --git a/client/html/post_upload_row.tpl b/client/html/post_upload_row.tpl index 0e61212..25ff3ae 100644 --- a/client/html/post_upload_row.tpl +++ b/client/html/post_upload_row.tpl @@ -44,13 +44,25 @@ <% } %> - <% if (ctx.canUploadAnonymously) { %> -
- <%= ctx.makeCheckbox({ - text: 'Upload anonymously', - name: 'anonymous', - checked: ctx.uploadable.anonymous, - }) %> -
- <% } %> +
+ <% if (ctx.canUploadAnonymously) { %> +
+ <%= ctx.makeCheckbox({ + text: 'Upload anonymously', + name: 'anonymous', + checked: ctx.uploadable.anonymous, + }) %> +
+ <% } %> + + <% if (['video'].includes(ctx.uploadable.type)) { %> +
+ <%= ctx.makeCheckbox({ + text: 'Loop video', + name: 'loop-video', + checked: true, + }) %> +
+ <% } %> +
diff --git a/client/js/controllers/post_upload_controller.js b/client/js/controllers/post_upload_controller.js index 3ec86a9..02b45cf 100644 --- a/client/js/controllers/post_upload_controller.js +++ b/client/js/controllers/post_upload_controller.js @@ -51,6 +51,7 @@ class PostUploadController { return promise.then(() => { let post = new Post(); post.safety = uploadable.safety; + post.flags = uploadable.flags; if (uploadable.url) { post.newContentUrl = uploadable.url; } else { diff --git a/client/js/views/post_upload_view.js b/client/js/views/post_upload_view.js index fd60f4e..b260381 100644 --- a/client/js/views/post_upload_view.js +++ b/client/js/views/post_upload_view.js @@ -20,10 +20,17 @@ function _mimeTypeToPostType(mimeType) { }[mimeType] || 'unknown'; } +function _listen(rootNode, selector, eventType, handler) { + for (let node of rootNode.querySelectorAll(selector)) { + node.addEventListener(eventType, e => handler(e)); + } +} + class Uploadable extends events.EventTarget { constructor() { super(); this.safety = 'safe'; + this.flags = ['loop']; this.anonymous = false; this.order = globalOrder; globalOrder++; @@ -288,6 +295,13 @@ class PostUploadView extends events.EventTarget { uploadable.anonymous = e.target.checked; } + _evtLoopVideoCheckboxChange(e, uploadable) { + uploadable.flags = uploadable.flags.filter(f => f !== 'loop'); + if (e.target.checked) { + uploadable.flags.push('loop'); + } + } + _normalizeUploadablesOrder() { let sortedUploadables = this._getSortedUploadables(); for (let i = 0; i < sortedUploadables.length; i++) { @@ -316,23 +330,19 @@ class PostUploadView extends events.EventTarget { {}, this._ctx, {uploadable: uploadable})); this._listNode.appendChild(rowNode); - for (let radioboxNode of rowNode.querySelectorAll('.safety input')) { - radioboxNode.addEventListener( - 'change', e => this._evtSafetyRadioboxChange(e, uploadable)); - } + _listen(rowNode, '.safety input', 'change', + e => this._evtSafetyRadioboxChange(e, uploadable)); + _listen(rowNode, '.anonymous input', 'change', + e => this._evtAnonymityCheckboxChange(e, uploadable)); + _listen(rowNode, '.loop-video input', 'change', + e => this._evtLoopVideoCheckboxChange(e, uploadable)); - const anonymousCheckboxNode = rowNode.querySelector('.anonymous input'); - if (anonymousCheckboxNode) { - anonymousCheckboxNode.addEventListener( - 'change', e => this._evtAnonymityCheckboxChange(e, uploadable)); - } - - rowNode.querySelector('a.remove').addEventListener( - 'click', e => this._evtRemoveClick(e, uploadable)); - rowNode.querySelector('a.move-up').addEventListener( - 'click', e => this._evtMoveUpClick(e, uploadable)); - rowNode.querySelector('a.move-down').addEventListener( - 'click', e => this._evtMoveDownClick(e, uploadable)); + _listen(rowNode, 'a.remove', 'click', + e => this._evtRemoveClick(e, uploadable)); + _listen(rowNode, 'a.move-up', 'click', + e => this._evtMoveUpClick(e, uploadable)); + _listen(rowNode, 'a.move-down', 'click', + e => this._evtMoveDownClick(e, uploadable)); uploadable.rowNode = rowNode; }