-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #282 from sentinel-hub/feat/multiple-scripts
Test for multiple evalscript in tabs
- Loading branch information
Showing
9 changed files
with
481 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
(function (jtd, undefined) { | ||
jtd.onReady(function () { | ||
|
||
var codeBlocks = document.querySelectorAll('div.highlighter-rouge, div.listingblock > div.content, figure.highlight'); | ||
|
||
// note: the SVG svg-copied and svg-copy is only loaded as a Jekyll include if site.enable_copy_code_button is true; see _includes/icons/icons.html | ||
var svgCDownload = '<svg xmlns="http://www.w3.org/2000/svg" width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>'; | ||
|
||
codeBlocks.forEach(codeBlock => { | ||
var copyButton = document.createElement('button'); | ||
var timeout = null; | ||
copyButton.style.cssText = 'right:40px'; | ||
copyButton.type = 'button'; | ||
copyButton.ariaLabel = 'Download code'; | ||
copyButton.innerHTML = svgCDownload; | ||
codeBlock.append(copyButton); | ||
|
||
copyButton.addEventListener('click', function () { | ||
if (timeout === null) { | ||
var code = (codeBlock.querySelector('pre:not(.lineno, .highlight)') || codeBlock.querySelector('code')).innerText; | ||
code = code.replace(/\n/g, "%0D%0A"); | ||
|
||
// create an anchor element that we can programmatically click | ||
const a = document.createElement('a'); | ||
|
||
console.log(code) | ||
|
||
// set up a data uri with the text | ||
a.href = `data:text/plain,${code}`; | ||
|
||
// set the download attribute so it downloads and uses this as a filename | ||
a.download = 'evalscript.js'; | ||
|
||
// stick it in the document | ||
document.body.appendChild(a); | ||
|
||
// click it | ||
a.click(); | ||
|
||
copyButton.innerHTML = svgCDownload; | ||
|
||
var timeoutSetting = 4000; | ||
|
||
timeout = setTimeout(function () { | ||
copyButton.innerHTML = svgCDownload; | ||
timeout = null; | ||
}, timeoutSetting); | ||
} | ||
}); | ||
}); | ||
// Get the element with id="defaultOpen" and click on it | ||
document.getElementById("defaultOpen").click(); | ||
|
||
}); | ||
})(window.jtd = window.jtd || {}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
layout: default | ||
--- | ||
|
||
<h1 class="d-inline" id={{page.slug}}> {{page.title}} </h1> | ||
|
||
<!-- Tab links --> | ||
<div class="tabcontainer"> | ||
<div class="tab", id="script"> | ||
<button class="tablinks" onclick="openTab(event, 'Visualization')" id="defaultOpen">Visualization</button> | ||
{% for script in page.scripts %} | ||
<button class="tablinks" onclick="openTab(event, '{{ script[0] }}')">{{ script[0] }}</button> | ||
{% endfor %} | ||
</div> | ||
|
||
<div class="line"></div> | ||
<div id="Visualization" class="tabcontent"> | ||
{% highlight javascript %} | ||
{% include_relative script.js %} | ||
{% endhighlight %} | ||
</div> | ||
|
||
{% for script in page.scripts %} | ||
{% assign file = script[1] %} | ||
<!-- Tab content --> | ||
<div id="{{ script[0] }}" class="tabcontent"> | ||
{% highlight javascript %} | ||
{% include_relative {{ file }} %} | ||
{% endhighlight %} | ||
</div> | ||
{% endfor %} | ||
|
||
<button class="expand" onclick="expand(event)">Show full evalscript</button> | ||
|
||
</div> | ||
|
||
{{content}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
title: Example product | ||
parent: Contribute | ||
|
||
layout: multiscript | ||
permalink: /contribute/example-multi/ | ||
nav_exclude: true | ||
scripts: | ||
- [EO-Browser, eob.js] | ||
- [Raw Values, raw.js] | ||
--- | ||
|
||
The layout `script` automatically adds the title defined in the front matter and adds buttons to visualize the script. For the buttons to work the evalscript has to be named `script.js` and must be in the same directory as the `README.md` file. | ||
|
||
## Evaluate and visualize | ||
- [EO Browser](https://apps.sentinel-hub.com/eo-browser/#lat=41.9&lng=12.5&zoom=10&datasource=Sentinel-2%20L1C&time=2017-10-08&preset=CUSTOM&layers=B01,B02,B03&evalscripturl=https://raw.githubusercontent.com/sentinel-hub/customScripts/master/example/script.js){:target="_blank"} | ||
|
||
## General description of the script | ||
|
||
## References | ||
- possible references (scientific articles, wiki/web references, ...) |
Oops, something went wrong.