# -*- coding: utf-8 -*-
"""
Description: Client side of sanity check
Author: Mike Ellis
Copyright 2017 Owner
"""
from htmltree import *
def start():
    console.log("Starting")
    newcontent = H1("Sanity check PASS", _class='test', style=dict(color='green'))
    console.log(newcontent.render(0))
    document.body.innerHTML = newcontent.render()
    console.log("Finished")
document.addEventListener('DOMContentLoaded', start)


# -*- coding: utf-8 -*-
"""
Description: Client side of sanity check
Uses JS functions insertAdjacentHTML, innerHTML and addEventListener.
See https://developer.mozilla.org/en-US/docs/Web/API/Element/insertAdjacentHTML
    https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML
    https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener

Author: Mike Ellis
Copyright 2017 Owner
"""
from htmltree import *
def start():
    console.log("Starting")
    ## insert a style element at the end of the <head?
    cssrules = {'.test':{'color':'green', 'text-align':'center'}}
    style = Style(**cssrules)
    document.head.insertAdjacentHTML('beforeend', style.render())

    ## Replace the <body> content
    newcontent = Div(H1("Sanity check PASS", _class='test'))
    document.body.innerHTML = newcontent.render()
    console.log("Finished")

## JS is event driven.
## Wait for DOM load to complete before firing
## our start() function.
document.addEventListener('DOMContentLoaded', start)


Fix <style> rendering under Transcrypt.
Fix <style> rendering under Transcrypt.

The hasattr test in renderCss() was failing when it shouldn't have.
Fixed by removal. Updated tests/client.py to create and append a style
element to detect problems related to Style() on the client side.
