-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
46 lines (39 loc) · 1.32 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import ScatterJS from 'scatterjs-core';
import ScatterEOS from 'scatterjs-plugin-eosjs';
import Vue from 'vue';
import Main from '@/Main.vue';
ScatterJS.plugins(new ScatterEOS());
const SmartGift = {
DEFAULT_OPTIONS: {
// Required. The selector or instance of target DOM. SmartGift UI will be appended to the DOM.
target: null,
// Required. The unique SmartGift ID.
giftId: null,
// Whether SmartGift should be auto loaded according to `SMART_GIFT_OPTIONS`.
// This is ignored in create().
autoLoad: false,
// When SmartGift ID is not initialized, there will be a button to guide for initialization.
// If this set to false, there will be no such button.
disableGiftCreationGuide: false,
},
create(userOptions = {}) {
const { target, autoLoad, ...options } = { ...SmartGift.DEFAULT_OPTIONS, ...userOptions };
if (!target) {
throw new Error('`target` must be specified.');
}
if (!options.giftId) {
throw new Error('`giftId` must be specified.');
}
const instance = new Vue({
...Main,
el: target,
propsData: { options },
});
return instance;
},
};
export default SmartGift;
// Auto create
if (typeof window === 'object' && window.SMART_GIFT_OPTIONS && window.SMART_GIFT_OPTIONS.autoLoad) {
SmartGift.create(window.SMART_GIFT_OPTIONS);
}