* Does a shallow clones the node into a new node. It will also exclude id attributes since * there should only be one id per document. * * @method clone * @return {tinymce.html.Node} New copy of the original node. * @example * const clonedNode = node.clone();
()
| 244 | * const clonedNode = node.clone(); |
| 245 | */ |
| 246 | public clone(): AstNode { |
| 247 | const self = this; |
| 248 | const clone = new AstNode(self.name, self.type); |
| 249 | const selfAttrs = self.attributes; |
| 250 | |
| 251 | // Clone element attributes |
| 252 | if (selfAttrs) { |
| 253 | const cloneAttrs = [] as unknown as Attributes; |
| 254 | (cloneAttrs as any).map = {}; |
| 255 | |
| 256 | for (let i = 0, l = selfAttrs.length; i < l; i++) { |
| 257 | const selfAttr = selfAttrs[i]; |
| 258 | |
| 259 | // Clone everything except id |
| 260 | if (selfAttr.name !== 'id') { |
| 261 | cloneAttrs[cloneAttrs.length] = { name: selfAttr.name, value: selfAttr.value }; |
| 262 | cloneAttrs.map[selfAttr.name] = selfAttr.value; |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | clone.attributes = cloneAttrs; |
| 267 | } |
| 268 | |
| 269 | clone.value = self.value; |
| 270 | |
| 271 | return clone; |
| 272 | } |
| 273 | |
| 274 | /** |
| 275 | * Wraps the node in in another node. |
no outgoing calls
no test coverage detected