Explorar el Código

Input -> Textarea

master
Roderic Day hace 5 años
padre
commit
17145b7d70
Se han modificado 2 ficheros con 23 adiciones y 11 borrados
  1. +7
    -2
      pico.css
  2. +16
    -9
      pico.js

+ 7
- 2
pico.css Ver fichero

display: grid; display: grid;
grid-template-areas: grid-template-areas:
'posts online' 'posts online'
'actions online'
'actions actions'
; ;
grid-template-columns: 1fr auto; grid-template-columns: 1fr auto;
grid-template-rows: 150px auto;
grid-template-rows: 140px auto;


position: fixed; position: fixed;
top: 0; top: 0;
} }
.actions { .actions {
grid-area: actions; grid-area: actions;
display: grid;
grid-template-columns: 1fr auto;
}
#textbox {
resize: vertical;
} }
.post > div { .post > div {
display: inline; display: inline;

+ 16
- 9
pico.js Ver fichero

const isLandscape = screen.width > screen.height
const State = { const State = {
username: null, username: null,
websocket: null, websocket: null,
const S = `0${dt.getSeconds()}`.slice(-2) const S = `0${dt.getSeconds()}`.slice(-2)
return `${H}:${M}:${S}` return `${H}:${M}:${S}`
} }
const hotKey = (e) => {
// if isDesktop, Enter posts, unless Shift+Enter
// use isLandscape as proxy for isDesktop
if(e.key === 'Enter' && isLandscape && !e.shiftKey) {
e.preventDefault()
Chat.sendPost()
}
}
const Video = { const Video = {
appendStream: ({username, stream}) => ({dom}) => { appendStream: ({username, stream}) => ({dom}) => {
dom.autoplay = true dom.autoplay = true
}, },
} }
const Chat = { const Chat = {
sendPost: (e) => {
e.preventDefault()
const field = e.target.text
if(field.value) {
wire({kind: 'post', value: field.value})
field.value = ''
sendPost: () => {
if(textbox.value) {
wire({kind: 'post', value: textbox.value})
textbox.value = ''
} }
}, },
view() { view() {
m('.text', post.value), m('.text', post.value),
)), )),
), ),
m('form.actions', {onsubmit: Chat.sendPost},
m('input', {oncreate: autoFocus, name: 'text', autocomplete: 'off'}),
m('button', 'Send'),
m('.actions',
m('textarea#textbox', {oncreate: autoFocus, onkeydown: hotKey}),
m('button', {onclick: Chat.sendPost}, 'Send'),
), ),
m('.online', m('.online',
m('button', {onclick: Login.sendLogout}, 'Logout'), m('button', {onclick: Login.sendLogout}, 'Logout'),

Cargando…
Cancelar
Guardar