Skip to content

Commit e5c52fa

Browse files
authored
Merge pull request #11 from RadarTech/master
Release v1.1.0
2 parents e942274 + ab6cf37 commit e5c52fa

4 files changed

Lines changed: 25 additions & 8 deletions

File tree

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ redshift.setOptions(options: WidgetOptions)
5252

5353
### Modal
5454

55-
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.
55+
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.
5656

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

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

69+
/**
70+
* Open the widget with invoice pre-populated
71+
*/
72+
redshift.open(invoice)
73+
6974
/**
7075
* Close the widget
7176
*/
@@ -75,6 +80,11 @@ redshift.close()
7580
* Toggle the widget
7681
*/
7782
redshift.toggle()
83+
84+
/**
85+
* Toggle the widget with invoice pre-populated
86+
*/
87+
redshift.toggle(invoice)
7888
```
7989

8090
#### How To

src/api/modal-api.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export class ModalApi extends OptionsApi {
77
private _isOpen: boolean;
88
private _attach: () => void;
99
private _remove: () => void;
10-
private _initMessaging: () => void;
10+
private _initMessaging: (invoice?: string) => void;
1111

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

3131
/**
3232
* Open the widget
33+
* @param invoice An optional invoice to pass to the widget (for pre-populating invoice input)
3334
*/
34-
public open() {
35+
public open(invoice?: string) {
3536
this._attach();
36-
this._initMessaging();
37+
this._initMessaging(invoice);
3738
this._isOpen = true;
3839
}
3940

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

4849
/**
4950
* Toggle the widget
51+
* @param invoice An optional invoice to pass to the widget (for pre-populating invoice input)
5052
*/
51-
public toggle() {
52-
this.isOpen ? this.close() : this.open();
53+
public toggle(invoice?: string) {
54+
this.isOpen ? this.close() : this.open(invoice);
5355
}
5456
}

src/mode/modal.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class Modal extends Shared {
1010
window.redshift = new ModalApi(
1111
this.attachToWebpage.bind(this),
1212
this.removeFromWebpage.bind(this),
13-
this.initializeXDomainMessaging.bind(this),
13+
this.initializeModalXDomainMessaging.bind(this),
1414
);
1515
}
1616

@@ -62,13 +62,17 @@ export class Modal extends Shared {
6262
/**
6363
* Initialize cross-domain messaging, which includes
6464
* the close modal method.
65+
* @param invoice An optional invoice to pass to the widget (for pre-populating invoice input)
6566
*/
66-
public initializeXDomainMessaging() {
67+
public initializeModalXDomainMessaging(invoice?: string) {
6768
super.initializeXDomainMessaging({
6869
closeModal: () => {
6970
this.removeFromWebpage();
7071
return true;
7172
},
73+
getInvoice: () => {
74+
return invoice;
75+
},
7276
});
7377
}
7478
}

src/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface WidgetOptions {
77
brandColor?: string; // Default: #262525
88
brandImageUrl?: string; // Default: REDSHIFT Image
99
containerId?: string; // The id of the container that the widget will be attached to. Default: body
10+
invoice?: string; // an optional invoice to pass to the widget. Used for pre-populating the invoice input.
1011
}
1112

1213
/**

0 commit comments

Comments
 (0)