(
meta: MetaDefinition,
forceCreation: boolean = false,
)
| 157 | } |
| 158 | |
| 159 | private _getOrCreateElement( |
| 160 | meta: MetaDefinition, |
| 161 | forceCreation: boolean = false, |
| 162 | ): HTMLMetaElement { |
| 163 | validateMetaDefinition(meta); |
| 164 | if (!forceCreation) { |
| 165 | const selector: string = parseSelector(meta); |
| 166 | // It's allowed to have multiple elements with the same name so it's not enough to |
| 167 | // just check that element with the same name already present on the page. We also need to |
| 168 | // check if element has tag attributes |
| 169 | const elem = this.getTags(selector).filter((elem) => containsAttributes(meta, elem))[0]; |
| 170 | if (elem !== undefined) return elem; |
| 171 | } |
| 172 | const element: HTMLMetaElement = this._dom.createElement('meta') as HTMLMetaElement; |
| 173 | setMetaElementAttributes(meta, element); |
| 174 | const head = this._doc.getElementsByTagName('head')[0]; |
| 175 | head.appendChild(element); |
| 176 | return element; |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | function buildMetaSelector(attrSelector: string): string { |
no test coverage detected