|
| 1 | + |
| 2 | + |
| 3 | +<chat-room-open> |
| 4 | + |
| 5 | + <template shadowrootmode=open> |
| 6 | + |
| 7 | + |
| 8 | + <style> |
| 9 | + |
| 10 | + #input-root |
| 11 | + {height:150px;display:flex;gap:20px;border-top:1px solid lightgray;padding-top:10px} |
| 12 | + |
| 13 | + #txt |
| 14 | + {height:100%;border:1px solid lightgray;border-radius:5px;padding:10px;flex:1;box-sizing:border-box;resize:none;outline:none} |
| 15 | + |
| 16 | + #info |
| 17 | + {display:flex;flex-direction:column;gap:10px} |
| 18 | + |
| 19 | + |
| 20 | + .label |
| 21 | + {display:inline-block;width:100px;text-align:right;margin-right:20px} |
| 22 | + |
| 23 | + [value=send] |
| 24 | + {margin-right:20px;min-width:80px} |
| 25 | + |
| 26 | + #pause |
| 27 | + {min-width:80px} |
| 28 | + |
| 29 | + |
| 30 | + input |
| 31 | + {font-size:16px;padding:5px 10px} |
| 32 | + input[type=button] |
| 33 | + {cursor:pointer} |
| 34 | + input[type=checkbox] |
| 35 | + {width:15px;height:15px;margin:0} |
| 36 | + textarea |
| 37 | + {font-size:16px} |
| 38 | + |
| 39 | + |
| 40 | + .icon |
| 41 | + {border:1px solid gray;border-radius:3px;box-sizing:border-box;width:30px;height:30px;cursor:pointer} |
| 42 | + |
| 43 | + |
| 44 | + </style> |
| 45 | + |
| 46 | + |
| 47 | + <section id=input-root> |
| 48 | + |
| 49 | + <div id=info> |
| 50 | + </div> |
| 51 | + |
| 52 | + <textarea id=txt></textarea> |
| 53 | + |
| 54 | + <div id=btns> |
| 55 | + <input value=send type=button title=ctrl+enter> |
| 56 | + <input id=pause value=pause type=button> |
| 57 | + </div> |
| 58 | + |
| 59 | + </section> |
| 60 | + |
| 61 | + |
| 62 | + </template> |
| 63 | + |
| 64 | + |
| 65 | + <script> |
| 66 | + |
| 67 | +(function({mod,host}){ |
| 68 | + |
| 69 | + var obj = {}; |
| 70 | + |
| 71 | + var df=true,did='chat-room-open'; |
| 72 | + |
| 73 | + |
| 74 | + var debug,$,post,poll |
| 75 | + ; |
| 76 | + |
| 77 | + obj.initmod = function(params){ |
| 78 | + |
| 79 | + debug = mod.rd(params,'debug',debug); |
| 80 | + $ = mod.rd(params,'$',$); |
| 81 | + post = mod.rd(params,'post',post); |
| 82 | + poll = mod.rd(params,'poll',poll); |
| 83 | + |
| 84 | + }//initmod |
| 85 | + |
| 86 | + |
| 87 | + //: |
| 88 | + |
| 89 | + |
| 90 | + var shadow; |
| 91 | + |
| 92 | + var ui = {}; |
| 93 | + |
| 94 | + |
| 95 | + Object.defineProperty(obj,'username',{get:()=>$(shadow,'#username').value}); |
| 96 | + Object.defineProperty(obj,'password',{get:()=>$(shadow,'#password').value}); |
| 97 | + |
| 98 | + |
| 99 | + var btn = {}; |
| 100 | + var kd = {}; |
| 101 | + |
| 102 | + //: |
| 103 | + |
| 104 | + |
| 105 | + obj.init = async function(){ |
| 106 | + debug=eval(debug.mod); |
| 107 | + debug('init'); |
| 108 | + }//init |
| 109 | + |
| 110 | + |
| 111 | + //: |
| 112 | + |
| 113 | + |
| 114 | + obj.initdom = async function(){ |
| 115 | + debug('initdom'); |
| 116 | + shadow = host.shadowRoot; |
| 117 | + |
| 118 | + var info = $(shadow,'#info'); |
| 119 | + $(info,'#show').onclick = btn.password; |
| 120 | + |
| 121 | + $(shadow,'#txt').onkeydown = kd.user; |
| 122 | + $(shadow,'#txt').focus(); |
| 123 | + |
| 124 | + $(shadow,'[value=send]').onclick = btn.send; |
| 125 | + ui.pause = $(shadow,'[value=pause]'); |
| 126 | + ui.pause.onclick = btn.pause; |
| 127 | + |
| 128 | + |
| 129 | + }//initdom |
| 130 | + |
| 131 | + |
| 132 | + //: |
| 133 | + |
| 134 | + |
| 135 | + btn.password = function(){ |
| 136 | + |
| 137 | + $(shadow,'#txt').focus(); |
| 138 | + |
| 139 | + var node = $(shadow,'#password'); |
| 140 | + if(node.getAttribute('type')=='password'){ |
| 141 | + node.removeAttribute('type'); |
| 142 | + }else{ |
| 143 | + node.setAttribute('type','password'); |
| 144 | + } |
| 145 | + |
| 146 | + }//password |
| 147 | + |
| 148 | + |
| 149 | + kd.user = function(e){ |
| 150 | + //console.log(e.ctrlKey,e.key); |
| 151 | + if(e.ctrlKey && e.key=='Enter'){ |
| 152 | + btn.send(); |
| 153 | + } |
| 154 | + if(e.ctrlKey && e.key==' '){ |
| 155 | + btn.pause(); |
| 156 | + } |
| 157 | + |
| 158 | + }//user |
| 159 | + |
| 160 | + |
| 161 | + btn.send = function(){ |
| 162 | + |
| 163 | + $(shadow,'#txt').focus(); |
| 164 | + |
| 165 | + var txt = $(shadow,'#txt').value; |
| 166 | + $(shadow,'#txt').value = ''; |
| 167 | + var username = $(shadow,'#username').value; |
| 168 | + var password = $(shadow,'#password').value; |
| 169 | + |
| 170 | + post.msg({username,password,txt}); |
| 171 | + |
| 172 | + }//send |
| 173 | + |
| 174 | + |
| 175 | + btn.pause = function(){ |
| 176 | + |
| 177 | + $(shadow,'#txt').focus(); |
| 178 | + |
| 179 | + if(poll.abort){ |
| 180 | + ui.pause.value = 'pause'; |
| 181 | + poll.abort = false; |
| 182 | + post.update.initial(); |
| 183 | + }else{ |
| 184 | + ui.pause.value = 'resume'; |
| 185 | + poll.abort = true; |
| 186 | + } |
| 187 | + |
| 188 | + }//pause |
| 189 | + |
| 190 | + |
| 191 | + |
| 192 | + return obj; |
| 193 | + |
| 194 | +//chat-room-open |
| 195 | +}) |
| 196 | + |
| 197 | + |
| 198 | + </script> |
| 199 | + |
| 200 | + |
| 201 | +</chat-room-open> |
| 202 | + |
| 203 | + |
| 204 | + |
0 commit comments