Merge pull request #678 from ZogStriP/improve-quote-reply-selection

improve quote reply selection
This commit is contained in:
Sam 2013-04-08 15:19:13 -07:00
commit bbdf47d26d
4 changed files with 22 additions and 19 deletions

View File

@ -36,17 +36,13 @@ Discourse.QuoteButtonController = Discourse.Controller.extend({
if (!this.get('controllers.topic.content.can_create_post')) return; if (!this.get('controllers.topic.content.can_create_post')) return;
// retrieve the selected range // retrieve the selected range
var range = window.getSelection().getRangeAt(0); var range = window.getSelection().getRangeAt(0),
var cloned = range.cloneRange(); cloned = range.cloneRange(),
$ancestor = $(range.commonAncestorContainer);
// don't display the "quote reply" button if you select text spanning two posts // don't display the "quote reply" button if you select text spanning two posts
// this basically look for the first "DIV" container... // note: the ".contents" is here to prevent selection of the topic summary
var commonDivAncestorContainer = range.commonAncestorContainer; if ($ancestor.closest('.topic-body > .contents').length === 0) return;
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;
var selectedText = Discourse.Utilities.selectedText(); var selectedText = Discourse.Utilities.selectedText();
if (this.get('buffer') === selectedText) return; if (this.get('buffer') === selectedText) return;

View File

@ -53,7 +53,7 @@ Discourse.PostView = Discourse.View.extend({
} }
if (!Discourse.get('currentUser.enable_quoting')) return; 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'); var qbc = this.get('controller.controllers.quoteButton');
if (qbc) { if (qbc) {

View File

@ -89,11 +89,6 @@
pre code { pre code {
max-height: 690px; max-height: 690px;
} }
.post-menu-area {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
}
@include hover { @include hover {
.gutter { .gutter {
.reply-new, .reply-new,
@ -104,6 +99,7 @@
} }
.gutter { .gutter {
@include unselectable;
.reply-new{ .reply-new{
.discourse-no-touch & { .discourse-no-touch & {
opacity: 0; opacity: 0;
@ -248,11 +244,13 @@
} }
section.post-menu-area { section.post-menu-area {
@include unselectable;
background-color: $post_footer; background-color: $post_footer;
border-top: 1px solid $inner_border; border-top: 1px solid $inner_border;
overflow: hidden; overflow: hidden;
@include box-shadow(inset 0 -4px 4px -4px rgba($black, 0.14)); @include box-shadow(inset 0 -4px 4px -4px rgba($black, 0.14));
nav.post-controls { nav.post-controls {
@include unselectable;
float: right; float: right;
padding: 0px; padding: 0px;
button { button {
@ -390,9 +388,6 @@
@include hover { @include hover {
background-color: mix($gray, $light_gray, 5%); background-color: mix($gray, $light_gray, 5%);
} }
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
} }
.embedded-posts.bottom { .embedded-posts.bottom {
@include border-radius-bottom(4px); @include border-radius-bottom(4px);
@ -749,6 +744,7 @@
} }
} }
.buttons { .buttons {
@include unselectable;
float: right; float: right;
.btn { .btn {
border: 0; border: 0;

View File

@ -160,3 +160,14 @@
border: 1px solid $color; border: 1px solid $color;
box-shadow: 0 0 5px $color; box-shadow: 0 0 5px $color;
} }
//
// --------------------------------------------------
// Unselectable
@mixin unselectable {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
}