Annotation of html5/spec/styler.js, revision 1.1

1.1     ! mike        1: function setStyleLink(link, style) {
        !             2:   document.getElementById(link).disabled = link != style;
        !             3:   if (link == style)
        !             4:     document.getElementById(link + '-radio').checked = true;
        !             5: }
        !             6: 
        !             7: function setStyle(style) {
        !             8:   var date = new Date();
        !             9:   date.setFullYear(date.getFullYear() + 1);
        !            10:   document.cookie = 'style=' + encodeURIComponent(style) + '; expires=' + date.toGMTString() + '; path=/';
        !            11:   setStyleLink('complete', style);
        !            12:   setStyleLink('author', style);
        !            13:   setStyleLink('highlight', style);
        !            14: }
        !            15: 
        !            16: function initStyler() {
        !            17:   var configUI = document.getElementById('configUI');
        !            18:   var stylesUI = document.createElement('p');
        !            19:   stylesUI.innerHTML =
        !            20:     '<label><input type=radio name=styles id=complete-radio value=complete onchange=setStyle(value)> Normal view</label>' + 
        !            21:     '<label><input type=radio name=styles id=author-radio value=author onchange=setStyle(value)> Web dev view</label>' +
        !            22:     '<label><input type=radio name=styles id=highlight-radio value=highlight onchange=setStyle(value)> Implementor view</label>' ;
        !            23:   configUI.appendChild(stylesUI);
        !            24:   // reset the style for webkit... XXX
        !            25:   setStyleLink('complete', '');
        !            26:   setStyleLink('author', '');
        !            27:   setStyleLink('highlight', '');
        !            28:   // put the style back to whatever the user last selected
        !            29:   var style = getCookie('style');
        !            30:   if (style != 'complete' && style != 'author' && style != 'highlight')
        !            31:     style = 'complete';
        !            32:   setStyle(style);
        !            33:   var hashChecker = function () {
        !            34:     if (style != 'author')
        !            35:       return;
        !            36:     var s = document.location.hash.substr(1);
        !            37:     if (s.length <= 0)
        !            38:       return;
        !            39:     var e = document.getElementById(s);
        !            40:     if (!e)
        !            41:       return;
        !            42:     while (e && (e != document.body)) {
        !            43:       if (getComputedStyle(e, '').display == 'none') {
        !            44:         var path = location.pathname;
        !            45:         var file = path.substr(path.lastIndexOf('/')+1);
        !            46:         showAlert('The link you followed is only available in the complete version of the specification:', file + '?style=highlight#' + s);
        !            47:         return;
        !            48:       }
        !            49:       e = e.parentNode;
        !            50:     }
        !            51:   };
        !            52:   window.addEventListener('hashchange', hashChecker, false);
        !            53:   hashChecker();
        !            54: }
        !            55: 
        !            56: var stylerTimer = new Date();
        !            57: initStyler();
        !            58: if (getCookie('profile') == '1')
        !            59:   document.getElementsByTagName('h2')[0].textContent += '; styler.js: ' + (new Date() - stylerTimer) + 'ms';

Webmaster