### Eclipse Workspace Patch 1.0
#P yui_editor
Index: plugins/img_browser.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/yui_editor/plugins/Attic/img_browser.js,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 img_browser.js
--- plugins/img_browser.js	25 Nov 2008 21:21:57 -0000	1.1.2.1
+++ plugins/img_browser.js	11 Jul 2009 23:23:38 -0000
@@ -2,9 +2,13 @@
  * ICME image browser integration
  * 
  * @author Dave Hall <info@davehall.com.au>
+ * @copyright Copyright (c) 2009 Dave Hall http://davehall.com.au
+ * @license GNU General Public License v2 (or later) http://www.gnu.org/licenses/gpl-2.0.html
  * 
  * @internal loosely based on the IMCE API docs - see http://ufku.com/drupal/imce/api
  * and the YUI editor img_upload plugin
+ * 
+ * @version $Id:$
  */
 
 /**
@@ -13,6 +17,11 @@
 var imcePopup;
 
 /**
+ * @var object dYUICurEditor Global id of the current YUI editor instance
+ */
+var dYUICurEditor = '';
+
+/**
  * IMCE integration bootstrapper
  * 
  * This function integrates IMCE into the YUI image insertion dialog box
@@ -21,7 +30,7 @@
  */
 function yui_editor_img_browser() {
 	var myEditor, config;
-	for ( var e in YAHOO.Drupal.editors) {
+	for ( var e in YAHOO.Drupal.editors ) {
 		myEditor = YAHOO.Drupal.editors[e].editor;
 		config = YAHOO.Drupal.editors[e].config;
 
@@ -40,56 +49,30 @@
  */
 function yui_editor_img_browser_attach(rte) {
 	rte.addListener('toolbarLoaded',function() {
-		rte.toolbar.addListener('insertimageClick',function(o) {
-			var imgPanel = new YAHOO.util.Element('yui-editor-panel');
-			imgPanel.on('contentReady', function() {
-				var Dom = YAHOO.util.Dom,
-					urlInput = Dom.get('insertimage_url'),
-					urlW = yui_editor_img_browser_pasreWidth(Dom.getStyle(urlInput, 'width')),
-					imceTrigger = new YAHOO.widget.Button(
-					{
-						id : 'imceTrigger',
-						label : 'Browse',
-						container : urlInput.parentNode,
-						onclick : {fn : yui_editor_img_browser_show}
-					}),
-					btnW = yui_editor_img_browser_pasreWidth(Dom.getStyle('imceTrigger', 'width'));
-
-				Dom.setStyle(urlInput, 'width', (urlW.val - (btnW.val * 1.1)) + urlW.unit);
-			});
-		});
-	});
-};
-
-/*
- * Parse a CSS width value
- * 
- * @param string w the width to parse
- * 
- * @return object the value (val) and the unit of measure (unit) 
- */
-function yui_editor_img_browser_pasreWidth(w) {
-	var l = w.length,
-		c = l - 2,
-		r = {val: 0, unit: ''};
-	return {val : w.substr(0, c), unit : w.substr(c, 2)};
-};
-
-/**
- * onClick handler which displays the IMCE popup window
- * 
- * @return void
- */
-function yui_editor_img_browser_show() {
-	if (typeof imcePopup == 'undefined' || imcePopup.closed) {
-		imcePopup = window.open('?q=imce', '',
-				'width=760,height=560,resizable=1');
-
-		imcePopup['imceOnLoad'] = function(win) {
-			win.imce.setSendTo('Update fields', yui_editor_img_browser_finish);
-		};
-	}
-	imcePopup.focus();
+		rte.toolbar.on('insertimageClick', function() {
+			dYUICurEditor = rte._configs.id.value;
+			var targetElm = rte._getSelectedElement();
+
+			if (targetElm && targetElm.tagName && (targetElm.tagName.toLowerCase() == 'img')) {
+				// do nothing - doesn't work on 2.5.x
+			} else {
+				
+				if ( typeof imcePopup == 'undefined' || imcePopup.closed ) {
+					imcePopup = window.open('?q=imce', 'imce', 'left=20,top=20,width=760,height=560,resizable=1,toolbar=0,status=1');
+					if (!imcePopup) { // blocked :(
+						alert('Please disable your popup blocker for this site'); // TODO t(msg)
+						return true; // bail out
+					}
+
+					imcePopup['imceOnLoad'] = function(win) {
+						win.imce.setSendTo('Update fields', yui_editor_img_browser_finish);
+					};
+				}
+				imcePopup.focus();
+				return false;
+			}
+		}, this, true);
+	}, rte, true);
 };
 
 /**
@@ -101,12 +84,12 @@
  * @return void
  */
 function yui_editor_img_browser_finish(file, win) {
-	var Dom = YAHOO.util.Dom;
-	Dom.get('insertimage_url').value = file.url;
-	Dom.get('insertimage_width').value = file.width;
-	Dom.get('insertimage_height').value = file.height;
+	var Dom = YAHOO.util.Dom,
+	  rte = win.opener.YAHOO.widget.EditorInfo.getEditorById(dYUICurEditor);
 
-	win.blur();
+	rte._focusWindow(); 
+	rte.execCommand('insertimage', file.url);
+	win.close();
 };
 
 YAHOO.Drupal.yui_editor_load.subscribe(yui_editor_img_browser);
\ No newline at end of file
Index: plugins/img_browser.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/yui_editor/plugins/Attic/img_browser.inc,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 img_browser.inc
--- plugins/img_browser.inc	25 Nov 2008 21:21:57 -0000	1.1.2.1
+++ plugins/img_browser.inc	11 Jul 2009 23:23:37 -0000
@@ -3,7 +3,10 @@
  * YUI Editor Image Browser Plugin - using IMCE
  *
  * @author Dave Hall <info@davehall.com.au>
+ * @copyright Copyright (c) 2009 Dave Hall http://davehall.com.au
  * @license GNU General Public License v2 (or later) http://www.gnu.org/licenses/gpl-2.0.html
+ *
+ * @version $Id:$
  */
 
 /**
@@ -42,5 +45,5 @@
     '#type' => 'checkbox',
     '#title' => t('Image Browser'),
     '#default_value' => $profile['img_browser'],
-    '#description' => t('Allow users to browse images directly from the editor for insertion into the editor. Note: IMCE module must be installed and configured for this to work. Works only with YUI 2.5.x at present.'));
+    '#description' => t('Replace image browser with IMCE.  Also handles image upload regardless of image upload setting.'));
 }
\ No newline at end of file
