Skip to content

Instantly share code, notes, and snippets.

@cmdcolin
Created November 29, 2023 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmdcolin/eedfcb11f8f153ba1fb07e56dfddd3b3 to your computer and use it in GitHub Desktop.
Save cmdcolin/eedfcb11f8f153ba1fb07e56dfddd3b3 to your computer and use it in GitHub Desktop.
/* eslint-disable no-restricted-globals */
;(function () {
class UMDLocPlugin {
name = 'UMDLocPlugin'
version = '1.0'
install(pluginManager) {
/* do nothing */
}
configure(pluginManager) {
const { when } = pluginManager.jbrequire('mobx')
;(async () => {
// modification compared with https://gist.github.com/cmdcolin/b71f0567597127bf869804a660b3bc46 which waits for session
await when(() => pluginManager.rootModel.session)
const session = pluginManager.rootModel.session
const view = session.views[0]
const url = new URL(window.location)
const myloc = url.searchParams.get('myloc') // use a different term than &loc=
if (myloc) {
// asynchronously navigates to the location specified by the url param
// e.g. &myloc=chr1:1-100
view.navToLocString(myloc).catch(e => {
// asynchronously catch the error and alert if something went wrong
session.notify(`${e}`, 'error')
})
// optional: remove the URL parameter
url.searchParams.delete('myloc')
window.history.replaceState(null, null, url)
}
})()
}
}
// the plugin will be included in both the main thread and web worker, so
// install plugin to either window or self (webworker global scope)
;(typeof self !== 'undefined' ? self : window).JBrowsePluginUMDLocPlugin = {
default: UMDLocPlugin,
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment