Created
April 3, 2020 13:23
-
-
Save tomhodgins/4c1c114d5ccade0d452a98dc3c302014 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<script type=module> | |
import computedVariables from 'https://unpkg.com/computed-variables/index.es.js'; | |
computedVariables( | |
'--python', | |
(value, event, rule) => { | |
if ('brython' in window === false) { | |
const tag = document.createElement('script'); | |
tag.onload = callback; | |
tag.src = 'https://cdnjs.cloudflare.com/ajax/libs/brython/3.8.8/brython.js'; | |
document.head.append(tag); | |
} else { | |
callback(); | |
} | |
function callback() { | |
const python = document.createElement('script'); | |
python.type = 'text/python'; | |
python.textContent = rule.style.getPropertyValue('--python-value').replace(/\\;/g, ';\n'); | |
document.head.append(python); | |
brython(); | |
} | |
}, | |
window, | |
['load'] | |
) | |
</script> | |
<style> | |
#demo { | |
--python: | |
from browser import document, alert\; | |
def hello(ev): alert("hello from python in CSS!")\; | |
document["demo"].bind("click", hello)\; | |
; | |
} | |
</style> | |
<button id=demo>Click me</button> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment