User:Janschejbal/common.js

// Proof of concept by Jan Schejbal // using code from https://github.com/itinerarium/phoneme-synthesis (GPLv3 by itinerarium) // see https://github.com/itinerarium/phoneme-synthesis/blob/master/LICENSE

var BASE_URL = 'https://www.janschejbal.de/temp/speakipa/sandbox_iframe.html#';

var oldframe;

function showPopup(el, ipa) { console.log('Showing popup for playing ' + ipa); if (oldframe) { oldframe.remove; oldframe = null; } var frame = document.createElement('iframe'); frame.sandbox="allow-scripts allow-same-origin"; frame.src = BASE_URL + encodeURIComponent(ipa); frame.width = 60; frame.height = 60; frame = $(frame); frame.css({position: 'fixed', top: '10px', left: '10px'}); // Uncomment to hide the iframe if autoplay works for you: frame.css('visibility', 'hidden'); $(document.body).append(frame); oldframe = frame; }

function add { var ipa = $(this).text; var play = $(' ⏵ '); play.css('color', '#0af'); play.click(function {showPopup(play, ipa)}); return play; }

$(function { jQuery('.IPA').after(add); });