From f3c7d85e1c440f17a0674484616fc96b34da8871 Mon Sep 17 00:00:00 2001
From: michal <michal_cksource@922884.no-reply.drupal.org>
Date: Fri, 24 Jun 2011 10:56:13 +0200
Subject: [PATCH 244/244] Small fix for imce plugin

---
 plugins/imce/plugin.js |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/plugins/imce/plugin.js b/plugins/imce/plugin.js
index 5210020..ef196b1 100644
--- a/plugins/imce/plugin.js
+++ b/plugins/imce/plugin.js
@@ -34,18 +34,20 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
       
       //function which receive imce response
       window.ckeditor_setFile = function (file, win) {
-        var cfunc = win.location.href.split('&');
       
+        var cfunc = win.location.href.split('&');      
         for (var x in cfunc) {
           if (cfunc[x].match(/^CKEditorFuncNum=\d+$/)) {
             cfunc = cfunc[x].split('=');
             break;
           }
         }
-        
+         
+         
         CKEDITOR.tools.callFunction(cfunc[1], file);
         win.close();
       };
+      
     }
   } );
   function setFile(file) {
@@ -53,7 +55,15 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
     if (file.width != 0 && file.height != 0) {
       this.insertHtml('<img src="' + file.url + '" style="width:' + file.width + 'px;height:' + file.height + 'px;" alt="' + file.name + '" />');
     } else {
-      this.insertHtml('<a href="' + file.url + '">' + file.name + '</a>');
+    	var sel = this.getSelection(),
+			text = sel.getSelectedText();
+			if (text)
+			{
+				this.insertHtml('<a href="' +document.location.protocol + '//'+ document.location.host + file.url + '">' + text + '</a>');
+			}else
+			{
+	      this.insertHtml('<a href="' + document.location.protocol + '//'+ document.location.host +  file.url + '">' + file.name + '</a>');
+      }
     }
   }
 } )();
-- 
1.7.4.msysgit.0

