click open, mouse button drag, open canceld disabled

This commit is contained in:
Jussi Rytkönen 2019-11-22 17:09:29 +02:00
parent 22547099bd
commit b41022ca91

View File

@ -17,6 +17,7 @@
/* UNBUILD */
;USE(function(module){
var noop = function(){}, u;
$.fn.or = function(s){ return this.length ? this : $(s||'body') };
var m = window.meta = {edit:[]};
@ -29,8 +30,7 @@
if(eve.repeat){ return }
var key = (k.eve = m.eve = eve).which = eve.which || eve.fake || eve.keyCode;
// ADDED
if(!m.flip.is() && !k.meta[key]){ return } // cancel non-open events when closed TODO make optional
//if(!m.flip.is() && !k.meta[key]){ return } // cancel non-open events when closed TODO make optional
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?
@ -53,7 +53,7 @@
}
k.up = function(eve){ var tmp;
var key = (k.eve = m.eve = eve).which = eve.which || eve.fake || eve.keyCode;
if(!m.flip.is() && !k.meta[key]){ return } // ADDED cancel non-open events when closed TODO make optional
//if(!m.flip.is() && !k.meta[key]){ return } // ADDED cancel non-open events when closed TODO make optional
// if(!eve.fake && $(eve.target).closest('input, textarea, [contenteditable=true]').length){
// if(k.meta[key]){
// k.down.meta = null;
@ -167,18 +167,18 @@
;USE(function(module){
/* UI */
meta.ui = {
blink: function(){ // hint visually that action has happened
blink: function(){ // hint visually that action has happened
$('#meta').css('transition', 'none').css('background', 'none')
setTimeout(function(){
$('#meta')[0].style.transition = null
$('#meta')[0].style.background = null
$('#meta')[0].style.transition = null
$('#meta')[0].style.background = null
})
},
depth: function(n){
if (n) {
$('#meta').css('background', 'hsl(60, 100%,'+(85-(n*10))+'%)');
$('#meta').css('background', 'hsl(60, 100%,'+(85-(n*10))+'%)');
} else {
$('#meta')[0].style.background = null
$('#meta')[0].style.background = null
}
}
}
@ -236,7 +236,8 @@
'border-radius': '1em',
'margin-left': '0.25em',
'margin-top': '0.25em',
'float': 'right'
'float': 'right',
'cursor': 'pointer'
},
'#meta a': {color: 'black'},
// '#meta:hover': {opacity: 1},
@ -274,6 +275,7 @@
})(USE, './metaUI');
;USE(function(module){
// include basic text editing by default.
var monotype = window.monotype || function(){console.log("monotype needed")};
var m = meta;
@ -420,7 +422,7 @@
})(USE, './metaText');
;USE(function(module){
var m = meta, k = m.key;
$(window).on('blur', k.wipe.bind(null, false)).on('focus', k.wipe.bind(null, false));
$(window).on('focus', k.wipe.bind(null, false)); // .on('blur', k.wipe.bind(null, false))
//$(document).on('mousedown mousemove mouseup', function(eve){
// m.tap.eve = eve;
// m.tap.x = eve.pageX||0;
@ -437,12 +439,17 @@
//$(document).on('touchstart', '#meta .meta-start', function(eve){ m.tap.stun = true });
$(document).on('click', '#meta .meta-menu li', function(eve){
var combo = $(this).data().combo;
eve.fake = eve.which = combo && combo.slice(-1)[0].charCodeAt(0);
var [start, end] = 'ontouchstart' in window
? ['touchstart', 'touchend']
: ['mousedown', 'mouseup']
$(document).on(start, '#meta .meta-menu li', function(eve){
var combo = $(this).data().combo;
eve.fake = eve.which = combo && combo.slice(-1)[0].charCodeAt(0);
eve.tap = true;
k.down(eve); k.up(eve);
return;
k.down(eve);
$(document).one(end, () => k.up(eve))
return;
// if(m.tap.stun){ return m.tap.stun = false }
// if(!(eve.fake = eve.which = (($(this).text().match(/[A-Z]/)||{})[0]||'').toUpperCase().charCodeAt(0))){ return }
// eve.tap = true;
@ -451,6 +458,11 @@
});
$(document).on('keydown', k.down).on('keyup', k.up);
$('#meta').on('click', function(ev) {
if (ev.target.tagName == 'LI' || ev.target.tagName == 'UL') return
meta.flip()
})
//$(document).on('select contextmenu keyup mouseup', '[contenteditable=true]', m.text.on);