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.

在编程中,`void test` 通常表示一个返回值类型为 `void`(即不返回任何值)且函数名为 `test` 的函数。以下以几种常见编程语言为例介绍其含义及应用: ### C/C++ 在 C 和 C++ 中,`void` 用于表示函数不返回任何值。`void test()` 可以定义一个名为 `test` 的函数,这个函数不返回值,常用于执行一些操作,比如打印信息、修改全局变量等。 ```c #include <stdio.h> // 定义一个返回值为 void 的 test 函数 void test() { printf("This is a test function.\n"); } int main() { test(); return 0; } ``` ### Java 在 Java 中,`void` 同样用于表示方法不返回任何值。可以定义一个名为 `test` 的方法来执行特定任务。 ```java public class Main { // 定义一个返回值为 void 的 test 方法 public static void test() { System.out.println("This is a test method."); } public static void main(String[] args) { test(); } } ``` ### Python Python 没有显式的 `void` 类型,因为函数不返回值时默认返回 `None`。可以定义一个名为 `test` 的函数来执行特定操作。 ```python def test(): print("This is a test function.") test() ``` ### 错误处理 在使用 `void test` 函数时,错误处理也很重要。在 C++ 中,可以使用异常处理机制;在 Java 中,有 `try-catch` 语句;Python 则使用 `try-except` 语句。 以下是 Java 中 `void test` 函数的错误处理示例: ```java public class Main { public static void test() { try { int[] arr = new int[2]; arr[3] = 10; // 会引发数组越界异常 } catch (ArrayIndexOutOfBoundsException e) { System.out.println("An error occurred: " + e.getMessage()); } } public static void main(String[] args) { test(); } } ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值