|
@ -0,0 +1,717 @@
|
|
1
|
<!DOCTYPE html>
|
|
2
|
<html>
|
|
3
|
|
|
4
|
<head>
|
|
5
|
<meta charset="utf-8">
|
|
6
|
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
|
|
7
|
<title></title>
|
|
8
|
<link href="../css/mui.min.css" rel="stylesheet" />
|
|
9
|
<link rel="stylesheet" type="text/css" href="../css/app.css" />
|
|
10
|
<link href="../css/mui.imageviewer.css" rel="stylesheet" />
|
|
11
|
<style>
|
|
12
|
html,
|
|
13
|
body {
|
|
14
|
height: 100%;
|
|
15
|
margin: 0px;
|
|
16
|
padding: 0px;
|
|
17
|
overflow: hidden;
|
|
18
|
-webkit-touch-callout: none;
|
|
19
|
-webkit-user-select: none;
|
|
20
|
}
|
|
21
|
footer {
|
|
22
|
position: fixed;
|
|
23
|
width: 100%;
|
|
24
|
height: 50px;
|
|
25
|
min-height: 50px;
|
|
26
|
border-top: solid 1px #bbb;
|
|
27
|
left: 0px;
|
|
28
|
bottom: 0px;
|
|
29
|
overflow: hidden;
|
|
30
|
padding: 0px 50px 0px 10px;
|
|
31
|
background-color: #fafafa;
|
|
32
|
}
|
|
33
|
.footer-left {
|
|
34
|
position: absolute;
|
|
35
|
width: 50px;
|
|
36
|
height: 50px;
|
|
37
|
left: 0px;
|
|
38
|
bottom: 0px;
|
|
39
|
text-align: center;
|
|
40
|
vertical-align: middle;
|
|
41
|
line-height: 100%;
|
|
42
|
padding: 12px 4px;
|
|
43
|
display:none;
|
|
44
|
}
|
|
45
|
.footer-right {
|
|
46
|
position: absolute;
|
|
47
|
width: 50px;
|
|
48
|
height: 50px;
|
|
49
|
right: 0px;
|
|
50
|
bottom: 0px;
|
|
51
|
text-align: center;
|
|
52
|
vertical-align: middle;
|
|
53
|
line-height: 100%;
|
|
54
|
padding: 12px 5px;
|
|
55
|
display: inline-block;
|
|
56
|
}
|
|
57
|
.footer-center {
|
|
58
|
height: 100%;
|
|
59
|
padding: 5px 0px;
|
|
60
|
}
|
|
61
|
.footer-center [class*=input] {
|
|
62
|
width: 100%;
|
|
63
|
height: 100%;
|
|
64
|
border-radius: 5px;
|
|
65
|
}
|
|
66
|
.footer-center .input-text {
|
|
67
|
background: #fff;
|
|
68
|
border: solid 1px #ddd;
|
|
69
|
padding: 10px !important;
|
|
70
|
font-size: 16px !important;
|
|
71
|
line-height: 18px !important;
|
|
72
|
font-family: verdana !important;
|
|
73
|
overflow: hidden;
|
|
74
|
}
|
|
75
|
.footer-center .input-sound {
|
|
76
|
background-color: #eee;
|
|
77
|
}
|
|
78
|
.mui-content {
|
|
79
|
height: 100%;
|
|
80
|
padding: 44px 0px 50px 0px;
|
|
81
|
overflow: auto;
|
|
82
|
background-color: #eaeaea;
|
|
83
|
}
|
|
84
|
#msg-list {
|
|
85
|
height: 100%;
|
|
86
|
overflow: auto;
|
|
87
|
-webkit-overflow-scrolling: touch;
|
|
88
|
}
|
|
89
|
.msg-item {
|
|
90
|
padding: 8px;
|
|
91
|
clear: both;
|
|
92
|
}
|
|
93
|
.msg-item .mui-item-clear {
|
|
94
|
clear: both;
|
|
95
|
}
|
|
96
|
.msg-item .msg-user {
|
|
97
|
width: 38px;
|
|
98
|
height: 38px;
|
|
99
|
border: solid 1px #d3d3d3;
|
|
100
|
display: inline-block;
|
|
101
|
background: #fff;
|
|
102
|
border-radius: 3px;
|
|
103
|
vertical-align: top;
|
|
104
|
text-align: center;
|
|
105
|
float: left;
|
|
106
|
padding: 3px;
|
|
107
|
color: #ddd;
|
|
108
|
}
|
|
109
|
|
|
110
|
.msg-item .msg-user-img{
|
|
111
|
width: 38px;
|
|
112
|
height: 38px;
|
|
113
|
display: inline-block;
|
|
114
|
border-radius: 3px;
|
|
115
|
vertical-align: top;
|
|
116
|
text-align: center;
|
|
117
|
float: left;
|
|
118
|
color: #ddd;
|
|
119
|
}
|
|
120
|
|
|
121
|
.msg-item .msg-content {
|
|
122
|
display: inline-block;
|
|
123
|
border-radius: 5px;
|
|
124
|
border: solid 1px #d3d3d3;
|
|
125
|
background-color: #FFFFFF;
|
|
126
|
color: #333;
|
|
127
|
padding: 8px;
|
|
128
|
vertical-align: top;
|
|
129
|
font-size: 15px;
|
|
130
|
position: relative;
|
|
131
|
margin: 0px 8px;
|
|
132
|
max-width: 75%;
|
|
133
|
min-width: 35px;
|
|
134
|
float: left;
|
|
135
|
}
|
|
136
|
.msg-item .msg-content .msg-content-inner {
|
|
137
|
overflow-x: hidden;
|
|
138
|
}
|
|
139
|
.msg-item .msg-content .msg-content-arrow {
|
|
140
|
position: absolute;
|
|
141
|
border: solid 1px #d3d3d3;
|
|
142
|
border-right: none;
|
|
143
|
border-top: none;
|
|
144
|
background-color: #FFFFFF;
|
|
145
|
width: 10px;
|
|
146
|
height: 10px;
|
|
147
|
left: -5px;
|
|
148
|
top: 12px;
|
|
149
|
-webkit-transform: rotateZ(45deg);
|
|
150
|
transform: rotateZ(45deg);
|
|
151
|
}
|
|
152
|
.msg-item-self .msg-user,
|
|
153
|
.msg-item-self .msg-content {
|
|
154
|
float: right;
|
|
155
|
}
|
|
156
|
.msg-item-self .msg-content .msg-content-arrow {
|
|
157
|
left: auto;
|
|
158
|
right: -5px;
|
|
159
|
-webkit-transform: rotateZ(225deg);
|
|
160
|
transform: rotateZ(225deg);
|
|
161
|
}
|
|
162
|
.msg-item-self .msg-content,
|
|
163
|
.msg-item-self .msg-content .msg-content-arrow {
|
|
164
|
background-color: #4CD964;
|
|
165
|
color: #fff;
|
|
166
|
border-color: #2AC845;
|
|
167
|
}
|
|
168
|
footer .mui-icon {
|
|
169
|
color: #000;
|
|
170
|
}
|
|
171
|
footer .mui-icon:active {
|
|
172
|
color: #007AFF !important;
|
|
173
|
}
|
|
174
|
footer .mui-icon-paperplane:before {
|
|
175
|
content: "发送";
|
|
176
|
color:lightgray;
|
|
177
|
}
|
|
178
|
footer .mui-icon-paperplane.addColor:before {
|
|
179
|
content: "发送";
|
|
180
|
color:#ff9900;
|
|
181
|
}
|
|
182
|
footer .mui-icon-paperplane {
|
|
183
|
/*-webkit-transform: rotateZ(45deg);
|
|
184
|
transform: rotateZ(45deg);*/
|
|
185
|
|
|
186
|
font-size: 16px;
|
|
187
|
word-break: keep-all;
|
|
188
|
line-height: 100%;
|
|
189
|
padding-top: 6px;
|
|
190
|
color: rgba(0, 135, 250, 1);
|
|
191
|
}
|
|
192
|
#msg-sound {
|
|
193
|
-webkit-user-select: none !important;
|
|
194
|
user-select: none !important;
|
|
195
|
}
|
|
196
|
.rprogress {
|
|
197
|
position: absolute;
|
|
198
|
left: 50%;
|
|
199
|
top: 50%;
|
|
200
|
width: 140px;
|
|
201
|
height: 140px;
|
|
202
|
margin-left: -70px;
|
|
203
|
margin-top: -70px;
|
|
204
|
background-image: url(../images/arecord.png);
|
|
205
|
background-repeat: no-repeat;
|
|
206
|
background-position: center center;
|
|
207
|
background-size: 30px 30px;
|
|
208
|
background-color: rgba(0, 0, 0, 0.7);
|
|
209
|
border-radius: 5px;
|
|
210
|
display: none;
|
|
211
|
-webkit-transition: .15s;
|
|
212
|
}
|
|
213
|
.rschedule {
|
|
214
|
background-color: rgba(0, 0, 0, 0);
|
|
215
|
border: 5px solid rgba(0, 183, 229, 0.9);
|
|
216
|
opacity: .9;
|
|
217
|
border-left: 5px solid rgba(0, 0, 0, 0);
|
|
218
|
border-right: 5px solid rgba(0, 0, 0, 0);
|
|
219
|
border-radius: 50px;
|
|
220
|
box-shadow: 0 0 15px #2187e7;
|
|
221
|
width: 46px;
|
|
222
|
height: 46px;
|
|
223
|
position: absolute;
|
|
224
|
left: 50%;
|
|
225
|
top: 50%;
|
|
226
|
margin-left: -23px;
|
|
227
|
margin-top: -23px;
|
|
228
|
-webkit-animation: spin 1s infinite linear;
|
|
229
|
animation: spin 1s infinite linear;
|
|
230
|
}
|
|
231
|
.r-sigh{
|
|
232
|
display: none;
|
|
233
|
border-radius: 50px;
|
|
234
|
box-shadow: 0 0 15px #2187e7;
|
|
235
|
width: 46px;
|
|
236
|
height: 46px;
|
|
237
|
position: absolute;
|
|
238
|
left: 50%;
|
|
239
|
top: 50%;
|
|
240
|
margin-left: -23px;
|
|
241
|
margin-top: -23px;
|
|
242
|
text-align: center;
|
|
243
|
line-height: 46px;
|
|
244
|
font-size: 40px;
|
|
245
|
font-weight: bold;
|
|
246
|
color: #2187e7;
|
|
247
|
}
|
|
248
|
.rprogress-sigh{
|
|
249
|
background-image: none !important;
|
|
250
|
}
|
|
251
|
.rprogress-sigh .rschedule{
|
|
252
|
display: none !important;
|
|
253
|
}
|
|
254
|
.rprogress-sigh .r-sigh{
|
|
255
|
display: block !important;
|
|
256
|
}
|
|
257
|
.rsalert {
|
|
258
|
font-size: 12px;
|
|
259
|
color: #bbb;
|
|
260
|
text-align: center;
|
|
261
|
position: absolute;
|
|
262
|
border-radius: 5px;
|
|
263
|
width: 130px;
|
|
264
|
margin: 5px 5px;
|
|
265
|
padding: 5px;
|
|
266
|
left: 0px;
|
|
267
|
bottom: 0px;
|
|
268
|
}
|
|
269
|
@-webkit-keyframes spin {
|
|
270
|
0% {
|
|
271
|
-webkit-transform: rotate(0deg);
|
|
272
|
}
|
|
273
|
100% {
|
|
274
|
-webkit-transform: rotate(360deg);
|
|
275
|
}
|
|
276
|
}
|
|
277
|
@keyframes spin {
|
|
278
|
0% {
|
|
279
|
transform: rotate(0deg);
|
|
280
|
}
|
|
281
|
100% {
|
|
282
|
transform: rotate(360deg);
|
|
283
|
}
|
|
284
|
}
|
|
285
|
#h {
|
|
286
|
background: #fff;
|
|
287
|
border: solid 1px #ddd;
|
|
288
|
padding: 10px !important;
|
|
289
|
font-size: 16px !important;
|
|
290
|
font-family: verdana !important;
|
|
291
|
line-height: 18px !important;
|
|
292
|
overflow: visible;
|
|
293
|
position: absolute;
|
|
294
|
left: -1000px;
|
|
295
|
right: 0px;
|
|
296
|
word-break: break-all;
|
|
297
|
word-wrap: break-word;
|
|
298
|
}
|
|
299
|
.cancel {
|
|
300
|
background-color: darkred;
|
|
301
|
}
|
|
302
|
</style>
|
|
303
|
</head>
|
|
304
|
|
|
305
|
<body contextmenu="return false;">
|
|
306
|
<header class="mui-bar mui-bar-nav toptitbox" style="z-index: 999;">
|
|
307
|
<span class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left topback" id="backBtn">
|
|
308
|
<a href="consultlist.html"></a>
|
|
309
|
</span>
|
|
310
|
<h1 class="mui-title toptit" id="chatName">
|
|
311
|
|
|
312
|
</h1>
|
|
313
|
<!--<span class="mui-icon mui-icon-contact mui-pull-right personhead"></span>-->
|
|
314
|
</header>
|
|
315
|
<pre id='h'></pre>
|
|
316
|
<script id='msg-template' type="text/template">
|
|
317
|
<% for(var i in record){ var item=record[i]; %>
|
|
318
|
<div class="msg-item <%= (item.sender=='self'?' msg-item-self':'') %>" msg-type='<%=(item.type)%>' msg-content='<%=(item.content)%>'>
|
|
319
|
<div style="text-align:center;margin-bottom:5px;"><span style="font-size:12px;border-radius: 5px;background:#d4d4d4;color:white;padding:2px 7px;">5月8号 18:00</span></div>
|
|
320
|
<% if(item.sender=='self' ) { %>
|
|
321
|
<img class="msg-user-img msg-user" src="../images/logo.png" alt="" style="border-radius:50%;"/>
|
|
322
|
<!--<i class="msg-user mui-icon mui-icon-person" style="border-radius:50%;" id="hu"></i>-->
|
|
323
|
<% } else { %>
|
|
324
|
<img class="msg-user-img" src="../images/logo.png" alt="" style="border-radius:50%;"/>
|
|
325
|
<% } %>
|
|
326
|
<div class="msg-content">
|
|
327
|
<div class="msg-content-inner">
|
|
328
|
<% if(item.type=='text' ) { %>
|
|
329
|
<%=( item.content|| ' ') %>
|
|
330
|
<% } else if(item.type=='image' ) { %>
|
|
331
|
<img class="msg-content-image" src="<%=(item.content)%>" style="max-width: 100px;" />
|
|
332
|
<% } else if(item.type=='sound' ) { %>
|
|
333
|
<span class="mui-icon mui-icon-mic" style="font-size: 18px;font-weight: bold;"></span>
|
|
334
|
<span class="play-state">点击播放</span>
|
|
335
|
<% } %>
|
|
336
|
</div>
|
|
337
|
<div class="msg-content-arrow"></div>
|
|
338
|
</div>
|
|
339
|
<div class="mui-item-clear"></div>
|
|
340
|
</div>
|
|
341
|
<% } %>
|
|
342
|
</script>
|
|
343
|
<div class="mui-content">
|
|
344
|
<div id='msg-list'>
|
|
345
|
</div>
|
|
346
|
</div>
|
|
347
|
<footer>
|
|
348
|
<div class="footer-left">
|
|
349
|
<i id='msg-image' class="mui-icon mui-icon-camera" style="font-size: 28px;"></i>
|
|
350
|
</div>
|
|
351
|
<div class="footer-center">
|
|
352
|
<textarea id='msg-text' type="text" class='input-text'></textarea>
|
|
353
|
<button id='msg-sound' type="button" class='input-sound' style="display: none;">按住说话</button>
|
|
354
|
</div>
|
|
355
|
<label for="" class="footer-right">
|
|
356
|
<i id='msg-type' class="mui-icon mui-icon-mic mui-icon-paperplane"></i>
|
|
357
|
</label>
|
|
358
|
</footer>
|
|
359
|
<div id='sound-alert' class="rprogress">
|
|
360
|
<div class="rschedule"></div>
|
|
361
|
<div class="r-sigh">!</div>
|
|
362
|
<div id="audio_tips" class="rsalert">手指上滑,取消发送</div>
|
|
363
|
</div>
|
|
364
|
<script src="../js/mui.min.js"></script>
|
|
365
|
<script src="../js/mui.imageViewer.js"></script>
|
|
366
|
<script>
|
|
367
|
console.log(document.getElementById("hu"));
|
|
368
|
</script>
|
|
369
|
<script src="../js/arttmpl.js"></script>
|
|
370
|
<script type="text/javascript" charset="utf-8">
|
|
371
|
(function($, doc) {
|
|
372
|
var MIN_SOUND_TIME = 800;
|
|
373
|
$.init({
|
|
374
|
gestureConfig: {
|
|
375
|
tap: true, //默认为true
|
|
376
|
doubletap: true, //默认为false
|
|
377
|
longtap: true, //默认为false
|
|
378
|
swipe: true, //默认为true
|
|
379
|
drag: true, //默认为true
|
|
380
|
hold: true, //默认为false,不监听
|
|
381
|
release: true //默认为false,不监听
|
|
382
|
}
|
|
383
|
});
|
|
384
|
template.config('escape', false);
|
|
385
|
//$.plusReady=function(fn){fn();};
|
|
386
|
$.plusReady(function() {
|
|
387
|
plus.webview.currentWebview().setStyle({
|
|
388
|
softinputMode: "adjustResize"
|
|
389
|
});
|
|
390
|
|
|
391
|
var showKeyboard = function() {
|
|
392
|
if ($.os.ios) {
|
|
393
|
var webView = plus.webview.currentWebview().nativeInstanceObject();
|
|
394
|
webView.plusCallMethod({
|
|
395
|
"setKeyboardDisplayRequiresUserAction": false
|
|
396
|
});
|
|
397
|
} else {
|
|
398
|
var Context = plus.android.importClass("android.content.Context");
|
|
399
|
var InputMethodManager = plus.android.importClass("android.view.inputmethod.InputMethodManager");
|
|
400
|
var main = plus.android.runtimeMainActivity();
|
|
401
|
var imm = main.getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
402
|
imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
|
|
403
|
//var view = ((ViewGroup)main.findViewById(android.R.id.content)).getChildAt(0);
|
|
404
|
imm.showSoftInput(main.getWindow().getDecorView(), InputMethodManager.SHOW_IMPLICIT);
|
|
405
|
//alert("ll");
|
|
406
|
}
|
|
407
|
};
|
|
408
|
var record = [{
|
|
409
|
sender: 'zs',
|
|
410
|
type: 'text',
|
|
411
|
content: 'Hi,我是 MUI 小管家!'
|
|
412
|
}];//消息数组
|
|
413
|
var ui = {
|
|
414
|
body: doc.querySelector('body'),
|
|
415
|
footer: doc.querySelector('footer'),
|
|
416
|
footerRight: doc.querySelector('.footer-right'),
|
|
417
|
footerLeft: doc.querySelector('.footer-left'),
|
|
418
|
btnMsgType: doc.querySelector('#msg-type'),//
|
|
419
|
boxMsgText: doc.querySelector('#msg-text'),
|
|
420
|
boxMsgSound: doc.querySelector('#msg-sound'),
|
|
421
|
btnMsgImage: doc.querySelector('#msg-image'),
|
|
422
|
areaMsgList: doc.querySelector('#msg-list'),
|
|
423
|
boxSoundAlert: doc.querySelector('#sound-alert'),
|
|
424
|
h: doc.querySelector('#h'),
|
|
425
|
content: doc.querySelector('.mui-content')
|
|
426
|
};
|
|
427
|
ui.h.style.width = ui.boxMsgText.offsetWidth + 'px';
|
|
428
|
//alert(ui.boxMsgText.offsetWidth );
|
|
429
|
var footerPadding = ui.footer.offsetHeight - ui.boxMsgText.offsetHeight;
|
|
430
|
var msgItemTap = function(msgItem, event) {
|
|
431
|
var msgType = msgItem.getAttribute('msg-type');
|
|
432
|
var msgContent = msgItem.getAttribute('msg-content')
|
|
433
|
if (msgType == 'sound') {
|
|
434
|
player = plus.audio.createPlayer(msgContent);
|
|
435
|
var playState = msgItem.querySelector('.play-state');
|
|
436
|
playState.innerText = '正在播放...';
|
|
437
|
player.play(function() {
|
|
438
|
playState.innerText = '点击播放';
|
|
439
|
}, function(e) {
|
|
440
|
playState.innerText = '点击播放';
|
|
441
|
});
|
|
442
|
}
|
|
443
|
};
|
|
444
|
var imageViewer = new $.ImageViewer('.msg-content-image', {
|
|
445
|
dbl: false
|
|
446
|
});
|
|
447
|
var bindMsgList = function() {
|
|
448
|
//绑定数据:
|
|
449
|
/*tp.bind({
|
|
450
|
template: 'msg-template',
|
|
451
|
element: 'msg-list',
|
|
452
|
model: record
|
|
453
|
});*/
|
|
454
|
ui.areaMsgList.innerHTML = template('msg-template', {
|
|
455
|
"record": record
|
|
456
|
});
|
|
457
|
var msgItems = ui.areaMsgList.querySelectorAll('.msg-item');
|
|
458
|
[].forEach.call(msgItems, function(item, index) {
|
|
459
|
item.addEventListener('tap', function(event) {
|
|
460
|
msgItemTap(item, event);
|
|
461
|
}, false);
|
|
462
|
});
|
|
463
|
imageViewer.findAllImage();
|
|
464
|
ui.areaMsgList.scrollTop = ui.areaMsgList.scrollHeight + ui.areaMsgList.offsetHeight;
|
|
465
|
};
|
|
466
|
bindMsgList();
|
|
467
|
window.addEventListener('resize', function() {
|
|
468
|
ui.areaMsgList.scrollTop = ui.areaMsgList.scrollHeight + ui.areaMsgList.offsetHeight;
|
|
469
|
}, false);
|
|
470
|
var send = function(msg) {
|
|
471
|
record.push(msg);
|
|
472
|
bindMsgList();
|
|
473
|
toRobot(msg.content);
|
|
474
|
};
|
|
475
|
var toRobot = function(info) {
|
|
476
|
var apiUrl = 'http://www.tuling123.com/openapi/api';
|
|
477
|
$.getJSON(apiUrl, {
|
|
478
|
"key": 'acfbca724ea1b5db96d2eef88ce677dc',
|
|
479
|
"info": info,
|
|
480
|
"userid": plus.device.uuid
|
|
481
|
}, function(data) {
|
|
482
|
alert(JSON.stringify(data));
|
|
483
|
record.push({
|
|
484
|
sender: 'zs',
|
|
485
|
type: 'text',
|
|
486
|
content: data.text
|
|
487
|
});
|
|
488
|
bindMsgList();
|
|
489
|
});
|
|
490
|
};
|
|
491
|
|
|
492
|
function msgTextFocus() {
|
|
493
|
ui.boxMsgText.focus();
|
|
494
|
setTimeout(function() {
|
|
495
|
ui.boxMsgText.focus();
|
|
496
|
}, 150);
|
|
497
|
}
|
|
498
|
//解决长按“发送”按钮,导致键盘关闭的问题;
|
|
499
|
ui.footerRight.addEventListener('touchstart', function(event) {
|
|
500
|
if (ui.btnMsgType.classList.contains('mui-icon-paperplane')) {
|
|
501
|
msgTextFocus();
|
|
502
|
event.preventDefault();
|
|
503
|
}
|
|
504
|
});
|
|
505
|
//解决长按“发送”按钮,导致键盘关闭的问题;
|
|
506
|
ui.footerRight.addEventListener('touchmove', function(event) {
|
|
507
|
if (ui.btnMsgType.classList.contains('mui-icon-paperplane')) {
|
|
508
|
msgTextFocus();
|
|
509
|
event.preventDefault();
|
|
510
|
}
|
|
511
|
});
|
|
512
|
// ui.footerRight.addEventListener('touchcancel', function(event) {
|
|
513
|
// if (ui.btnMsgType.classList.contains('mui-icon-paperplane')) {
|
|
514
|
// msgTextFocus();
|
|
515
|
// event.preventDefault();
|
|
516
|
// }
|
|
517
|
// });
|
|
518
|
// ui.footerRight.addEventListener('touchend', function(event) {
|
|
519
|
// if (ui.btnMsgType.classList.contains('mui-icon-paperplane')) {
|
|
520
|
// msgTextFocus();
|
|
521
|
// event.preventDefault();
|
|
522
|
// }
|
|
523
|
// });
|
|
524
|
ui.footerRight.addEventListener('release', function(event) {
|
|
525
|
if (ui.btnMsgType.classList.contains('mui-icon-paperplane')) {
|
|
526
|
if(!ui.btnMsgType.classList.contains('addColor')) {
|
|
527
|
return;
|
|
528
|
}
|
|
529
|
//showKeyboard();
|
|
530
|
ui.boxMsgText.focus();
|
|
531
|
setTimeout(function() {
|
|
532
|
ui.boxMsgText.focus();
|
|
533
|
}, 150);
|
|
534
|
// event.detail.gesture.preventDefault();
|
|
535
|
send({
|
|
536
|
sender: 'self',
|
|
537
|
type: 'text',
|
|
538
|
content: ui.boxMsgText.value.replace(new RegExp('\n', 'gm'), '<br/>')
|
|
539
|
});
|
|
540
|
ui.boxMsgText.value = '';
|
|
541
|
$.trigger(ui.boxMsgText, 'input', null);
|
|
542
|
} else if (ui.btnMsgType.classList.contains('mui-icon-mic')) {
|
|
543
|
ui.btnMsgType.classList.add('mui-icon-compose');
|
|
544
|
ui.btnMsgType.classList.remove('mui-icon-mic');
|
|
545
|
ui.boxMsgText.style.display = 'none';
|
|
546
|
ui.boxMsgSound.style.display = 'block';
|
|
547
|
ui.boxMsgText.blur();
|
|
548
|
document.body.focus();
|
|
549
|
} else if (ui.btnMsgType.classList.contains('mui-icon-compose')) {
|
|
550
|
ui.btnMsgType.classList.add('mui-icon-mic');
|
|
551
|
ui.btnMsgType.classList.remove('mui-icon-compose');
|
|
552
|
ui.boxMsgSound.style.display = 'none';
|
|
553
|
ui.boxMsgText.style.display = 'block';
|
|
554
|
//--
|
|
555
|
//showKeyboard();
|
|
556
|
ui.boxMsgText.focus();
|
|
557
|
setTimeout(function() {
|
|
558
|
ui.boxMsgText.focus();
|
|
559
|
}, 150);
|
|
560
|
}
|
|
561
|
}, false);
|
|
562
|
ui.footerLeft.addEventListener('tap', function(event) {
|
|
563
|
var btnArray = [{
|
|
564
|
title: "拍照"
|
|
565
|
}, {
|
|
566
|
title: "从相册选择"
|
|
567
|
}];
|
|
568
|
plus.nativeUI.actionSheet({
|
|
569
|
title: "选择照片",
|
|
570
|
cancel: "取消",
|
|
571
|
buttons: btnArray
|
|
572
|
}, function(e) {
|
|
573
|
var index = e.index;
|
|
574
|
switch (index) {
|
|
575
|
case 0:
|
|
576
|
break;
|
|
577
|
case 1:
|
|
578
|
var cmr = plus.camera.getCamera();
|
|
579
|
cmr.captureImage(function(path) {
|
|
580
|
send({
|
|
581
|
sender: 'self',
|
|
582
|
type: 'image',
|
|
583
|
content: "file://" + plus.io.convertLocalFileSystemURL(path)
|
|
584
|
});
|
|
585
|
}, function(err) {});
|
|
586
|
break;
|
|
587
|
case 2:
|
|
588
|
plus.gallery.pick(function(path) {
|
|
589
|
send({
|
|
590
|
sender: 'self',
|
|
591
|
type: 'image',
|
|
592
|
content: path
|
|
593
|
});
|
|
594
|
}, function(err) {}, null);
|
|
595
|
break;
|
|
596
|
}
|
|
597
|
});
|
|
598
|
}, false);
|
|
599
|
var setSoundAlertVisable=function(show){
|
|
600
|
if(show){
|
|
601
|
ui.boxSoundAlert.style.display = 'block';
|
|
602
|
ui.boxSoundAlert.style.opacity = 1;
|
|
603
|
}else{
|
|
604
|
ui.boxSoundAlert.style.opacity = 0;
|
|
605
|
//fadeOut 完成再真正隐藏
|
|
606
|
setTimeout(function(){
|
|
607
|
ui.boxSoundAlert.style.display = 'none';
|
|
608
|
},200);
|
|
609
|
}
|
|
610
|
};
|
|
611
|
var recordCancel = false;
|
|
612
|
var recorder = null;
|
|
613
|
var audio_tips = document.getElementById("audio_tips");
|
|
614
|
var startTimestamp = null;
|
|
615
|
var stopTimestamp = null;
|
|
616
|
var stopTimer = null;
|
|
617
|
ui.boxMsgSound.addEventListener('hold', function(event) {
|
|
618
|
recordCancel = false;
|
|
619
|
if(stopTimer)clearTimeout(stopTimer);
|
|
620
|
audio_tips.innerHTML = "手指上划,取消发送";
|
|
621
|
ui.boxSoundAlert.classList.remove('rprogress-sigh');
|
|
622
|
setSoundAlertVisable(true);
|
|
623
|
recorder = plus.audio.getRecorder();
|
|
624
|
if (recorder == null) {
|
|
625
|
plus.nativeUI.toast("不能获取录音对象");
|
|
626
|
return;
|
|
627
|
}
|
|
628
|
startTimestamp = (new Date()).getTime();
|
|
629
|
recorder.record({
|
|
630
|
filename: "_doc/audio/"
|
|
631
|
}, function(path) {
|
|
632
|
if (recordCancel) return;
|
|
633
|
send({
|
|
634
|
sender: 'self',
|
|
635
|
type: 'sound',
|
|
636
|
content: path
|
|
637
|
});
|
|
638
|
}, function(e) {
|
|
639
|
plus.nativeUI.toast("录音时出现异常: " + e.message);
|
|
640
|
});
|
|
641
|
}, false);
|
|
642
|
ui.body.addEventListener('drag', function(event) {
|
|
643
|
//console.log('drag');
|
|
644
|
if (Math.abs(event.detail.deltaY) > 50) {
|
|
645
|
if (!recordCancel) {
|
|
646
|
recordCancel = true;
|
|
647
|
if (!audio_tips.classList.contains("cancel")) {
|
|
648
|
audio_tips.classList.add("cancel");
|
|
649
|
}
|
|
650
|
audio_tips.innerHTML = "松开手指,取消发送";
|
|
651
|
}
|
|
652
|
} else {
|
|
653
|
if (recordCancel) {
|
|
654
|
recordCancel = false;
|
|
655
|
if (audio_tips.classList.contains("cancel")) {
|
|
656
|
audio_tips.classList.remove("cancel");
|
|
657
|
}
|
|
658
|
audio_tips.innerHTML = "手指上划,取消发送";
|
|
659
|
}
|
|
660
|
}
|
|
661
|
}, false);
|
|
662
|
ui.boxMsgSound.addEventListener('release', function(event) {
|
|
663
|
//console.log('release');
|
|
664
|
if (audio_tips.classList.contains("cancel")) {
|
|
665
|
audio_tips.classList.remove("cancel");
|
|
666
|
audio_tips.innerHTML = "手指上划,取消发送";
|
|
667
|
}
|
|
668
|
//
|
|
669
|
stopTimestamp = (new Date()).getTime();
|
|
670
|
if (stopTimestamp - startTimestamp < MIN_SOUND_TIME) {
|
|
671
|
audio_tips.innerHTML = "录音时间太短";
|
|
672
|
ui.boxSoundAlert.classList.add('rprogress-sigh');
|
|
673
|
recordCancel = true;
|
|
674
|
stopTimer=setTimeout(function(){
|
|
675
|
setSoundAlertVisable(false);
|
|
676
|
},800);
|
|
677
|
}else{
|
|
678
|
setSoundAlertVisable(false);
|
|
679
|
}
|
|
680
|
recorder.stop();
|
|
681
|
}, false);
|
|
682
|
ui.boxMsgSound.addEventListener("touchstart", function(e) {
|
|
683
|
//console.log("start....");
|
|
684
|
e.preventDefault();
|
|
685
|
});
|
|
686
|
ui.boxMsgText.addEventListener('input', function(event) {
|
|
687
|
ui.btnMsgType.classList[ui.boxMsgText.value == '' ? 'remove' : 'add']('addColor');
|
|
688
|
ui.btnMsgType.setAttribute("for", ui.boxMsgText.value == '' ? '' : 'msg-text');
|
|
689
|
ui.h.innerText = ui.boxMsgText.value.replace(new RegExp('\n', 'gm'), '\n-') || '-';
|
|
690
|
ui.footer.style.height = (ui.h.offsetHeight + footerPadding) + 'px';
|
|
691
|
ui.content.style.paddingBottom = ui.footer.style.height;
|
|
692
|
});
|
|
693
|
var focus = false;
|
|
694
|
ui.boxMsgText.addEventListener('tap', function(event) {
|
|
695
|
ui.boxMsgText.focus();
|
|
696
|
setTimeout(function() {
|
|
697
|
ui.boxMsgText.focus();
|
|
698
|
}, 0);
|
|
699
|
focus = true;
|
|
700
|
setTimeout(function () {
|
|
701
|
focus = false;
|
|
702
|
},1000);
|
|
703
|
event.detail.gesture.preventDefault();
|
|
704
|
}, false);
|
|
705
|
//点击消息列表,关闭键盘
|
|
706
|
ui.areaMsgList.addEventListener('click',function (event) {
|
|
707
|
if(!focus){
|
|
708
|
ui.boxMsgText.blur();
|
|
709
|
}
|
|
710
|
})
|
|
711
|
|
|
712
|
});
|
|
713
|
}(mui, document));
|
|
714
|
</script>
|
|
715
|
</body>
|
|
716
|
|
|
717
|
</html>
|