changeset 3969:1d0ed74ec4be

make select plugin works on IE. fix attachment plugin works on IE
author Byeongweon [tasyblue@gmail.com]
date Sat, 05 Jul 2008 06:26:29 +0900
parents 0731503e211e
children 69c8c705bea1
files wiki/htdocs/applets/moinFCKplugins/moinattachment/fck_attachment.js wiki/htdocs/applets/moinFCKplugins/moinlink/fck_link.js wiki/htdocs/applets/moinFCKplugins/selection/fckplugin.js
diffstat 3 files changed, 161 insertions(+), 153 deletions(-) [+]
line wrap: on
line diff
--- a/wiki/htdocs/applets/moinFCKplugins/moinattachment/fck_attachment.js	Fri Jul 04 21:41:57 2008 +0900
+++ b/wiki/htdocs/applets/moinFCKplugins/moinattachment/fck_attachment.js	Sat Jul 05 06:26:29 2008 +0900
@@ -18,7 +18,8 @@
  *   Frederico Caldeira Knabben (fredck@fckeditor.net)
  */
 
-var oEditor  = window.parent.InnerDialogLoaded();
+var dialog	= window.parent ;
+var oEditor = dialog.InnerDialogLoaded() ;
 var FCK   = oEditor.FCK;
 var FCKLang  = oEditor.FCKLang;
 var FCKConfig = oEditor.FCKConfig;
@@ -56,9 +57,9 @@
 //#### Initialization Code
 
 // oLink: The actual selected link in the editor.
-var oLink = FCK.Selection.MoveToAncestorNode('A');
-if (oLink)
- FCK.Selection.SelectNode(oLink);
+var oLink = dialog.Selection.GetSelection().MoveToAncestorNode( 'A' ) ;
+if ( oLink )
+  FCK.Selection.SelectNode( oLink ) ;
 
 window.onload = function()
 {
@@ -83,7 +84,7 @@
           oLink.getAttribute('title').startsWith('attachment:'))
  {
   GetE('txtAttachmentname').value = decodeUrl(
-     oLink.getAttribute('title').remove(0, 'attachment:'.length));
+     oLink.getAttribute('title').Remove(0, 'attachment:'.length));
  }
 
 }
@@ -120,39 +121,41 @@
 //#### The OK button was hit.
 function Ok()
 {
- var sUri;
- var sText = '';
+  var sUri;
+  var sText = '';
 
-   sUri = GetE('txtAttachmentname').value;
-   if (sUri.length == 0)
-   {
+  sUri = GetE('txtAttachmentname').value;
+  if (sUri.length == 0)
+  {
     alert(FCKLang.DlnLnkMsgNoUrl);
     return false;
-   }
-   sText = sUri;
-   sUri = encodeUrl(sUri);
+  }
+  sText = sUri;
+  sUri = encodeUrl(sUri);
 
- if (oLink) // Modifying an existent link.
-  oLink.href = sUri;
- else   // Creating a new link.
- {
-  oLink = oEditor.FCK.CreateLink(sUri);
-  if (! oLink)
+  if (oLink) // Modifying an existent link.
   {
-    oLink = oEditor.FCK.CreateElement('A');
     oLink.href = sUri;
-    oLink.appendChild(oEditor.FCK.EditorDocument.createTextNode(sText)); 
   }
- }
-
+  else   // Creating a new link.
+  {
+    oLink = oEditor.FCK.CreateLink(sUri)[0];
+    if (! oLink)
+    {
+      oLink = oEditor.FCK.CreateElement('A');
+      oLink.href = sUri;
+      oLink.appendChild(oEditor.FCK.EditorDocument.createTextNode(sText)); 
+    }
+  }
+  
   SetAttribute(oLink, 'title', 'attachment:' + sUri);
 
- return true;
+  return true;
 }
 
 function SetUrl(url)
 {
- document.getElementById('txtUrl').value = url;
- OnUrlChange();
+  document.getElementById('txtUrl').value = url;
+  OnUrlChange();
 }
 
--- a/wiki/htdocs/applets/moinFCKplugins/moinlink/fck_link.js	Fri Jul 04 21:41:57 2008 +0900
+++ b/wiki/htdocs/applets/moinFCKplugins/moinlink/fck_link.js	Sat Jul 05 06:26:29 2008 +0900
@@ -19,7 +19,7 @@
  */
 
 var dialog	= window.parent ;
-var oEditor  = window.parent.InnerDialogLoaded();
+var oEditor  = dialog.InnerDialogLoaded();
 var FCK   = oEditor.FCK;
 var FCKLang  = oEditor.FCKLang;
 var FCKConfig = oEditor.FCKConfig;
--- a/wiki/htdocs/applets/moinFCKplugins/selection/fckplugin.js	Fri Jul 04 21:41:57 2008 +0900
+++ b/wiki/htdocs/applets/moinFCKplugins/selection/fckplugin.js	Sat Jul 05 06:26:29 2008 +0900
@@ -12,146 +12,100 @@
   alert(res);
 }
 
