From b08eac1a7d65f79a0cb6cc02ac9308ea47ce5576 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Wed, 2 Jan 2019 21:23:04 -0800 Subject: [PATCH] dabbles --- examples/style.css | 1 + lib/metae.js | 112 ++++++++++++++++++++++++++++++++++++--------- test/tmp/time.html | 94 ++++++++++++++++++++----------------- 3 files changed, 144 insertions(+), 63 deletions(-) diff --git a/examples/style.css b/examples/style.css index 9acf5b74..a81e9b72 100644 --- a/examples/style.css +++ b/examples/style.css @@ -339,6 +339,7 @@ ul, li { background: url(https://cdn.jsdelivr.net/npm/gun/examples/pop.png) no-repeat; background-position: -2800px 0; pointer-events: none; + z-index: 999999999; animation: joy 1s steps(28); } @keyframes joy { diff --git a/lib/metae.js b/lib/metae.js index f592ae56..d21fc13d 100644 --- a/lib/metae.js +++ b/lib/metae.js @@ -10,29 +10,97 @@ $(function(){ || ua.search('iphone') >= 0 || ua.search('ipad') >= 0)? "ios":false } - m.key = {ctrl: 17, cmd: 91}; - m.key.meta = (m.os.is.win||m.os.is.lin||m.os.is.and)? m.key.ctrl : m.key.cmd; - m.key.on = {}; - $(document).on('keydown', function(e){ + var k = m.key = {ctrl: 17, cmd: 91}; + k.meta = (m.os.is.win||m.os.is.lin||m.os.is.and)? k.ctrl : k.cmd; + k.on = {}; + k.down = function(e){ var tmp; m.e = e; - console.log('keydown', e.keyCode); - m.key.on[e.code = e.keyCode] = !0; - }).on('keyup', function(e){ + e.which = e.which || e.keyCode; + if(e.which === k.last){ return } + if(tmp = (k.meta === e.which)){ m.wipe() } + k.on[k.last = e.which] = !0; + $('#debug').val(JSON.stringify(m.key.on, null, 2)); + if(tmp){ + (tmp = $('#create .menu')).is(':visible')? + tmp.addClass('none') : tmp.removeClass('none'); + } + if($('#create .menu').is(':visible')){ + (k.combo || (k.combo = [])).push(e.which) + m.check('on', e.which, k.at || (k.at = m.edit)); + } + } + k.up = function(e){ m.e = e; - delete m.key.on[e.code = e.keyCode]; - }).on('keydown', '[contenteditable=true]', function(e){ - return; - var r = monotype(); - console.log("keys down", Gun.obj.copy(m.key.on)); - $.each(m.edit, function(i,edit){ var tmp = true; - $.each(edit.keys||[''], function(i,k){ - if(!m.key.on[k.length? k.charCodeAt(0) : k]){ tmp = false } - }); - console.log(tmp, edit); - }) - r.restore(); + k.last = null; + e.which = e.which || e.keyCode; + delete k.on[e.which]; + $('#debug').val(JSON.stringify(k.on, null, 2)); + //if(m.key.on[m.key.meta]){ m.check('up') } + if($('#create .menu').is(':visible')){ m.check('up', e.which) } + if(k.meta === e.which){ m.wipe() } + } + m.check = function(how, key, at){ + at = k.at || m.edit; + var edit = at[key], tmp; + if(!edit){ return } + if(edit[how]){ + edit[how](m.e); + return; + } + at = k.at = edit; + } + m.wipe = function(){ + k.at = m.edit; + k.combo = []; + k.on = {}; + }; + $(document).on('keydown', k.down).on('keyup', k.up); + $(window).on('blur', m.wipe).on('focus', m.wipe); + //.on('keydown', '[contenteditable=true]', function(e){}); + meta.edit = function(edit){ + var tmp = edit.combow = []; + $.each(edit.combo || (edit.combo = []), function(i,k){ + if(!k || !k.length){ return } + tmp.push(k.toUpperCase().charCodeAt(0)); + }); + var at = meta.edit, l = edit.combo.length; + $.each(tmp, function(i,k){ at = at[k] = (++i >= l)? edit : at[k] || {} }); + edit.combow = edit.combow.join(','); + } + // on fires when shortcut keydowns or on touch after command selected and then touchdown + meta.edit({ + name: "Bold", + combo: ['B'], + on: function(e){ + console.log("OO!!", e); + var r = monotype(); + console.log("YAY!"); + e.preventDefault(); + }, + up: function(){ + console.log("END!") + } + }); + meta.edit({ + name: "Italic", + combo: ['I'], + on: function(e){ + console.log("YAY!"); + e.preventDefault(); + }, + up: function(){ + console.log("END!") + } + }); + meta.edit({ + name: "Under", + combo: ['U'], + on: function(e){ + console.log("YAY!"); + e.preventDefault(); + }, + up: function(){ + console.log("END!") + } }); - m.edit.push({keys: ['B'], on: function(){ - console.log('hi!'); - }}) }); \ No newline at end of file diff --git a/test/tmp/time.html b/test/tmp/time.html index 7bf617ec..4d1c1d49 100644 --- a/test/tmp/time.html +++ b/test/tmp/time.html @@ -1,60 +1,72 @@ -

User

- -
- - - - -
+

Infinite Stream of Tweets/Chats:

- -
- - -
+
while in scroll, latest tweet should show here
+Scroll: + + - - - + + \ No newline at end of file