source: trip-planner-front/node_modules/@angular/cdk/esm2015/drag-drop/clone-node.js@ e29cc2e

Last change on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 9.0 KB
Line 
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8/** Creates a deep clone of an element. */
9export function deepCloneNode(node) {
10 const clone = node.cloneNode(true);
11 const descendantsWithId = clone.querySelectorAll('[id]');
12 const nodeName = node.nodeName.toLowerCase();
13 // Remove the `id` to avoid having multiple elements with the same id on the page.
14 clone.removeAttribute('id');
15 for (let i = 0; i < descendantsWithId.length; i++) {
16 descendantsWithId[i].removeAttribute('id');
17 }
18 if (nodeName === 'canvas') {
19 transferCanvasData(node, clone);
20 }
21 else if (nodeName === 'input' || nodeName === 'select' || nodeName === 'textarea') {
22 transferInputData(node, clone);
23 }
24 transferData('canvas', node, clone, transferCanvasData);
25 transferData('input, textarea, select', node, clone, transferInputData);
26 return clone;
27}
28/** Matches elements between an element and its clone and allows for their data to be cloned. */
29function transferData(selector, node, clone, callback) {
30 const descendantElements = node.querySelectorAll(selector);
31 if (descendantElements.length) {
32 const cloneElements = clone.querySelectorAll(selector);
33 for (let i = 0; i < descendantElements.length; i++) {
34 callback(descendantElements[i], cloneElements[i]);
35 }
36 }
37}
38// Counter for unique cloned radio button names.
39let cloneUniqueId = 0;
40/** Transfers the data of one input element to another. */
41function transferInputData(source, clone) {
42 // Browsers throw an error when assigning the value of a file input programmatically.
43 if (clone.type !== 'file') {
44 clone.value = source.value;
45 }
46 // Radio button `name` attributes must be unique for radio button groups
47 // otherwise original radio buttons can lose their checked state
48 // once the clone is inserted in the DOM.
49 if (clone.type === 'radio' && clone.name) {
50 clone.name = `mat-clone-${clone.name}-${cloneUniqueId++}`;
51 }
52}
53/** Transfers the data of one canvas element to another. */
54function transferCanvasData(source, clone) {
55 const context = clone.getContext('2d');
56 if (context) {
57 // In some cases `drawImage` can throw (e.g. if the canvas size is 0x0).
58 // We can't do much about it so just ignore the error.
59 try {
60 context.drawImage(source, 0, 0);
61 }
62 catch (_a) { }
63 }
64}
65//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xvbmUtbm9kZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uL3NyYy9jZGsvZHJhZy1kcm9wL2Nsb25lLW5vZGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBRUgsMENBQTBDO0FBQzFDLE1BQU0sVUFBVSxhQUFhLENBQUMsSUFBaUI7SUFDN0MsTUFBTSxLQUFLLEdBQUcsSUFBSSxDQUFDLFNBQVMsQ0FBQyxJQUFJLENBQWdCLENBQUM7SUFDbEQsTUFBTSxpQkFBaUIsR0FBRyxLQUFLLENBQUMsZ0JBQWdCLENBQUMsTUFBTSxDQUFDLENBQUM7SUFDekQsTUFBTSxRQUFRLEdBQUcsSUFBSSxDQUFDLFFBQVEsQ0FBQyxXQUFXLEVBQUUsQ0FBQztJQUU3QyxrRkFBa0Y7SUFDbEYsS0FBSyxDQUFDLGVBQWUsQ0FBQyxJQUFJLENBQUMsQ0FBQztJQUU1QixLQUFLLElBQUksQ0FBQyxHQUFHLENBQUMsRUFBRSxDQUFDLEdBQUcsaUJBQWlCLENBQUMsTUFBTSxFQUFFLENBQUMsRUFBRSxFQUFFO1FBQ2pELGlCQUFpQixDQUFDLENBQUMsQ0FBQyxDQUFDLGVBQWUsQ0FBQyxJQUFJLENBQUMsQ0FBQztLQUM1QztJQUVELElBQUksUUFBUSxLQUFLLFFBQVEsRUFBRTtRQUN6QixrQkFBa0IsQ0FBQyxJQUF5QixFQUFFLEtBQTBCLENBQUMsQ0FBQztLQUMzRTtTQUFNLElBQUksUUFBUSxLQUFLLE9BQU8sSUFB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2xvbmUuZ2V0Q29udGV4dCgnMmQnKTtcblxuICBpZiAoY29udGV4dCkge1xuICAgIC8vIEluIHNvbWUgY2FzZXMgYGRyYXdJbWFnZWAgY2FuIHRocm93IChlLmcuIGlmIHRoZSBjYW52YXMgc2l6ZSBpcyAweDApLlxuICAgIC8vIFdlIGNhbid0IGRvIG11Y2ggYWJvdXQgaXQgc28ganVzdCBpZ25vcmUgdGhlIGVycm9yLlxuICAgIHRyeSB7XG4gICAgICBjb250ZXh0LmRyYXdJbWFnZShzb3VyY2UsIDAsIDApO1xuICAgIH0gY2F0Y2gge31cbiAgfVxufVxuIl19
Note: See TracBrowser for help on using the repository browser.