From 51fc1d860f3b47b8f002c954306705f11395a4d7 Mon Sep 17 00:00:00 2001 From: Fabien Benetou Date: Mon, 12 Jun 2023 18:30:08 +0200 Subject: [PATCH] when dropping URL pointing to plaintext content, load in nearby editor --- index.html | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 41db328..532a401 100644 --- a/index.html +++ b/index.html @@ -3388,11 +3388,46 @@ function ontouch(){ }, 20) } +function setOnDropFromAttribute(){ + // add to file descriptor from offtopus + // could also be prototyped with a URL instead, doesn't need offtopus even cached version + // could also prototype by doing so via https://webdav.benetou.fr/fot-demo-day/mobydick-extract.txt + targets.map( el => { + if ( el.getAttribute('ondrop')?.length > 0 ) + el.addEventListener('released', e => { + let code = el.getAttribute('ondrop') + console.log('do', code) + try { + eval( code ) + } catch (error) { + console.error(`Evaluation failed with ${error}`); + } + }) + } ) + // if dropped close enough to an editor, load file content in editor + // could try a jxr command... +} + +function setNearbyEditor(el){ + let pos = el.getAttribute('position') + fetch(el.getAttribute('value')).then( res => res.text() ).then( content => { + console.log( content ) + // assumes plain text + editors.map( ed => { + console.log(ed) + if ( pos.distanceTo( ed.element.getAttribute('position') ) < 1 ) + updateCodeEditorWithContent(ed, content) + }) + }) +} + // used for testing AFRAME.registerComponent('startfunctions', { init: function () { - ontouch() + addCodeMultipleEditors(1, 'hello world', '', name='editortodropon') + setOnDropFromAttribute() + //ontouch() //tensionVisualized() //startExperience() //doublePinchToScale() @@ -3471,6 +3506,10 @@ AFRAME.registerComponent('startfunctions', { + +