1
0

im-chat.html 20 KB

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