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