twitterTimeline shortcode added

#240
This commit is contained in:
zzossig 2020-04-02 09:48:57 +09:00
parent b6a54acfde
commit 4c77300eeb
2 changed files with 77 additions and 3 deletions

View File

@ -529,16 +529,24 @@
}
}
var utterances = document.querySelector('iframe');
var utterances = document.getElementById('utterances');
if (utterances) {
utterances.contentWindow.postMessage({
utterances.querySelector('iframe').contentWindow.postMessage({
type: 'set-theme',
theme: selectedThemeVariant === "dark" || selectedThemeVariant === "hacker" ? 'photon-dark' : selectedThemeVariant === 'kimbie' ? 'github-dark-orange' : 'github-light',
}, 'https://utteranc.es');
}
var twitterCards = document.querySelectorAll('.twitter-timeline');
if (twitterCards) {
window.postMessage({
type: 'set-twitter-theme',
theme: selectedThemeVariant === 'light' || selectedThemeVariant === 'solarized' ? 'light' : 'dark',
});
}
});
}) : null;
// ============================================================
// ============================================================
// ========================== search ==========================

View File

@ -0,0 +1,66 @@
{{ $id := substr (md5 .Inner) 0 16 }}
<div id="{{ $id }}">
</div>
<script>
'use strict';
var id = JSON.parse({{ $id | jsonify }});
var root = document.getElementById('root');
{{ $href := (.Get "href") }}
var href = JSON.parse({{ $href | jsonify }});
{{ $height := (.Get "height") }}
var height = JSON.parse({{ $height | jsonify }});
{{ $width := (.Get "width") }}
var width = JSON.parse({{ $width | jsonify }});
{{ $inner := .Inner }}
var inner = JSON.parse({{ $inner | jsonify }});
function makeCard() {
var card = document.createElement('a');
card.setAttribute('class', 'twitter-timeline');
card.setAttribute('href', href);
card.setAttribute('data-chrome', 'nofooter');
var script = document.createElement('script');
script.setAttribute('src', 'https://platform.twitter.com/widgets.js');
script.setAttribute('charset', 'utf-8');
if (height) {
card.setAttribute('data-height', height);
}
if (width) {
card.setAttribute('data-width', width);
}
if (inner) {
card.textContent = inner;
}
var themeOption = root.getAttribute('class');
if (themeOption.includes('light') || themeOption.includes('solarized')) {
card.setAttribute('data-theme', 'light');
} else {
card.setAttribute('data-theme', 'dark');
}
var timeline = document.getElementById(id);
timeline.innerHTML = '';
timeline.appendChild(script);
timeline.appendChild(card);
}
var twitterCards = document.querySelectorAll('.twitter-timeline');
if (twitterCards) {
window.addEventListener('message', function (e) {
if (e.data.type === 'set-twitter-theme') {
makeCard();
}
});
}
makeCard();
</script>