Index: yui_editor.js
===================================================================
RCS file: /cvs/drupal/contributions/modules/yui_editor/yui_editor.js,v
retrieving revision 1.1.2.13
diff -u -r1.1.2.13 yui_editor.js
--- yui_editor.js	28 Apr 2008 16:05:29 -0000	1.1.2.13
+++ yui_editor.js	28 Apr 2008 20:15:36 -0000
@@ -26,6 +26,7 @@
     });
 
     var myEditor = new YAHOO.widget.Editor(id, myConfig);
+    yuiImgUploader(myEditor, '/yui_editor/image_upload','files[upload]');
     if (! config.titlebar) {
       myEditor._defaultToolbar.titlebar = config.titlebar;
     }
Index: yui_editor.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/yui_editor/yui_editor.module,v
retrieving revision 1.1.2.14
diff -u -r1.1.2.14 yui_editor.module
--- yui_editor.module	28 Apr 2008 16:05:29 -0000	1.1.2.14
+++ yui_editor.module	28 Apr 2008 20:15:36 -0000
@@ -13,6 +13,12 @@
 function yui_editor_menu($may_cache) {
   if ($may_cache) {
     $items[] = array(
+      'path' => 'yui_editor/image_upload',
+      'callback' => 'yui_editor_image_upload',
+      'access' => user_access('upload files'),
+      'type' => MENU_CALLBACK
+    );
+    $items[] = array(
       'path' => 'admin/settings/yui_editor',
       'title' => t('YUI editor settings'),
       'callback' => 'drupal_get_form',
@@ -138,16 +144,6 @@
     return;
   }
 
-  $ids = variable_get('yui_editor_ids', '');
-
-  $textareas = array();
-  if (!empty($ids)) {
-    $textareas = explode("\r\n", $ids);
-  }
-  else {
-    $textareas[] = 'edit-body';
-  }
-
   $yui_source = variable_get('yui_source','http://yui.yahooapis.com/2.5.1');
   yui_add_css('editor', $yui_source, '/build/menu/assets/skins/sam/menu.css');
   yui_add_css('editor', $yui_source, '/build/button/assets/skins/sam/button.css');
@@ -165,10 +161,12 @@
   yui_add_js('editor', $yui_source, '/build/resize/resize-beta-min.js');
   yui_add_js('editor', $yui_source, '/build/editor/editor-beta-min.js');
 
-  drupal_add_css(drupal_get_path("module", "yui_editor")."/yui_editor.css");
-  drupal_add_js(drupal_get_path("module", "yui_editor")."/yui_editor.js");
-  drupal_add_js(drupal_get_path("module", "yui_editor")."/toolbars/".variable_get('yui_editor_button_profile', 'yui_editor_toolbar_default.js'));
-
+  $module_path = drupal_get_path("module", "yui_editor");
+  drupal_add_css($module_path ."/yui_editor.css");
+  drupal_add_js($module_path."/yui_editor.js");
+  drupal_add_js($module_path."/toolbars/".variable_get('yui_editor_button_profile', 'yui_editor_toolbar_default.js'));
+  drupal_add_js($module_path."/yui-image-uploader.js"); 
+  
   $ids = variable_get('yui_editor_ids', '');
 
   $textareas = array();
@@ -196,3 +194,23 @@
       "});", "inline", "footer");
   }
 }
+
+/**
+ * Menu-callback for JavaScript-based uploads.
+ */
+function yui_editor_image_upload() {
+  header("content-type: text/html"); // the return type must be text/html
+  
+  $path = file_directory_path();
+  //Append trailing slash to path if not there 
+  if (! (substr($path, -1) == '/')) {
+    $path .= '/';
+  }
+  $path .= 'images';
+  $file = file_save_upload('upload', $path, FILE_EXISTS_REPLACE);
+  if (!$file) {
+    echo "{status:'Error Reading Uploaded File.'}";
+    return;
+  }
+  echo "{status:'UPLOADED', image_url:'/$file->filepath'}";
+}
Index: yui-image-uploader.js
===================================================================
RCS file: yui-image-uploader.js
diff -N yui-image-uploader.js
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ yui-image-uploader.js	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,87 @@
+/*
+ yuiImgUploader
+ variables: 
+  rte: The YAHOO.widget.Editor instance
+  upload_url: the url to post the file to
+  upload_image_name: the name of the post parameter to send the file as
+  
+ Your server must handle the posted image.  You must return a JSON object
+ with the result url that the image can be viewed at on your server.  If 
+ the upload fails, you can return an error message.  For successful
+ uploads, the status must be set to UPLOADED.  All other status messages,
+ or the lack of a status message is interpreted as an error.  IE will 
+ try to open a new document window when the response is returned if your
+ content-type header on your response is not set to 'text/javascript'
+ 
+ Example Success:
+ {status:'UPLOADED', image_url:'/somedirectory/filename'}
+ Example Failure:
+ {status:'We only allow JPEG Images.'}
+
+*/
+function yuiImgUploader(rte, upload_url, upload_image_name) {
+	// customize the editor img button 
+	
+	YAHOO.log( "Adding Click Listener" ,'debug');
+	rte.addListener('toolbarLoaded',function() {
+		rte.toolbar.addListener ( 'insertimageClick', function(o) {
+			try {
+				var imgPanel=new YAHOO.util.Element('yui-editor-panel');
+				imgPanel.on ( 'contentReady', function() {
+					try {
+						var Dom=YAHOO.util.Dom;
+						var label=document.createElement('label');
+						label.innerHTML='<strong>Upload:</strong>'+
+							'<input type="file" id="insertimage_upload" name="'+upload_image_name+
+							'" size="10" style="width: 20%"/>'+
+							'<a href="#"  id="insertimage_upload_btn" style="width: 20%; margin-left: 10em;">Upload Image</a>'+
+							'</label>'; 
+					
+						var img_elem=Dom.get('insertimage_url');
+						Dom.getAncestorByTagName(img_elem, 'form').encoding = 'multipart/form-data';
+						
+						Dom.insertAfter(
+							label,
+							img_elem.parentNode);
+							
+						YAHOO.util.Event.on ( 'insertimage_upload_btn', 'click', function(ev) {
+// 							//alert ( "Upload Click" );
+							YAHOO.util.Event.stopEvent(ev); // no default click action
+							YAHOO.util.Connect.setForm ( img_elem.form, true, true );
+							var c=YAHOO.util.Connect.asyncRequest(
+							'POST', upload_url, {
+								upload:function(r){
+									try {
+										// strip pre tags if they got added somehow
+										resp=r.responseText.replace( /<pre>/i, '').replace ( /<\/pre>/i, '');
+										var o=eval('('+resp+')');
+										if (o.status=='UPLOADED') {
+											Dom.get('insertimage_upload').value='';
+											Dom.get('insertimage_url').value=o.image_url;
+											// tell the image panel the url changed
+											// hack instead of fireEvent('blur')
+											// which for some reason isn't working
+											Dom.get('insertimage_url').focus();
+											Dom.get('insertimage_upload').focus();
+										} else {
+										alert ( "Upload Failed: "+o.status );
+									}
+									
+									} catch ( eee ) {
+										YAHOO.log( eee.message, 'error' )
+									}
+								}
+							}
+							);
+							return false;
+						});
+						
+					} catch ( ee ) { YAHOO.log( ee.message, 'error' ) }
+				});
+			} catch ( e ) {
+				YAHOO.log( e.message, 'error' )
+			}
+		});
+	});
+	
+}
