diff --git a/lib/meta.js b/lib/meta.js index 64615605..1c2ab297 100644 --- a/lib/meta.js +++ b/lib/meta.js @@ -12,281 +12,281 @@ /* UNBUILD */ ;USE(function(module){ - var noop = function(){}, u; - $.fn.or = function(s){ return this.length ? this : $(s||'body') }; - var m = window.meta = {edit:[]}; - var k = m.key = {}; - k.meta = {17:17, 91:17, 93:17, 224:17, 18: 17}; // ALT added - function withMeta(eve){ return eve.metaKey || eve.ctrlKey || eve.altKey } // ALT added - k.down = function(eve){ - var key = (k.eve = m.eve = eve).which = eve.which || eve.fake || eve.keyCode; - if(eve.repeat){ return } - if(!k.meta[key] && withMeta(eve) && !k.at[key]) { - return m.flip(false) - } // cancel and close when no action and "meta key" held down (e.g. ctrl+c) - if(!eve.fake && key === k.last){ return }; k.last = key; // jussi: polyfilling eve.repeat? - if(!eve.fake && $(eve.target).closest('input, textarea, [contenteditable=true]').length && !$(eve.target).closest('#meta').length){ - if(meta.flip.is() && !withMeta(eve)) eve.preventDefault() - } - m.check('on', key, k.at || (k.at = m.edit)); - if(k.meta[key]){ m.flip() } - } - k.down.keys = {} // currently pressed keys - k.up = function(eve){ var tmp; - var key = (k.eve = m.eve = eve).which = eve.which || eve.fake || eve.keyCode; - k.last = null; - m.check('up', key); - if(k.meta[key] && m.check.fired){ - m.close() - } - } - m.flip = function(tmp){ - m.flip.active = true; - ((tmp === false) || (!tmp && m.ui.board.is(':visible')))? - m.close() : m.open(); - m.flip.active = false; - } - m.open = function(){ - m.check.fired = null; - m.ui.board.removeClass('meta-none'); - } - m.close = function(){ - Object.keys(k.down.keys).forEach((keyDown) => { - m.check('up', keyDown); - }) - m.ui.board.addClass('meta-none') - } - m.flip.is = function(){ - return m.ui.board.is(':visible'); - } - m.flip.wait = 500; - m.check = function(how, key, at){ - if(!m.flip.is() && !k.meta[key]){ return } // TEMP: cancel non-open events when closed TODO make optional - at = k.at || m.edit; - var next = at[key]; - if(!next){ return } - var tmp = k.eve || noop; - if(tmp.preventDefault){ tmp.preventDefault()} // prevent typing (etc) when action found - if(next[how]){ - next[how](m.eve); - meta.ui.blink(); - m.check.fired = true; - if(how == 'up') delete k.down.keys[key] - else k.down.keys[key] = 1; - } - if('up' == how){ return } - if(at != next && !next.back){ next.back = at } - (k.combo || (k.combo = [])).push(key); - m.list(next, true); - } - function defaultSort(a,b){ - a = a.combo.slice(-1)[0] || 0; - if(a.length){ a = a.toUpperCase().charCodeAt(0) } - b = b.combo.slice(-1)[0] || 0; - if(b.length){ b = b.toUpperCase().charCodeAt(0) } - return (a < b)? -1 : 1; - } - m.list = function(at, opt){ - if(!at){ return m.flip(false) } - var l = []; - $.each(at, function(i,k){ 'back' != i && k && k.combo && k.name && l.push(k) }); - if(!l.length){ return } - k.at = at; - if(at.sort !== null){ l = l.sort(at.sort || defaultSort) } - var $ul = $('#meta .meta-menu ul') - $ul.children('li').addClass('meta-none').hide(); setTimeout(function(){ $ul.children('.meta-none').remove() },250); // necessary fix for weird bug glitch - $.each(l, function(i, k){ - var $li = $('