home *** CD-ROM | disk | FTP | other *** search
/ Computer Active Guide 2009 July / CAG7.ISO / Internetas / SafariSetup.exe / AppleApplicationSupport.msi / WebKit.resources_inspector_AuditResultView.js < prev    next >
Encoding:
Text File  |  2010-06-03  |  4.3 KB  |  107 lines

  1. /*
  2.  * Copyright (C) 2009 Google Inc. All rights reserved.
  3.  *
  4.  * Redistribution and use in source and binary forms, with or without
  5.  * modification, are permitted provided that the following conditions are
  6.  * met:
  7.  *
  8.  *     * Redistributions of source code must retain the above copyright
  9.  * notice, this list of conditions and the following disclaimer.
  10.  *     * Redistributions in binary form must reproduce the above
  11.  * copyright notice, this list of conditions and the following disclaimer
  12.  * in the documentation and/or other materials provided with the
  13.  * distribution.
  14.  *     * Neither the name of Google Inc. nor the names of its
  15.  * contributors may be used to endorse or promote products derived from
  16.  * this software without specific prior written permission.
  17.  *
  18.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29.  */
  30.  
  31. WebInspector.AuditResultView = function(categoryResults)
  32. {
  33.     WebInspector.View.call(this);
  34.     this.element.className = "audit-result-view";
  35.  
  36.     function categorySorter(a, b) {
  37.         return (a.title || "").localeCompare(b.title || "");
  38.     }
  39.     categoryResults.sort(categorySorter);
  40.     for (var i = 0; i < categoryResults.length; ++i)
  41.         this.element.appendChild(new WebInspector.AuditCategoryResultPane(categoryResults[i]).element);
  42. }
  43.  
  44. WebInspector.AuditResultView.prototype.__proto__ = WebInspector.View.prototype;
  45.  
  46.  
  47. WebInspector.AuditCategoryResultPane = function(categoryResult)
  48. {
  49.     WebInspector.SidebarPane.call(this, categoryResult.title);
  50.     var treeOutlineElement = document.createElement("ol");
  51.     this.bodyElement.addStyleClass("audit-result-tree");
  52.     this.bodyElement.appendChild(treeOutlineElement);
  53.  
  54.     this._treeOutline = new TreeOutline(treeOutlineElement);
  55.     this._treeOutline.expandTreeElementsWhenArrowing = true;
  56.  
  57.     function ruleSorter(a, b)
  58.     {
  59.         var result = WebInspector.AuditRule.SeverityOrder[a.severity || 0] - WebInspector.AuditRule.SeverityOrder[b.severity || 0];
  60.         if (!result)
  61.             result = (a.value || "").localeCompare(b.value || "");
  62.         return result;
  63.     }
  64.  
  65.     categoryResult.ruleResults.sort(ruleSorter);
  66.  
  67.     for (var i = 0; i < categoryResult.ruleResults.length; ++i) {
  68.         var ruleResult = categoryResult.ruleResults[i];
  69.         var treeElement = this._appendResult(this._treeOutline, ruleResult);
  70.         treeElement.listItemElement.addStyleClass("audit-result");
  71.  
  72.         if (ruleResult.severity) {
  73.             var severityElement = document.createElement("img");
  74.             severityElement.className = "severity-" + ruleResult.severity;
  75.             treeElement.listItemElement.appendChild(severityElement);
  76.         }
  77.     }
  78.     this.expand();
  79. }
  80.  
  81. WebInspector.AuditCategoryResultPane.prototype = {
  82.     _appendResult: function(parentTreeElement, result)
  83.     {
  84.         var title = result.value;
  85.         if (result.violationCount)
  86.             title = String.sprintf("%s (%d)", title, result.violationCount);
  87.  
  88.         var treeElement = new TreeElement(title, null, !!result.children);
  89.         parentTreeElement.appendChild(treeElement);
  90.  
  91.         if (result.className)
  92.             treeElement.listItemElement.addStyleClass(result.className);
  93.         if (result.children) {
  94.             for (var i = 0; i < result.children.length; ++i)
  95.                 this._appendResult(treeElement, result.children[i]);
  96.         }
  97.         if (result.expanded) {
  98.             treeElement.listItemElement.removeStyleClass("parent");
  99.             treeElement.listItemElement.addStyleClass("parent-expanded");
  100.             treeElement.expand();
  101.         }
  102.         return treeElement;
  103.     }
  104. }
  105.  
  106. WebInspector.AuditCategoryResultPane.prototype.__proto__ = WebInspector.SidebarPane.prototype;
  107.