From 2a3a5d4b509e527d1871b6a993f49b29c734c268 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 20 Feb 2017 20:13:42 +0900 Subject: [PATCH] wip --- src/web/app/auth/tags/form.tag | 4 +- src/web/app/auth/tags/index.tag | 2 +- src/web/app/common/scripts/contains.js | 8 + src/web/app/common/tags/signin.tag | 2 +- src/web/app/common/tags/signup.tag | 4 +- src/web/app/desktop/tags/analog-clock.tag | 156 ++++++++--------- .../desktop/tags/autocomplete-suggestion.tag | 164 ++++++++++-------- .../app/desktop/tags/big-follow-button.tag | 8 +- src/web/app/desktop/tags/contextmenu.tag | 60 +++---- src/web/app/desktop/tags/dialog.tag | 79 +++++---- src/web/app/desktop/tags/drive/browser.tag | 4 +- .../desktop/tags/drive/file-contextmenu.tag | 2 +- .../desktop/tags/drive/folder-contextmenu.tag | 2 +- src/web/app/desktop/tags/drive/folder.tag | 4 +- src/web/app/desktop/tags/drive/nav-folder.tag | 4 +- src/web/app/desktop/tags/ellipsis-icon.tag | 4 - src/web/app/desktop/tags/follow-button.tag | 8 +- src/web/app/desktop/tags/go-top.tag | 14 -- src/web/app/desktop/tags/images-viewer.tag | 2 +- src/web/app/desktop/tags/index.js | 1 - src/web/app/desktop/tags/input-dialog.tag | 42 +++-- src/web/app/desktop/tags/post-detail-sub.tag | 4 +- src/web/app/desktop/tags/post-detail.tag | 4 +- src/web/app/desktop/tags/post-form.tag | 2 +- src/web/app/desktop/tags/repost-form.tag | 4 +- src/web/app/desktop/tags/search-posts.tag | 4 +- src/web/app/desktop/tags/sub-post-content.tag | 24 ++- src/web/app/desktop/tags/timeline-post.tag | 103 +++++++---- src/web/app/desktop/tags/window.tag | 2 +- src/web/app/dev/tags/new-app-form.tag | 2 +- src/web/app/mobile/tags/drive/file-viewer.tag | 4 +- src/web/app/mobile/tags/follow-button.tag | 8 +- src/web/app/mobile/tags/post-detail.tag | 4 +- src/web/app/mobile/tags/search-posts.tag | 20 +-- src/web/app/mobile/tags/user-timeline.tag | 10 +- 35 files changed, 402 insertions(+), 367 deletions(-) create mode 100644 src/web/app/common/scripts/contains.js delete mode 100644 src/web/app/desktop/tags/go-top.tag diff --git a/src/web/app/auth/tags/form.tag b/src/web/app/auth/tags/form.tag index 21a9a74048..619c71065e 100644 --- a/src/web/app/auth/tags/form.tag +++ b/src/web/app/auth/tags/form.tag @@ -114,13 +114,13 @@ this.cancel = () => { this.api('auth/deny', { token: @session.token - .then => + }).then(() => { this.trigger('denied'); this.accept = () => { this.api('auth/accept', { token: @session.token - .then => + }).then(() => { this.trigger('accepted'); diff --git a/src/web/app/auth/tags/index.tag b/src/web/app/auth/tags/index.tag index 13abf07905..e52aeed4d2 100644 --- a/src/web/app/auth/tags/index.tag +++ b/src/web/app/auth/tags/index.tag @@ -110,7 +110,7 @@ if @session.app.is_authorized this.api('auth/accept', { token: @session.token - .then => + }).then(() => { @accepted! else this.state = 'waiting' diff --git a/src/web/app/common/scripts/contains.js b/src/web/app/common/scripts/contains.js new file mode 100644 index 0000000000..fe73666193 --- /dev/null +++ b/src/web/app/common/scripts/contains.js @@ -0,0 +1,8 @@ +module.exports = function(parent, child) { + let node = child.parentNode; + while (node) { + if (node == parent) return true; + node = node.parentNode; + } + return false; +} diff --git a/src/web/app/common/tags/signin.tag b/src/web/app/common/tags/signin.tag index 7b297b7b8e..e2b8736821 100644 --- a/src/web/app/common/tags/signin.tag +++ b/src/web/app/common/tags/signin.tag @@ -126,7 +126,7 @@ this.api('signin', { username: this.refs.username.value password: this.refs.password.value - .then => + }).then(() => { location.reload(); .catch => alert 'something happened' diff --git a/src/web/app/common/tags/signup.tag b/src/web/app/common/tags/signup.tag index 7646f8c861..39d4522e79 100644 --- a/src/web/app/common/tags/signup.tag +++ b/src/web/app/common/tags/signup.tag @@ -277,11 +277,11 @@ username: username, password: password, 'g-recaptcha-response': grecaptcha.getResponse() - .then => + }).then(() => { this.api('signin', { username: username password: password - .then => + }).then(() => { location.href = CONFIG.url .catch => alert '何らかの原因によりアカウントの作成に失敗しました。再度お試しください。' diff --git a/src/web/app/desktop/tags/analog-clock.tag b/src/web/app/desktop/tags/analog-clock.tag index ec627ec65f..4ac6d2281c 100644 --- a/src/web/app/desktop/tags/analog-clock.tag +++ b/src/web/app/desktop/tags/analog-clock.tag @@ -6,100 +6,92 @@ display block width 256px height 256px - diff --git a/src/web/app/desktop/tags/autocomplete-suggestion.tag b/src/web/app/desktop/tags/autocomplete-suggestion.tag index 40f5f57591..c7cc29dc19 100644 --- a/src/web/app/desktop/tags/autocomplete-suggestion.tag +++ b/src/web/app/desktop/tags/autocomplete-suggestion.tag @@ -80,108 +80,118 @@ diff --git a/src/web/app/desktop/tags/big-follow-button.tag b/src/web/app/desktop/tags/big-follow-button.tag index ba607c8372..309e6ce8ed 100644 --- a/src/web/app/desktop/tags/big-follow-button.tag +++ b/src/web/app/desktop/tags/big-follow-button.tag @@ -106,21 +106,21 @@ if this.user.is_following this.api('following/delete', { user_id: this.user.id - .then => + }).then(() => { this.user.is_following = false .catch (err) -> console.error err - .then => + }).then(() => { this.wait = false this.update(); else this.api('following/create', { user_id: this.user.id - .then => + }).then(() => { this.user.is_following = true .catch (err) -> console.error err - .then => + }).then(() => { this.wait = false this.update(); diff --git a/src/web/app/desktop/tags/contextmenu.tag b/src/web/app/desktop/tags/contextmenu.tag index 92c8b71a2e..8df11c3819 100644 --- a/src/web/app/desktop/tags/contextmenu.tag +++ b/src/web/app/desktop/tags/contextmenu.tag @@ -1,4 +1,5 @@ - + + diff --git a/src/web/app/desktop/tags/dialog.tag b/src/web/app/desktop/tags/dialog.tag index 61a40e7b39..c0df0b330f 100644 --- a/src/web/app/desktop/tags/dialog.tag +++ b/src/web/app/desktop/tags/dialog.tag @@ -79,69 +79,72 @@ diff --git a/src/web/app/desktop/tags/drive/browser.tag b/src/web/app/desktop/tags/drive/browser.tag index 13019dd160..51c26943a2 100644 --- a/src/web/app/desktop/tags/drive/browser.tag +++ b/src/web/app/desktop/tags/drive/browser.tag @@ -408,7 +408,7 @@ this.api('drive/files/update', { file_id: file folder_id: if this.folder? then this.folder.id else null - .then => + }).then(() => { // something .catch (err, text-status) => console.error err @@ -425,7 +425,7 @@ this.api('drive/folders/update', { folder_id: folder parent_id: if this.folder? then this.folder.id else null - .then => + }).then(() => { // something .catch (err) => if err == 'detected-circular-definition' diff --git a/src/web/app/desktop/tags/drive/file-contextmenu.tag b/src/web/app/desktop/tags/drive/file-contextmenu.tag index 9a615a9022..933ae6db01 100644 --- a/src/web/app/desktop/tags/drive/file-contextmenu.tag +++ b/src/web/app/desktop/tags/drive/file-contextmenu.tag @@ -68,7 +68,7 @@ this.api('drive/files/update', { file_id: this.file.id name: name - .then => + }).then(() => { // something .catch (err) => console.error err diff --git a/src/web/app/desktop/tags/drive/folder-contextmenu.tag b/src/web/app/desktop/tags/drive/folder-contextmenu.tag index 833eff42e2..582aa5e52c 100644 --- a/src/web/app/desktop/tags/drive/folder-contextmenu.tag +++ b/src/web/app/desktop/tags/drive/folder-contextmenu.tag @@ -54,7 +54,7 @@ this.api('drive/folders/update', { folder_id: this.folder.id name: name - .then => + }).then(() => { // something .catch (err) => console.error err diff --git a/src/web/app/desktop/tags/drive/folder.tag b/src/web/app/desktop/tags/drive/folder.tag index fff3c13ebe..c9bc5d7f04 100644 --- a/src/web/app/desktop/tags/drive/folder.tag +++ b/src/web/app/desktop/tags/drive/folder.tag @@ -118,7 +118,7 @@ this.api('drive/files/update', { file_id: file folder_id: this.folder.id - .then => + }).then(() => { // something .catch (err, text-status) => console.error err @@ -133,7 +133,7 @@ this.api('drive/folders/update', { folder_id: folder parent_id: this.folder.id - .then => + }).then(() => { // something .catch (err) => if err == 'detected-circular-definition' diff --git a/src/web/app/desktop/tags/drive/nav-folder.tag b/src/web/app/desktop/tags/drive/nav-folder.tag index 3f57fc1293..b485ddb53e 100644 --- a/src/web/app/desktop/tags/drive/nav-folder.tag +++ b/src/web/app/desktop/tags/drive/nav-folder.tag @@ -72,7 +72,7 @@ this.api('drive/files/update', { file_id: file folder_id: if this.folder? then this.folder.id else null - .then => + }).then(() => { // something .catch (err, text-status) => console.error err @@ -87,7 +87,7 @@ this.api('drive/folders/update', { folder_id: folder parent_id: if this.folder? then this.folder.id else null - .then => + }).then(() => { // something .catch (err, text-status) => console.error err diff --git a/src/web/app/desktop/tags/ellipsis-icon.tag b/src/web/app/desktop/tags/ellipsis-icon.tag index 731c2525f1..8462bfc4af 100644 --- a/src/web/app/desktop/tags/ellipsis-icon.tag +++ b/src/web/app/desktop/tags/ellipsis-icon.tag @@ -33,9 +33,5 @@ 40% transform scale(1) - - - - diff --git a/src/web/app/desktop/tags/follow-button.tag b/src/web/app/desktop/tags/follow-button.tag index 7b5ab7d0e4..64055a158f 100644 --- a/src/web/app/desktop/tags/follow-button.tag +++ b/src/web/app/desktop/tags/follow-button.tag @@ -103,21 +103,21 @@ if this.user.is_following this.api('following/delete', { user_id: this.user.id - .then => + }).then(() => { this.user.is_following = false .catch (err) -> console.error err - .then => + }).then(() => { this.wait = false this.update(); else this.api('following/create', { user_id: this.user.id - .then => + }).then(() => { this.user.is_following = true .catch (err) -> console.error err - .then => + }).then(() => { this.wait = false this.update(); diff --git a/src/web/app/desktop/tags/go-top.tag b/src/web/app/desktop/tags/go-top.tag deleted file mode 100644 index cb75c04807..0000000000 --- a/src/web/app/desktop/tags/go-top.tag +++ /dev/null @@ -1,14 +0,0 @@ - - - - diff --git a/src/web/app/desktop/tags/images-viewer.tag b/src/web/app/desktop/tags/images-viewer.tag index 986debab4f..8d10ec6564 100644 --- a/src/web/app/desktop/tags/images-viewer.tag +++ b/src/web/app/desktop/tags/images-viewer.tag @@ -39,7 +39,7 @@ this.click = () => { dialog = document.body.appendChild(document.createElement('mk-image-dialog')); - riot.mount dialog, do + riot.mount dialog, do image: @image diff --git a/src/web/app/desktop/tags/index.js b/src/web/app/desktop/tags/index.js index ed100ef75c..a90e42211d 100644 --- a/src/web/app/desktop/tags/index.js +++ b/src/web/app/desktop/tags/index.js @@ -16,7 +16,6 @@ require('./crop-window.tag'); require('./settings.tag'); require('./settings-window.tag'); require('./analog-clock.tag'); -require('./go-top.tag'); require('./ui-header.tag'); require('./ui-header-account.tag'); require('./ui-header-notifications.tag'); diff --git a/src/web/app/desktop/tags/input-dialog.tag b/src/web/app/desktop/tags/input-dialog.tag index dbfd1cfc70..aa417f0a7e 100644 --- a/src/web/app/desktop/tags/input-dialog.tag +++ b/src/web/app/desktop/tags/input-dialog.tag @@ -1,13 +1,17 @@ - { parent.title } - -
- -
-
- - -
+ + + { parent.title } + + +
+ +
+
+ + +
+
diff --git a/src/web/app/desktop/tags/post-detail.tag b/src/web/app/desktop/tags/post-detail.tag index 3b5671452a..00426ea9bb 100644 --- a/src/web/app/desktop/tags/post-detail.tag +++ b/src/web/app/desktop/tags/post-detail.tag @@ -412,13 +412,13 @@ if this.p.is_liked this.api('posts/likes/delete', { post_id: this.p.id - .then => + }).then(() => { this.p.is_liked = false this.update(); else this.api('posts/likes/create', { post_id: this.p.id - .then => + }).then(() => { this.p.is_liked = true this.update(); diff --git a/src/web/app/desktop/tags/post-form.tag b/src/web/app/desktop/tags/post-form.tag index fe435c4e4f..cb1693420c 100644 --- a/src/web/app/desktop/tags/post-form.tag +++ b/src/web/app/desktop/tags/post-form.tag @@ -455,7 +455,7 @@ .catch (err) => console.error err @notify '投稿できませんでした' - .then => + }).then(() => { this.wait = false this.update(); diff --git a/src/web/app/desktop/tags/repost-form.tag b/src/web/app/desktop/tags/repost-form.tag index c3e3e02dfe..7d309bf754 100644 --- a/src/web/app/desktop/tags/repost-form.tag +++ b/src/web/app/desktop/tags/repost-form.tag @@ -127,14 +127,14 @@ this.wait = true this.api('posts/create', { repost_id: this.opts.post.id - text: if @quote then this.refs.text.value else undefined + text: if this.quote then this.refs.text.value else undefined }).then((data) => { this.trigger('posted'); @notify 'Repostしました!' .catch (err) => console.error err @notify 'Repostできませんでした' - .then => + }).then(() => { this.wait = false this.update(); diff --git a/src/web/app/desktop/tags/search-posts.tag b/src/web/app/desktop/tags/search-posts.tag index bad055eb04..248b8cc87d 100644 --- a/src/web/app/desktop/tags/search-posts.tag +++ b/src/web/app/desktop/tags/search-posts.tag @@ -42,7 +42,7 @@ window.addEventListener 'scroll' this.on-scroll this.api('posts/search', { - query: @query + query: this.query }).then((posts) => { this.is-loading = false this.is-empty = posts.length == 0 @@ -68,7 +68,7 @@ this.more-loading = true this.update(); this.api('posts/search', { - query: @query + query: this.query page: this.page + 1 }).then((posts) => { this.more-loading = false diff --git a/src/web/app/desktop/tags/sub-post-content.tag b/src/web/app/desktop/tags/sub-post-content.tag index 8d4a06b49d..e0509ab7d4 100644 --- a/src/web/app/desktop/tags/sub-post-content.tag +++ b/src/web/app/desktop/tags/sub-post-content.tag @@ -1,5 +1,11 @@ - +
+ + + + + RP: ... +
({ post.media.length }つのメディア) @@ -31,15 +37,17 @@ this.mixin('text'); this.mixin('user-preview'); - this.post = this.opts.post + this.post = this.opts.post; this.on('mount', () => { - if this.post.text? - tokens = @analyze this.post.text - this.refs.text.innerHTML = @compile tokens, false + if (this.post.text) { + const tokens = this.analyze(this.post.text); + this.refs.text.innerHTML = this.compile(tokens, false); - this.refs.text.children.forEach (e) => - if e.tag-name == 'MK-URL' - riot.mount e + this.refs.text.children.forEach(e => { + if (e.tagName == 'MK-URL') riot.mount(e); + }); + } + }); diff --git a/src/web/app/desktop/tags/timeline-post.tag b/src/web/app/desktop/tags/timeline-post.tag index 5b656f812d..440d5d9f42 100644 --- a/src/web/app/desktop/tags/timeline-post.tag +++ b/src/web/app/desktop/tags/timeline-post.tag @@ -324,7 +324,7 @@ this.mixin('NotImplementedException'); this.post = this.opts.post; - this.isRepost = this.post.repost != null && this.post.text == null; + this.isRepost = this.post.repost && this.post.text == null; this.p = this.isRepost ? this.post.repost : this.post; this.title = this.dateStringify(this.p.created_at); @@ -354,58 +354,87 @@ }); this.reply = () => { - form = document.body.appendChild(document.createElement('mk-post-form-window')); - riot.mount form, do + riot.mount(document.body.appendChild(document.createElement('mk-post-form-window')), { reply: this.p + }); + }; this.repost = () => { - form = document.body.appendChild(document.createElement('mk-repost-form-window')); - riot.mount form, do + riot.mount(document.body.appendChild(document.createElement('mk-repost-form-window')), { post: this.p + }); + }; this.like = () => { - if this.p.is_liked + if (this.p.is_liked) { this.api('posts/likes/delete', { post_id: this.p.id - .then => - this.p.is_liked = false + }).then(() => { + this.p.is_liked = false; this.update(); - else + }); + } else { this.api('posts/likes/create', { post_id: this.p.id - .then => - this.p.is_liked = true + }).then(() => { + this.p.is_liked = true; this.update(); + }); + } + }; - this.toggle-detail = () => { - this.is-detail-opened = !@is-detail-opened - this.update(); + this.toggleDetail = () => { + this.update({ + isDetailOpened: !this.isDetailOpened + }); + }; - this.on-key-down = (e) => { - should-be-cancel = true - switch - | e.which == 38 or e.which == 74 or (e.which == 9 and e.shift-key) => // ↑, j or Shift+Tab - focus this.root, (e) -> e.previousElementSibling - | e.which == 40 or e.which == 75 or e.which == 9 => // ↓, k or Tab - focus this.root, (e) -> e.nextElementSibling - | e.which == 81 or e.which == 69 => // q or e - @repost! - | e.which == 70 or e.which == 76 => // f or l - @like! - | e.which == 82 => // r - @reply! - | _ => - should-be-cancel = false + this.onKeyDown = e => { + let shouldBeCancel = true; - if should-be-cancel - e.preventDefault(); + switch (true) { + case e.which == 38: // [↑] + case e.which == 74: // [j] + case e.which == 9 && e.shiftKey: // [Shift] + [Tab] + focus(this.root, e => e.previousElementSibling); + break; - function focus(el, fn) - target = fn el - if target? - if target.has-attribute 'tabindex' + case e.which == 40: // [↓] + case e.which == 75: // [k] + case e.which == 9: // [Tab] + focus(this.root, e => e.nextElementSibling); + break; + + case e.which == 81: // [q] + case e.which == 69: // [e] + this.repost(); + break; + + case e.which == 70: // [f] + case e.which == 76: // [l] + this.like(); + break; + + case e.which == 82: // [r] + this.reply(); + break; + + default: + shouldBeCancel = false; + } + + if (shouldBeCancel) e.preventDefault(); + }; + + function focus(el, fn) { + const target = fn(el); + if (target) { + if (target.hasAttribute('tabindex')) { target.focus(); - else - focus target, fn + } else { + focus(target, fn); + } + } + } diff --git a/src/web/app/desktop/tags/window.tag b/src/web/app/desktop/tags/window.tag index 33bb244fa7..bd9df88231 100644 --- a/src/web/app/desktop/tags/window.tag +++ b/src/web/app/desktop/tags/window.tag @@ -501,7 +501,7 @@ this.ondragover = (e) => { e.dataTransfer.dropEffect = 'none' - this.on-keydown = (e) => { + this.onKeydown = (e) => { if e.which == 27 // Esc if @can-close e.preventDefault(); diff --git a/src/web/app/dev/tags/new-app-form.tag b/src/web/app/dev/tags/new-app-form.tag index 6be1c54487..c75eec37dd 100644 --- a/src/web/app/dev/tags/new-app-form.tag +++ b/src/web/app/dev/tags/new-app-form.tag @@ -233,7 +233,7 @@ description: description callback_url: cb permission: permission.join ',' - .then => + }).then(() => { location.href = '/apps' .catch => alert 'アプリの作成に失敗しました。再度お試しください。' diff --git a/src/web/app/mobile/tags/drive/file-viewer.tag b/src/web/app/mobile/tags/drive/file-viewer.tag index 5f2c5f61fb..e91a451c0d 100644 --- a/src/web/app/mobile/tags/drive/file-viewer.tag +++ b/src/web/app/mobile/tags/drive/file-viewer.tag @@ -192,9 +192,9 @@ name = window.prompt '名前を変更' this.file.name if name? and name != '' and name != this.file.name this.api('drive/files/update', { - file_id: this.file.id + file_id: this.file.id, name: name - .then => + }).then(() => { this.parent.cf this.file, true diff --git a/src/web/app/mobile/tags/follow-button.tag b/src/web/app/mobile/tags/follow-button.tag index ecd0dc594d..43fcc3499c 100644 --- a/src/web/app/mobile/tags/follow-button.tag +++ b/src/web/app/mobile/tags/follow-button.tag @@ -84,21 +84,21 @@ if this.user.is_following this.api('following/delete', { user_id: this.user.id - .then => + }).then(() => { this.user.is_following = false .catch (err) -> console.error err - .then => + }).then(() => { this.wait = false this.update(); else this.api('following/create', { user_id: this.user.id - .then => + }).then(() => { this.user.is_following = true .catch (err) -> console.error err - .then => + }).then(() => { this.wait = false this.update(); diff --git a/src/web/app/mobile/tags/post-detail.tag b/src/web/app/mobile/tags/post-detail.tag index 61983a1592..2b4bef1da3 100644 --- a/src/web/app/mobile/tags/post-detail.tag +++ b/src/web/app/mobile/tags/post-detail.tag @@ -406,13 +406,13 @@ if this.p.is_liked this.api('posts/likes/delete', { post_id: this.p.id - .then => + }).then(() => { this.p.is_liked = false this.update(); else this.api('posts/likes/create', { post_id: this.p.id - .then => + }).then(() => { this.p.is_liked = true this.update(); diff --git a/src/web/app/mobile/tags/search-posts.tag b/src/web/app/mobile/tags/search-posts.tag index 83c4b9cfb4..2dbb162d7b 100644 --- a/src/web/app/mobile/tags/search-posts.tag +++ b/src/web/app/mobile/tags/search-posts.tag @@ -9,24 +9,24 @@ diff --git a/src/web/app/mobile/tags/user-timeline.tag b/src/web/app/mobile/tags/user-timeline.tag index 2d3716b848..71fb1ac272 100644 --- a/src/web/app/mobile/tags/user-timeline.tag +++ b/src/web/app/mobile/tags/user-timeline.tag @@ -11,21 +11,21 @@