Only in .: frameset.patch
diff -urp ../../../../../dev-modules/img_assist-6.x-3.x-dev/img_assist/img_assist.js ./img_assist.js
--- ../../../../../dev-modules/img_assist-6.x-3.x-dev/img_assist/img_assist.js	2008-07-23 01:07:44.000000000 +0200
+++ ./img_assist.js	2009-01-11 21:49:57.359375000 +0100
@@ -15,7 +15,7 @@ Drupal.theme.prototype.img_assist_link =
   if (Drupal.settings.img_assist.link == 'icon') {
     link = '<img src="'+ Drupal.settings.basePath + Drupal.settings.img_assist.icon +'" alt="'+ link +'" title="'+ link +'" />';
   }
-  html += '<a href="'+ Drupal.settings.basePath +'index.php?q=img_assist/load/textarea&textarea='+ el.name +'" class="img_assist-link" id="img_assist-link-'+ el.id +'" title="'+ Drupal.t('Click here to add images') +'" onclick="window.open(this.href, \'img_assist_link\', \'width=600,height=350,scrollbars=yes,status=yes,resizable=yes,toolbar=no,menubar=no\'); return false;">'+ link +'</a>';
+  html += '<a href="'+ Drupal.settings.basePath +'index.php?q=img_assist/load/textarea/img_assist_browser/'+ el.name +'" class="img_assist-link" id="img_assist-link-'+ el.id +'" title="'+ Drupal.t('Click here to add images') +'" onclick="window.open(this.href, \'img_assist_link\', \'width=600,height=350,scrollbars=yes,status=yes,resizable=yes,toolbar=no,menubar=no\'); return false;">'+ link +'</a>';
   html += '</div>';
   return html;
 }
diff -urp ../../../../../dev-modules/img_assist-6.x-3.x-dev/img_assist/img_assist.module ./img_assist.module
--- ../../../../../dev-modules/img_assist-6.x-3.x-dev/img_assist/img_assist.module	2008-12-25 20:14:44.000000000 +0100
+++ ./img_assist.module	2009-01-11 21:51:27.515625000 +0100
@@ -8,6 +8,8 @@
  * Implements a javascript-driven user interface to upload images to a Drupal
  * site and select a previously uploaded image for displaying inline in a
  * content.
+ *
+ * @todo instead of passing editor and html element name through arguments just save them in the parent window.
  */
 
 /**
@@ -56,35 +58,24 @@ function img_assist_menu() {
     'access arguments' => array('access content'),
     'type' => MENU_CALLBACK,
   );
-  $items['img_assist/load'] = array(
+  $items['img_assist/load/%/%/%'] = array(
     'title' => 'Image assist',
     'page callback' => 'img_assist_loader',
+    'page arguments' => array(2,3,4),
     'access arguments' => array('access content'),
     'type' => MENU_CALLBACK,
   );
   // Page callbacks called internally by img_assist/load.
-  $items['img_assist/header'] = array(
-    'title' => 'Image assist header',
-    'page callback' => 'img_assist_header',
-    'page arguments' => array(2),
-    'access arguments' => array('access content'),
-    'type' => MENU_CALLBACK,
-  );
-  $items['img_assist/thumbs'] = array(
-    'title' => 'Image assist thumbnails',
-    'page callback' => 'img_assist_thumbs',
-    'access arguments' => array('access content'),
-    'type' => MENU_CALLBACK,
-  );
-  $items['img_assist/upload'] = array(
+  $items['img_assist/upload/%/%'] = array(
     'title' => 'Image assist upload',
     'page callback' => 'img_assist_upload',
     'access arguments' => array('access content'),
     'type' => MENU_CALLBACK,
   );
-  $items['img_assist/properties'] = array(
+  $items['img_assist/properties/%/%/%/%'] = array(
     'title' => 'Image assist properties',
     'page callback' => 'img_assist_properties',
+    'page arguments' => array(2,3,4,5),
     'access arguments' => array('access content'),
     'type' => MENU_CALLBACK,
   );
@@ -96,13 +87,6 @@ function img_assist_menu() {
     'access arguments' => array('access content'),
     'type' => MENU_CALLBACK,
   );
-  // Insert callback (only for inserting HTML, not filter tag).
-  $items['img_assist/insert_html'] = array(
-    'title' => 'Insert callback',
-    'page callback' => 'img_assist_insert_html',
-    'access arguments' => array('access content'),
-    'type' => MENU_CALLBACK,
-  );
   $items['admin/settings/img_assist'] = array(
     'title' => 'Image assist',
     'description' => 'Change settings for the Image assist module.',
@@ -559,52 +543,51 @@ function img_assist_cache_clear() {
 /**
  * @defgroup img_assist_pages Image Assist Pages
  * @{
- * All but img_assist_loader() are in frames.
  */
 
 /**
- * Output main img_assist interface HTML.
- * 
- * @todo Remove hard-coded TinyMCE integration.
+ * @todo validate parameters
  */
