Index: img_assist.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/img_assist/img_assist.module,v
retrieving revision 1.75.2.5
diff -u -r1.75.2.5 img_assist.module
--- img_assist.module	18 Jul 2008 22:54:36 -0000	1.75.2.5
+++ img_assist.module	20 Jul 2008 18:32:58 -0000
@@ -28,9 +28,6 @@
  */
 function img_assist_theme() {
   return array(
-    'img_assist_textarea_link' => array(
-      'arguments' => array('element' => NULL, 'link' => NULL),
-    ),
     'img_assist_inline' => array(
       'arguments' => array('node' => NULL, 'size' => NULL, 'attributes' => NULL),
     ),
@@ -121,12 +118,12 @@
  */
 function img_assist_init() {
   $path = drupal_get_path('module', 'img_assist');
-  if (variable_get('img_assist_page_styling', 'yes') == 'yes') {
+  if (arg(0) == 'img_assist') {
+    drupal_add_css($path .'/img_assist_popup.css');
+  }
+  else if (variable_get('img_assist_page_styling', 'yes') == 'yes') {
     drupal_add_css($path .'/img_assist.css');
   }
-  // Assign base_path to insert in image source by javascript.
-  drupal_add_js('var BASE_URL = "'. base_path() .'";', 'inline');
-  drupal_add_js($path .'/img_assist.js');
 }
 
 /**
@@ -147,24 +144,38 @@
 }
 
 /**
- * Add image link underneath textareas.
+ * Add JavaScript settings for generating the image link underneath textareas.
  */
 function img_assist_textarea($element) {
-  // FAPI #wysiwyg support.
-  if (isset($element['#wysiwyg']) && $element['#wysiwyg']) {
-    return $element;
-  }
+  static $initialized = FALSE;
+
   $link = variable_get('img_assist_link', 'icon');
-  if ($link == 'icon' || $link == 'text') {
+  if (($link == 'icon') || ($link == 'text')) {
     if (_img_assist_textarea_match($element['#id']) && _img_assist_page_match() && !strstr($_GET['q'], 'img_assist')) {
       if (user_access('access img_assist')) {
-        $output = theme('img_assist_textarea_link', $element, $link);
-        $element['#suffix'] = (isset($element['#suffix']) ? $element['#suffix'] . $output : $output);
+        if (!$initialized) {
+          // Add javascript.
+          drupal_add_js(drupal_get_path('module', 'img_assist') .'/img_assist.js');
+
+          // Add settings.
+          $settings['link'] = $link;
+          if ($link == 'icon') {
+            $settings['icon'] = drupal_get_path('module', 'img_assist') .'/add-image.jpg';
+          }
+          drupal_add_js(array('img_assist' => $settings), 'setting');
+          $initialized = TRUE;
+        }
+
+        // Attach behavior.
+        if (!isset($element['#attributes']['class'])) {
+          $element['#attributes']['class'] = 'img_assist';
+        }
+        else {
+          $element['#attributes']['class'] += ' img_assist';
+        }
       }
     }
   }
-  return $element;
-}
 
 /**
  * Implementation of hook_block().
@@ -518,7 +529,7 @@
   $output .= "--></script>\n";
   
   $path = drupal_get_path('module', 'img_assist');
-  $output .= '<script type="text/javascript" src="'. base_path() . $path .'/img_assist.js"></script>'."\n";
+  $output .= '<script type="text/javascript" src="'. base_path() . $path .'/img_assist_popup.js"></script>'."\n";
   if ($editor == 'tinymce') {
     $tinymce_path = drupal_get_path('module', 'wysiwyg_editor');
     $tinymce_js = base_path() . $tinymce_path .'/tinymce/jscripts/tiny_mce/tiny_mce_popup.js';
@@ -1605,28 +1616,6 @@
  * @ingroup themeable
  */
 
-/**
- * Render a link text or button (underneath textareas).
- */
-function theme_img_assist_textarea_link($element, $link) {
-  $output = '<div class="img_assist-button">';
-  if ($link == 'icon') {
-    $link = theme('image', drupal_get_path('module', 'img_assist') .'/add-image.jpg', t('Add image'));
-  }
-  else {
-    $link = t('Add image');
-  }
-  $attribs = array(
-    'class'   => 'img_assist-link',
-    'id'      => 'img_assist-link-'. $element['#id'],
-    'title'   => 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;',
-  );
-  $output .= l($link, 'img_assist/load/textarea', array('attributes' => $attribs, 'query' => 'textarea='. $element['#name'], 'html' => TRUE));
-  $output .= '</div>';
-  return $output;
-}
-
 function theme_img_assist_inline($node, $size, $attributes) {
   if ($attributes['title'] && $attributes['desc']) {
     $caption = '<strong>'. $attributes['title'] .': </strong>'. $attributes['desc'];
Index: img_assist.css
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/img_assist/img_assist.css,v
retrieving revision 1.6
diff -u -r1.6 img_assist.css
--- img_assist.css	6 Apr 2008 16:43:18 -0000	1.6
+++ img_assist.css	20 Jul 2008 18:32:57 -0000
@@ -1,115 +1,6 @@
 /* $Id: img_assist.css,v 1.6 2008/04/06 16:43:18 sun Exp $ */
 
 /**
- * IMG ASSIST WINDOW
- */ 
-body.img_assist {
-  margin: 0px;
-  padding: 5px;
-  width: auto;
-  min-width: 0;
-  color: #000000;
-  font-family: Arial, Helvetica, sans-serif;
-  font-size: .8em;
-  background-color: #efefef;
-}
-/* Thin line between the header frame and the main frame */
-body#img_assist_thumbs, body#img_assist_upload, body#img_assist_properties {
-  border-top: 1px solid #000;
-}
-/* Darker background color in the header frame */
-body#img_assist_header {
-  background-color:#ccc;
-  margin: 0;
-}
-/* Thin border around images */
-.img_assist img  {
-  border: 1px solid #000;
-}
-.img_assist-button {
-  font-weight: bold;
-  margin: 3px;
-}
-.img_assist img {
-  display: inline; /* pushbutton theme changes the display to block */
-}
-.img_assist .messages {
-  border: 1px solid #000;
-  background-color: #ccc;
-  padding: 2px;
-  margin: 3px 0px 6px 0px;
-}
-
-/* Upload Window */
-.img_assist .node-form {
-  width: 95%;
-}
-
-/* Properties Window */
-.img_assist #preview {
-  padding: 5px 10px 5px 5px;
-}
-.img_assist .form-item { /* the first form field on the properties frame should be at the top of the page  */
-  margin-top: 0px;
-  margin-bottom: 1em;
-}
-.img_assist #caption {
-  display: block;
-}
-.img_assist #header-browse div.form-item,
-.img_assist #link-group div.form-item,
-.img_assist #edit-size div.form-item,
-.img_assist #size-other div.form-item {
-  display: inline;
-}
-.img_assist #alignment {
-  text-align: left;
-}
-.img_assist #edit-title, .img_assist #edit-desc {
-  width: 99%;
-}
-.img_assist #edit-link {
-  width: 155px;
-}
-.img_assist #edit-url {
-  width: 150px;
-}
-.img_assist #edit-align {
-  width: 100px;
-}  
-#finalhtmlcode {
-  display: none;
-  visibility: hidden;
-}
-
-/* Header Frame */
-#header-uploading, #header-properties, #header-browse {
-  float: left; 
-  width: 80%;
-}
-#header-startover, #header-cancel {
-  float: right;
-  width: 19%;
-  text-align: right;
-}
-
-#header-uploading input, #header-properties input, #header-browse input, #header-startover input, #header-cancel input, #header-uploading select, #header-properties select, #header-browse select {
-  margin-top: 0;
-  margin-bottom: 0;
-  vertical-align: baseline;
-}
-
-
-/**
- * POPUP IMAGES WINDOW
- */
-body#img_assist_popup {
-  margin: 0;
-  padding: 0;
-}
-
-/**
- * FINAL PAGE (node)
  * You may want to copy these styles to your theme's CSS file and then set img_assist.css 
  * not to load on every page.  This can be set on the img_assist settings page.
  */ 
