unknown href links now open in browsertab (incl. from iframe)
This commit is contained in:
parent
a170aabfb6
commit
78eac1c12b
4 changed files with 23 additions and 18 deletions
|
|
@ -64,7 +64,6 @@ window.AFRAME.registerComponent('xrf', {
|
|||
let url = opts.xrf.string
|
||||
let isLocal = url.match(/^#/)
|
||||
let hasPos = url.match(/pos=/)
|
||||
if( !isLocal && !url.match(/^http/) ) return // dont fade/load for custom protocol handlers
|
||||
if( isLocal && hasPos ){
|
||||
// local teleports only
|
||||
let fastFadeMs = 200
|
||||
|
|
|
|||
|
|
@ -89,6 +89,7 @@ window.matrix = (opts) => new Proxy({
|
|||
},
|
||||
|
||||
connect(opts){
|
||||
this.createLink() // ensure link
|
||||
if( opts.selectedWebcam == this.profile.name ) this.useWebcam = true
|
||||
if( opts.selectedChatnetwork == this.profile.name ) this.useChat = true
|
||||
if( opts.selectedScene == this.profile.name ) this.useScene = true
|
||||
|
|
@ -229,8 +230,8 @@ window.matrix = (opts) => new Proxy({
|
|||
if( !url.match(this.profile.protocol) ) return
|
||||
let parts = url.replace(this.profile.protocol,'').split("/")
|
||||
if( parts[0] == 'r' ){ // room
|
||||
let server = parts.split("/")[1].replace(/:.*/,'')
|
||||
let channel = parts.split("/")[1].replace(/.*:/,'')
|
||||
let server = parts[1].replace(/:.*/,'')
|
||||
let channel = parts[1].replace(/.*:/,'')
|
||||
$connections.show()
|
||||
$connections.selectedChatnetwork = this.profile.name
|
||||
$connections.selectedScene = this.profile.name
|
||||
|
|
@ -241,7 +242,7 @@ window.matrix = (opts) => new Proxy({
|
|||
return false
|
||||
},
|
||||
|
||||
t0nkr0nst0nreateLink(opts){
|
||||
createLink(opts){
|
||||
let hash = document.location.hash
|
||||
if( !this.link ){
|
||||
const meeting = network.getMeetingFromUrl(document.location.href)
|
||||
|
|
@ -258,7 +259,6 @@ window.matrix = (opts) => new Proxy({
|
|||
let href = mesh.userData.href
|
||||
let isLocal = href[0] == '#'
|
||||
let isTeleport = href.match(/(pos=|http:)/)
|
||||
console.log("href detected")
|
||||
if( isLocal && !isTeleport && this.client && this.useScene ){
|
||||
console.log("sending href")
|
||||
this.yhref.set( document.location.hash )
|
||||
|
|
|
|||
|
|
@ -8,19 +8,19 @@ xrf.navigator.to = (url,flags,loader,data) => {
|
|||
|
||||
return new Promise( (resolve,reject) => {
|
||||
let {urlObj,dir,file,hash,ext} = xrf.parseUrl(url)
|
||||
if( !file || (!data && xrf.model.file == file) ){ // we're already loaded
|
||||
if( hash == document.location.hash.substr(1) ) return // block duplicate calls
|
||||
hashbus.pub( url, xrf.model, flags ) // and eval local URI XR fragments
|
||||
if( (!file && hash) || (!data && xrf.model.file == file) ){ // we're already loaded
|
||||
if( hash == document.location.hash.substr(1) ) return // block duplicate calls
|
||||
hashbus.pub( url, xrf.model, flags ) // and eval local URI XR fragments
|
||||
xrf.navigator.updateHash(hash)
|
||||
return resolve(xrf.model)
|
||||
}
|
||||
|
||||
if( xrf.model && xrf.model.scene ) xrf.model.scene.visible = false
|
||||
if( !loader ){
|
||||
const Loader = xrf.loaders[ext]
|
||||
if( !Loader ) throw 'xrfragment: no loader passed to xrfragment for extension .'+ext
|
||||
if( !Loader ) return reject('xrfragment: no loader passed to xrfragment for extension .'+ext)
|
||||
loader = loader || new Loader().setPath( dir )
|
||||
}
|
||||
if( xrf.model && xrf.model.scene ) xrf.model.scene.visible = false
|
||||
|
||||
// force relative path for files which dont include protocol or relative path
|
||||
if( dir ) dir = dir[0] == '.' || dir.match("://") ? dir : `.${dir}`
|
||||
|
|
|
|||
|
|
@ -40,19 +40,25 @@ xrf.frag.href = function(v, opts){
|
|||
.emit('href',{click:true,mesh,xrf:v}) // let all listeners agree
|
||||
.then( () => {
|
||||
let {urlObj,dir,file,hash,ext} = xrf.parseUrl(v.string)
|
||||
//if( !file.match(/\./) || file.match(/\.html/) ){
|
||||
// debugger
|
||||
// let inIframe
|
||||
// try { inIframe = window.self !== window.top; } catch (e) { inIframe = true; }
|
||||
// return inIframe ? window.parent.postMessage({ url: v.string }, '*') : window.open( v.string, '_blank')
|
||||
//}
|
||||
const flags = v.string[0] == '#' ? xrf.XRF.PV_OVERRIDE : undefined
|
||||
let toFrag = xrf.URI.parse( v.string, xrf.XRF.NAVIGATOR | xrf.XRF.PV_OVERRIDE | xrf.XRF.METADATA )
|
||||
// *TODO* support for multiple protocols
|
||||
if( v.string[0] != '#' && !v.string.match(/^http/) ) return
|
||||
// always commit current location in case of teleport (keep a trail of last positions before we navigate)
|
||||
if( !e.nocommit && !document.location.hash.match(lastPos) ) xrf.navigator.to(`#${lastPos}`)
|
||||
xrf.navigator.to(v.string) // let's surf to HREF!
|
||||
.catch( (e) => { // not something we can load
|
||||
let inIframe
|
||||
try { inIframe = window.self !== window.top; } catch (e) { inIframe = true; }
|
||||
return inIframe ? window.parent.postMessage({ url: v.string }, '*') : window.open( v.string, '_blank')
|
||||
// in case you're running in an iframe, then use this in the parent page:
|
||||
//
|
||||
// window.addEventListener("message", (e) => {
|
||||
// if (e.data && e.data.url){
|
||||
// window.open( e.data.url, '_blank')
|
||||
// }
|
||||
// },
|
||||
// false,
|
||||
// );
|
||||
})
|
||||
})
|
||||
.catch( console.error )
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue