w3c / wot-thing-description

Web of Things (WoT) Thing Description
http://w3c.github.io/wot-thing-description/
Other
131 stars 63 forks source link

Published TD document - JS Code does not work as expected #1423

Closed danielpeintner closed 2 years ago

danielpeintner commented 2 years ago

The recently published TD version has a minor bug with JS code

See Example 4, https://www.w3.org/TR/2022/WD-wot-thing-description11-20220311/#example-4

Clicking “with Default Values” does not work (it works for the editors draft which uses reSpec).

Uncaught TypeError: document.respec is undefined

Hence, the following code

https://github.com/w3c/wot-thing-description/blob/9ee62da2514cb4b874bf5d5ad98ec8b5a932057b/index.html#L236-L262

should be changed to

  <script>
    //document.addEventListener('DOMContentLoaded', () => {
    //    // let ReSpec do syntax highlighting first
    //    document.respecIsReady.then(() => {
    //
    // W3C specs on the W3C server don't use ReSpec, so remove the
    // above three lines to avoid dependency on ReSpec.
    // instead add the following two lines. (*1)
    document.addEventListener('readystatechange', () => {
        if (document.readyState === 'complete') {

            document.querySelectorAll('.with-default').forEach(n => {
                let wo = n.querySelector('pre:nth-of-type(1)');
                let w = n.querySelector('pre:nth-of-type(2)');
                let cbox = n.querySelector('.with-default-control input[type="checkbox"]');

                w.classList.add('selected');
                cbox.checked = true;

                cbox.addEventListener('change', e => {
                    if (e.target.checked) {
                        // with default
                        w.classList.add('selected');
                        wo.classList.remove('selected');
                    } else {
                        // without
                        w.classList.remove('selected');
                        wo.classList.add('selected');
                    }
                });
            });
        //});
        } // According to the change above (*1), the blacket should be also changed from "});" to "}".
    });
  </script>
ashimura commented 2 years ago

fixed.

Please see: https://www.w3.org/TR/2022/WD-wot-thing-description11-20220311/

I've added a note to the README.md on How to edit the draft for publication as well.

danielpeintner commented 2 years ago

TODO: find a way to have a script that works in both cases without the hurdles of changing JS code for publication.

danielpeintner commented 2 years ago

I've added a note to the README.md on How to edit the draft for publication as well.

@ashimura shall we remove the note again OR leave it in 3-wd folder. I wasn't sure whether there is a template that is used for future publications. I proposed a fix (see #1489).