when dropping URL pointing to plaintext content, load in nearby editor

ondrop
Fabien Benetou 11 months ago
parent 6ae4f08e57
commit 51fc1d860f
  1. 41
      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', {
<a-console position="0 1.1 -0.8" rotation="-45 0 0" height=2 font-size="34" height=0.5 skip-intro=true></a-console>
<a-box target position="0 1.65 -0.5" scale="0.01 0.01 0.01"></a-box>
<a-troika-text anchor=left target ondrop="setNearbyEditor(el)"
value="https://webdav.benetou.fr/fot-demo-day/mobydick-extract.txt"
position=" -0.3 1.65 -.4" rotation="0 90 0" scale="0.1 0.1 0.1"></a-troika-text>
</a-scene>
</body>

Loading…
Cancel
Save