-function img_assist_loader() {
-  $path = drupal_get_path('module', 'img_assist');
-  $editor = arg(2) ? arg(2) : 'textarea';
-
-  drupal_add_js($path .'/img_assist_popup.js');
-  if ($editor == 'tinymce') {
-    $tinymce_path = drupal_get_path('module', 'wysiwyg');
-    drupal_add_js($tinymce_path .'/tinymce/jscripts/tiny_mce/tiny_mce_popup.js');
-  }
-  drupal_add_js($path .'/img_assist_'. $editor .'.js');
-
-  $output  = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN">'."\n";
-  $output .= "<html>\n";
-  $output .= "<head>\n";
-  $output .= '<title>'. t('Add image') ."</title>\n";
-  $output .= drupal_get_js();
-  $output .= "</head>\n\n";
-  
-  $output .= '<frameset rows="38, *" onload="initLoader()" frameborder="0" border="0" framespacing="0">' . "\n";
-  $output .= '<frame name="img_assist_header" src="" class="img_assist_header" noresize="noresize" />' . "\n";
-  $output .= '<frame name="img_assist_main" src="" class="img_assist_main" noresize="noresize" />' . "\n";
-  $output .= "</frameset>\n";
-  
-  $output .= "</html>\n";
-  echo $output;
-  exit;
-}
-
-function img_assist_header($mode) {
-  // Mode may be 'uploading', 'properties' or 'browse'.
-  $output = drupal_get_form('img_assist_header_form', $mode);
-  echo theme('img_assist_page', $output, array('id' => 'img_assist_header', 'onload' => 'parent.initHeader();', 'class' => 'img_assist'));
+function img_assist_loader($editor = 'textarea', $view_name = 'img_assist_browser', $element = 'body') {
+  global $user;
+  // Get view arguments from path.  
+  $args = explode('/', $_GET['q']);
+  if (!in_array($view_name, variable_get('img_assist_views', array()))) {
+    $view_name = 'img_assist_browser';
+  }
+  $args = array_slice($args, 5);
+
+  // Check sanity and permissions for the 'img_assist_browser' view.
+  if ($view_name == 'img_assist_browser') {
+    if (empty($args[0])) {
+      $args[0] =  (user_access('access all images') ? 'all' : $user->uid);
+    }
+  }
+  $view = views_get_view($view_name);
+  $view->set_display('default');
+  $view->set_arguments($args);
+  $view->is_cacheable = FALSE;
+  $view->override_path = "img_assist/load/$editor/$view_name/$element";
+  $view->build('default');
+  $view->execute();
+  
+  $output = drupal_get_form('img_assist_header_form');
+  $output .= $view->render(); 
+  echo theme('img_assist_page', $output, array('id' => 'img_assist_thumbs', 'class' => 'img_assist'));
   exit;
 }
 
-function img_assist_header_form(&$form_state, $mode) {
+function img_assist_header_form(&$form_state, $editor = 'textarea', $element = 'body', $mode = '') {
   global $user;
-  
+  // hidden fields for editor and element
+  $form['editor'] = array(
+      '#type' => 'hidden',
+      '#value' => $editor,
+  );
+  $form['element'] = array(
+      '#type' => 'hidden',
+      '#value' => $element,
+  );
   // Upload image.
   if ($mode == 'uploading') {
     $form[] = array('#value' => '<div id="header-uploading">');
@@ -614,7 +597,7 @@ function img_assist_header_form(&$form_s
       '#type' => 'button',
       '#value' => t('Start Over'),
       '#button_type' => 'button',
-      '#attributes' => array('onclick' => 'parent.onClickStartOver();'),
+      '#attributes' => array('onclick' => 'onClickStartOver();'),
     );
     $form[] = array('#value' => '</div>');
   }
@@ -626,71 +609,31 @@ function img_assist_header_form(&$form_s
       '#type' => 'button',
       '#value' => t('Start Over'),
       '#button_type' => 'button',
-      '#attributes' => array('onclick' => 'parent.onClickStartOver()'),
+      '#attributes' => array('onclick' => 'onClickStartOver()'),
     );
     $form[] = array('#value' => '</div>');
   }
   // Browse images.
   else {
     $form[] = array('#value' => '<div id="header-browse">');
-    $form[] = array('#value' => '<strong>'. t('Browse Images: ') .'</strong>');
-    
+    $form[] = array('#value' => '<strong>'. t('Browse Images ') .'</strong>');
+
     $views = variable_get('img_assist_views', drupal_map_assoc(array('img_assist_browser')));
-    foreach ($views as $view_name => $view_title) {
-      if ($view_name == 'img_assist_browser') {
-        // @todo execute() performs a full query, we just need the count here.
-        // Get my images and count.
-        $myimages = views_get_view('img_assist_browser');
-        $myimages->set_arguments(array($user->uid));
-        $myimages->execute();
-        $options['img_assist_browser/' . $user->uid] = t('My Images') ." ($myimages->total_rows)";
-        
-        // Get all images and count.
-        if (user_access('access all images')) {
-          $allimages = views_get_view('img_assist_browser');
-          $allimages->set_arguments(array('all'));
-          $allimages->execute();
-          $options['img_assist_browser/all'] = t('All Images') ." ($allimages->total_rows)";
-        }
-        // Get category list.
-        if (module_exists('taxonomy')) {
-          $vocabs = (array)variable_get('img_assist_vocabs', array());
-          
-          // Get all images or only user's images depending on permissions.
-          $user_arg = (user_access('access all images')) ? 'all' : $user->uid;
-          
-          $term_images = array();
-          foreach ($vocabs as $vid) {
-            $vocab = taxonomy_vocabulary_load($vid);
-            $terms = taxonomy_get_tree($vid);
-            if ($terms) {
-              foreach ($terms as $key => $value) {
-                $tid = $value->tid;
-                $name = $value->name;
-                
-                // Get term images and count.
-                $term_images[$tid] = views_get_view('img_assist_browser');
-                $term_images[$tid]->set_arguments(array($user_arg, $tid));
-                $term_images[$tid]->execute();
-                $options[$vocab->name]["img_assist_browser/$user_arg/" . $tid] = $name ." ({$term_images[$tid]->total_rows})";
-              }
-            }
-          }
-        }
-      }
-      else {
+    // if there is more than one view enabled display a dropdown of views to choose from
+    if (count($views) > 1) {
+      foreach ($views as $view_name => $view_title) {
         $view = views_get_view($view_name);
         $view->execute();
         $view_title = ($view->get_title() == '') ? $view_name : $view->get_title();
         $options[$view_name] = "$view_title ($view->total_rows)";
       }
+      $form['browse'] = array(
+        '#type' => 'select',
+        '#default_value' => 'img_assist_browser/' . $user->uid,
+        '#options' => $options,
+        '#attributes' => array('onchange' => 'onChangeBrowseBy(this)'),
+      );
     }
-    $form['browse'] = array(
-      '#type' => 'select',
-      '#default_value' => 'img_assist_browser/' . $user->uid,
-      '#options' => $options,
-      '#attributes' => array('onchange' => 'parent.onChangeBrowseBy(this)'),
-    );
     if (user_access('create images')) {
       $form['upload'] = array(
         '#type' => 'button',
@@ -698,7 +641,7 @@ function img_assist_header_form(&$form_s
         '#value' => t('Upload'),
         '#suffix' => ' '. t('a new image'),
         '#button_type' => 'button',
-        '#attributes' => array('onclick' => 'parent.onClickUpload()'),
+        '#attributes' => array('onclick' => 'onClickUpload("' . $editor . '", "' . $element . '"); return false;'),
       );
     }
     $form[] = array('#value' => '</div><div id="header-cancel">');
@@ -706,33 +649,34 @@ function img_assist_header_form(&$form_s
       '#type' => 'button',
       '#value' => t('Cancel'),
       '#button_type' => 'button',
-      '#attributes' => array('onclick' => 'parent.cancelAction()'),
+      '#attributes' => array('onclick' => 'cancelAction()'),
     );
     $form[] = array('#value' => '</div>');
   }
+  // clear the floating of the header form
+  $form[] = array('#value' => '<br style="clear: both" />');
   return $form;
 }
 
+function img_assist_header_form_submit($form, &$form_state) {
+  if ($form_state['editor'] && $form_state['element']) {
+    // Send to different url.
+    $form_state['redirect'] = 'img_assist/upload/' . $form_state['editor'] . '/' . $form_state['element'];
+  }
+}
+
 /**
  * Interface for adding images. Uses the regular image node form.
+ *
+ * @todo: define hidden fields for editor and element
  */
-function img_assist_upload() {
+function img_assist_upload($editor = 'textarea', $element = 'body') {
   global $user;
   module_load_include('inc', 'node', 'node.pages');
 
   if (module_exists('image') && user_access('create images')) {
-    // On other img_assist_pages I've added the javascript using the body onload
-    // attribute, but for this page will also need the collapse functions and
-    // setting the body onload interferes with this. To solve this, I'm forced
-    // use the $(document).ready call. I should probably switch all the pages to
-    // this format to be more Drupal friendly, but at the same time I don't know
-    // if it really matters. If a user doesn't have Javascript, she can't use
-    // img_assist at all.
-    $output  = "<script type=\"text/javascript\"><!-- \n";
-    $output .= "  if (Drupal.jsEnabled) { \n";
-    $output .= "    $(document).ready(parent.initUpload);\n";
-    $output .= "  } \n";
-    $output .= "--></script>\n";
+    // get the "start over" button
+    $output = drupal_get_form('img_assist_header_form', $editor, $element, 'uploading');
     
     // Define an empty node and fetch an image node form
     $node = array('uid' => $user->uid, 'name' => $user->name, 'type' => 'image');
@@ -760,6 +704,15 @@ function img_assist_upload() {
  */
 function img_assist_form_alter(&$form, &$form_state, $form_id) {
   if ($form_id == 'image_node_form' && arg(0) == 'img_assist') {
+    // hidden fields for editor and element
+    $form['editor'] = array(
+        '#type' => 'hidden',
+        '#value' => arg(2),
+    );
+    $form['element'] = array(
+        '#type' => 'hidden',
+        '#value' => arg(3),
+    );
     $form['buttons']['submit']['#submit'] = array('img_assist_node_form_submit');
   }
   // If a view uses exposed filters in the image browser, we need to modify #action.
@@ -774,79 +727,24 @@ function img_assist_form_alter(&$form, &
 function img_assist_node_form_submit($form, &$form_state) {
   // Execute regular node submit handler.
   node_form_submit($form, $form_state);
-
   if ($form_state['nid']) {
     // Send to different url.
-    $form_state['redirect'] = 'img_assist/properties/'. $form_state['nid'];
-  }
-}
-
-/**
- * Load the thumbnail display pane.
- *
- * Loads a View displaying the thumbnails. The view name is picked from the 
- * third path argument and any remaining arguments are used as arguments to the
- * view.
- * Module developers may add options to img_assist_header_form using 
- * hook_form_alter() if they wish to use custom views and/or arguments.
- */
-function img_assist_thumbs() {
-  global $user;
-  
-  if (module_exists('image') && module_exists('views')) {
-    $view_name = ((arg(2) != '') ? arg(2) : 'img_assist_browser');
-    
-    // Get view arguments from path.
-    $args = explode('/', $_GET['q']);
-    $args = array_slice($args, 3);
-    
-    // Check sanity and permissions for the 'img_assist_browser' view.
-    if ($view_name == 'img_assist_browser') {
-      if (empty($args[0]) || !user_access('access all images')) {
-        $args[0] = $user->uid;
-      }
-      if (isset($args[1])) {
-        $args[1] = (int) $args[1];
-      }
-    }
-    
-    $view = views_get_view($view_name);
-    if ($view) {
-      $view_output = $view->execute_display(NULL, $args);
-      if (empty($view_output)) {
-        $output = t('No images were found. Please upload a new image or browse images by a different category.');
-      }
-      else {
-        $output = $view_output;
-      }
-    }
-    else {
-      $output = t('Error: The specified view was not found.');
-    }
+    $form_state['redirect'] = 'img_assist/properties/'. $form_state['nid'] . '/0/' . $form_state['editor'] . '/' . $form_state['element'];
   }
-  else {
-    $output = t('The Image and Views modules must be enabled to use Image assist.');
-  }
-  echo theme('img_assist_page', $output, array('id' => 'img_assist_thumbs', 'onload' => 'parent.initThumbs();', 'class' => 'img_assist'));
-  exit;
 }
 
 /**
  * Load the image properties pane.
  */
-function img_assist_properties() {
-  $nid = arg(2);
-  // Update is put into a hidden field so the javascript can see it.
-  $update = (arg(3)) ? 1 : 0;
-  
+function img_assist_properties($nid, $update = 0, $editor = 'textarea', $element = 'body') {
   if (is_numeric($nid)) {
-    $output = drupal_get_form('img_assist_properties_form', node_load($nid), $update);
+    $output = drupal_get_form('img_assist_properties_form', node_load($nid), $update, $editor, $element);
   }
   else {
     $output = t('Image ID not found');
   }
-  
-  echo theme('img_assist_page', $output, array('id' => 'img_assist_properties', 'onload' => 'parent.initProperties();', 'class' => 'img_assist'));
+
+  echo theme('img_assist_page', $output, array('id' => 'img_assist_properties', 'onload' => 'initProperties();', 'class' => 'img_assist'));
   exit;
 }
 
@@ -860,7 +758,7 @@ function img_assist_sanitize($text) {
 /**
  * Construct the image properties form.
  */
-function img_assist_properties_form($form_state, $node, $update) {
+function img_assist_properties_form($form_state, $node, $update, $editor, $element) {
   require_once drupal_get_path('module', 'img_assist') .'/includes/img_assist.token.inc';
 
   $image_info = image_get_info(file_create_path($node->images[IMAGE_ORIGINAL]));
@@ -951,7 +849,16 @@ function img_assist_properties_form($for
   $form[] = array('#value' => '<tr><td valign="top" rowspan="3" id="preview">');
   $form[] = array('#value' => $properties_image);
   $form[] = array('#value' => '<span id="caption" style="width: '. $properties_size['width'] .'px;">'. $node->title .'</span>');
-
+  // hidden fields for editor and element
+  $form['editor'] = array(
+      '#type' => 'hidden',
+      '#value' => $editor,
+  );
+  $form['element'] = array(
+      '#type' => 'hidden',
+      '#value' => $element,
+  );
+  
   // Image node properties fieldset.
   $form['properties'] = array('#type' => 'fieldset', '#title' => t('Image properties'));
   $form['properties'][] = array('#value' => '<div class="field field-type-text"><div class="field-label">'. t('Size') .': </div><div class="field-items"><div class="field-item">'. strtr('@widthx@height px', array('@width' => $image_info['width'], '@height' => $image_info['height'])) .'</div></div></div>');
@@ -978,7 +885,7 @@ function img_assist_properties_form($for
     '#size' => 50,
     '#maxlength' => 255,
     '#description' => NULL,
-    '#attributes' => array('onblur' => 'parent.updateCaption()'),
+    '#attributes' => array('onblur' => 'updateCaption()'),
   );
   $form['desc'] = array(
     '#type' => 'textfield',
@@ -987,7 +894,7 @@ function img_assist_properties_form($for
     '#size' => 50,
     '#maxlength' => 255,
     '#description' => NULL,
-    '#attributes' => array('onblur' => 'parent.updateCaption()'),
+    '#attributes' => array('onblur' => 'updateCaption()'),
   );
   
   // Size.
@@ -998,7 +905,7 @@ function img_assist_properties_form($for
     '#type' => 'select',
     '#default_value' => variable_get('img_assist_default_label', '100x100'),
     '#options' => $derivatives,
-    '#attributes' => array('onchange' => 'parent.onChangeSizeLabel()'),
+    '#attributes' => array('onchange' => 'onChangeSizeLabel()'),
   );
   $form[] = array('#value' => '<div class="form-item" id="size-other">');
   $form['width'] = array(
@@ -1006,7 +913,7 @@ function img_assist_properties_form($for
     '#default_value' => $default_width,
     '#size' => 4,
     '#maxlength' => 4,
-    '#attributes' => array('onblur' => 'parent.onChangeWidth()'),
+    '#attributes' => array('onblur' => 'onChangeWidth()'),
   );
   $form[] = array('#value' => ' x ');
   $form['height'] = array(
@@ -1014,7 +921,7 @@ function img_assist_properties_form($for
     '#default_value' => $default_height,
     '#size' => 4,
     '#maxlength' => 4,
-    '#attributes' => array('onblur' => 'parent.onChangeHeight()'),
+    '#attributes' => array('onblur' => 'onChangeHeight()'),
   );
   $form[] = array('#value' => '</div></div>');
   $form[] = array('#value' => '</td><td>');
@@ -1038,7 +945,7 @@ function img_assist_properties_form($for
       '#title' => t('Link'),
       '#default_value' => variable_get('img_assist_default_link_behavior', 'none'),
       '#options' => array('none' => t('Not a link'), 'node' => t('Link to image page'), 'popup' => t('Open in popup window'), 'url' => t('Go to URL')),
-      '#attributes' => array('onchange' => 'parent.onChangeLink()'),
+      '#attributes' => array('onchange' => 'onChangeLink()'),
     );
     $form['url'] = array(
       '#type' => 'textfield',
@@ -1110,13 +1017,13 @@ function img_assist_properties_form($for
   $form['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(
     '#type' => 'button',
     '#value' => t('Cancel'),
     '#button_type' => 'button',
-    '#attributes' => array('onclick' => 'parent.cancelAction()', 'style' => 'float: right;'),
+    '#attributes' => array('onclick' => 'cancelAction()', 'style' => 'float: right;'),
   );
   
   $form[] = array('#value' => '</div>');
@@ -1126,53 +1033,20 @@ function img_assist_properties_form($for
   return $form;
 }
 
-function img_assist_properties_form_validate($form, &$form_state) {
-  $html = img_assist_render_image($form_state['values']);
-  img_assist_set_htmlcode($html);
-  drupal_goto('img_assist/insert_html');
-}
 
 /**
- * Store image tag or HTML in session.
- *
- * Used for saving HTML code so it can be inserted instead of the filter tags.
- *
- * @param string $htmlcode
- *   A filter tag or HTML code. If omitted, session variable is emptied.
- *
- * @return string
- *   A previously stored value in the user session.
+ * @todo Write own submit handler and insert the HTML code there.
  */
-function img_assist_set_htmlcode($htmlcode = NULL) {
-  if (isset($htmlcode)) {
-    $_SESSION['htmlcode'] = urlencode($htmlcode);
+function img_assist_properties_form_submit($form, &$form_state) {
+  $val = $form_state['values'];
+  if ($val['insertmode'] == 'html') {
+    $content = img_assist_render_image($val);
+  } else { // filtertag
+    $content =  '[img_assist|nid=' . $val['nid'] . '|title=' . $val['title'] . '|desc=' . $val['desc'] . '|link=' . $val['link'];
+    $content .= '|align=' . $val['align'] . '|width=' . $val['width'] . '|height=' . $val['height'] . ']';
   }
-  else {
-    $html = urldecode($_SESSION['htmlcode']);
-    $_SESSION['htmlcode'] = '';
-    return $html;
-  }
-}
-
-function img_assist_insert_html() {
-  $output = drupal_get_form('img_assist_insert_html_form');
-  echo theme('img_assist_page', $output, array('id' => 'img_assist_insert_html', 'onload' => 'parent.insertImage();', 'class' => 'img_assist'));
-}
-
-function img_assist_insert_html_form() {
-  $htmlcode = img_assist_set_htmlcode();
-  $form[] = array(
-    '#id' => 'finalhtmlcode',
-    '#type' => 'hidden',
-    '#value' => $htmlcode,
-  );
-  
-  $form['insertmode'] = array(
-    '#type' => 'hidden',
-    '#value' => 'html2',
-  );
-  
-  return $form;
+  echo theme('img_assist_page', 'You can close this window now.', array('id' => 'img_assist_thumbs', 'class' => 'img_assist', 'onload' => 'insertToEditor(\'' . $val['element'] . '\', \'' . $content . '\');'));
+  exit();
 }
 
 /**
@@ -1778,6 +1652,14 @@ function theme_img_assist_popup($content
 
 function theme_img_assist_page($content, $attributes = NULL) {
   $title = drupal_get_title();
+  $path = drupal_get_path('module', 'img_assist');
+  drupal_add_js($path .'/img_assist_popup.js', 'module', 'header', FALSE, FALSE);
+  $editor = 'textarea';
+  if ($editor == 'tinymce') {
+    $tinymce_path = drupal_get_path('module', 'wysiwyg');
+    drupal_add_js($tinymce_path .'/tinymce/jscripts/tiny_mce/tiny_mce_popup.js');
+  }
+  drupal_add_js($path .'/img_assist_'. $editor .'.js', 'module', 'header', FALSE, FALSE);
   $output = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
   $output .= '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">'."\n";
   $output .= "<head>\n";
@@ -1805,6 +1687,10 @@ function theme_img_assist_page($content,
   // was loaded.
   $output .= drupal_get_html_head();
   $output .= drupal_get_js();
+  /*
+   @todo this should go to the JS file
+   @todo note: modules css should not go after the theme! themes may override every modules css!
+   
   $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";
@@ -1823,7 +1709,8 @@ function theme_img_assist_page($content,
   // Ensure that img_assist.js is imported last.
   $path = drupal_get_path('module', 'img_assist') .'/img_assist_popup.css';
   $output .= "<style type=\"text/css\" media=\"all\">@import \"". base_path() . $path ."\";</style>\n";
-  
+  */
+  $output .= drupal_get_css();
   $output .= "</head>\n";
   $output .= '<body'. drupal_attributes($attributes) .">\n";
   
@@ -2027,5 +1914,3 @@ function theme_img_assist_legacy() {
 /**
  * @} End of "defgroup img_assist_legacy".
  */
-
-
diff -urp ../../../../../dev-modules/img_assist-6.x-3.x-dev/img_assist/img_assist_popup.css ./img_assist_popup.css
--- ../../../../../dev-modules/img_assist-6.x-3.x-dev/img_assist/img_assist_popup.css	2008-07-23 01:07:44.000000000 +0200
+++ ./img_assist_popup.css	2009-01-11 21:52:52.078125000 +0100
@@ -84,7 +84,6 @@ body#img_assist_header {
   visibility: hidden;
 }
 
-/* Header frame */
 #header-uploading, #header-properties, #header-browse {
   float: left; 
   width: 80%;
diff -urp ../../../../../dev-modules/img_assist-6.x-3.x-dev/img_assist/img_assist_popup.js ./img_assist_popup.js
--- ../../../../../dev-modules/img_assist-6.x-3.x-dev/img_assist/img_assist_popup.js	2008-12-25 20:14:44.000000000 +0100
+++ ./img_assist_popup.js	2009-01-11 21:52:53.968750000 +0100
@@ -1,23 +1,21 @@
 /* $Id: img_assist_popup.js,v 1.2 2008/12/25 19:14:44 sun Exp $ */
 
-var currentMode;
-
 function onChangeBrowseBy(el) {
-  frames['img_assist_main'].window.location.href = Drupal.settings.basePath + 'index.php?q=img_assist/thumbs/' + el.value;
+  window.location.href = Drupal.settings.basePath + 'index.php?q=img_assist/thumbs/' + el.value;
 }
 
-function onClickUpload() {
-  frames['img_assist_main'].window.location.href = Drupal.settings.basePath + 'index.php?q=img_assist/upload';
+function onClickUpload(editor, element) {
+  window.location.href = Drupal.settings.basePath + 'index.php?q=img_assist/upload/'+editor+'/'+element;
 }
 
 function onClickStartOver() {
-  frames['img_assist_main'].window.location.href = Drupal.settings.basePath + 'index.php?q=img_assist/thumbs/img_assist_browser';
+  window.location.href = Drupal.settings.basePath + 'index.php?q=img_assist/thumbs/img_assist_browser';
 }
 
 function updateCaption() {
-  var caption = frames['img_assist_main'].document.getElementById('caption');
-  var title = frames['img_assist_main'].document.img_assist['edit-title'].value;
-  var desc = frames['img_assist_main'].document.img_assist['edit-desc'].value;
+  var caption = window.document.getElementById('caption');
+  var title = window.document.img_assist['edit-title'].value;
+  var desc = window.document.img_assist['edit-desc'].value;
   if (desc != '') {
     title = title + ': ';
   }
@@ -25,21 +23,21 @@ function updateCaption() {
 }
 
 function onChangeHeight() {
-  var formObj = frames['img_assist_main'].document.forms[0];
+  var formObj = window.document.forms[0];
   var aspect = formObj['edit-aspect'].value;
   var height = formObj['edit-height'].value;
   formObj['edit-width'].value = Math.round(height * aspect);
 }
 
 function onChangeWidth() {
-  var formObj = frames['img_assist_main'].document.forms[0];
+  var formObj = window.document.forms[0];
   var aspect = formObj['edit-aspect'].value;
   var width = formObj['edit-width'].value;
   formObj['edit-height'].value = Math.round(width / aspect);
 }
 
 function onChangeLink() {
-  var formObj = frames['img_assist_main'].document.forms[0];
+  var formObj = window.document.forms[0];
   if (formObj['edit-link-options-visible'].value == 1) {
     if (formObj['edit-link'].value == 'url') {
       showElement('edit-url', 'inline');
@@ -51,7 +49,7 @@ function onChangeLink() {
 }
 
 function onChangeSizeLabel() {
-  var formObj = frames['img_assist_main'].document.forms[0];
+  var formObj = window.document.forms[0];
   if (formObj['edit-size-label'].value == 'other') {
     showElement('size-other', 'inline');
   }
@@ -78,15 +76,8 @@ function onChangeSizeLabel() {
   }
 }
 
-function setHeader(mode) {
-  if (currentMode != mode) {
-    frames['img_assist_header'].window.location.href = Drupal.settings.basePath + 'index.php?q=img_assist/header/' + mode;
-  }
-  currentMode = mode;
-}
-
 function showElement(id, format) {
-  var docObj = frames['img_assist_main'].document;
+  var docObj = window.document;
   format = (format) ? format : 'block';
   if (docObj.layers) {
     docObj.layers[id].display = format;
@@ -100,7 +91,7 @@ function showElement(id, format) {
 }
 
 function hideElement(id) {
-  var docObj = frames['img_assist_main'].document;
+  var docObj = window.document;
   if (docObj.layers) {
     docObj.layers[id].display = 'none';
   }
@@ -112,33 +103,7 @@ function hideElement(id) {
   }
 }
 
-function insertImage() {
-  if (window.opener || !tinyMCEPopup.isWindow) {
-    // 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;
-  }
-}
-
 function getHTML(formObj) {
-  var html = frames['img_assist_main'].document.getElementById('finalhtmlcode').value;
+  var html = window.document.getElementById('finalhtmlcode').value;
   return html;
 }
diff -urp ../../../../../dev-modules/img_assist-6.x-3.x-dev/img_assist/img_assist_textarea.js ./img_assist_textarea.js
--- ../../../../../dev-modules/img_assist-6.x-3.x-dev/img_assist/img_assist_textarea.js	2008-12-25 20:14:44.000000000 +0100
+++ ./img_assist_textarea.js	2009-01-11 21:52:58.750000000 +0100
@@ -9,77 +9,28 @@
  * img_assist.module will be necessary, at least in img_assist_menu() and
  * img_assist_loader().
  */
+function initProperties() {
+  updateCaption();
+  onChangeLink();
+  onChangeSizeLabel();
+}
 
-// Declare global variables
-var myDoc, myForm, myTextarea, hasInputFormat;
-
-function initLoader() {
-  // Save the references to the parent form and textarea to be used later. 
-  myDoc      = window.opener.document; // global (so don't use var keyword)
-  myForm     = '';
-  myTextarea = '';
-  hasInputFormat = false;
-  
-  var args = getArgs(); // get the querystring arguments
-  var textarea = args.textarea;
+function insertToEditor(element, content) {
+  var myDoc      = window.opener.document; // global (so don't use var keyword)
+  var myTextarea = '';
   
   // Reference the form object for this textarea.
   if (myDoc.getElementsByTagName) {
     var f = myDoc.getElementsByTagName('form');
     for (var i=0; i<f.length; i++) {
-      // Is this textarea is using an input format?
-      if (f[i]['edit-format']) {
-        hasInputFormat = true;
-      }
-      if (f[i][textarea]) {
+      if (f[i][element]) {
         myForm = f[i];
-        myTextarea = f[i][textarea];
+        myTextarea = f[i][element];
         break;
       }
     }
   }
-  frames['img_assist_main'].window.location.href = Drupal.settings.basePath + 'index.php?q=img_assist/thumbs/img_assist_browser';
-}
-
-function initProperties() {
-  setHeader('properties');
-  updateCaption();
-  onChangeLink();
-  onChangeSizeLabel();
-}
-
-function initThumbs() {
-  setHeader('browse');
-}
 
-function initHeader() {
-}
-
-function initUpload() {
-  setHeader('uploading');
-}
-
-function getFilterTag(formObj) {
-  var nid          = formObj['edit-nid'].value;
-  var captionTitle = formObj['edit-title'].value;
-  var captionDesc  = formObj['edit-desc'].value;
-  var link         = formObj['edit-link'].value;
-  var url          = formObj['edit-url'].value;
-  var align        = formObj['edit-align'].value;
-  var width        = formObj['edit-width'].value;
-  var height       = formObj['edit-height'].value;
-  
-  // Create the image placeholder tag
-  var miscAttribs = 'nid=' + nid + '|title=' + captionTitle + '|desc=' + captionDesc + '|link=' + link;
-  if (url != formObj['edit-default-url'].value) {
-    miscAttribs += '|url=' + url;
-  }
-  var content = '[img_assist|' + miscAttribs + '' + '|align=' + align + '|width=' + width + '|height=' + height + ']';
-  
-  return content;
-}
-
-function insertToEditor(content) {
   // Insert the image
   if (myDoc.selection) {
   	// IE
@@ -109,32 +60,3 @@ function cancelAction() {
   // Close the dialog
   window.close();
 }
-
-/**
- * getArgs() by Jim K - From Orielly JSB pp 244
- *
- * This function parses comma separated name=value argument pairs from the query
- * string of the URL. It stores the name=value pairs in properties of an object
- * and then returns that object.
- * 
- * @example
- *   var args = getArgs();
- *   alert(args.CSSPATH);
- */
-function getArgs() {
-  var args = new Object();
-
-  var query = location.search.substring(1); // Get Query String
-  var pairs = query.split("&"); // Split query at the ampersand
-  
-  for(var i = 0; i < pairs.length; i++) { // Begin loop through the querystring
-    var pos = pairs[i].indexOf('='); // Look for "name=value"
-    if (pos == -1) continue; // if not found, skip to next
-    
-    var argname = pairs[i].substring(0,pos); // Extract the name
-    var value = pairs[i].substring(pos+1); // Extract the value
-    args[argname] = unescape(value); // Store as a property
-  }
-  return args; // Return the Object
-}
-
diff -urp ../../../../../dev-modules/img_assist-6.x-3.x-dev/img_assist/includes/img_assist.views_default.inc ./includes/img_assist.views_default.inc
--- ../../../../../dev-modules/img_assist-6.x-3.x-dev/img_assist/includes/img_assist.views_default.inc	2008-09-12 23:17:42.000000000 +0200
+++ ./includes/img_assist.views_default.inc	2009-01-11 21:47:54.218750000 +0100
@@ -83,48 +83,8 @@ function img_assist_views_default_views(
       'validate_argument_type' => 'tid',
       'validate_argument_php' => '',
     ),
-    'tid' => array(
-      'default_action' => 'ignore',
-      'style_plugin' => 'default_summary',
-      'style_options' => array(),
-      'wildcard' => 'all',
-      'wildcard_substitution' => 'All',
-      'title' => '',
-      'default_argument_type' => 'fixed',
-      'default_argument' => '',
-      'validate_type' => 'numeric',
-      'validate_fail' => 'ignore',
-      'break_phrase' => 0,
-      'add_table' => 0,
-      'require_value' => 0,
-      'reduce_duplicates' => 0,
-      'set_breadcrumb' => 0,
-      'id' => 'tid',
-      'table' => 'term_node',
-      'field' => 'tid',
-      'relationship' => 'none',
-      'default_options_div_prefix' => '',
-      'default_argument_user' => 0,
-      'default_argument_fixed' => '',
-      'default_argument_php' => '',
-      'validate_argument_node_type' => array(
-        'image' => 0,
-        'page' => 0,
-        'story' => 0,
-      ),
-      'validate_argument_node_access' => 0,
-      'validate_argument_nid_type' => 'nid',
-      'validate_argument_vocabulary' => array(
-        '4' => 0,
-        '2' => 0,
-        '1' => 0,
-        '3' => 0,
-      ),
-      'validate_argument_type' => 'tid',
-      'validate_argument_php' => '',
-    ),
   ));
-  $handler->override_option('filters', array(
+  $filters = array(
     'type' => array(
       'operator' => 'in',
       'value' => array(
@@ -155,7 +115,35 @@ function img_assist_views_default_views(
       'field' => 'status',
       'relationship' => 'none',
     ),
-  ));
+  );
+  // this adds an exposed taxonomy filter iff taxonomy is enabled 
+  // and a vocabulary was chosen in the img_assist settings.
+  if (module_exists('taxonomy') && variable_get('img_assist_vocabs', array())) {
+    $filters['tid'] = array(
+        'operator' => 'or',
+        'value' => array(),
+        'group' => '0',
+        'exposed' => true,
+        'expose' => array(
+          'use_operator' => 0,
+          'operator' => 'tid_op',
+          'identifier' => 'tid',
+          'label' => 'Taxonomy: Term',
+          'optional' => 1,
+          'single' => 1,
+          'remember' => 0,
+          'reduce' => 0,
+        ),
+        'type' => 'select',
+        'vid' => '1',
+        'id' => 'tid',
+        'table' => 'term_node',
+        'field' => 'tid',
+        'hierarchy' => 1,
+        'relationship' => 'none',
+    );
+  }
+  $handler->override_option('filters',$filters);
   $handler->override_option('access', array(
     'type' => 'none',
     'role' => array(),
diff -urp ../../../../../dev-modules/img_assist-6.x-3.x-dev/img_assist/theme/theme.inc ./theme/theme.inc
--- ../../../../../dev-modules/img_assist-6.x-3.x-dev/img_assist/theme/theme.inc	2008-10-27 20:14:46.000000000 +0100
+++ ./theme/theme.inc	2009-01-11 21:47:43.578125000 +0100
@@ -9,14 +9,15 @@
 
 /**
  * Setup variables for the browser thumbnail template.
- * 
+ * @todo pass the editor and element name to the view (e.g. as null arguments).
  * @param array $vars
  */
 function template_preprocess_img_assist_browser_thumbnail(&$vars) {
   $node = node_load($vars['row']->nid);
+  $args = explode('/', $_GET['q']);
 
   $vars['thumbnail'] = img_assist_display($node, IMAGE_THUMBNAIL);
-  $vars['path'] = url('img_assist/properties/'. $node->nid); 
+  $vars['path'] = url('img_assist/properties/' . $node->nid . '/0/' . $args[2] . '/' . $args[4]); 
   $vars['title'] = $node->title; 
 }
 
