2023-08-15 18:27:26 +02:00
|
|
|
xrf.frag.defaultPredefinedView = (opts) => {
|
|
|
|
|
let {scene,model} = opts;
|
|
|
|
|
let frag = {}
|
|
|
|
|
xrf.Parser.parse("#","",frag)
|
|
|
|
|
xrf.frag.updatePredefinedView({frag,model,scene})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xrf.frag.updatePredefinedView = (opts) => {
|
2023-10-12 17:04:46 +02:00
|
|
|
let {frag,scene,model,renderer} = opts
|
2023-06-08 17:45:21 +02:00
|
|
|
|
2023-09-14 10:21:16 +02:00
|
|
|
// if this query was triggered by an src-value, lets filter it
|
|
|
|
|
const isSRC = opts.embedded && opts.embedded.fragment == 'src'
|
2023-10-18 22:07:20 +02:00
|
|
|
if( !isSRC ){ // spec : https://xrfragment.org/#src
|
2023-09-14 10:21:16 +02:00
|
|
|
for ( let i in frag ) {
|
|
|
|
|
let v = frag[i]
|
2023-10-25 12:47:23 +02:00
|
|
|
let id = v.string || v.fragment
|
2023-10-25 17:32:19 +02:00
|
|
|
if( id == '#' || !id ) return
|
2023-10-25 12:47:23 +02:00
|
|
|
let match = xrf.XRWG.match(id)
|
|
|
|
|
|
2023-09-14 10:21:16 +02:00
|
|
|
if( v.is( xrf.XRF.PV_EXECUTE ) ){
|
2023-10-25 17:32:19 +02:00
|
|
|
console.log("pv_execute")
|
2023-09-14 10:21:16 +02:00
|
|
|
scene.XRF_PV_ORIGIN = v.string
|
2023-10-25 12:47:23 +02:00
|
|
|
// evaluate aliases
|
|
|
|
|
match.map( (w) => {
|
|
|
|
|
if( w.key == `#${id}` ){
|
|
|
|
|
if( w.value && w.value[0] == '#' ){
|
|
|
|
|
// if value is alias, execute fragment value
|
|
|
|
|
xrf.hashbus.pub( w.value, xrf.model, xrf.XRF.METADATA | xrf.XRF.PV_OVERRIDE | xrf.XRF.NAVIGATOR )
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
xrf.emit('dynamicKey',{ ...opts,v,frag,id,match,scene })
|
2023-10-25 17:32:19 +02:00
|
|
|
}else{
|
|
|
|
|
console.log("non pv_execute")
|
|
|
|
|
xrf.emit('dynamicKeyValue',{ ...opts,v,frag,id,match,scene })
|
2023-09-14 10:21:16 +02:00
|
|
|
}
|
|
|
|
|
}
|
2023-06-08 17:45:21 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-15 19:42:37 +02:00
|
|
|
// react to enduser typing url
|
|
|
|
|
xrf.addEventListener('hash', (opts) => {
|
2023-10-25 17:32:19 +02:00
|
|
|
let frag = xrf.URI.parse( opts.hash )
|
2023-09-14 10:21:16 +02:00
|
|
|
xrf.frag.updatePredefinedView({frag,scene:xrf.scene})
|
|
|
|
|
})
|
2023-06-08 17:45:21 +02:00
|
|
|
|
|
|
|
|
// clicking href url with predefined view
|
|
|
|
|
xrf.addEventListener('href', (opts) => {
|
|
|
|
|
if( !opts.click || opts.xrf.string[0] != '#' ) return
|
2023-08-15 18:27:26 +02:00
|
|
|
let frag = xrf.URI.parse( opts.xrf.string, xrf.XRF.NAVIGATOR | xrf.XRF.PV_OVERRIDE | xrf.XRF.METADATA )
|
|
|
|
|
xrf.frag.updatePredefinedView({frag,scene:xrf.scene,href:opts.xrf})
|
2023-06-08 17:45:21 +02:00
|
|
|
})
|