From b7a7d8b006cf655b1b1ce6fde546722d60d1c9bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Sat, 30 Mar 2013 02:52:52 +0100 Subject: [PATCH] Get the "quote reply" button working on iOS --- .../javascripts/discourse/views/post_view.js | 26 ++++++++++++++++++- .../application/topic-post.css.scss | 8 ++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/views/post_view.js b/app/assets/javascripts/discourse/views/post_view.js index dd798255844..7d1765937ad 100644 --- a/app/assets/javascripts/discourse/views/post_view.js +++ b/app/assets/javascripts/discourse/views/post_view.js @@ -49,10 +49,11 @@ Discourse.PostView = Discourse.View.extend({ this.toggleProperty('post.selected'); } + if (!Discourse.get('currentUser.enable_quoting')) return; if ($(e.target).closest('.cooked').length === 0) return; var qbc = this.get('controller.controllers.quoteButton'); - if (qbc && Discourse.get('currentUser.enable_quoting')) { + if (qbc) { e.context = this.get('post'); qbc.selectText(e); } @@ -259,6 +260,29 @@ Discourse.PostView = Discourse.View.extend({ if (controller && controller.postRendered) { controller.postRendered(post); } + + // make the selection work under iOS + // "selectionchange" event is only supported in IE, Safari & Chrome + var postView = this; + $(document).on('selectionchange', function(e) { + // quoting as been disabled by the user + if (!Discourse.get('currentUser.enable_quoting')) return; + // find out whether we currently are selecting inside a post + var closestPosts = $(window.getSelection().anchorNode).closest('.topic-post'); + if (closestPosts.length === 0) return; + // this event is bound for every posts in the topic, but is triggered on "document" + // we should therefore filter the event to only the right post + if (closestPosts[0].id !== postView.elementId) return; + var qbc = postView.get('controller.controllers.quoteButton'); + if (qbc) { + e.context = postView.get('post'); + qbc.selectText(e); + } + }); + }, + + willDestroyElement: function() { + $(document).off('selectionchange'); } }); diff --git a/app/assets/stylesheets/application/topic-post.css.scss b/app/assets/stylesheets/application/topic-post.css.scss index e2442b6f7fb..88d4cf05000 100644 --- a/app/assets/stylesheets/application/topic-post.css.scss +++ b/app/assets/stylesheets/application/topic-post.css.scss @@ -89,6 +89,11 @@ pre code { max-height: 690px; } + .post-menu-area { + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + } @include hover { .gutter { .reply-new, @@ -387,6 +392,9 @@ @include hover { background-color: mix($gray, $light_gray, 5%); } + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; } .embedded-posts.bottom { @include border-radius-bottom(4px);