(global, data)
| 61 | * @param {!Object} data |
| 62 | */ |
| 63 | export function embedly(global, data) { |
| 64 | const card = global.document.createElement('a'); |
| 65 | |
| 66 | card.href = data.url; |
| 67 | card.classList.add(CARD_CSS_CLASS); |
| 68 | |
| 69 | // Add permissible data attributes and values to card |
| 70 | // when these are provided by component. |
| 71 | for (const key in CardOptions) { |
| 72 | if (hasOwn(CardOptions, key) && typeof data[key] !== 'undefined') { |
| 73 | card.setAttribute(`data-${CardOptions[key]}`, data[key]); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | const container = global.document.getElementById('c'); |
| 78 | |
| 79 | // Adds support to embedly dark theme not set by the sdk |
| 80 | if (data['cardTheme'] === 'dark') { |
| 81 | setStyle(container, 'background', 'rgba(51, 51, 51)'); |
| 82 | } |
| 83 | |
| 84 | container.appendChild(card); |
| 85 | |
| 86 | getEmbedly(global, function () { |
| 87 | // Given by the parent frame. |
| 88 | delete data.width; |
| 89 | delete data.height; |
| 90 | |
| 91 | global.window['embedly']('card', card); |
| 92 | |
| 93 | // Use embedly SDK to listen to resize event from loaded card |
| 94 | global.window['embedly']('on', RESIZE_EVENT_NAME, function (iframe) { |
| 95 | context.requestResize( |
| 96 | iframe./*OK*/ width, |
| 97 | parseInt(iframe./*OK*/ height, 10) + /* margin */ 5 |
| 98 | ); |
| 99 | }); |
| 100 | }); |
| 101 | } |
nothing calls this directly
no test coverage detected