? img_assist_plugin.patch
Index: img_assist.js
===================================================================
RCS file: /cvs/drupal/contributions/modules/img_assist/Attic/img_assist.js,v
retrieving revision 1.4
diff -u -p -r1.4 img_assist.js
--- img_assist.js	13 Feb 2007 22:48:31 -0000	1.4
+++ img_assist.js	8 Mar 2007 09:46:01 -0000
@@ -126,24 +126,28 @@ function insertImage() {
   if (window.opener) {
     // Get variables from the fields on the properties frame
     var formObj = frames['img_assist_main'].document.forms[0];
-		// Get mode	(see img_assist.module for detailed comments)
-		if (formObj['edit-insertmode'].value == 'html') { // return so the page can submit normally and generate the HTML code
-			return true;
-		} else if (formObj['edit-insertmode'].value == 'html2') { // HTML step 2 (processed code, ready to be inserted)
-			var content = getHTML(formObj);
-		} else {
-			var content = getFilterTag(formObj);
-		}
-		insertToEditor(content);
-		return false;
-		
-  } else {
-		alert('The image cannot be inserted because the parent window cannot be found.');
-		return false;
-	}
+    // Construct name of handler function depending on insertion mode
+    var functionName = 'getFilterTag_' + formObj['edit-insertmode'].value;
+    if (window[functionName]) {
+      // Call specific handler function if it exists
+      var content = window[functionName](formObj);
+    }
+    else {
+      // Fallback to default handler function
+      getFilterTag(formObj);
+    }
+    if (typeof(content) == 'boolean') {
+      // Return value of boolean is not inserted, but propagated
+      return content;
+    }
+    else {
+      // Insert return value of handler function into editor
+      insertToEditor(content);
+      return false;
+    }
+  }
+  else {
+    alert('The image cannot be inserted because the parent window cannot be found.');
+    return false;
+  }
 }
-
-function getHTML(formObj) {
-	var html = frames['img_assist_main'].document.getElementById("finalhtmlcode").innerHTML;
-	return html;
-}
\ No newline at end of file
Index: img_assist.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/img_assist/Attic/img_assist.module,v
retrieving revision 1.68.2.6
diff -u -p -r1.68.2.6 img_assist.module
--- img_assist.module	7 Mar 2007 17:02:46 -0000	1.68.2.6
+++ img_assist.module	8 Mar 2007 09:46:02 -0000
@@ -315,7 +315,7 @@ function img_assist_admin_settings() {
     '#type' => 'select',
     '#title' => t('Default insert mode'),
     '#default_value' => variable_get('img_assist_default_insert_mode', 'none'),
-    '#options' => array('filtertag' => t('Filter Tag'), 'html' => t('HTML Code')),
+    '#options' => _img_assist_filter_data('names'),
     '#description' => t('The link behavior can be overriden when inserting images by users with the proper permissions, but these defaults will still be used for everyone else.'),
   );
   $form['properties']['img_assist_load_title'] = array(
@@ -441,6 +441,10 @@ function img_assist_loader() {
 	}
 	$editor_js = base_path() . $path . '/img_assist_' . $editor . '.js';
 	$output .= "<script type=\"text/javascript\" src=\"$editor_js\"></script>\n";
+	foreach(_img_assist_filter_data() as $plugin) {
+		$plugin_js = base_path() . $plugin['javascript'];
+		$output .= "<script type=\"text/javascript\" src=\"$plugin_js\"></script>\n";
+	}
 
 	$output .= "</head>\n\n";
 
@@ -900,7 +904,7 @@ function img_assist_properties_form($nod
       '#type' => 'select',
       '#title' => t('Insert mode'),
       '#default_value' => variable_get('img_assist_default_insert_mode', 'filtertag'),
-      '#options' => array('filtertag' => t('Filter Tag'), 'html' => t('HTML Code')),
+      '#options' => _img_assist_filter_data('names'),
     );
     $form[] = array('#value' => "</div>\n");
   } else {
@@ -1663,3 +1667,51 @@ function theme_img_assist_legacy() {
 	return "<div class=\"%image-class\">\n  <a href=\"%node-link\"><img src=\"%src\" width=\"%width\" height=\"%height\" alt=\"%alt\" /></a>\n  <div class=\"caption\">%caption</div>\n</div>";
 }
 
+/**
+ * Data about image assist filter types.
+ * @return
+ *   Array which maps an filter id to an array with keys 'name', 'javascript', 'css'
+ */
+function _img_assist_filter_data($op = 'array') {
+  static $data = NULL;
+  if (is_null($data)) {
+    // First run, collect data
+    $filters = module_invoke_all('img_assist');
+    foreach($filters as $filter) {
+      $data[$filter['id']] = $filter;
+    }
+  }
+  $result = NULL;
+  switch ($op) {
+    case 'array':
+      $result = $data;
+      break;
+
+    case 'names':
+      foreach($data as $item) {
+        $result[$item['id']] = $item['name'];
+      }
+      break;
+  }
+  return $result;
+}
+
+/**
+ * Implementation of hook_img_assist().
+ */
+function img_assist_img_assist() {
+  return array(
+    array(
+      'id' => 'img_assist',
+      'name' => 'Image assist filter',
+      'javascript' => drupal_get_path('module', 'img_assist') . '/img_assist.js',
+      'css' => ''
+    ),
+    array(
+      'id' => 'html',
+      'name' => 'HTML Code',
+      'javascript' => drupal_get_path('module', 'img_assist') . '/img_assist.js',
+      'css' => ''
+    )
+  );
+}
Index: img_assist_textarea.js
===================================================================
RCS file: /cvs/drupal/contributions/modules/img_assist/Attic/img_assist_textarea.js,v
retrieving revision 1.2
diff -u -p -r1.2 img_assist_textarea.js
--- img_assist_textarea.js	13 Feb 2007 22:48:31 -0000	1.2
+++ img_assist_textarea.js	8 Mar 2007 09:46:03 -0000
@@ -58,6 +58,18 @@ function initUpload() {
 }
 
 function getFilterTag(formObj) {
+  return getFilterTag_img_assist(formObj);
+}
+
+function getFilterTag_html(formObj) {
+  return true;
+}
+
+function getFilterTag_html2(formObj) {
+  return frames['img_assist_main'].document.getElementById("finalhtmlcode").innerHTML;
+}
+
+function getFilterTag_img_assist(formObj) {
   var nid          = formObj['edit-nid'].value;
   var captionTitle = formObj['edit-title'].value;
   var captionDesc  = formObj['edit-desc'].value;