-// --------------------------------
-// Gecko. it changed. also able to use FCKSelection.GetSelection in IE
+
 // --------------------------------
-if (FCKSelection.GetSelection) 
-{ 
-  // assume exactly one selection
-  
-  FCKSelection.GetStartNode = function()
-    {
-      var oSelection = FCKSelection.GetSelection();
-      var oContainer = oSelection.getRangeAt(0).startContainer;
-      var iOffset = oSelection.getRangeAt(0).startOffset;
-      if (oContainer.childNodes.length>iOffset) 
-        return oContainer.childNodes[iOffset];
-      else
-        return oContainer;
-        
-    }
-  // only valid if GetStartNode() returns text node
-  FCKSelection.GetStartOffset = function()
-    {
-      var oSelection = FCKSelection.GetSelection();
-      return oSelection.getRangeAt(0).startOffset;    
-    }
-  FCKSelection.GetEndNode = function()
-    {
-      var oSelection = FCKSelection.GetSelection();
-      var oContainer = oSelection.getRangeAt(0).endContainer;
-      var iOffset = oSelection.getRangeAt(0).startEndset;
-      if (oContainer.childNodes.length>iOffset) 
-        return oContainer.childNodes[iOffset];
-      else
-        return oContainer;
-
-    }
-  // only valid if GetEndNode() returns text node
-  FCKSelection.GetEndOffset = function()
-    {
-      var oSelection = FCKSelection.GetSelection();
-      return oSelection.getRangeAt(0).endOffset;    
-    }
-  FCKSelection.IsCollapsed = function()
-    {
-      var oSelection = FCKSelection.GetSelection();
-      return oSelection.getRangeAt(0).collapsed;    
-    }
-  FCKSelection.GetText = function()
-    {
-      return FCKSelection.GetSelection().toString();
-    }
-}
-/* ##########################################################################
- * ###   IE  : it dosen't work. ie also use FCKSelection.
- * #########################################################################
- */
-else if (FCK.EditorDocument.selection)
-{
-
+// IE
+// --------------------------------
+if (sSuffix == 'ie') {
+  // initialize startNode and endNode
   function invalidSelection()
-    {
+  {
       FCKSelection._startNode = null;
       FCKSelection._endNode = null;
-    }
+  }
 
   FCK.AttachToOnSelectionChange(invalidSelection);
 
   FCKSelection._startNode = null;
   FCKSelection._endNode = null;
 
+
+  // get StartNode
   FCKSelection.GetStartNode = function()
+  {
+    if (!FCKSelection._startNode) 
     {
-      if (!FCKSelection._startNode) 
-      {
-	FCKSelection._startNode = FCKSelection._getStartNode()
-      }
-      return FCKSelection._startNode;
+      FCKSelection._startNode = FCKSelection._getStartNode()
     }
-
+    return FCKSelection._startNode;
+  }
 
   FCKSelection._getStartNode = function()
+  {
+    if (FCKSelection._startNode) return FCKSelection._startNode;
+
+    var oRange = FCKSelection.GetSelection().createRange();
+
+    if (FCKSelection.GetType()=="Control")
     {
-      if (FCKSelection._startNode) return FCKSelection._startNode;
-      var oRange = FCK.EditorDocument.selection.createRange();
-      if (FCKSelection.GetType()=="Control")
-      {
-        return oRange.item(0);
-      }
-      else // Text, None
+      return oRange.item(0);
+    }
+    else // Text, None
+    {
+      var oTmpRange = FCKSelection.GetSelection().createRange();
+      var parent = oRange.parentElement();
+      var oNode = null;
+      var following_text = 0;
+      if (!parent.hasChildNodes()) 
+        return parent; // selection in empty tag
+
+      oNode = parent.firstChild;
+      var oLastText = oNode;
+
+      while (oNode)
       {
-        var oTmpRange = FCK.EditorDocument.selection.createRange();
-        var parent = oRange.parentElement();
-        var oNode = null;
-	var following_text = 0;
-        if (!parent.hasChildNodes()) 
-          return parent; // selection in empty tag
-        oNode = parent.firstChild;
-        var oLastText = oNode;
-        while (oNode)
+        if (oNode.nodeName != "#text") 
         {
-          if (oNode.nodeName!="#text") 
-            {
-	      following_text = false;
-              oTmpRange.moveToElementText(oNode);
-              if (oRange.compareEndPoints('StartToEnd', oTmpRange)<0)
-                {
-                  // found
-                  if (oRange.compareEndPoints('StartToStart', oTmpRange)<=0)
-                    return oLastText; // already inside selection
-                  oNode = oNode.firstChild;
-                }
-              else
-                oNode = oNode.nextSibling;
-            }
-          else
-            {
-	      if (!following_text)
-		{
-		  oLastText = oNode;
-		  following_text = true;
-		}
-              try {
-                 oNode = oNode.nextSibling;
-              }
-              catch (e) {
-		if (parent.childNodes.length>=2)
-		  oNode = parent.childNodes[1];
-		else
-		  return parent;
-		  
-                 // alert(e);
-                 //showObj('parent', parent);
-		 //showObj('node', oNode);
-                 // showObj('childNodes[0]', parent.childNodes[0]);
-                 //oNode = false;
-              }
-            }
+          following_text = false;
+          oTmpRange.moveToElementText(oNode);
+          if (oRange.compareEndPoints('StartToEnd', oTmpRange)<0)
+          {
+            // found
+            if (oRange.compareEndPoints('StartToStart', oTmpRange)<=0)
+            return oLastText; // already inside selection
+            oNode = oNode.firstChild;
+          }
+          else 
+          {
+            oNode = oNode.nextSibling;
+          }
         }
-        return oLastText;
-      }
-    }
+        else
+        {
+          if (!following_text)
+          {
+            oLastText = oNode;
+            following_text = true;
+          }
+          try {
+            oNode = oNode.nextSibling;
+          }
+          catch (e) {
+            if (parent.childNodes.length>=2)
+              oNode = parent.childNodes[1];
+            else
+              // alert(e);
+              // showObj('parent', parent);
+              // showObj('node', oNode);
+              // showObj('childNodes[0]', parent.childNodes[0]);
+              // oNode = false;
+              return parent;
+          } // end of catch
+        } // end of else
+      } // end of while
+      return oLastText;
+    } // end of else
+  }
 
   FCKSelection.GetStartOffset = function() 
     {
@@ -159,7 +113,7 @@
       var oNode = FCKSelection.GetStartNode();
       if (oNode.nodeType!=3) return 0; // not a text node 
       var startoffset = 0;
-      var selrange = FCK.EditorDocument.selection.createRange();
+      var selrange = FCKSelection.GetSelection().createRange();
       var elrange = selrange.duplicate();
       if (oNode.previousSilbing)
       {
@@ -194,14 +148,14 @@
   FCKSelection._getEndNode = function()
     {
       FCKSelection.sEnd = "";
-      var oRange = FCK.EditorDocument.selection.createRange();
+      var oRange = FCKSelection.GetSelection().createRange();
       if (FCKSelection.GetType()=="Control")
       {
         return oRange.item(oRange.length-1);
       }
       else // Text, None
       {
-        var oTmpRange = FCK.EditorDocument.selection.createRange();
+        var oTmpRange = FCKSelection.GetSelection().createRange();
         var oNode = oRange.parentElement()
         var following_text = false;
         if (!oNode.hasChildNodes()) return oNode; // selection in empty tag
@@ -250,7 +204,7 @@
       var oNode = FCKSelection.GetEndNode();
       if (oNode.nodeType!=3) return 0; // not a text node 
       var endoffset = 0;
-      var selrange = FCK.EditorDocument.selection.createRange();
+      var selrange = FCKSelection.GetSelection().createRange();
       var elrange = selrange.duplicate();
       if (oNode.nextSilbing)
       {
@@ -276,7 +230,7 @@
 
   FCKSelection.GetText = function()
     {
-      var oRange = FCK.EditorDocument.selection.createRange();
+      var oRange = FCKSelection.GetSelection().createRange();
       return oRange.text;
     }
   FCKSelection.IsCollapsed = function()
@@ -284,6 +238,57 @@
       return FCKSelection.GetType()=='None';
     }
 }
+// --------------------------------
+// Others
+// --------------------------------
+else {
+  // assume exactly one selection
+  FCKSelection.GetStartNode = function()
+    {
+      var oSelection = FCKSelection.GetSelection();
+      var oContainer = oSelection.getRangeAt(0).startContainer;
+      var iOffset = oSelection.getRangeAt(0).startOffset;
+      if (oContainer.childNodes.length>iOffset) 
+        return oContainer.childNodes[iOffset];
+      else
+        return oContainer;
+        
+    }
+  // only valid if GetStartNode() returns text node
+  FCKSelection.GetStartOffset = function()
+    {
+      var oSelection = FCKSelection.GetSelection();
+      return oSelection.getRangeAt(0).startOffset;    
+    }
+  FCKSelection.GetEndNode = function()
+    {
+      var oSelection = FCKSelection.GetSelection();
+      var oContainer = oSelection.getRangeAt(0).endContainer;
+      var iOffset = oSelection.getRangeAt(0).startEndset;
+      if (oContainer.childNodes.length>iOffset) 
+        return oContainer.childNodes[iOffset];
+      else
+        return oContainer;
+
+    }
+  // only valid if GetEndNode() returns text node
+  FCKSelection.GetEndOffset = function()
+    {
+      var oSelection = FCKSelection.GetSelection();
+      return oSelection.getRangeAt(0).endOffset;    
+    }
+  FCKSelection.IsCollapsed = function()
+    {
+      var oSelection = FCKSelection.GetSelection();
+      return oSelection.getRangeAt(0).collapsed;    
+    }
+  FCKSelection.GetText = function()
+    {
+      return FCKSelection.GetSelection().toString();
+    }
+}
+
+
 
 /* 
  * Checks if the name of any of the selected nodes or the nodes surrounding