Update of 
/var/cvs/contributions/CMSContainer/cmsc/richtext/src/webapp/mmbase/edit/wizard/xinha
In directory james.mmbase.org:/tmp/cvs-serv5305

Modified Files:
        my-htmlarea.js 
Log Message:
CMSC-681 Asset Maintenance   An error happens then using richtext in IE


See also: 
http://cvs.mmbase.org/viewcvs/contributions/CMSContainer/cmsc/richtext/src/webapp/mmbase/edit/wizard/xinha
See also: http://www.mmbase.org/jira/browse/CMSC-681


Index: my-htmlarea.js
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer/cmsc/richtext/src/webapp/mmbase/edit/wizard/xinha/my-htmlarea.js,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- my-htmlarea.js      30 Dec 2008 16:07:38 -0000      1.9
+++ my-htmlarea.js      19 Jan 2009 10:15:15 -0000      1.10
@@ -203,15 +203,16 @@
                   link = link.parentNode;
             }
       }
-
       var sel = editor._getSelection();
-
+       var sel_value = sel;
+       var range = this._createRange(sel);
+       if(HTMLArea.is_ie) sel_value = range.text;
       if (link){
             outparam = {
                   f_href   : HTMLArea.is_ie ? editor.stripBaseURL(link.href) : 
link.getAttribute("href"),
                   f_destination : HTMLArea.is_ie ? link.destination : 
link.getAttribute("destination"),
-                  f_linkName : sel,
-                  f_title  : link.title,
+                       f_name   : link.name?link.name: sel_value,
+                       f_title  :link.title?link.title:'',
                   f_target : link.target,
                   f_usetarget : editor.config.makeLinkShowsTarget
             };
@@ -220,55 +221,62 @@
             outparam = {
                   f_href   : "Click \"New Url\" to enter URL",
                   f_destination : null,
-                  f_linkName : sel,
-                  f_title  : null,
-                  f_target : null,
+                       f_name   : sel_value?sel_value:'',
+                       f_title  : '',
+                       f_target : '',
                   f_usetarget : editor.config.makeLinkShowsTarget
             };
       }
-      this._popupDialog(
-                       "insertinline_link.html", 
-                  function(param) {
-                        if (!param) { return false; }
+       this._popupDialog( "insertinline_link.html", function(param) {
+       if (!param) { return false; } //user must have pressed cancel
                         var a = link;
-                        if (!a) {
-                              var sel = editor._getSelection();
-                              if(sel == null || sel == ""){
-                                    var aLink = document.createElement('a');
-                                    editor.insertNodeAtSelection(aLink);
-                                    a = aLink;
-                                    a.href = param.f_href.trim();
-                                    a.innerHTML = param.f_linkName.trim();
-                              }
-                              else {
+               if ( !a ){
+                  try
+                       {
                                      editor._doc.execCommand("createlink", 
false, param.f_href);
                                      a = editor.getParentElement();
+                        var sel = editor._getSelection();
                                   var range = editor._createRange(sel);
-                                  if (!HTMLArea.is_ie) {
-                                   if (a == null || !(/^a$/i.test(a.tagName))) 
{
+                        if(editor._selectionEmpty(sel))
+                        {
+                              editor.insertHTML("<a 
href='"+param.f_href+"'title='"+param.f_title+"' 
name='"+param.f_name+"'>"+param.f_name+"</a>");
+                        }
+                        else{
+                              if ( !HTMLArea.is_ie )
+                              {
                                        a = range.startContainer;
-                                       if ( ! ( /^a$/i.test(a.tagName) ) ) {
+                                    if ( ! ( /^a$/i.test(a.tagName) ) )
+                                    {
                                              a = a.nextSibling;
-                                             if ( a === null ) {
+                                          if ( a === null )
+                                          {
                                                    a = 
range.startContainer.parentNode;
                                              }
                                        }
+                                    a.innerHTML = param.f_name.trim();
                                    }
                                   }
-                                  else {
-                                      while (a) {
-                                          if (/^a$/i.test(a.tagName)) break; 
//Search for the enclosing A tag, if found: continue and use it.
-                                          if (/^body$/i.test(a.tagName)) { a = 
null; break } //Stop searching when Body-tag is found, don't go too deep.
-                                          a = a.parentNode;
-                                      }
+                       } catch(ex) {}
                                   }
+               else
+               {
+                       var href = param.f_href.trim();
+                       editor.selectNodeContents(a);
+                       if ( href === '' )
+                       {
+                         editor._doc.execCommand("unlink", false, null);
+                         editor.updateToolbar();
+                         return false;
                               }
+                       else
+                       {
+                         a.href = href;
+                          a.innerHTML = param.f_name.trim();
                         } 
-                        else{
-                              a.href = param.f_href.trim();
                         }
-                       
+               a.target = param.f_target.trim();
                         a.title = param.f_title.trim();
+               a.name = param.f_name.trim();
 
                         if (HTMLArea.is_ie) {
                               a.destination = param.f_destination.trim();
@@ -282,8 +290,6 @@
                                     a.removeAttribute("relationID");
                               }
                         }
-
-                        a.target = param.f_target.trim();
                         editor.selectNodeContents(a);
                         editor.updateToolbar();
                   }, 
_______________________________________________
Cvs mailing list
Cvs@lists.mmbase.org
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to