<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[11466] sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse: Openverse: Fix 404s and embed height, send frame meta data</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/11466">11466</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/11466","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>iandunn</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2022-01-24 20:56:49 +0000 (Mon, 24 Jan 2022)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Openverse: Fix 404s and embed height, send frame meta data
* changes supplied path to lowercase to prevent 404 on case variations of https://wordpress.org/openverse
* uses a fixed value of --header-height to make the iframe occupy 100vh - header height
* adds functionality for sending meta-data from iframe to the parent window
* updates test page (also adds tips for certain fields)
* updates README.md and .wp-env.json to setup a dev environment
Props dhruvkb, sarayourfriend, zackkrida
Fixes <a href="http://meta.trac.wordpress.org/ticket/6041">#6041</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgopenversewpenvjson">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/.wp-env.json</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgopenverseREADMEmd">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/README.md</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgopenversecssopenversecss">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/css/openverse.css</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgopenverseheaderphp">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/header.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgopenversejsiframe_navjs">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/js/iframe_nav.js</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgopenversejsmessagejs">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/js/message.js</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgopenversejsmessage_testhtml">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/js/message_test.html</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgopenversewpenvjson"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/.wp-env.json</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/.wp-env.json 2022-01-24 09:00:36 UTC (rev 11465)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/.wp-env.json 2022-01-24 20:56:49 UTC (rev 11466)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,6 +1,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ "core": "WordPress/WordPress#master",
</ins><span class="cx" style="display: block; padding: 0 10px"> "themes": [
</span><span class="cx" style="display: block; padding: 0 10px"> ".",
</span><span class="cx" style="display: block; padding: 0 10px"> "../wporg"
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- ]
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ ],
+ "mappings": {
+ "wp-content/mu-plugins": "./wporg-mu-plugins/mu-plugins",
+ "wp-content/mu-plugins/mu-plugins.php": "./mu-plugins.php"
+ },
+ "config": {
+ "FEATURE_2021_GLOBAL_HEADER_FOOTER": true
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgopenverseREADMEmd"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/README.md</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/README.md 2022-01-24 09:00:36 UTC (rev 11465)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/README.md 2022-01-24 20:56:49 UTC (rev 11466)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -13,9 +13,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 1. Build the parent theme WordPress.org theme.
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 1. `cd` into the parent theme directory at `../wporg`
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 1. `cd` into the parent theme directory at `../wporg`
</ins><span class="cx" style="display: block; padding: 0 10px"> (i.e. `wordpress.org/wordpress.org/public_html/wp-content/themes/pub/wporg`).
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 3. Install all the required `npm` packages.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 2. Install all the required `npm` packages.
</ins><span class="cx" style="display: block; padding: 0 10px"> ```bash
</span><span class="cx" style="display: block; padding: 0 10px"> $ npm install
</span><span class="cx" style="display: block; padding: 0 10px"> ```
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -26,7 +26,27 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 4. `cd` back to the Openverse theme directory at `../wporg-openverse`
</span><span class="cx" style="display: block; padding: 0 10px"> (i.e. `wordpress.org/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse`).
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-2. You can choose to set up a new environment automatically or work in an
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+2. Build the MU plugins.
+
+ 1. Clone the `WordPress/wporg-mu-plugins` repo right into this directory.
+ It's `.gitignored` so it shouldn't affect anything.
+ ```bash
+ $ git clone https://github.com/WordPress/wporg-mu-plugins.git
+ ```
+ 2. `cd` into this directory at `./wporg-mu-plugins`
+ (i.e. `wordpress.org/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/wporg-mu-plugins`).
+ 3. Install all the required `npm` packages.
+ ```bash
+ $ npm install
+ ```
+ 4. Build the theme assets.
+ ```bash
+ $ npm run build
+ ```
+ 5. `cd` back to the Openverse theme directory at `..`
+ (i.e. `wordpress.org/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse`).
+
+3. You can choose to set up a new environment automatically or work in an
</ins><span class="cx" style="display: block; padding: 0 10px"> existing environment with manual setup.
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> **Automatic:**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -49,9 +69,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> **Manual:**
</span><span class="cx" style="display: block; padding: 0 10px"> If you prefer a manual approach, you can also set up your own WordPress
</span><span class="cx" style="display: block; padding: 0 10px"> instance and load both the `wporg` (parent) and `wporg-openverse` (child)
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- themes into the `wp-content/themes` directory.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ themes into the `wp-content/themes` directory. You must also load the MU
+ plugins and activate them using the `mu-plugins.php` file.
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-3. Activate and customize the theme.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+4. Activate and customize the theme.
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 1. Log into `/wp-admin`.
</span><span class="cx" style="display: block; padding: 0 10px"> 2. Under Appearance > Themes, activate the theme 'WordPress.org Openverse'.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -58,7 +79,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 3. To change the embed URL, open the customizer at Appearance > Customize
</span><span class="cx" style="display: block; padding: 0 10px"> and update the value in the 'Openverse embed' panel.
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-4. Test message passing.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+5. Test message passing.
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 1. Change the Openverse embed to
</span><span class="cx" style="display: block; padding: 0 10px"> `/wp-content/themes/wporg-openverse/js/message_test.html`.
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgopenversecssopenversecss"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/css/openverse.css</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/css/openverse.css 2022-01-24 09:00:36 UTC (rev 11465)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/css/openverse.css 2022-01-24 20:56:49 UTC (rev 11466)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,8 +1,19 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+:root {
+ --header-height: 117px;
+}
+
+@media (min-width: 890px) {
+ :root {
+ --header-height: 104.453px;
+ }
+}
+
+
</ins><span class="cx" style="display: block; padding: 0 10px"> #openverse_embed {
</span><span class="cx" style="display: block; padding: 0 10px"> display: block;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> width: 100%;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- height: var(--openverse-embed-height, 100vh); /* This will be updated by JavaScript */
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ height: calc(100vh - var(--header-height));
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> border: none;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgopenverseheaderphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/header.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/header.php 2022-01-24 09:00:36 UTC (rev 11465)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/header.php 2022-01-24 20:56:49 UTC (rev 11466)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -13,12 +13,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> \WordPressdotorg\skip_to( '#content' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-if ( FEATURE_2021_GLOBAL_HEADER_FOOTER ) {
- echo do_blocks( '<!-- wp:wporg/global-header /-->' );
-} else {
- get_template_part( 'header', 'wporg' );
-}
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+get_template_part( 'header', 'wporg' );
+?>
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-?>
</del><span class="cx" style="display: block; padding: 0 10px"> <div id="page" class="site">
</span><span class="cx" style="display: block; padding: 0 10px"> <div id="content" class="site-content">
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgopenversejsiframe_navjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/js/iframe_nav.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/js/iframe_nav.js 2022-01-24 09:00:36 UTC (rev 11465)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/js/iframe_nav.js 2022-01-24 20:56:49 UTC (rev 11466)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,7 +1,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> document.addEventListener('DOMContentLoaded', () => {
</span><span class="cx" style="display: block; padding: 0 10px"> const { pathname: path, search: query } = window.location; // starts with /
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- let iframePath = path.replace(openverseSubpath, '').replace(/^\/$/, ''); // Remove Openverse site subpath
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ let iframePath = path
+ .toLocaleLowerCase()
+ .replace(openverseSubpath, '')
+ .replace(/^\/$/, ''); // Remove Openverse site subpath
</ins><span class="cx" style="display: block; padding: 0 10px"> iframePath = `${openverseUrl}${iframePath}${query}`; // Add domain and query
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> console.log(`Navigating iframe to ${iframePath}`);
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgopenversejsmessagejs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/js/message.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/js/message.js 2022-01-24 09:00:36 UTC (rev 11465)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/js/message.js 2022-01-24 20:56:49 UTC (rev 11466)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,25 +1,4 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Update the height of the nested `iframe` to match the height of the nested
- * element. This function sets the value of the `--openverse-embed-height` CSS
- * custom property (which is `100vh`, by default).
- *
- * @param {{ height: number }} value - the new dimensions of the iframe
- */
-function updateHeight(value) {
- const height = value.height;
- let heightProp;
- if (height) {
- heightProp = `${height}px`;
- } else {
- heightProp = '100vh';
- }
- document
- .documentElement
- .style
- .setProperty('--openverse-embed-height', heightProp);
-}
-
-/**
</del><span class="cx" style="display: block; padding: 0 10px"> * Update the URL in the address bar when a page navigation occurs inside the
</span><span class="cx" style="display: block; padding: 0 10px"> * `iframe` This function uses the History API to change the address without a
</span><span class="cx" style="display: block; padding: 0 10px"> * page reload.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -48,6 +27,33 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Set the meta attributes on the top-level document based on the meta tags
+ * passed by the `iframe`.
+ *
+ * @param {{
+ * meta: [{
+ * name: string,
+ * content: string,
+ * }]
+ * }} value - the meta data data supplied by the `iframe`
+ */
+function updateMeta(value) {
+ value.meta.forEach((metaItem) => {
+ let metaTag = document.head.querySelector(`meta[name="${metaItem.name}"]`);
+ if (metaTag) {
+ // Update the tag, if it already exists
+ metaTag.content = metaItem.content;
+ } else {
+ // Create a new tag, otherwise
+ metaTag = document.createElement('meta');
+ metaTag.name = metaItem.name;
+ metaTag.content = metaItem.content;
+ document.head.appendChild(metaTag);
+ }
+ })
+}
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Emit a message to the `iframe` containing information about the current
</span><span class="cx" style="display: block; padding: 0 10px"> * locale. This function combines the locale from WordPress with attributes
</span><span class="cx" style="display: block; padding: 0 10px"> * from the top-level HTML document.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -95,12 +101,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> let handler;
</span><span class="cx" style="display: block; padding: 0 10px"> switch (data.type) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- case 'resize':
- handler = updateHeight;
- break;
</del><span class="cx" style="display: block; padding: 0 10px"> case 'urlChange':
</span><span class="cx" style="display: block; padding: 0 10px"> handler = updatePath;
</span><span class="cx" style="display: block; padding: 0 10px"> break;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ case 'setMeta':
+ handler = updateMeta;
+ break;
</ins><span class="cx" style="display: block; padding: 0 10px"> case 'localeGet':
</span><span class="cx" style="display: block; padding: 0 10px"> handler = emitLocale;
</span><span class="cx" style="display: block; padding: 0 10px"> break;
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgopenversejsmessage_testhtml"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/js/message_test.html</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/js/message_test.html 2022-01-24 09:00:36 UTC (rev 11465)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/js/message_test.html 2022-01-24 20:56:49 UTC (rev 11466)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -12,6 +12,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> display: inline-block;
</span><span class="cx" style="display: block; padding: 0 10px"> width: 5em;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ .tip {
+ color: #555;
+ font-size: 0.875em;
+ margin-top: 2px;
+ }
+
+ .tip::before {
+ content: '💡'
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> </style>
</span><span class="cx" style="display: block; padding: 0 10px"> <script>
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -66,6 +76,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> sendMessage('urlChange', message);
</span><span class="cx" style="display: block; padding: 0 10px"> });
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ document.forms.setMeta.addEventListener('submit', (event) => {
+ event.preventDefault();
+
+ const metaInput = document.getElementById('metaInput');
+ const meta = JSON.parse(metaInput.value);
+
+ const message = { meta };
+ sendMessage('setMeta', message);
+ });
+
</ins><span class="cx" style="display: block; padding: 0 10px"> document.forms.localeGet.addEventListener('submit', (event) => {
</span><span class="cx" style="display: block; padding: 0 10px"> event.preventDefault();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -89,24 +109,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <body>
</span><span class="cx" style="display: block; padding: 0 10px"> <h1>Message exchange</h1>
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <h2>Test resize</h2>
- <form name="resize">
- <div class="row">
- <label for="height">Height*:</label>
- <input
- id="height"
- type="number"
- placeholder="Height (px)"
- required/>
- <code>{number}</code>
- </div>
- <div class="row">
- <button type="submit">
- Send message
- </button>
- </div>
- </form>
-
</del><span class="cx" style="display: block; padding: 0 10px"> <h2>Test URL change</h2>
</span><span class="cx" style="display: block; padding: 0 10px"> <form name="urlChange">
</span><span class="cx" style="display: block; padding: 0 10px"> <div class="row">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -117,6 +119,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> placeholder="Absolute path"
</span><span class="cx" style="display: block; padding: 0 10px"> required/>
</span><span class="cx" style="display: block; padding: 0 10px"> <code>{string}</code>
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <p class="tip">Start the path with a '/'.</p>
</ins><span class="cx" style="display: block; padding: 0 10px"> </div>
</span><span class="cx" style="display: block; padding: 0 10px"> <div class="row">
</span><span class="cx" style="display: block; padding: 0 10px"> <label for="titleInput">Title:</label>
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -125,6 +128,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> type="text"
</span><span class="cx" style="display: block; padding: 0 10px"> placeholder="Title"/>
</span><span class="cx" style="display: block; padding: 0 10px"> <code>{string?}</code>
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <p class="tip">Add the '- Openverse' suffix.</p>
</ins><span class="cx" style="display: block; padding: 0 10px"> </div>
</span><span class="cx" style="display: block; padding: 0 10px"> <div class="row">
</span><span class="cx" style="display: block; padding: 0 10px"> <button type="submit">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -133,6 +137,27 @@
</span><span class="cx" style="display: block; padding: 0 10px"> </div>
</span><span class="cx" style="display: block; padding: 0 10px"> </form>
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <h2>Test meta tag passing</h2>
+ <form name="setMeta">
+ <div class="row">
+ <label for="metaInput">Meta*:</label>
+ <textarea
+ id="metaInput"
+ type="text"
+ placeholder="Meta JSON"
+ cols="24"
+ rows="4"
+ required></textarea>
+ <code>JSON ~ [{name: string, content: string}]</code>
+ <p class="tip">Try a 'theme-color' meta tag if your browser supports it.</p>
+ </div>
+ <div class="row">
+ <button type="submit">
+ Send message
+ </button>
+ </div>
+ </form>
+
</ins><span class="cx" style="display: block; padding: 0 10px"> <h2>Test locale get</h2>
</span><span class="cx" style="display: block; padding: 0 10px"> <form name="localeGet">
</span><span class="cx" style="display: block; padding: 0 10px"> <div class="row">
</span></span></pre>
</div>
</div>
</body>
</html>