Index: easylink.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/easylink/easylink.module,v
retrieving revision 1.3.2.6
diff -u -p -r1.3.2.6 easylink.module
--- easylink.module	12 Oct 2007 15:48:56 -0000	1.3.2.6
+++ easylink.module	4 Oct 2008 00:44:02 -0000
@@ -84,7 +84,7 @@ function easylink_loader() {
   $view_text = views_build_view('embed', $myview, FALSE, TRUE, $myview->nodes_per_page);
 
   // Add javascript onClick action to insert link except on pager links
-  $view_text = preg_replace_callback('/<a href=".*">/i', "check_pager", $view_text);
+  $view_text = preg_replace_callback('|<a href=".*">.*</a>|i', "check_pager", $view_text);
   $output .= '<div class="easylink">' . $view_text . '</div>';
   $output .= "</div></div></div></html>\n";
   
@@ -94,12 +94,12 @@ function easylink_loader() {
 // Check if link is a pager link or not.  Only replace non-pager links
 function check_pager($matches){
   foreach ($matches as $match){
-    if (preg_match('/.*\?page=/', $match)||preg_match('/.*\?sort=/', $match)){
+    if (preg_match('/.*\?page=/', $match)||preg_match('/.*class="pager/', $match)||preg_match('/.*\?sort=/', $match)){
       return $match;
     } else {
       // Reg-ex fix from Jose San Martin
-      $search = '/<a href="(.*?)"[^>]*>/i';
-      $replace = '<a href="javascript:void(0);" onClick="addLink(\'$1\')">'; 
+      $search = '|<a href="(.*?)"[^>]*>(.*)</a>|i';
+      $replace = '<a href="javascript:void(0);" onClick="addLink(\'$1\', \'$2\')">$2</a>'; 
       return preg_replace($search, $replace, $match);
     }
   }
Index: easylink/jscripts/easylink.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/easylink/easylink/jscripts/easylink.js,v
retrieving revision 1.1
diff -u -p -r1.1 easylink.js
--- easylink/jscripts/easylink.js	14 May 2007 19:16:57 -0000	1.1
+++ easylink/jscripts/easylink.js	4 Oct 2008 00:44:02 -0000
@@ -1,8 +1,4 @@
-function addLink(addr){
-	insertLink(addr);
-}
-
-function insertLink(url) {
+function addLink(url, text){
   var inst = tinyMCE.getInstanceById(tinyMCE.getWindowArg('editor_id'));
   var elm = inst.getFocusElement();
 
@@ -12,11 +8,18 @@ function insertLink(url) {
 
   // Create new anchor elements
   if (elm == null) {
-    if (tinyMCE.isSafari)
-      tinyMCEPopup.execCommand("mceInsertContent", false, '<a href="'+url+'">' + inst.selection.getSelectedHTML() + '</a>');
-    else
-      tinyMCEPopup.execCommand("createlink", false, url);
-
+    selection = inst.selection.getSelectedHTML();
+    if (selection.length == 0) {
+      // Insert a new link using the title of the selected node
+      tinyMCEPopup.execCommand("mceInsertContent", false, '<a href="'+url+'">' + text + '</a>');
+    }
+    else {
+      // Insert a link using the selected text
+      if (tinyMCE.isSafari)
+        tinyMCEPopup.execCommand("mceInsertContent", false, '<a href="'+url+'">' + selection + '</a>');
+      else
+        tinyMCEPopup.execCommand("createlink", false, url);
+    }
     var elementArray = tinyMCE.getElementsByAttributeValue(inst.getBody(), "a", "href", url);
     for (var i=0; i<elementArray.length; i++) {
       var elm = elementArray[i];
@@ -40,14 +43,42 @@ function insertLink(url) {
         sel.removeAllRanges();
         sel.addRange(rng);
       }
-
-      //setAllAttribs(elm);
     }
-  } //else
-    //setAllAttribs(elm);
+  } 
+  else {
+    // Update link URL if an existing link is already selected
+    setAttrib(elm, 'href', url);
+  }
 
   tinyMCE._setEventsEnabled(inst.getBody(), false);
   tinyMCEPopup.execCommand("mceEndUndoLevel");
   tinyMCEPopup.close();
 }
 
+function setAttrib(elm, attrib, value) {
+  var formObj = document.forms[0];
+  var valueElm = formObj.elements[attrib.toLowerCase()];
+
+  if (typeof(value) == "undefined" || value == null) {
+      value = "";
+
+      if (valueElm)
+          value = valueElm.value;
+  }
+
+  if (value != "") {
+      elm.setAttribute(attrib.toLowerCase(), value);
+
+      if (attrib == "style")
+          attrib = "style.cssText";
+
+      if (attrib.substring(0, 2) == 'on')
+          value = 'return true;' + value;
+
+      if (attrib == "class")
+          attrib = "className";
+
+      eval('elm.' + attrib + "=value;");
+  } else
+      elm.removeAttribute(attrib);
+}
\ No newline at end of file
