insertAdjacentHTML

David Faure faure at kde.org
Mon Oct 18 13:46:16 CEST 2004


An IE extension, but one that is used quite often, and not too difficult to support.

----------  Forwarded Message  ----------

Subject: kdelibs/khtml
Date: Sunday 17 October 2004 13:58
From: Stephan Kulow <coolo at kde.org>
To: kde-cvs at kde.org
Cc: khtml-cvs at kde.org, 33968-done at bugs.kde.org

CVS commit by coolo: 

applying patch to support insertAdjacentHTML after testing it (most test 
cases available online are interactive though)
FEATURE: 33968


  M +5 -0      ChangeLog   1.304
  M +27 -0     ecma/kjs_dom.cpp   1.181
  M +1 -1      ecma/kjs_dom.h   1.72


--- kdelibs/khtml/ChangeLog  #1.303:1.304
@@ -1,2 +1,7 @@
+2004-10-17  Stephan Kulow  <coolo at kde.org>
+
+        * ecma/kjs_dom.cpp: adding patch by Richard Lärkäng to support IE
+        extension insertAdjacentHTML (#33968)
+
 2004-10-16  Allan Sandfeld Jensen <kde at carewolf.com>
         * html/html_formimpl.cpp: Escape otherwise unencodable characters.

--- kdelibs/khtml/ecma/kjs_dom.cpp  #1.180:1.181
@@ -65,4 +65,5 @@ using namespace KJS;
 # IE extensions
   contains      DOMNode::Contains               DontDelete|Function 1
+  insertAdjacentHTML    DOMNode::InsertAdjacentHTML     DontDelete|Function 2
 # "DOM level 0" (from Gecko DOM reference; also in WinIE)
   item          DOMNode::Item           DontDelete|Function 1
@@ -497,4 +498,30 @@ Value DOMNodeProtoFunc::tryCall(ExecStat
         return Undefined();
     }
+    case DOMNode::InsertAdjacentHTML:
+    {
+      // see http://www.faqts.com/knowledge_base/view.phtml/aid/5756 
+      // and http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/insertAdjacentHTML.asp 
+      Range range = node.ownerDocument().createRange();
+
+      range.setStartBefore(node);
+
+      DocumentFragment docFrag = range.createContextualFragment(args[1].toString(exec).string());
+
+      DOMString where = args[0].toString(exec).string();
+
+      if (where == "beforeBegin" || where == "BeforeBegin")
+        node.parentNode().insertBefore(docFrag, node);
+      else if (where == "afterBegin" || where == "AfterBegin")
+        node.insertBefore(docFrag, node.firstChild());
+      else if (where == "beforeEnd" || where == "BeforeEnd")
+        return getDOMNode(exec, node.appendChild(docFrag));
+      else if (where == "afterEnd" || where == "AfterEnd")
+        if (!node.nextSibling().isNull())
+          node.parentNode().insertBefore(docFrag, node.nextSibling());
+        else
+          node.parentNode().appendChild(docFrag);
+
+      return Undefined();
+    }
     case DOMNode::Item:
       return getDOMNode(exec, node.childNodes().item(static_cast<unsigned long>(args[0].toNumber(exec))));

--- kdelibs/khtml/ecma/kjs_dom.h  #1.71:1.72
@@ -60,5 +60,5 @@ namespace KJS {
            ReplaceChild, RemoveChild, AppendChild, HasAttributes, HasChildNodes,
            CloneNode, Normalize, IsSupported, AddEventListener, RemoveEventListener,
-           DispatchEvent, Contains,
+           DispatchEvent, Contains, InsertAdjacentHTML,
            OnAbort, OnBlur, OnChange, OnClick, OnDblClick, OnDragDrop, OnError,
            OnFocus, OnKeyDown, OnKeyPress, OnKeyUp, OnLoad, OnMouseDown,




-------------------------------------------------------

-- 
David Faure, faure at kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).


More information about the Khtml-devel mailing list