Skip to content

Commit

Permalink
Reuse iframe (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
danipv authored Jun 17, 2024
1 parent d3fe3b6 commit 03d5d8c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 28 deletions.
16 changes: 8 additions & 8 deletions dist/vt-augment.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@virustotal/vt-augment",
"version": "1.7.1",
"version": "1.7.2",
"description": "Client library that wraps common patterns when interact with the VirusTotal Augment product",
"main": "dist/vt-augment.min.js",
"keywords": [
Expand Down
32 changes: 13 additions & 19 deletions src/vt-augment.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,25 @@ class VTAugment {
if (!url) return this;

const safeUrl = this.safeUrl_(url);
this.clean_();
this.loading(true);
this.createIframe_(this.container, safeUrl);
const iframe = this.container.querySelector('iframe');
if (iframe) {
iframe.src = SafeUrl.unwrap(safeUrl);
} else {
this.createIframe_(this.container, safeUrl);
}

return this;
}

/**
* @export
* @param {string} url
* @return {!VTAugment}
*/
preload(url) {
reload() {
this.loading(true);
const iframe = this.container.querySelector('iframe');
iframe.src = iframe.src
return this;
}

Expand Down Expand Up @@ -271,18 +278,6 @@ class VTAugment {
}
}

/**
* @private
* @return {void}
*/
clean_() {
let iframe = /** @type {?HTMLIFrameElement} */ (
this.container.querySelector('iframe'));
if (iframe) {
iframe.parentNode.removeChild(iframe);
}
}

/**
* @private
* @param {!Element} container
Expand Down Expand Up @@ -322,9 +317,8 @@ class VTAugment {
this.closeDrawer();
break;
case 'VTAUGMENT:CLEAR_CACHE':
const iframe = /** @type {?HTMLIFrameElement} */ (
this.container.querySelector('iframe'));
if (iframe) this.load(iframe.src);
case 'VTAUGMENT:RELOAD':
this.reload();
break;
default:
}
Expand Down

0 comments on commit 03d5d8c

Please sign in to comment.