Skip to content

Commit

Permalink
Merge pull request #21 from VirusTotal/feature/standalone-doc
Browse files Browse the repository at this point in the history
Add docs and fix standalone spinner
  • Loading branch information
danipv authored Jul 27, 2021
2 parents 2fabd34 + 0bd1917 commit 8eb73a0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 19 deletions.
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,17 @@ vtaugment.load("[url]").openDrawer()

## Modes

#### Drawer
### Drawer

This is the default mode, VT Augment will be shown in a right side panel.
This is the default mode, VT Augment will be shown in a right side panel when the `openDrawer` method is called.

### Standalone

This mode allows you to integrate the widget as a non-animated div in your page. See [Options](#options).

# API

#### vtaugment(container = null, opts = {})
### vtaugment(container = null, opts = {})

Creates a new object with a html element and a set of options. An iframe is dynamically created inside the container to host the VT API response.

Expand Down Expand Up @@ -108,6 +112,11 @@ vtaugment.loading(true)

```js
{
background: '#fff', // Background color for loading states
// Background color for loading states. Default ''.
background: '#fff',
// Force to closing the widget only with the X button. Default true.
closingFromOutside: true | false,
// Select the widget mode. Default drawer.
mode: 'drawer' | 'standalone',
}
```
4 changes: 2 additions & 2 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.6.0",
"version": "1.7.0",
"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: 20 additions & 12 deletions src/vt-augment.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ let Options;
/** @type {string} */
const CSS_STYLESHEET = `
.vt-augment {
position: relative;
display: flex;
justify-content: center;
align-items: center;
Expand Down Expand Up @@ -109,9 +110,12 @@ const CSS_STYLESHEET = `
}
`;

const DRAWER_MODE = 'drawer';
const STANDALONE_MODE = 'standalone';

/** @type {Options} */
const DEFAULT_OPTIONS = {
'mode': 'drawer',
'mode': DRAWER_MODE,
'background': '',
'closingFromOutside': true,
}
Expand All @@ -134,8 +138,8 @@ class VTAugment {
this.container.style.background = this.options['background'];
}

if (this.options['mode'] === 'drawer') {
this.container.classList.add('drawer');
if (this.options['mode'] === DRAWER_MODE) {
this.container.classList.add(DRAWER_MODE);
}

if (this.options['closingFromOutside']) {
Expand Down Expand Up @@ -180,9 +184,11 @@ class VTAugment {
* @return {!VTAugment}
*/
openDrawer() {
const iframe = this.container.querySelector('iframe');
this.container.setAttribute('opened', '');
iframe && iframe.removeAttribute('tabindex');
if (this.options['mode'] === DRAWER_MODE) {
const iframe = this.container.querySelector('iframe');
this.container.setAttribute('opened', '');
iframe && iframe.removeAttribute('tabindex');
}
return this;
}

Expand All @@ -191,11 +197,13 @@ class VTAugment {
* @return {!VTAugment}
*/
closeDrawer() {
const iframe = this.container.querySelector('iframe');
this.container.removeAttribute('opened');
if (iframe) {
iframe.setAttribute('tabindex', '-1');
iframe.style.display = 'none';
if (this.options['mode'] === DRAWER_MODE) {
const iframe = this.container.querySelector('iframe');
this.container.removeAttribute('opened');
if (iframe) {
iframe.setAttribute('tabindex', '-1');
iframe.style.display = 'none';
}
}
return this;
}
Expand Down Expand Up @@ -243,7 +251,7 @@ class VTAugment {
'title': "VirusTotal Augment",
};

if (this.options['mode'] === 'standalone') {
if (this.options['mode'] === STANDALONE_MODE) {
iframeAttrs['name'] = this.options['mode'];
}

Expand Down

0 comments on commit 8eb73a0

Please sign in to comment.