Skip to content

Commit

Permalink
Merge pull request #11 from RadarTech/master
Browse files Browse the repository at this point in the history
Release v1.1.0
  • Loading branch information
cavanmflynn authored Jan 21, 2020
2 parents e942274 + ab6cf37 commit e5c52fa
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ redshift.setOptions(options: WidgetOptions)

### Modal

This mode is likely preferable for most websites because it does not disrupt the existing UI in any way. Simply slap `onclick="redshift.open()"` on a button and you're in business.
This mode is likely preferable for most websites because it does not disrupt the existing UI in any way. Simply slap `onclick="redshift.open()"` on a button and you're in business. You can optionally pre-populate the widget's invoice field by passing it into the open or toggle methods.

#### [View Live Demo](https://codepen.io/cavan-radar/details/pooJxvj?preview_height=650)

Expand All @@ -66,6 +66,11 @@ This mode is likely preferable for most websites because it does not disrupt the
*/
redshift.open()

/**
* Open the widget with invoice pre-populated
*/
redshift.open(invoice)

/**
* Close the widget
*/
Expand All @@ -75,6 +80,11 @@ redshift.close()
* Toggle the widget
*/
redshift.toggle()

/**
* Toggle the widget with invoice pre-populated
*/
redshift.toggle(invoice)
```

#### How To
Expand Down
12 changes: 7 additions & 5 deletions src/api/modal-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class ModalApi extends OptionsApi {
private _isOpen: boolean;
private _attach: () => void;
private _remove: () => void;
private _initMessaging: () => void;
private _initMessaging: (invoice?: string) => void;

/**
* Whether or not the trade widget is open
Expand All @@ -30,10 +30,11 @@ export class ModalApi extends OptionsApi {

/**
* Open the widget
* @param invoice An optional invoice to pass to the widget (for pre-populating invoice input)
*/
public open() {
public open(invoice?: string) {
this._attach();
this._initMessaging();
this._initMessaging(invoice);
this._isOpen = true;
}

Expand All @@ -47,8 +48,9 @@ export class ModalApi extends OptionsApi {

/**
* Toggle the widget
* @param invoice An optional invoice to pass to the widget (for pre-populating invoice input)
*/
public toggle() {
this.isOpen ? this.close() : this.open();
public toggle(invoice?: string) {
this.isOpen ? this.close() : this.open(invoice);
}
}
8 changes: 6 additions & 2 deletions src/mode/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class Modal extends Shared {
window.redshift = new ModalApi(
this.attachToWebpage.bind(this),
this.removeFromWebpage.bind(this),
this.initializeXDomainMessaging.bind(this),
this.initializeModalXDomainMessaging.bind(this),
);
}

Expand Down Expand Up @@ -62,13 +62,17 @@ export class Modal extends Shared {
/**
* Initialize cross-domain messaging, which includes
* the close modal method.
* @param invoice An optional invoice to pass to the widget (for pre-populating invoice input)
*/
public initializeXDomainMessaging() {
public initializeModalXDomainMessaging(invoice?: string) {
super.initializeXDomainMessaging({
closeModal: () => {
this.removeFromWebpage();
return true;
},
getInvoice: () => {
return invoice;
},
});
}
}
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface WidgetOptions {
brandColor?: string; // Default: #262525
brandImageUrl?: string; // Default: REDSHIFT Image
containerId?: string; // The id of the container that the widget will be attached to. Default: body
invoice?: string; // an optional invoice to pass to the widget. Used for pre-populating the invoice input.
}

/**
Expand Down

0 comments on commit e5c52fa

Please sign in to comment.