(data)
| 382 | } |
| 383 | |
| 384 | getLink (data) { |
| 385 | let holder |
| 386 | let link |
| 387 | |
| 388 | /* Get mime type of the link */ |
| 389 | const mime = data.mediaType || 'application/javascript' |
| 390 | const type = mime.split('/')[0] |
| 391 | |
| 392 | /* Template to generate the link href */ |
| 393 | const href = this.jsoneditor.compileTemplate(data.href, this.template_engine) |
| 394 | const relTemplate = this.jsoneditor.compileTemplate(data.rel ? data.rel : data.href, this.template_engine) |
| 395 | |
| 396 | /* Template to generate the link's download attribute */ |
| 397 | let download = null |
| 398 | if (data.download) download = data.download |
| 399 | |
| 400 | if (download && download !== true) { |
| 401 | download = this.jsoneditor.compileTemplate(download, this.template_engine) |
| 402 | } |
| 403 | |
| 404 | /* Image links */ |
| 405 | if (type === 'image') { |
| 406 | holder = this.theme.getBlockLinkHolder() |
| 407 | link = document.createElement('a') |
| 408 | link.setAttribute('target', '_blank') |
| 409 | const image = document.createElement('img') |
| 410 | |
| 411 | this.theme.createImageLink(holder, link, image) |
| 412 | |
| 413 | /* When a watched field changes, update the url */ |
| 414 | this.link_watchers.push(vars => { |
| 415 | const url = href(vars) |
| 416 | const rel = relTemplate(vars) |
| 417 | link.setAttribute('href', url) |
| 418 | link.setAttribute('title', rel || url) |
| 419 | image.setAttribute('src', url) |
| 420 | }) |
| 421 | /* Audio/Video links */ |
| 422 | } else if (['audio', 'video'].includes(type)) { |
| 423 | holder = this.theme.getBlockLinkHolder() |
| 424 | |
| 425 | link = this.theme.getBlockLink() |
| 426 | link.setAttribute('target', '_blank') |
| 427 | |
| 428 | const media = document.createElement(type) |
| 429 | media.setAttribute('controls', 'controls') |
| 430 | |
| 431 | this.theme.createMediaLink(holder, link, media) |
| 432 | |
| 433 | /* When a watched field changes, update the url */ |
| 434 | this.link_watchers.push(vars => { |
| 435 | const url = href(vars) |
| 436 | const rel = relTemplate(vars) |
| 437 | link.setAttribute('href', url) |
| 438 | link.textContent = rel || url |
| 439 | media.setAttribute('src', url) |
| 440 | }) |
| 441 | /* Text links or blank link */ |
no test coverage detected