浏览代码

fix last commit bug

Hongcai Deng 9 年之前
父节点
当前提交
e18daa58aa
共有 3 个文件被更改,包括 12 次插入3 次删除
  1. 6 0
      modules/io.js
  2. 4 2
      public/index.html
  3. 2 1
      public/js/app.js

+ 6 - 0
modules/io.js

@@ -29,6 +29,12 @@ module.exports = function(io) {
       onlines.set(socket.shortid, socket); // add incomming connection to online table
       socket.emit('shortid', socket.shortid);
     });
+
+    socket.on('set shortid', function(id) {
+      onlines.delete(socket.shortid);
+      socket.shortid = id;
+      onlines.set(socket.shortid, socket);
+    })
   });
 
   io.on('disconnect', socket => {

+ 4 - 2
public/index.html

@@ -14,8 +14,10 @@
       <img class="logo" src="http://semantic-ui.com/examples/assets/images/logo.png" alt="logo">
       Forsaken Mail
     </div>
-    <div class="ui label item right floated mailaddress">
-      <i class="mail icon copyable"></i>
+    <div class="ui label item right floated mailaddress" style="width: 35%;">
+      <button class="ui icon button">
+        <i class="mail icon copyable"></i>
+      </button>
       <div class="ui icon input">
         <input id="shortid" type="text" placeholder="请等待分配临时邮箱" disabled>
         <i id="refreshShortid" class="circular refresh link icon"></i>

+ 2 - 1
public/js/app.js

@@ -28,7 +28,7 @@ $(function(){
   var setMailAddress = function(id) {
     localStorage.setItem('shortid', id);
     var mailaddress = id + '@' + location.hostname;
-    $('#shortid').val(mailaddress).parent().siblings('i').attr('data-clipboard-text', mailaddress);
+    $('#shortid').val(mailaddress).parent().siblings('button').find('.mail').attr('data-clipboard-text', mailaddress);
   };
 
   if(('localStorage' in window)) {
@@ -37,6 +37,7 @@ $(function(){
       socket.emit('request shortid', true);
     }
     else {
+      socket.emit('set shortid', true);
       setMailAddress(shortid);
     }
   }