test

Description

I have put together a small ajax enhancement for sending quotes directly to the comment box if the comment box is on the same page as the quote link. This also means you can quote multiple posts in one go by just clicking on different comments' quote links.

It requires a tiny patch to quote.module to set up the ajax callback, and a javascript function which attaches the required functionality to any link marked with a class of "quote" that is contained within a comment. I have the javascript in a utility file that I load for my site via my page template, but it could be added as an include file with this module if the maintainer wants to add this patch to the codebase.

/* Instant copying of comment quotes to comment textarea */
var instaQuotes = function() {
  if (!$('textarea#edit-comment').get(0)) return;

  $('.comment a.quote').click( function() {
    // Extract comment id from link
    var cid = ///comment//reply///d+//(/d+)/.exec(this.href)[1];

    // Scroll down to comment form
    window.location.hash = '#comment-form';

    // Get comment via ajax then append to new comment textarea
    $.get('/quote/comment/' + cid, null, function(data) {
      var quote = data.split(':::', 2);
      var textarea = $('textarea#edit-comment').get(0);
      textarea.value += ('[quote=' + quote[0] + ']' + quote[1] + '[/quote]/n/n');
      textarea.scrollTop = textarea.scrollHeight; // scrolls to bottom of textarea
    });
    return false;
  });
}

if (Drupal.jsEnabled) {
  $(instaQuotes);
}

It uses ajax because it is the easiest way to get a clean copy of the comment. I tried to extract it from the html source at first so no server interaction would be required but it became an ugly mess of code to replace P and BR tags with line-break characters and stripping of other html tags. This way is better as it preserves all original formatting within the quotes.

Caveat: I have upgraded jQuery from drupal's default to the latest (1.2.3?), but there is nothing too fancy in there so it should still work with the older jQuery shipping with drupal.

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值