From a9aafa18eb7d8a1b85281870f515b47bb9ff7142 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Tue, 18 Dec 2018 17:05:08 -0800 Subject: [PATCH] monotype / normalize / for future meta editor stuff --- lib/metae.js | 38 ++++++++ lib/monotype.js | 230 +++++++++++++++++++++++++++++++++++++++++++++++ lib/normalize.js | 21 +++-- sea/verify.js | 1 + 4 files changed, 279 insertions(+), 11 deletions(-) create mode 100644 lib/metae.js create mode 100644 lib/monotype.js diff --git a/lib/metae.js b/lib/metae.js new file mode 100644 index 00000000..f592ae56 --- /dev/null +++ b/lib/metae.js @@ -0,0 +1,38 @@ +$(function(){ + var m = window.meta = {edit:[], os:{}}, ua = ''; + try{ua = navigator.userAgent.toLowerCase()}catch(e){} + m.os.is = { + win: (ua.search("win") >= 0)? "windows":false, + lin: (ua.search("linux") >= 0)? "linux":false, + mac: (ua.search("mac") >= 0)? "macintosh":false, + and: (ua.search("android") >= 0)? "android":false, + ios: (ua.search('ipod') >= 0 + || 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){ + m.e = e; + console.log('keydown', e.keyCode); + m.key.on[e.code = e.keyCode] = !0; + }).on('keyup', 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(); + }); + m.edit.push({keys: ['B'], on: function(){ + console.log('hi!'); + }}) +}); \ No newline at end of file diff --git a/lib/monotype.js b/lib/monotype.js new file mode 100644 index 00000000..fd5a50e7 --- /dev/null +++ b/lib/monotype.js @@ -0,0 +1,230 @@ +;var monotype = monotype || (function(monotype){ + monotype.range = function(n){ + var R, s, t, n = n || 0, win = monotype.win || window, doc = win.document; + if(!arguments.length) return doc.createRange(); + if(!(win.Range && R instanceof Range)){ + s = win.getSelection? win.getSelection() : {}; + if(s.rangeCount){ + R = s.getRangeAt(n); + } else { + if(doc.createRange){ + R = doc.createRange(); + R.setStart(doc.body, 0); + } else + if (doc.selection){ // ').append(a.$.contents())); + a.$.replaceWith(a.$ = $('<'+ (a.tag = tmp.toLowerCase()) +'>').append(a.$.contents())); h.attr(a.$, a.attr, a.attrs); } ,function(a, tmp){ // lookahead - if((tmp = n.joint(a.$,1)) && (t = t.contents()).length === 1 && a.tag === n.tag(t = t.first())){ - a.$.append(t.parent()); // no need to unwrap the child, since the recursion will do it for us + if((tmp = n.joint(a.$,1)) && (tmp = tmp.contents()).length === 1 && a.tag === n.tag(tmp = tmp.first())){ + a.$.append(tmp.parent()); // no need to unwrap the child, since the recursion will do it for us } } ,function(a){ // recurse // this needs to precede the exclusion and empty. normalize(a); } - ,function(a){ // exclude - var t; + ,function(a, tmp){ // exclude if(!n.get(a.opt,'tags.' + a.tag) - || ((t = n.get(a.opt,'tags.'+ a.tag +'.exclude')) - && a.$.parents($.map(t,function(i,v){return v})+' ').length) + || ((tmp = n.get(a.opt,'tags.'+ a.tag +'.exclude')) + && a.$.parents($.map(tmp,function(i,v){return v})+' ').length) ){ a.$.replaceWith(a.$.contents()); } } - ,function(a){ // prior - var t; - if((t = n.joint(a.$)).length && a.tag === n.tag(t)){ - t.append(a.$.contents()); + ,function(a, tmp){ // prior + if((tmp = n.joint(a.$)).length && a.tag === n.tag(tmp)){ + tmp.append(a.$.contents()); } } ,function(a){ // empty diff --git a/sea/verify.js b/sea/verify.js index f82df282..909bed30 100644 --- a/sea/verify.js +++ b/sea/verify.js @@ -46,3 +46,4 @@ }}); module.exports = SEA.verify; + \ No newline at end of file