Index: img_assist.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/img_assist/img_assist.js,v
retrieving revision 1.6.4.1
diff -u -r1.6.4.1 img_assist.js
--- img_assist.js	18 Jul 2008 22:54:36 -0000	1.6.4.1
+++ img_assist.js	20 Jul 2008 18:32:57 -0000
@@ -1,162 +1,22 @@
 /* $Id: img_assist.js,v 1.6.4.1 2008/07/18 22:54:36 sun Exp $ */
 
-var currentMode;
-
-function onChangeBrowseBy(el) {
-	frames['img_assist_main'].window.location.href = BASE_URL + 'index.php?q=img_assist/thumbs/' + el.value;
-}
-
-function onClickUpload() {
-  frames['img_assist_main'].window.location.href = BASE_URL + 'index.php?q=img_assist/upload';
-}
-
-function onClickStartOver() {
-  frames['img_assist_main'].window.location.href = BASE_URL + '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;
-  if (desc != '') {
-    title = title + ': ';
-  }
-  caption.innerHTML = '<strong>' + title + '</strong>' + desc;
-}
-
-function onChangeHeight() {
-  var formObj = frames['img_assist_main'].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 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];
-	if (formObj['edit-link-options-visible'].value == 1) {
-		if (formObj['edit-link'].value == 'url') {
-			showElement('edit-url', 'inline');
-		}
-		else {
-			hideElement('edit-url');
-		}
-	}
-}
-
-function onChangeSizeLabel() {
-  var formObj = frames['img_assist_main'].document.forms[0];
-  if (formObj['edit-size-label'].value == 'other') {
-    showElement('size-other', 'inline');
-  }
-  else {
-    hideElement('size-other');
-    // get the new width and height
-    var size = formObj['edit-size-label'].value.split('x');
-    // this array is probably a bounding box size, not an actual image
-    // size, so now we use the known aspect ratio to find the actual size
-    var aspect = formObj['edit-aspect'].value;
-    var width = size[0];
-    var height = size[1];
-    if (Math.round(width / aspect) <= height) {
-    	// width is controlling factor
-      height = Math.round(width / aspect);
-    }
-    else {
-    	// height is controlling factor
-      width = Math.round(height * aspect);
+Drupal.behaviors.img_assist = function(context) {
+  $('textarea.img_assist:not(.img_assist-processed)', context).each(function() {
+    // Drupal's teaser behavior is a destructive one and needs to be run first.
+    if ($(this).is('textarea.teaser:not(.teaser-processed)')) {
+      Drupal.behaviors.teaser(context);  
     }
-    // fill the hidden width and height textboxes with these values
-    formObj['edit-width'].value = width;
-    formObj['edit-height'].value = height;
-  }
-}
-
-function setHeader(mode) {
-	if (currentMode != mode) {
-		frames['img_assist_header'].window.location.href = BASE_URL + 'index.php?q=img_assist/header/' + mode;
-	}
-	currentMode = mode;
+    $(this).addClass('img_assist-processed').parent().append(Drupal.theme('img_assist_link', this));
+  });
 }
 
-function showElement(id, format) {
-  var docObj = frames['img_assist_main'].document;
-  format = (format) ? format : 'block';
-  if (docObj.layers) {
-    docObj.layers[id].display = format;
-  }
-  else if (docObj.all) {
-    docObj.all[id].style.display = format;
-  }
-  else if (docObj.getElementById) {
-    docObj.getElementById(id).style.display = format;
-  }
-}
-
-function hideElement(id) {
-  var docObj = frames['img_assist_main'].document;
-  if (docObj.layers) {
-    docObj.layers[id].display = 'none';
-  }
-  else if (docObj.all) {
-    docObj.all[id].style.display = 'none';
+Drupal.theme.prototype.img_assist_link = function(el) {
+  var html = '<div class="img_assist-button">', link = Drupal.t('Add image');
+  if (Drupal.settings.img_assist.link == 'icon') {
+    link = '<img src="'+ Drupal.settings.basePath + Drupal.settings.img_assist.icon +'" alt="'+ link +'" title="'+ link +'" />';
   }
-  else if (docObj.getElementById) {
-    docObj.getElementById(id).style.display = 'none';
-  }
-}
-
-function launch_popup(nid, mw, mh) {
-	var ox = mw;
-	var oy = mh;
-	if((ox>=screen.width) || (oy>=screen.height)) {
-		var ox = screen.width-150;
-		var oy = screen.height-150;
-		var winx = (screen.width / 2)-(ox / 2);
-		var winy = (screen.height / 2)-(oy / 2);
-		var use_scrollbars = 1;
-	}
-	else {
-		var winx = (screen.width / 2)-(ox / 2);
-		var winy = (screen.height / 2)-(oy / 2);
-		var use_scrollbars = 0;
-	}
-	var win = window.open(BASE_URL + 'index.php?q=img_assist/popup/' + nid, 'imagev', 'height='+oy+'-10,width='+ox+',top='+winy+',left='+winx+',scrollbars='+use_scrollbars+',resizable');
-}
-
-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;
-	}
-}
-
-function getHTML(formObj) {
-	var html = frames['img_assist_main'].document.getElementById('finalhtmlcode').value;
-	return html;
+  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 += '</div>';
+  return html;
 }
+ 
\ No newline at end of file
Index: img_assist_popup.css
===================================================================
RCS file: img_assist_popup.css
diff -N img_assist_popup.css
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ img_assist_popup.css	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,102 @@
+/* $Id$ */
+
+body#img_assist_popup {
+  margin: 0;
+  padding: 0;
+}
+
+body.img_assist {
+  margin: 0px;
+  padding: 5px;
+  width: auto;
+  min-width: 0;
+  color: #000000;
+  font-family: Arial, Helvetica, sans-serif;
+  font-size: .8em;
+  background-color: #efefef;
+}
+/* Thin line between the header frame and the main frame */
+body#img_assist_thumbs, body#img_assist_upload, body#img_assist_properties {
+  border-top: 1px solid #000;
+}
+/* Darker background color in the header frame */
+body#img_assist_header {
+  background-color:#ccc;
+  margin: 0;
+}
+/* Thin border around images */
+.img_assist img  {
+  border: 1px solid #000;
+}
+.img_assist-button {
+  font-weight: bold;
+  margin: 3px;
+}
+.img_assist img {
+  display: inline; /* pushbutton theme changes the display to block */
+}
+.img_assist .messages {
+  border: 1px solid #000;
+  background-color: #ccc;
+  padding: 2px;
+  margin: 3px 0px 6px 0px;
+}
+
+/* Upload Window */
+.img_assist .node-form {
+  width: 95%;
+}
+
+/* Properties Window */
+.img_assist #preview {
+  padding: 5px 10px 5px 5px;
+}
+.img_assist .form-item { /* the first form field on the properties frame should be at the top of the page  */
+  margin-top: 0px;
+  margin-bottom: 1em;
+}
+.img_assist #caption {
+  display: block;
+}
+.img_assist #header-browse div.form-item,
+.img_assist #link-group div.form-item,
+.img_assist #edit-size div.form-item,
+.img_assist #size-other div.form-item {
+  display: inline;
+}
+.img_assist #alignment {
+  text-align: left;
+}
+.img_assist #edit-title, .img_assist #edit-desc {
+  width: 99%;
+}
+.img_assist #edit-link {
+  width: 155px;
+}
+.img_assist #edit-url {
+  width: 150px;
+}
+.img_assist #edit-align {
+  width: 100px;
+}  
+#finalhtmlcode {
+  display: none;
+  visibility: hidden;
+}
+
+/* Header Frame */
+#header-uploading, #header-properties, #header-browse {
+  float: left; 
+  width: 80%;
+}
+#header-startover, #header-cancel {
+  float: right;
+  width: 19%;
+  text-align: right;
+}
+
+#header-uploading input, #header-properties input, #header-browse input, #header-startover input, #header-cancel input, #header-uploading select, #header-properties select, #header-browse select {
+  margin-top: 0;
+  margin-bottom: 0;
+  vertical-align: baseline;
+}
Index: img_assist_popup.js
===================================================================
RCS file: img_assist_popup.js
diff -N img_assist_popup.js
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ img_assist_popup.js	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,162 @@
+/* $Id: img_assist.js,v 1.4.2.5 2007/11/19 02:27:49 sun Exp $ */
+
+var currentMode;
+
+function onChangeBrowseBy(el) {
+	frames['img_assist_main'].window.location.href = BASE_URL + 'index.php?q=img_assist/thumbs/' + el.value;
+}
+
+function onClickUpload() {
+  frames['img_assist_main'].window.location.href = BASE_URL + 'index.php?q=img_assist/upload';
+}
+
+function onClickStartOver() {
+  frames['img_assist_main'].window.location.href = BASE_URL + 'index.php?q=img_assist/thumbs/myimages';
+}
+
+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;
+  if (desc != '') {
+    title = title + ': ';
+  }
+  caption.innerHTML = '<strong>' + title + '</strong>' + desc;
+}
+
+function onChangeHeight() {
+  var formObj = frames['img_assist_main'].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 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];
+	if (formObj['edit-link-options-visible'].value == 1) {
+		if (formObj['edit-link'].value == 'url') {
+			showElement('edit-url', 'inline');
+		}
+		else {
+			hideElement('edit-url');
+		}
+	}
+}
+
+function onChangeSizeLabel() {
+  var formObj = frames['img_assist_main'].document.forms[0];
+  if (formObj['edit-size-label'].value == 'other') {
+    showElement('size-other', 'inline');
+  }
+  else {
+    hideElement('size-other');
+    // get the new width and height
+    var size = formObj['edit-size-label'].value.split('x');
+    // this array is probably a bounding box size, not an actual image
+    // size, so now we use the known aspect ratio to find the actual size
+    var aspect = formObj['edit-aspect'].value;
+    var width = size[0];
+    var height = size[1];
+    if (Math.round(width / aspect) <= height) {
+    	// width is controlling factor
+      height = Math.round(width / aspect);
+    }
+    else {
+    	// height is controlling factor
+      width = Math.round(height * aspect);
+    }
+    // fill the hidden width and height textboxes with these values
+    formObj['edit-width'].value = width;
+    formObj['edit-height'].value = height;
+  }
+}
+
+function setHeader(mode) {
+	if (currentMode != mode) {
+		frames['img_assist_header'].window.location.href = BASE_URL + 'index.php?q=img_assist/header/' + mode;
+	}
+	currentMode = mode;
+}
+
+function showElement(id, format) {
+  var docObj = frames['img_assist_main'].document;
+  format = (format) ? format : 'block';
+  if (docObj.layers) {
+    docObj.layers[id].display = format;
+  }
+  else if (docObj.all) {
+    docObj.all[id].style.display = format;
+  }
+  else if (docObj.getElementById) {
+    docObj.getElementById(id).style.display = format;
+  }
+}
+
+function hideElement(id) {
+  var docObj = frames['img_assist_main'].document;
+  if (docObj.layers) {
+    docObj.layers[id].display = 'none';
+  }
+  else if (docObj.all) {
+    docObj.all[id].style.display = 'none';
+  }
+  else if (docObj.getElementById) {
+    docObj.getElementById(id).style.display = 'none';
+  }
+}
+
+function launch_popup(nid, mw, mh) {
+	var ox = mw;
+	var oy = mh;
+	if((ox>=screen.width) || (oy>=screen.height)) {
+		var ox = screen.width-150;
+		var oy = screen.height-150;
+		var winx = (screen.width / 2)-(ox / 2);
+		var winy = (screen.height / 2)-(oy / 2);
+		var use_scrollbars = 1;
+	}
+	else {
+		var winx = (screen.width / 2)-(ox / 2);
+		var winy = (screen.height / 2)-(oy / 2);
+		var use_scrollbars = 0;
+	}
+	var win = window.open(BASE_URL + 'index.php?q=img_assist/popup/' + nid, 'imagev', 'height='+oy+'-10,width='+ox+',top='+winy+',left='+winx+',scrollbars='+use_scrollbars+',resizable');
+}
+
+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;
+	}
+}
+
+function getHTML(formObj) {
+	var html = frames['img_assist_main'].document.getElementById('finalhtmlcode').value;
+	return html;
+}
