Index: img_assist.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/img_assist/img_assist.module,v
retrieving revision 1.95
diff -u -p -r1.95 img_assist.module
--- img_assist.module	18 Jan 2009 21:51:07 -0000	1.95
+++ img_assist.module	1 Feb 2009 08:21:14 -0000
@@ -1119,23 +1119,26 @@ function img_assist_properties_form($for
   );
   
   // Buttons.
-  $form[] = array('#value' => '<div id="buttons">');
-  $form['insert'] = array(
+  $form['buttons'] = array(
+    '#prefix' => '<div id="buttons">',
+    '#suffix' => '</div>',
+  );
+  $form['#attributes']['onsubmit'] = 'return parent.insertImage();';
+  $form['buttons']['insert'] = array(
     '#type' => 'submit',
     '#value' => ($update) ? t('Update') : t('Insert'),
-    '#attributes' => array('onclick' => 'parent.insertImage()', 'style' => 'float: left;'),
+    '#attributes' => array('style' => 'float: left;'),
   );
-  $form['cancel'] = array(
+  $form['buttons']['cancel'] = array(
     '#type' => 'button',
     '#value' => t('Cancel'),
     '#button_type' => 'button',
-    '#attributes' => array('onclick' => 'parent.cancelAction()', 'style' => 'float: right;'),
+    '#attributes' => array('onclick' => 'return parent.cancelAction();', 'style' => 'float: right;'),
   );
   
-  $form[] = array('#value' => '</div>');
   $form[] = array('#value' => '</td></tr></table></div>');
   
-  $form['#attributes'] = array('name' => 'img_assist');
+  $form['#attributes']['name'] = 'img_assist';
   return $form;
 }
 
@@ -1819,8 +1822,8 @@ function theme_img_assist_page($content,
   $output .= drupal_get_html_head();
   $output .= drupal_get_js();
   $output .= "\n<script type=\"text/javascript\"><!-- \n";
-  $output .= "  if (parent.tinyMCE) {\n";
-  $output .= "    document.write('<link href=\"' + parent.tinyMCEPopup.getParam(\"popups_css\") + '\" rel=\"stylesheet\" type=\"text/css\">');\n";
+  $output .= "  if (parent.tinyMCE && parent.tinyMCEPopup && parent.tinyMCEPopup.getParam('popups_css')) {\n";
+  $output .= "    document.write('<link href=\"' + parent.tinyMCEPopup.getParam('popups_css') + '\" rel=\"stylesheet\" type=\"text/css\">');\n";
   $output .= "  } else {\n";
   foreach (drupal_add_css() as $media => $type) {
     $paths = array_merge($type['module'], $type['theme']);
@@ -1855,22 +1858,12 @@ function theme_img_assist_page($content,
  */
 
 /**
- * Implementation of hook_wysiwyg_plugin().
+ * Implementation of hook_wysiwyg_include_directory().
  */
-function img_assist_wysiwyg_plugin($editor, $version) {
-  switch ($editor) {
-    case 'tinymce':
-      if ($version > 3) {
-        return array(
-          'img_assist' => array(
-            'path' => drupal_get_path('module', 'img_assist') .'/drupalimage/editor_plugin.js',
-            'buttons' => array('img_assist' => t('Image Assist')),
-            'url' => 'http://drupal.org/project/img_assist',
-            'extended_valid_elements' => array('img[class|src|border=0|alt|title|width|height|align|name|style]'),
-          ),
-        );
-      }
-      break;
+function img_assist_wysiwyg_include_directory($type) {
+  switch ($type) {
+    case 'plugins':
+      return $type;
   }
 }
 
Index: img_assist_popup.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/img_assist/img_assist_popup.js,v
retrieving revision 1.2
diff -u -p -r1.2 img_assist_popup.js
--- img_assist_popup.js	25 Dec 2008 19:14:44 -0000	1.2
+++ img_assist_popup.js	1 Feb 2009 08:17:59 -0000
@@ -113,7 +113,7 @@ function hideElement(id) {
 }
 
 function insertImage() {
-  if (window.opener || !tinyMCEPopup.isWindow) {
+  if (window.opener || (tinyMCEPopup.editor && tinyMCEPopup.editor.id)) {
     // 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)
@@ -126,11 +126,10 @@ function insertImage() {
       var content = getHTML(formObj);
     }
     else {
+      // formObj['edit-insertmode'].value == 'filtertag'
       var content = getFilterTag(formObj);
     }
-    insertToEditor(content);
-    return false;
-    
+    return insertToEditor(content);
   }
   else {
     alert('The image cannot be inserted because the parent window cannot be found.');
@@ -139,6 +138,5 @@ function insertImage() {
 }
 
 function getHTML(formObj) {
-  var html = frames['img_assist_main'].document.getElementById('finalhtmlcode').value;
-  return html;
+  return frames['img_assist_main'].document.getElementById('finalhtmlcode').value;
 }
Index: img_assist_textarea.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/img_assist/img_assist_textarea.js,v
retrieving revision 1.6
diff -u -p -r1.6 img_assist_textarea.js
--- img_assist_textarea.js	25 Dec 2008 19:14:44 -0000	1.6
+++ img_assist_textarea.js	1 Feb 2009 08:16:47 -0000
@@ -101,13 +101,13 @@ function insertToEditor(content) {
   }
   
   // Close the dialog
-  cancelAction();
-  return false;
+  return cancelAction();
 }
 
 function cancelAction() {
   // Close the dialog
   window.close();
+  return false;
 }
 
 /**
Index: img_assist_tinymce.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/img_assist/img_assist_tinymce.js,v
retrieving revision 1.6
diff -u -p -r1.6 img_assist_tinymce.js
--- img_assist_tinymce.js	18 Jan 2009 04:10:25 -0000	1.6
+++ img_assist_tinymce.js	1 Feb 2009 08:35:54 -0000
@@ -106,7 +106,7 @@ function getFilterTag(formObj) {
   var content = '<img src="' + Drupal.settings.basePath + 'index.php?q=image/view/' + nid + '"'
               + ' width="' + width + '" height="' + height + '" align="' + align + '"'
               + ' alt="' + miscAttribs + '" title="' + miscAttribs + '"'
-              + ' name="mceItemDrupalImage" class="mceItemDrupalImage" />';
+              + ' name="mceItemDrupalImage" class="img-assist" />';
   
   return content;
 }
@@ -116,12 +116,12 @@ function insertToEditor(content) {
   tinyMCEPopup.editor.execCommand('mceInsertContent', false, content);
   
   // Close the dialog
-  tinyMCEPopup.close();
-  return false;
+  return cancelAction();
 }
 
 function cancelAction() {
   // Close the dialog
   tinyMCEPopup.close();
+  return false;
 }
 
Index: plugins/img_assist.inc
===================================================================
RCS file: plugins/img_assist.inc
diff -N plugins/img_assist.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ plugins/img_assist.inc	1 Feb 2009 07:23:21 -0000
@@ -0,0 +1,31 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Wysiwyg API integration.
+ */
+
+/**
+ * Implementation of hook_wysiwyg_plugin().
+ */
+function img_assist_img_assist_plugin() {
+  $plugins = array();
+  $plugins['img_assist'] = array(
+    'title' => t('Image Assist'),
+    'vendor url' => 'http://drupal.org/project/img_assist',
+    'icon file' => 'img_assist.gif',
+    'icon title' => t('Insert or update an embedded image'),
+    'settings' => array(
+      'dialog' => array(
+        'url' => base_path() . 'index.php?q=img_assist/load/tinymce',
+        'width' => 700,
+        'height' => 500,
+      ),
+    ),
+    // @todo Use a more granular way to validate contents for input formats.
+    'extended_valid_elements' => array('img[class|src|border=0|alt|title|width|height|align|name|style]'),
+  );
+  return $plugins;
+}
+
Index: plugins/img_assist/img_assist.css
===================================================================
RCS file: plugins/img_assist/img_assist.css
diff -N plugins/img_assist/img_assist.css
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ plugins/img_assist/img_assist.css	1 Feb 2009 07:24:17 -0000
@@ -0,0 +1,10 @@
+/* $Id: drupalimage.css,v 1.1.4.1.2.1 2008/07/18 00:14:51 sun Exp $ */
+
+img.img-assist {
+  border: 1px dotted #cc0000;
+  background-image: url('images/img_assist.gif');
+  background-position: center;
+  background-repeat: no-repeat;
+  background-color: #ffffcc;
+}
+
Index: plugins/img_assist/img_assist.js
===================================================================
RCS file: plugins/img_assist/img_assist.js
diff -N plugins/img_assist/img_assist.js
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ plugins/img_assist/img_assist.js	1 Feb 2009 06:43:58 -0000
@@ -0,0 +1,94 @@
+// $Id: editor_plugin.js 201 2008-02-12 15:56:56Z sun $
+
+Drupal.wysiwyg.plugins.img_assist = {
+
+  /**
+   * Return whether the passed node belongs to this plugin.
+   */
+  isNode: function (node) {
+    return ($(node).is('img.img-assist'));
+  },
+
+  /**
+   * Execute the button.
+   */
+  invoke: function (data, settings, instanceId) {
+    if (data.format == 'html') {
+      // captionTitle and captionDesc for backwards compatibility.
+      var options = {nid: '', title: '', captionTitle: '', desc: '', captionDesc: '', link: '', url: '', align: '', width: '', height: '', id: instanceId, action: 'insert'};
+      if ($(data.node).is('img.img-assist')) {
+        options.width = data.node.width;
+        options.height = data.node.height;
+        options.align = data.node.align;
+        // Expand inline tag in alt attribute
+        data.node.alt = decodeURIComponent(data.node.alt);
+        var chunks = data.node.alt.split('|');
+        for (var i in chunks) {
+          chunks[i].replace(/([^=]+)=(.*)/g, function(o, property, value) {
+            options[property] = value;
+          });
+        }
+        options.captionTitle = options.title;
+        options.captionDesc = options.desc;
+        options.action = 'update';
+      }
+    }
+    else {
+      // @todo Plain text support.
+    }
+    if (typeof options != 'undefined') {
+      Drupal.wysiwyg.instances[instanceId].openDialog(settings.dialog, options);
+    }
+  },
+
+  /**
+   * Replace inline tags in content with images.
+   */
+  attach: function (content, settings, instanceId) {
+    content = content.replace(/\[img_assist\|([^\[\]]+)\]/g, function(orig, match) {
+      var node = {}, chunks = match.split('|');
+      for (var i in chunks) {
+        chunks[i].replace(/([^=]+)=(.*)/g, function(o, property, value) {
+          node[property] = value;
+        });
+      }
+      node.name = 'mceItemDrupalImage';
+      node.class = 'img-assist';
+      node.src = Drupal.settings.basePath + 'index.php?q=image/view/' + node.nid;
+      node.alt = 'nid=' + node.nid + '|title=' + node.title + '|desc=' + node.desc;
+      if (node.link.indexOf(',') != -1) {
+        var link = node.link.split(',', 2);
+        node.alt += '|link=' + link[0] + '|url=' + link[1];
+      }
+      else {
+        node.alt += '|link=' + node.link;
+      }
+      if (typeof node.url != 'undefined') {
+        node.alt += '|url=' + node.url;
+      }
+      node.alt = encodeURIComponent(node.alt);
+      var element = '<img ';
+      for (var property in node) {
+        element += property + '="' + node[property] + '" ';
+      }
+      element += '/>';
+      return element;
+    });
+    return content;
+  },
+
+  /**
+   * Replace images with inline tags in content upon detaching editor.
+   */
+  detach: function (content, settings, instanceId) {
+    $content = $('<div>' + content + '</div>'); // No .outerHTML() in jQuery :(
+    $('img', $content).each(function(node) {
+      if (this.className != 'img-assist') {
+        return;
+      }
+      var inlineTag = '[img_assist|' + decodeURIComponent(this.alt) + '|align=' + this.align + '|width=' + this.width + '|height=' + this.height + ']';
+      $(this).replaceWith(inlineTag);
+    });
+    return $content.html();
+  }
+};
Index: plugins/img_assist/images/img_assist.gif
===================================================================
RCS file: plugins/img_assist/images/img_assist.gif
diff -N plugins/img_assist/images/img_assist.gif
Binary files /dev/null and img_assist.gif differ
