You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by pa...@apache.org on 2023/05/24 16:54:51 UTC
[beam] branch master updated: Fix Playground on home page with Safari (#26860)
This is an automated email from the ASF dual-hosted git repository.
pabloem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git
The following commit(s) were added to refs/heads/master by this push:
new 92b5c1f8b2e Fix Playground on home page with Safari (#26860)
92b5c1f8b2e is described below
commit 92b5c1f8b2ee30a7b57072f2f0ef92f8f25d6711
Author: alexeyinkin <le...@inkin.ru>
AuthorDate: Wed May 24 20:54:43 2023 +0400
Fix Playground on home page with Safari (#26860)
* Do not change the initial URL in Playground iframe (#26844)
* Create the embedded Playground iframes in JS (#26844)
* Fix the embedded Playground on home page being stuck on Java (#26844)
* Add the initial SDK to the embedded Playground iframe URL (#26844)
* Hide Playground tabs on home page, show playground on mobile elsewhere (#26844)
---
website/www/site/assets/js/language-switch-v2.js | 18 +++++++--
website/www/site/assets/scss/_playground.sass | 11 ++++--
website/www/site/layouts/index.html | 46 +++++++++++-----------
.../www/site/layouts/shortcodes/playground.html | 15 +++----
4 files changed, 51 insertions(+), 39 deletions(-)
diff --git a/website/www/site/assets/js/language-switch-v2.js b/website/www/site/assets/js/language-switch-v2.js
index fad7788b07d..f4dd73a5b04 100644
--- a/website/www/site/assets/js/language-switch-v2.js
+++ b/website/www/site/assets/js/language-switch-v2.js
@@ -208,15 +208,27 @@ $(document).ready(function() {
* send messages to them. This is cheap when the page only started loading.
*/
"onInit": function (lang) {
- const playgroundIframes = $(".code-snippet-playground iframe").get();
+ const playgroundIframeContainers = document.getElementsByClassName("code-snippet-playground");
const sdk = this.langToSdk(lang);
- for (const iframe of playgroundIframes) {
- const url = new URL(iframe.src);
+ for (const div of playgroundIframeContainers) {
+ const src = div.dataset.src;
+ const width = div.dataset.width;
+ const height = div.dataset.height;
+
+ const url = new URL(src);
const searchParams = new URLSearchParams(url.search);
searchParams.set("sdk", sdk);
url.search = searchParams.toString();
+
+ const iframe = document.createElement('iframe');
iframe.src = url.href;
+ iframe.width = width;
+ iframe.height = height;
+ iframe.className = 'playground';
+ iframe.allow = 'clipboard-write';
+
+ div.appendChild(iframe);
}
},
diff --git a/website/www/site/assets/scss/_playground.sass b/website/www/site/assets/scss/_playground.sass
index 7c3b4b99c34..b8785623708 100644
--- a/website/www/site/assets/scss/_playground.sass
+++ b/website/www/site/assets/scss/_playground.sass
@@ -39,10 +39,13 @@
width: 100%
@media (max-width: $mobile)
- .playground
- display: none
- .playground__mobile
- display: flex
+ .playground_or_image
+ .playground-wrapper
+ display: none
+ .playground__mobile
+ display: flex
+ img
+ box-shadow: 0 4px 16px 0 rgba(0, 0, 0, .16), 0 4px 4px 0 rgba(0, 0, 0, .16)
@media (min-width: $mobile)
.playground__mobile
diff --git a/website/www/site/layouts/index.html b/website/www/site/layouts/index.html
index 2e29c27df5f..f1c8ce0734b 100644
--- a/website/www/site/layouts/index.html
+++ b/website/www/site/layouts/index.html
@@ -57,33 +57,33 @@ limitations under the License. See accompanying LICENSE file.
</p>
<br>
<br>
- <a class="playground__mobile" href="https://play.beam.apache.org/">
- <img src="images/playground.png" alt="beam playground">
- </a>
+ <div class="playground_or_image">
+ <a class="playground__mobile" href="https://play.beam.apache.org/">
+ <img src="images/playground.png" alt="beam playground">
+ </a>
- <div class="playground-wrapper">
- <div class="playground-snippets">
- <div class="language-java playground-snippet" data-sdk="java"></div>
- <div class="language-py playground-snippet" data-sdk="python"></div>
- <div class="language-go playground-snippet" data-sdk="go"></div>
- <div class="language-scio playground-snippet" data-sdk="scio"></div>
- </div>
+ <div class="playground-wrapper">
+ <div class="playground-snippets">
+ <div class="language-java playground-snippet" data-sdk="java"></div>
+ <div class="language-py playground-snippet" data-sdk="python"></div>
+ <div class="language-go playground-snippet" data-sdk="go"></div>
+ <div class="language-scio playground-snippet" data-sdk="scio"></div>
+ </div>
- {{ $javaDict := dict "sdk" "java" "path" "SDK_JAVA_MinimalWordCount" }}
- {{ $pythonDict := dict "sdk" "python" "path" "SDK_PYTHON_WordCountWithMetrics" }}
- {{ $goDict := dict "sdk" "go" "path" "SDK_GO_MinimalWordCount" }}
- {{ $scioDict := dict "sdk" "scio" "path" "SDK_SCIO_MinimalWordCount" }}
- {{ $examples := slice $javaDict $pythonDict $goDict $scioDict }}
+ {{ $javaDict := dict "sdk" "java" "path" "SDK_JAVA_MinimalWordCount" }}
+ {{ $pythonDict := dict "sdk" "python" "path" "SDK_PYTHON_WordCountWithMetrics" }}
+ {{ $goDict := dict "sdk" "go" "path" "SDK_GO_MinimalWordCount" }}
+ {{ $scioDict := dict "sdk" "scio" "path" "SDK_SCIO_MinimalWordCount" }}
+ {{ $examples := slice $javaDict $pythonDict $goDict $scioDict }}
- <div class="code-snippet code-snippet-playground">
- <iframe
- src="https://play.beam.apache.org/embedded?sdk=java&examples={{ jsonify $examples }}"
- width="100%"
- height="700px"
- allow="clipboard-write"
- ></iframe>
+ <div
+ class="code-snippet code-snippet-playground"
+ data-src="https://play.beam.apache.org/embedded?examples={{ jsonify $examples }}"
+ data-width="100%"
+ data-height="700px"
+ ></div>
+ <div class="playground-iframe-overlay"></div>
</div>
- <div class="playground-iframe-overlay"></div>
</div>
</div>
{{ end }}
diff --git a/website/www/site/layouts/shortcodes/playground.html b/website/www/site/layouts/shortcodes/playground.html
index c23f8d571db..b68dc70bf2b 100644
--- a/website/www/site/layouts/shortcodes/playground.html
+++ b/website/www/site/layouts/shortcodes/playground.html
@@ -77,13 +77,10 @@ See playground_snippet for all supported options.
{{ $snippets := printf "%s%s%s" "[" (delimit $snippetsList ",") "]" }}
{{ $editable := 1 }}{{ if isset .Params "editable" }}{{ $editable = index .Params "editable" }}{{ end }}
- <div class="code-snippet code-snippet-playground">
- <iframe
- src="https://play.beam.apache.org/embedded?editable={{ $editable }}&examples={{ $snippets }}"
- width="100%"
- height="{{ .Get "height" }}"
- class="playground"
- allow="clipboard-write"
- ></iframe>
- </div>
+ <div
+ class="code-snippet code-snippet-playground"
+ data-src="https://play.beam.apache.org/embedded?editable={{ $editable }}&examples={{ $snippets }}"
+ data-width="100%"
+ data-height="{{ .Get "height" }}"
+ ></div>
</div>