]> source.dussan.org Git - svg.js.git/commitdiff
New paremeter assignNewIds for Dom.clone()
authorPhilippe Bernard <philippe.bernard@gmail.com>
Wed, 14 Oct 2020 09:20:20 +0000 (11:20 +0200)
committerPhilippe Bernard <philippe.bernard@gmail.com>
Wed, 14 Oct 2020 09:20:20 +0000 (11:20 +0200)
src/elements/Dom.js
svg.js.d.ts

index 7c360785c5d4ad971c85d5bb5aa18e6982bf8e35..508bbc272cc87ddeebe9a3bee288adf589fe9ea2 100644 (file)
@@ -67,12 +67,17 @@ export default class Dom extends EventTarget {
   }
 
   // Clone element
-  clone (deep = true) {
+  clone (deep = true, assignNewIds = true) {
     // write dom data to the dom so the clone can pickup the data
     this.writeDataToDom()
 
-    // clone element and assign new id
-    return new this.constructor(assignNewId(this.node.cloneNode(deep)))
+    // clone element
+    var nodeClone = this.node.cloneNode(deep);
+    if (assignNewIds) {
+      // assign new id
+      nodeClone = assignNewId(nodeClone);
+    }
+    return new this.constructor(nodeClone)
   }
 
   // Iterates over all children and invokes a given block
index c347d4d06df5fce4db96d576f69aaffb4e5dd8f3..6196e63458b5772afabf9d9d208abdcc5bc428ea 100644 (file)
@@ -933,7 +933,7 @@ declare module "@svgdotjs/svg.js" {
         addTo(parent: Dom | HTMLElement | string): this\r
         children(): List<Element>;\r
         clear(): this;\r
-        clone(): this;\r
+        clone(deep?: boolean, assignNewIds?: boolean): this;\r
         each(block: (index: number, children: Element[]) => void, deep?: boolean): this;\r
         element(element: string, inherit?: object): this;\r
         first(): Element;\r
@@ -1180,7 +1180,7 @@ declare module "@svgdotjs/svg.js" {
         click(cb: Function | null): this;\r
         clipper(): ClipPath;\r
         clipWith(element: Element): this;\r
-        clone(): this;\r
+        clone(deep?: boolean, assignNewIds?: boolean): this;\r
         ctm(): Matrix;\r
         cx(): number;\r
         cx(x: number): this;\r