Skip to content

Commit

Permalink
Merge pull request #2762 from MissAllSunday/quote
Browse files Browse the repository at this point in the history
Selected text to quote
  • Loading branch information
live627 committed Mar 24, 2015
2 parents 1754491 + e385ae4 commit 75c0467
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 8 deletions.
5 changes: 4 additions & 1 deletion Sources/Display.php
Expand Up @@ -961,7 +961,7 @@ function Display()
$context['topic_notification'] = !empty($user_info['id']) ? $topicinfo['notify_prefs'] : array();
// 0 => unwatched, 1 => normal, 2 => receive alerts, 3 => receive emails
$context['topic_notification_mode'] = !$user_info['is_guest'] ? ($context['topic_unwatched'] ? 0 : ($topicinfo['notify_prefs']['pref'] & 0x02 ? 3 : ($topicinfo['notify_prefs']['pref'] & 0x01 ? 2 : 1))) : 0;

$attachments = array();

// If there _are_ messages here... (probably an error otherwise :!)
Expand Down Expand Up @@ -1276,6 +1276,9 @@ function Display()
// topic.js
loadJavascriptFile('topic.js', array('default_theme' => true, 'defer' => false), 'smf_topic');

// quotedText.js
loadJavascriptFile('quotedText.js', array('default_theme' => true, 'defer' => true), 'smf_quotedText');

// Mentions
if (!empty($modSettings['enable_mentions']) && allowedTo('mention'))
{
Expand Down
3 changes: 3 additions & 0 deletions Sources/Post.php
Expand Up @@ -1174,6 +1174,9 @@ function Post($post_errors = array())
loadJavascriptFile('mentions.js', array('default_theme' => true, 'defer' => true), 'smf_mention');
}

// quotedText.js
loadJavascriptFile('quotedText.js', array('default_theme' => true, 'defer' => true), 'smf_quotedText');

// Finally, load the template.
if (WIRELESS && WIRELESS_PROTOCOL != 'wap')
$context['sub_template'] = WIRELESS_PROTOCOL . '_post';
Expand Down
10 changes: 9 additions & 1 deletion Themes/default/Display.template.php
Expand Up @@ -568,7 +568,7 @@ function template_single_post($message)
', $txt['post_awaiting_approval'], '
</div>';
echo '
<div class="inner" id="msg_', $message['id'], '"', $ignoring ? ' style="display:none;"' : '', '>', $message['body'], '</div>
<div class="inner" data-msgid="', $message['id'], '" id="msg_', $message['id'], '"', $ignoring ? ' style="display:none;"' : '', '>', $message['body'], '</div>
</div>';

// Assuming there are attachments...
Expand Down Expand Up @@ -697,6 +697,11 @@ function template_single_post($message)
echo '
<ul class="quickbuttons">';

// Selected quote.
if ($context['can_quote'])
echo '
<li style="display:none;" id="quoteSelected_', $message['id'], '"><a href="javascript:void(0)" class="quote_selected_button">', $txt['quote_selected_action'] ,'</a></li>';

// Can they reply?
if ($context['can_quote'])
echo '
Expand Down Expand Up @@ -946,6 +951,9 @@ function onDocReceived(XMLDoc)
sJumpAnchor: "quickreply",
bIsFull: true
});
var oEditorID = "', $context['post_box_name'] ,'";
var oEditorObject = oEditorHandle_', $context['post_box_name'], ';
var oJumpAnchor = "quickreply";
// ]]></script>';
}
?>
5 changes: 4 additions & 1 deletion Themes/default/Post.template.php
Expand Up @@ -804,6 +804,8 @@ function onDocSent(XMLDoc)
});';

echo '
var oEditorID = "', $context['post_box_name'] ,'";
var oEditorObject = oEditorHandle_', $context['post_box_name'], ';
// ]]></script>';

// If the user is replying to a topic show the previous posts.
Expand Down Expand Up @@ -834,6 +836,7 @@ function onDocSent(XMLDoc)
{
echo '
<ul class="quickbuttons" id="msg_', $post['id'], '_quote">
<li style="display:none;" id="quoteSelected_', $post['id'], '" data-msgid="', $post['id'], '"><a href="javascript:void(0)" class="quote_selected_button">', $txt['quote_selected_action'] ,'</a></li>
<li id="post_modify"><a href="#postmodify" onclick="return insertQuoteFast(', $post['id'], ');" class="quote_button">', $txt['quote'], '</a></li>
</ul>';
}
Expand All @@ -851,7 +854,7 @@ function onDocSent(XMLDoc)
}

