From 2424a656e800adc4db4aba3beec7de156934b718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 8 Apr 2013 23:43:52 +0200 Subject: [PATCH] improve quote reply selection --- .../controllers/quote_button_controller.js | 14 +++++--------- .../javascripts/discourse/views/post_view.js | 2 +- .../stylesheets/application/topic-post.css.scss | 12 ++++-------- app/assets/stylesheets/foundation/mixins.scss | 13 ++++++++++++- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/quote_button_controller.js b/app/assets/javascripts/discourse/controllers/quote_button_controller.js index fa630f326..79acd24b7 100644 --- a/app/assets/javascripts/discourse/controllers/quote_button_controller.js +++ b/app/assets/javascripts/discourse/controllers/quote_button_controller.js @@ -36,17 +36,13 @@ Discourse.QuoteButtonController = Discourse.Controller.extend({ if (!this.get('controllers.topic.content.can_create_post')) return; // retrieve the selected range - var range = window.getSelection().getRangeAt(0); - var cloned = range.cloneRange(); + var range = window.getSelection().getRangeAt(0), + cloned = range.cloneRange(), + $ancestor = $(range.commonAncestorContainer); // don't display the "quote reply" button if you select text spanning two posts - // this basically look for the first "DIV" container... - var commonDivAncestorContainer = range.commonAncestorContainer; - while (commonDivAncestorContainer.nodeName !== 'DIV') { - commonDivAncestorContainer = commonDivAncestorContainer.parentNode; - } - // ... and check it has the 'cooked' class (which indicates we're in a post) - if (commonDivAncestorContainer.className.indexOf('cooked') === -1) return; + // note: the ".contents" is here to prevent selection of the topic summary + if ($ancestor.closest('.topic-body > .contents').length === 0) return; var selectedText = Discourse.Utilities.selectedText(); if (this.get('buffer') === selectedText) return; diff --git a/app/assets/javascripts/discourse/views/post_view.js b/app/assets/javascripts/discourse/views/post_view.js index 264c6a409..77b9fd225 100644 --- a/app/assets/javascripts/discourse/views/post_view.js +++ b/app/assets/javascripts/discourse/views/post_view.js @@ -53,7 +53,7 @@ Discourse.PostView = Discourse.View.extend({ } if (!Discourse.get('currentUser.enable_quoting')) return; - if ($(e.target).closest('.cooked').length === 0) return; + if ($(e.target).closest('.topic-body').length === 0) return; var qbc = this.get('controller.controllers.quoteButton'); if (qbc) { diff --git a/app/assets/stylesheets/application/topic-post.css.scss b/app/assets/stylesheets/application/topic-post.css.scss index a83bb7e8f..2038ad0ab 100644 --- a/app/assets/stylesheets/application/topic-post.css.scss +++ b/app/assets/stylesheets/application/topic-post.css.scss @@ -89,11 +89,6 @@ 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, @@ -104,6 +99,7 @@ } .gutter { + @include unselectable; .reply-new{ .discourse-no-touch & { opacity: 0; @@ -248,11 +244,13 @@ } section.post-menu-area { + @include unselectable; background-color: $post_footer; border-top: 1px solid $inner_border; overflow: hidden; @include box-shadow(inset 0 -4px 4px -4px rgba($black, 0.14)); nav.post-controls { + @include unselectable; float: right; padding: 0px; button { @@ -390,9 +388,6 @@ @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); @@ -749,6 +744,7 @@ } } .buttons { + @include unselectable; float: right; .btn { border: 0; diff --git a/app/assets/stylesheets/foundation/mixins.scss b/app/assets/stylesheets/foundation/mixins.scss index 2c03065f4..dbc8b5c07 100644 --- a/app/assets/stylesheets/foundation/mixins.scss +++ b/app/assets/stylesheets/foundation/mixins.scss @@ -159,4 +159,15 @@ @mixin glow($color) { border: 1px solid $color; box-shadow: 0 0 5px $color; -} \ No newline at end of file +} + +// +// -------------------------------------------------- + +// Unselectable + +@mixin unselectable { + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; +}