mirror of
https://github.com/amark/gun.git
synced 2026-03-11 03:04:49 +00:00
tweaks
This commit is contained in:
54
lib/meta.js
54
lib/meta.js
@@ -1,27 +1,17 @@
|
||||
$(function(){
|
||||
var m = window.meta = {edit:[], os:{}}, ua = '', u;
|
||||
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
|
||||
}
|
||||
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;
|
||||
var m = window.meta = {edit:[]}, u;
|
||||
var k = m.key = {};
|
||||
k.meta = {17:1, 91:1, 93:1, 224:1};
|
||||
k.down = function(eve){
|
||||
if($(eve.target).is('input') || eve.repeat){ return }
|
||||
(k.eve = m.eve = eve).which = eve.which || eve.fake || eve.keyCode;
|
||||
if(!eve.fake && eve.which === k.last){ return }
|
||||
if(k.meta === (k.last = eve.which)){ k.down.meta = m.flip(k.wipe()) || true }
|
||||
if(k.meta[(k.last = eve.which)]){ k.down.meta = m.flip(k.wipe()) || true }
|
||||
if(m.flip.is()){
|
||||
(k.combo || (k.combo = [])).push(eve.which);
|
||||
m.check('on', eve.which, k.at || (k.at = m.edit));
|
||||
}
|
||||
if(eve.metaKey && (k.meta !== eve.which)){ k.up(eve) } // on some systems, meta hijacks keyup
|
||||
if(eve.metaKey && (!k.meta[eve.which])){ k.up(eve) } // on some systems, meta hijacks keyup
|
||||
}
|
||||
k.up = function(eve){ var tmp;
|
||||
if($(eve.target).is('input')){ return }
|
||||
@@ -29,7 +19,7 @@ $(function(){
|
||||
k.last = null;
|
||||
eve.which = eve.which || eve.fake || eve.keyCode;
|
||||
if(m.flip.is()){ m.check('up', eve.which) }
|
||||
if(tmp = (k.meta === eve.which)){ k.down.meta = false }
|
||||
if(tmp = (k.meta[eve.which])){ k.down.meta = false }
|
||||
if(tmp && k.at === m.edit){ k.wipe() }
|
||||
if(27 === eve.which){ return m.flip(false) }
|
||||
}
|
||||
@@ -355,6 +345,38 @@ $(function(){
|
||||
// Size Spacing
|
||||
// Size Super
|
||||
// Size Sub
|
||||
/*
|
||||
meta.edit({name: "Edit", combo: ['E']});
|
||||
meta.edit({name: "Add", combo: ['E','A'],
|
||||
on: function(e){
|
||||
console.log(111);
|
||||
var r = m.tap.range || monotype();
|
||||
r.insert($('<div>hi</div>'));
|
||||
}
|
||||
});
|
||||
meta.edit({name: "Color", combo: ['E','C'],
|
||||
on: function(e){
|
||||
console.log(111);
|
||||
var r = m.tap.range || monotype();
|
||||
meta.ask('Color name or code?', function(color){
|
||||
r.get().closest('div').css({background: color});
|
||||
});
|
||||
}
|
||||
});
|
||||
meta.edit({name: "Width", combo: ['E','W'],
|
||||
on: function(e){
|
||||
var r = m.tap.range || monotype(), s = e.pageX||0, on = r.get().closest('div'), was = on.width();
|
||||
console.log(1);
|
||||
$(document).on('mousemove.tmp', function(eve){
|
||||
var w = was + ((eve.pageX||0) - was);
|
||||
console.log(w);
|
||||
on.css({width: w});
|
||||
})
|
||||
}, up: function(){
|
||||
console.log(0);
|
||||
$(document).off('mousemove.tmp');
|
||||
}
|
||||
});
|
||||
*/
|
||||
}());
|
||||
});
|
||||
@@ -29,12 +29,13 @@
|
||||
hierarchy: ['div', 'pre', 'ol', 'ul', 'li',
|
||||
'h1', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'a', // block
|
||||
'b', 'code', 'i', 'span', 's', 'sub', 'sup', 'u', // inline
|
||||
'br'] // empty
|
||||
'br', 'img'] // empty
|
||||
,tags: {
|
||||
'a': {attrs:{'href':1}, exclude:{'a':1}},
|
||||
'b': {exclude:{'b':1,'p':1}},
|
||||
'br': {empty: 1},
|
||||
'i': {exclude:{'i':1,'p':1}},
|
||||
'img': {attrs:{'src':1}, empty: 1},
|
||||
'span': {exclude:{'p':1,'ul':1,'ol':1,'li':1,'br':1}},
|
||||
's': {space:1},
|
||||
'u': {exclude:{'u':1,'p':1},space:1},
|
||||
@@ -138,12 +139,17 @@
|
||||
return $(($(e)[0]||{})[d]);
|
||||
}
|
||||
|
||||
var xssattr = /[^a-z:]/ig, xssjs = /javascript:/ig;
|
||||
// url("javascript: // and all permutations
|
||||
// stylesheets can apparently have XSS?
|
||||
|
||||
// create key val attributes object from elements attributes
|
||||
function attrsAsObj(e, filterCb){
|
||||
var attrObj = {};
|
||||
(e = $(e)) && e.length && $(e[0].attributes||[]).each(function(value,name){
|
||||
name = name.nodeName||name.name;
|
||||
value = e.attr(name);
|
||||
if(value.replace(xssattr,'').match(xssjs)){ e.removeAttr(name); return }
|
||||
value = filterCb? filterCb(value,name,e) : value;
|
||||
if(value !== undefined && value !== false)
|
||||
attrObj[name] = value;
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
function ename(t){ return encodeURIComponent(t).replace(/\*/g, '%2A') }
|
||||
function atomic(v){ return u !== v && (!v || 'object' != typeof v) }
|
||||
var map = Gun.obj.map;
|
||||
var LOG = false;
|
||||
|
||||
if(!opt.store){
|
||||
return opt.log("ERROR: Radisk needs `opt.store` interface with `{get: fn, put: fn (, list: fn)}`!");
|
||||
@@ -167,9 +168,9 @@
|
||||
}
|
||||
f.write = function(){
|
||||
var tmp = ename(file);
|
||||
//var start = (+new Date); // comment this out!
|
||||
var start; LOG && (start = (+new Date)); // comment this out!
|
||||
opt.store.put(tmp, f.text, function(err){
|
||||
//console.log("wrote JSON in", (+new Date) - start); // comment this out!
|
||||
LOG && console.log("wrote JSON in", (+new Date) - start); // comment this out!
|
||||
if(err){ return cb(err) }
|
||||
r.list.add(tmp, cb);
|
||||
});
|
||||
@@ -198,10 +199,10 @@
|
||||
|
||||
r.write.jsonify = function(f, file, rad, cb, o){
|
||||
var raw;
|
||||
//var start = (+new Date); // comment this out!
|
||||
var start; LOG && (start = (+new Date)); // comment this out!
|
||||
try{raw = JSON.stringify(rad.$);
|
||||
}catch(e){ return cb("Record too big!") }
|
||||
//console.log("stringified JSON in", (+new Date) - start); // comment this out!
|
||||
LOG && console.log("stringified JSON in", (+new Date) - start); // comment this out!
|
||||
if(opt.chunk < raw.length && !o.force){
|
||||
if(Radix.map(rad, f.each, true)){ return }
|
||||
}
|
||||
@@ -291,12 +292,12 @@
|
||||
}
|
||||
info.parsed = data.length;
|
||||
|
||||
//var start = (+new Date); // keep this commented out in production!
|
||||
var start; LOG && (start = (+new Date)); // keep this commented out in production!
|
||||
if(opt.jsonify){ // temporary testing idea
|
||||
try{
|
||||
var json = JSON.parse(data);
|
||||
p.disk.$ = json;
|
||||
//console.log('parsed JSON in', (+new Date) - start); // keep this commented out in production!
|
||||
LOG && console.log('parsed JSON in', (+new Date) - start); // keep this commented out in production!
|
||||
map(q, p.ack);
|
||||
return;
|
||||
}catch(e){ tmp = e }
|
||||
@@ -306,7 +307,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
//var start = (+new Date); // keep this commented out in production!
|
||||
var start; LOG && (start = (+new Date)); // keep this commented out in production!
|
||||
var tmp = p.split(data), pre = [], i, k, v;
|
||||
if(!tmp || 0 !== tmp[1]){
|
||||
p.err = "File '"+file+"' does not have root radix! ";
|
||||
@@ -329,7 +330,7 @@
|
||||
if(u !== k && u !== v){ p.disk(pre.join(''), v) }
|
||||
tmp = p.split(tmp[2]);
|
||||
}
|
||||
//console.log('parsed JSON in', (+new Date) - start); // keep this commented out in production!
|
||||
LOG && console.log('parsed JSON in', (+new Date) - start); // keep this commented out in production!
|
||||
//cb(err, p.disk);
|
||||
map(q, p.ack);
|
||||
};
|
||||
|
||||
@@ -55,6 +55,7 @@ Gun.on('create', function(root){
|
||||
if((tmp = get['%']) || opt.limit){
|
||||
opt.limit = (tmp <= (opt.pack || (1000 * 100)))? tmp : 1;
|
||||
}
|
||||
//var start = (+new Date);
|
||||
//console.log("GET!", id, JSON.stringify(key));
|
||||
rad(key||'', function(err, data, o){
|
||||
if(data){
|
||||
@@ -67,7 +68,7 @@ Gun.on('create', function(root){
|
||||
}
|
||||
if(!graph && data){ each(data, '') }
|
||||
}
|
||||
//console.log("GOT!", id, JSON.stringify(key));
|
||||
//console.log("GOT!", id, JSON.stringify(key), ((+new Date) - start));
|
||||
root.on('in', {'@': id, put: graph, err: err? err : u, rad: Radix});
|
||||
}, opt);
|
||||
function each(val, has, a,b){
|
||||
|
||||
Reference in New Issue
Block a user