-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
170 lines (161 loc) · 6.15 KB
/
index.html
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Paint Sample</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<canvas id="canvas"></canvas>
<button id="btnShare" type="button" class="btn btn-primary">Share</button>
<button id="btnSend" type="button" class="btn btn-info">Send</button>
</div>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/signature_pad.min.js"></script>
<script src="https://static.line-scdn.net/liff/edge/2.1/sdk.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
const canvas = document.querySelector('#canvas');
const signaturePad = new SignaturePad(canvas, {
backgroundColor: 'rgb(238,238,238)',
});
$(window).on('load', function(){
canvas.setAttribute('width', $('.container').width());
canvas.setAttribute('height', window.innerHeight - $('#btnSend').outerHeight() - 10);
signaturePad.clear();
const useNodeJS = true; // if you are not using a node server, set this value to false
const defaultLiffId = ""; // change the default LIFF value if you are not using a node server
// DO NOT CHANGE THIS
let myLiffId = "";
// if node is used, fetch the environment variable and pass it to the LIFF method
// otherwise, pass defaultLiffId
if (useNodeJS) {
fetch('/api/send-id')
.then(function(reqResponse) {
return reqResponse.json();
})
.then(function(jsonResponse) {
myLiffId = jsonResponse.id;
initializeLiff(myLiffId);
})
.catch(function(error) {
alert(err);
});
} else {
myLiffId = defaultLiffId;
initializeLiff(myLiffId);
}
});
/**
* Initialize LIFF
* @param {string} myLiffId The LIFF ID of the selected element
*/
function initializeLiff(myLiffId) {
liff.init({
liffId: myLiffId
})
.then(() => {
if (!liff.isLoggedIn()) {
liff.login();
}
})
.catch((err) => {
alert(err);
});
}
/**
* Alert the user if LIFF is opened in an external browser and unavailable buttons are tapped
*/
function sendAlertIfNotInClient() {
alert('This button is unavailable as LIFF is currently being opened in an external browser.');
}
$('#btnShare').on('click', function() {
const jsonData = {
image: signaturePad.toDataURL('image/jpeg')
}
$.ajax({
type: 'POST',
url: '/api/save',
data: JSON.stringify(jsonData),
contentType: 'application/json',
dataType: "json",
success: function (res, status) {
liff.getProfile().then(function (profile) {
if(liff.isApiAvailable('shareTargetPicker')){
liff.shareTargetPicker([
{
type: 'image',
originalContentUrl: 'https://' + res.accountname + '.blob.core.windows.net/images/' + res.filename,
previewImageUrl: 'https://' + res.accountname + '.blob.core.windows.net/images/' + res.filename
},
{
type: 'text',
text: 'From:' + profile.displayName
}
]).then(function () {
//window.alert("ShareTargetPicker was launched")
}).catch(function (error) {
window.alert("Failed to launch ShareTargetPicker");
});
}else{
window.alert("Failed to launch ShareTargetPicker");
}
}).catch(function (error) {
window.alert("Error getting profile: " + error.message);
});
},
error: function (res) {
window.alert('Error saving image: ' + res.status);
},
complete: function(data) {
}
});
});
$('#btnSend').on('click', function() {
const jsonData = {
image: signaturePad.toDataURL('image/jpeg')
}
$.ajax({
type: 'POST',
url: '/api/save',
data: JSON.stringify(jsonData),
contentType: 'application/json',
dataType: "json",
success: function (res, status) {
liff.getProfile().then(function (profile) {
if (!liff.isInClient()) {
sendAlertIfNotInClient();
} else {
liff.sendMessages([
{
type: 'image',
originalContentUrl: 'https://' + res.accountname + '.blob.core.windows.net/images/' + res.filename,
previewImageUrl: 'https://' + res.accountname + '.blob.core.windows.net/images/' + res.filename
},
{
type: 'text',
text: 'From:' + profile.displayName
}
]).then(function () {
liff.closeWindow();
}).catch(function (error) {
window.alert('Error sending message: ' + error.message);
});
}
}).catch(function (error) {
window.alert("Error getting profile: " + error.message);
});
},
error: function (res) {
window.alert('Error saving image: ' + res.status);
},
complete: function(data) {
}
});
});
</script>
</body>
</html>