diff --git a/config/plugins/visualizations/fits_image_viewer/package.json b/config/plugins/visualizations/fits_image_viewer/package.json index f895a17bf537..5e09ac1369f6 100644 --- a/config/plugins/visualizations/fits_image_viewer/package.json +++ b/config/plugins/visualizations/fits_image_viewer/package.json @@ -8,9 +8,10 @@ "license": "AFL-3.0", "dependencies": { "aladin-lite-galaxy": "^1.0.0", - "parcel-bundler": "^1.4.1" + "parcel-bundler": "^1.4.1", + "cpy-cli": "^5.0.0" }, "scripts": { - "build": "cp -r node_modules/aladin-lite-galaxy static/dist && parcel build src/script.js -d static" + "build": "cpy --flat node_modules/aladin-lite-galaxy static/dist/aladin-lite-galaxy && parcel build src/script.js -d static" } } diff --git a/config/plugins/visualizations/fits_image_viewer/src/script.js b/config/plugins/visualizations/fits_image_viewer/src/script.js index 1568f1408465..3cebefd5b8e7 100644 --- a/config/plugins/visualizations/fits_image_viewer/src/script.js +++ b/config/plugins/visualizations/fits_image_viewer/src/script.js @@ -1,7 +1,31 @@ -let aladin; +var aladin; -A.init.then(() => { - aladin = A.aladin('#aladin-lite-div', {showCooGridControl: true}); - aladin.displayFITS(file_url) - aladin.showCooGrid(true); -}); \ No newline at end of file +function initializeAladinLite() { + A.init.then(() => { + aladin = A.aladin('#aladin-lite-div', {showCooGridControl: true}); + aladin.displayFITS(fileUrl) + aladin.showCooGrid(true); + }); +} + +function localScriptLoadingError() { + addScriptToHead(appRoot+aladinLiteScriptAlternativeLocation); +} + +function cdnLoadingError() { + addScriptToHead(appRoot+aladinLiteScriptLocation, localScriptLoadingError); +} + +function addScriptToHead(url, onerrorFunction) { + const scriptToAdd = document.createElement("script"); + scriptToAdd.onload = initializeAladinLite; + + if(onerrorFunction) { + scriptToAdd.onerror = onerrorFunction + } + + document.head.appendChild(scriptToAdd); + scriptToAdd.src = url; +} + +addScriptToHead(aladinLiteCDNUrl, cdnLoadingError); diff --git a/config/plugins/visualizations/fits_image_viewer/templates/fits_image_viewer.mako b/config/plugins/visualizations/fits_image_viewer/templates/fits_image_viewer.mako index 63a8cb17e731..064171af8b45 100644 --- a/config/plugins/visualizations/fits_image_viewer/templates/fits_image_viewer.mako +++ b/config/plugins/visualizations/fits_image_viewer/templates/fits_image_viewer.mako @@ -13,15 +13,19 @@ ${h.stylesheet_link( app_root + 'style.css' )} - ${h.javascript_link( app_root + 'dist/aladin-lite-galaxy/aladin.js' )}
FITS aladin viewer : ${hda.name | h}
+ ${h.javascript_link( app_root + 'script.js' )} - \ No newline at end of file +