--- ajax_checklist.module.orig	2008-11-16 03:05:08.000000000 -0700
+++ ajax_checklist.module	2010-01-02 16:23:50.000000000 -0700
@@ -29,15 +29,24 @@ function ajax_checklist_menu() {
 
 // include the .js file in nodes
 function ajax_checklist_nodeapi(&$node, $op, $a3 = NULL, $a4 =NULL) {
-  if ($op="prepare") {
-    // This will currently load the js for all pages. This could be improved.
-    $js_path = drupal_get_path('module', 'ajax_checklist');
-    drupal_add_js($js_path . '/ajax_checklist.js');
-    //TODO: this won't work on CCK fields in views
-    $node->body=str_replace('%AJAXCHECKLISTNID',$node->nid,$node->body);
+  if ($op == "alter") {
+    if (!(strpos($node->body, '!ajax_checklist_nid') === FALSE)) {
+      $js_path = drupal_get_path('module', 'ajax_checklist'); 
+      drupal_add_js($js_path . '/ajax_checklist.js');
+    }
   }
 }
 
+/**
+ * Substitute the token !ajax_checklist_nid for the actual node id.
+ * We do this in the preprocess level to keep CCK and other modules from overriding this.
+ */
+function ajax_checklist_preprocess_node(&$vars) {
+  if (!(strpos($vars['content'], 'ajax_checklist_nid') === FALSE)) {
+    $vars['content'] = strtr($vars['content'], array('!ajax_checklist_nid' => $vars['nid']));
+  } 
+}
+
 function ajax_checklist_update_access() {
   $access["update"]=user_access('update ajax checklists');
   print drupal_to_js($access);
@@ -53,10 +62,10 @@ function ajax_checklist_loadnid ($nid) {
   $dcvals = array();
   // any checkbox id that starts with user- we remember the current user's settings
   // any other id is global and we use user=0
-  $result=db_query("select qid,state from ajax_checklist ".
+  $result=db_query("select qid,state from {ajax_checklist} ".
                    " where nid=%d and qid not like 'user-%' and user=0 ".
                    " union ".
-                   "select qid,state from ajax_checklist ".
+                   "select qid,state from {ajax_checklist} ".
                    "where nid=%d and qid like 'user-%' and user=%d ",$nid,$nid,$uid);
   while ($data=db_fetch_object($result)) {
     $dcvals[] = array (qid => $data->qid, state => $data->state, access => $access);
@@ -74,16 +83,16 @@ function ajax_checklist_save ($nid,$qid,
     $uid=0;
   }
 
-  $existing=db_result(db_query("select count(state) from ajax_checklist ".
+  $existing=db_result(db_query("select count(state) from {ajax_checklist} ".
                                "where nid=%d and user=%d and qid='%s'",$nid,$uid,$qid));
   if ($existing == 0) {
-    db_query("insert into ajax_checklist (nid,user,qid,state) ".
+    db_query("insert into {ajax_checklist} (nid,user,qid,state) ".
              "values (%d,%d,'%s',%d)",$nid,$uid,$qid,$state);
   } elseif ( $current != $state ) {
-    $current=db_result(db_query("select state from ajax_checklist ".
+    $current=db_result(db_query("select state from {ajax_checklist} ".
                                 " where nid=%d and user=%d and qid='%s'",$nid,$uid,$qid));
     if ($current != $state) {
-      db_query("update ajax_checklist ".
+      db_query("update {ajax_checklist} ".
                "set state=%d where nid=%d and user=%d and qid='%s'",$state,$nid,$uid,$qid);
     }
   }
@@ -91,17 +100,16 @@ function ajax_checklist_save ($nid,$qid,
   exit();
 }
 
-// implementation of hool_filter to create the checkbox filter
+// implementation of hook_filter to create the checkbox filter
 function ajax_checklist_filter($op, $delta = 0, $format = -1, $text = '' ) {
   global $ajax_checklist_matchcount;
   $ajax_checklist_matchcount = 0;
 
   switch($op) {
     case 'list':
-      return array (0 => t('Ajax Checkbox filter'));
+      return array (0 => t('AJAX checkbox filter'));
     case 'description':
-      return t('Allows checkboxes in nodes with [cb someid "Example?"]'.
-	'that saves their state with AJAX to the database');
+      return t('Allows checkboxes in nodes defined as [cb unique_checkbox_id Check this!], whose state is saved with AJAX to the database.');
     case 'settings':
       break;
     case 'no cache':
@@ -115,10 +123,11 @@ function ajax_checklist_filter($op, $del
         return $text;
       }
       else {
-        $output  = "<form action=\"/dummy\" method=\"post\" class=\"ajaxchecklist\" id=\"%AJAXCHECKLISTNID\">\n";
-        $output .= "<input name=\"nid\" class=\"ajaxchecklist-nid\" value=\"%AJAXCHECKLISTNID\" type=\"hidden\">\n";
+        // Changing the node id token to standard form seems to allow checkboxes to work on CCK fields.
+        $output  = '<form action="/dummy" method="post" class="ajaxchecklist" id="!ajax_checklist_nid">' . "\n";
+        $output .= '<input name="nid" class="ajaxchecklist-nid" value="!ajax_checklist_nid" type="hidden" />' . "\n";
         $output .= preg_replace_callback("|\[cb ([^ ]*)([^]]*)\]|i",'ajax_checklist_docheckbox',$text);
-        $output .="</form>";
+        $output .= "</form>";
         return $output;
       }
       break;
@@ -127,6 +136,13 @@ function ajax_checklist_filter($op, $del
   } 
 }
 
+/**
+ * Implementation of hook_filter_tips().
+ */
+function ajax_checklist_filter_tips($delta, $format, $long = FALSE) {
+  return t('AJAX checkboxes can be added to this post, defined like this:  [cb unique_checkbox_id Check this!].');
+}
+
 // helper function for preg_replace_callback to generate the html for each checkbox
 // Form API not used as that would float all the checkboxes to the top/bottom of the page.
 function ajax_checklist_docheckbox ($matches) {