echo '
<div class="list_posts smalltext" id="msg_', $post['id'], '_body">', $post['message'], '</div>
<div class="list_posts smalltext" id="msg_', $post['id'], '_body" data-msgid="', $post['id'], '">', $post['message'], '</div>
</div>
</div>';
}
Expand Down
2 changes: 1 addition & 1 deletion Themes/default/css/index.css
Expand Up @@ -1390,7 +1390,7 @@ ul li.greeting {
.quickbuttons a:hover {
color: #a70;
}
.quickbuttons li a.quote_button {
.quickbuttons li a.quote_button, .quickbuttons li a.quote_selected_button {
background-position: 0 -1px;
padding: 0 2px 0 20px;
}
Expand Down
1 change: 1 addition & 0 deletions Themes/default/languages/index.english.php
Expand Up @@ -419,6 +419,7 @@
$txt['quote_from'] = 'Quote from';
$txt['quote'] = 'Quote';
$txt['quote_action'] = 'Quote';
$txt['quote_selected_action'] = 'Quote selected text';
$txt['fulledit'] = 'Full&nbsp;edit';
$txt['edit'] = 'Edit';
$txt['quick_edit'] = 'Quick Edit';
Expand Down
108 changes: 108 additions & 0 deletions Themes/default/scripts/quotedText.js
@@ -0,0 +1,108 @@
function getSelectedText(divID)
{
if (typeof divID == 'undefined' || divID == false)
return false;

var text = '',
selection,
found = 0;

if (window.getSelection)
{
selection = window.getSelection();
text = selection.toString();
}
else if (document.selection && document.selection.type != 'Control')
{
selection = document.selection.createRange();
text = selection.text;
}

// Need to be sure the selected text does belong to the right div.
for (var i = 0; i < selection.rangeCount; i++) {
s = selection.getRangeAt(i).startContainer.parentNode.id;
e = selection.getRangeAt(i).endContainer.parentNode.id;

if (s == divID || (s != divID && e == 'child'))
{
found = 1;
break;
}
}

return found === 1 ? text : false;
}

function quotedTextClick(oOptions)
{
text = '';

// The process has been started, hide the button.
$('#quoteSelected_' + oOptions.msgID).hide();

// Do a call to make sure this is a valid message.
$.ajax({
url: smf_prepareScriptUrl(smf_scripturl) + 'action=quotefast;quote=' + oOptions.msgID + ';xml;pb='+ oEditorID + ';mode=' + (oEditorObject.bRichTextEnabled ? 1 : 0),
type: 'GET',
dataType: 'xml',
beforeSend: function () {
ajax_indicator(true);
},
success: function (data, textStatus, xhr) {
// Search the xml data to get the quote tag.
text = $(data).find('quote').text();

// Insert the selected text between the quotes BBC tags.
text = text.match(/^\[quote(.*)]/ig) + oOptions.text + '[/quote]' + '\n\n';

// Add the whole text to the editor's instance.
$('#' + oEditorID).data('sceditor').InsertText(text);

// Move the view to the quick reply box. If available.
if (typeof oJumpAnchor != 'undefined'){
if (navigator.appName == 'Microsoft Internet Explorer')
window.location.hash = oJumpAnchor;
else
window.location.hash = '#' + oJumpAnchor;
}

ajax_indicator(false);
},
error: function (xhr, textStatus, errorThrown) {
ajax_indicator(false);
}
});
}

$(function() {

// Event for handling selected quotes.
$(document).on('mouseup', '.inner, .list_posts', function() {

// Get everything we need.
var oSelected = {
divID : $(this).attr('id'),
msgID : $(this).data('msgid'),
};

// If the button is already visible, hide it!
$('#quoteSelected_' + oSelected.msgID).hide();

// Get any selected text.
oSelected.text = getSelectedText(oSelected.divID);

// Do we have some selected text?
if (typeof oSelected.text == 'undefined' || oSelected.text == false)
return false;

// Show the "quote this" button.
$('#quoteSelected_' + oSelected.msgID).show();

$(document).one('click', '#quoteSelected_' + oSelected.msgID + ' a', function(e){
e.preventDefault();
quotedTextClick(oSelected);
});

return false;
});
});
9 changes: 5 additions & 4 deletions Themes/default/scripts/topic.js
Expand Up @@ -257,6 +257,7 @@ QuickReply.prototype.quote = function (iMessageId, xDeprecated)
ajax_indicator(true);
if (this.bIsFull)
insertQuoteFast(iMessageId);

else
getXMLDocument(smf_prepareScriptUrl(this.opt.sScriptUrl) + 'action=quotefast;quote=' + iMessageId + ';xml', this.onQuoteReceived);
}
Expand Down Expand Up @@ -760,18 +761,18 @@ function ignore_toggles(msgids, text)
}
}

// Likes count for messages.
// On document ready.
$(function() {

// Likes count for messages.
$(document).on('click', '.like_count a', function(e){
e.preventDefault();
var title = $(this).parent().text(),
url = $(this).attr('href') + ';js=1';
return reqOverlayDiv(url, title);
});
});

// Message likes.
$(function() {
// Message likes.
$(document).on('click', '.msg_like', function(event){
var obj = $(this);
event.preventDefault();
Expand Down

0 comments on commit 75c0467

Please sign in to comment.