var annotator = { QUERY_URI: "http://test.csswg.org/harness/status.php", STYLESHEET_URI: "style/annotate.css", NEED_TEST_ICON_URI: "images/please_help_32.png", mResponse: null , mClosed: false , removeAnnotation: function (anchorName){ try { var annotation = document.getElementById('annotation_' + ((0 < _AN_Read_length('length', anchorName))? anchorName: 'root_')); if (annotation) { annotation.parentNode.removeChild(annotation); } } catch (err) { } } , removeAllAnnotations: function (){ try { if (this.mResponse && this.mResponse.sections) { for (index in this.mResponse.sections){ this.removeAnnotation(this.mResponse.sections[index].anchorName); } } } catch (err) { } } , toggleAnnotations: function (){ this.mClosed = (!this.mClosed); this.removeAllAnnotations(); this.addAnnotations(); } , addAnnotationTo: function (anchorElement, section, first){ try { var headings = { 'h1': '', 'h2': '', 'h3': '', 'h4': '', 'h5': '', 'h6': '', 'H1': '', 'H2': '', 'H3': '', 'H4': '', 'H5': '', 'H6': ''} ; var targetElement = anchorElement; while (targetElement && (Node.ELEMENT_NODE == targetElement.nodeType) && (!(targetElement.tagName in headings))){ targetElement = targetElement.parentNode; } if (targetElement && (Node.ELEMENT_NODE == targetElement.nodeType)) { var annotation = _AN_Call_createelement('createElement', document, 'div'); _AN_Call_setattribute('setAttribute', annotation, 'id', 'annotation_' + ((0 == _AN_Read_length('length', section.anchorName))? 'root_': section.anchorName)); var annotationClass = 'annotation'; if (first) { annotationClass += ' first'; } if (0 < section.needCount) { annotationClass += ' need'; } if (this.mClosed) { annotationClass += ' closed'; } _AN_Call_setattribute('setAttribute', annotation, 'class', annotationClass); _AN_Call_setattribute('setAttribute', annotation, 'testCount', section.testCount); _AN_Call_setattribute('setAttribute', annotation, 'needCount', section.needCount); if (first) { var disclosure = _AN_Call_createelement('createElement', document, 'div'); _AN_Call_setattribute('setAttribute', disclosure, 'class', 'disclosureBox'); _AN_Call_setattribute('setAttribute', disclosure, 'onclick', 'annotator.toggleAnnotations()'); _AN_Call_appendchild('appendChild', annotation, disclosure); } var closeBox = _AN_Call_createelement('createElement', document, 'div'); _AN_Call_setattribute('setAttribute', closeBox, 'class', 'closeBox'); if (first) { _AN_Call_setattribute('setAttribute', closeBox, 'onclick', 'annotator.removeAllAnnotations()'); } else { _AN_Call_setattribute('setAttribute', closeBox, 'onclick', 'annotator.removeAnnotation("' + section.anchorName + '")'); } _AN_Call_appendchild('appendChild', annotation, closeBox); var heading = _AN_Call_createelement('createElement', document, 'div'); _AN_Call_setattribute('setAttribute', heading, 'class', 'heading'); var testLink = _AN_Call_createelement('createElement', document, 'a'); _AN_Call_setattribute('setAttribute', testLink, 'href', section.testURI); if (1 == section.testCount) { _AN_Call_appendchild('appendChild', testLink, document.createTextNode('1 Test')); } else { _AN_Call_appendchild('appendChild', testLink, document.createTextNode(section.testCount + ' Tests')); } if ((!this.mClosed) && (0 < section.needCount)) { var image = _AN_Call_createelement('createElement', document, 'img'); _AN_Call_setattribute('setAttribute', image, 'src', this.NEED_TEST_ICON_URI); _AN_Call_setattribute('setAttribute', image, 'class', 'need'); _AN_Call_appendchild('appendChild', testLink, image); if (1 == section.needCount) { _AN_Call_setattribute('setAttribute', testLink, 'title', '1 test needs results from your client, please click here to run test'); } else { _AN_Call_setattribute('setAttribute', testLink, 'title', section.needCount + ' tests need results from your client, please click here to run tests'); } var untested = _AN_Call_createelement('createElement', document, 'span'); _AN_Call_appendchild('appendChild', untested, document.createTextNode(' ' + section.needCount + '\u00A0untested, please\u00A0test')); _AN_Call_appendchild('appendChild', testLink, untested); } _AN_Call_appendchild('appendChild', heading, testLink); _AN_Call_appendchild('appendChild', annotation, heading); if (!this.mClosed) { var engines = _AN_Call_createelement('createElement', document, 'div'); _AN_Call_setattribute('setAttribute', engines, 'class', 'engines'); for (index in section.engines){ var engine = section.engines[index]; var resultCount = (engine.passCount + engine.failCount); var toolTip = ''; var engineClass = ''; if (0 < resultCount) { if (engine.passCount == section.testCount) { toolTip = 'All tests pass'; engineClass = 'pass'; } else { if (engine.failCount == section.testCount) { toolTip = 'All tests fail'; engineClass = 'fail'; } else { if (0 < engine.passCount) { toolTip = engine.passCount + ' pass'; } if (0 < engine.failCount) { if (toolTip.length) { toolTip += ', '; } toolTip += engine.failCount + ' fail'; } if (resultCount < section.testCount) { if (toolTip.length) { toolTip += ', '; } toolTip += (section.testCount - resultCount) + ' untested'; } if ((resultCount / section.testCount) < 0.95) { engineClass = 'untested'; } else { engineClass = 'p' + Math.round((engine.passCount / section.testCount) * 10) + '0'; } } } } else { toolTip = 'No data'; } if (0 < resultCount) { var engineNode = _AN_Call_createelement('createElement', document, 'span'); _AN_Call_setattribute('setAttribute', engineNode, 'title', toolTip); if (engine.name == this.mResponse.clientEngineName) { engineClass += ' active'; } _AN_Call_setattribute('setAttribute', engineNode, 'class', engine.name + ' ' + engineClass); _AN_Call_setattribute('setAttribute', engineNode, 'passCount', engine.passCount); _AN_Call_setattribute('setAttribute', engineNode, 'failCount', engine.failCount); _AN_Call_setattribute('setAttribute', engineNode, 'needCount', section.testCount - resultCount); if (0 < resultCount) { var detailsLink = _AN_Call_createelement('createElement', document, 'a'); _AN_Call_setattribute('setAttribute', detailsLink, 'href', engine.detailsURI); _AN_Call_appendchild('appendChild', detailsLink, document.createTextNode(engine.title)); _AN_Call_appendchild('appendChild', engineNode, detailsLink); } else { _AN_Call_appendchild('appendChild', engineNode, document.createTextNode(engine.title)); } _AN_Call_appendchild('appendChild', engines, engineNode); _AN_Call_appendchild('appendChild', engines, document.createTextNode(' ')); } } _AN_Call_appendchild('appendChild', annotation, engines); } targetElement.insertBefore(annotation, targetElement.firstChild); return true ; } } catch (err) { } return false ; } , addAnnotation: function (section, first){ try { var anchorName = section.anchorName; if (anchorName) { var found = false ; anchor = document.getElementById(anchorName); if (!(anchor && this.addAnnotationTo(anchor, section, first))) { var anchors = document.getElementsByName(anchorName); for (index in anchors){ var anchor = anchors[index]; if (this.addAnnotationTo(anchor, section, first)) { break ; } } } } else if (first) { var headings = _AN_Call_getelementsbytagname('getElementsByTagName', document, 'h1'); if (headings && (0 < _AN_Read_length('length', headings))) { this.addAnnotationTo(headings[0], section, first); } } } catch (err) { } } , addAnnotations: function (){ try { if (this.mResponse && this.mResponse.sections) { if (0 < _AN_Read_length('length', this.mResponse.sections)) { if (this.mClosed) { this.addAnnotation(this.mResponse.sections[0], true ); } else { var first = true ; for (index in this.mResponse.sections){ this.addAnnotation(this.mResponse.sections[index], first); first = false ; } } } } } catch (err) { } } , processResponse: function (contentType, responseText){ try { if (-1 < contentType.indexOf('application/json')) { var response = JSON.parse(responseText); if (response) { this.mResponse = response; this.addAnnotations(); } } } catch (err) { } } , annotate: function (){ try { var testSuiteName = ''; var scripts = _AN_Call_getelementsbytagname('getElementsByTagName', document, 'script'); for (index in scripts){ if (scripts[index].hasAttribute('src')) { var scriptSource = _AN_Call_getattribute('getAttribute', scripts[index], 'src'); if (-1 < scriptSource.indexOf('/annotate.js#')) { testSuiteName = scriptSource.substr(scriptSource.indexOf('#') + 1); if ('!' == testSuiteName[0]) { testSuiteName = testSuiteName.substr(1); this.mClosed = true ; } break ; } } } if (0 < _AN_Read_length('length', testSuiteName)) { var styleSheet = _AN_Call_createelement('createElement', document, 'link'); _AN_Call_setattribute('setAttribute', styleSheet, 'rel', 'stylesheet'); _AN_Call_setattribute('setAttribute', styleSheet, 'type', 'text/css'); _AN_Call_setattribute('setAttribute', styleSheet, 'href', this.STYLESHEET_URI); _AN_Call_appendchild('appendChild', _AN_Call_getelementsbytagname('getElementsByTagName', document, 'head')[0], styleSheet); var statusURI = this.QUERY_URI + '?s=' + encodeURIComponent(testSuiteName) + '&x=' + encodeURIComponent(document.baseURI); if (window.XDomainRequest) { var xdr = new XDomainRequest(); if (xdr) { xdr.onload = function (){ annotator.processResponse(xdr.contentType, xdr.responseText); } ; _AN_Call_open('open', xdr, 'GET', statusURI); _AN_Call_send('send', xdr); } } else { var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function (){ if (4 == xhr.readyState) { if (200 == xhr.status) { annotator.processResponse(xhr.getResponseHeader('Content-Type'), xhr.responseText); } else if (500 == xhr.status) { } else { } } } ; _AN_Call_open('open', xhr, 'GET', statusURI, true ); xhr.setRequestHeader('Accept', 'application/json,text/html'); _AN_Call_send('send', xhr); } } } catch (err) { } } , addLoadEvent: function (){ try { var oldOnLoad = window.onload; if (typeof window.onload != 'function') { window.onload = this.annotate(); } else { window.onload = function (){ if (oldOnLoad) { oldOnLoad(); } annotator.annotate(); } ; } } catch (err) { } } } ; annotator.addLoadEvent();