OLD | NEW |
(Empty) | |
| 1 /** |
| 2 * The const var for SVG and xlink namespaces |
| 3 */ |
| 4 const SVGNS = 'http://www.w3.org/2000/svg'; |
| 5 const XLINKNS = 'http://www.w3.org/1999/xlink'; |
| 6 |
| 7 /** |
| 8 * Appends a svg element to the parent. |
| 9 * |
| 10 * @param test The testharness.js Test object. If provided, this will be used |
| 11 * to register a cleanup callback to remove the div when the test |
| 12 * finishes. |
| 13 * @param tag The element tag name. |
| 14 * @param parent The parent element of this new created svg element. |
| 15 * @param attrs A dictionary object with attribute names and values to set on |
| 16 * the div. |
| 17 */ |
| 18 function createSVGElement(test, tag, parent, attrs) { |
| 19 var elem = document.createElementNS(SVGNS, tag); |
| 20 if (attrs) { |
| 21 for (var attrName in attrs) { |
| 22 elem.setAttribute(attrName, attrs[attrName]); |
| 23 } |
| 24 } |
| 25 parent.appendChild(elem); |
| 26 test.add_cleanup(function() { |
| 27 elem.remove(); |
| 28 }); |
| 29 return elem; |
| 30 } |
| 31 |
| 32 /** |
| 33 * Create a Promise object which resolves when a specific event fires. |
| 34 * |
| 35 * @param object The event target. |
| 36 * @param name The event name. |
| 37 */ |
| 38 function waitEvent(object, name) { |
| 39 return new Promise(function(resolve) { |
| 40 object.addEventListener(name, resolve, { once: true }); |
| 41 }); |
| 42 } |
OLD | NEW |