Procházet zdrojové kódy

Add cssRedundantChildNodesSelectors rule

Gaël Métais před 10 roky
rodič
revize
6bb2be532a
2 změnil soubory, kde provedl 19 přidání a 4 odebrání
  1. 14 0
      app/node_views/results.html
  2. 5 4
      app/public/scripts/resultsCtrl.js

+ 14 - 0
app/node_views/results.html

@@ -504,6 +504,20 @@
                                     </modal-dialog>
                                     </modal-dialog>
                                 </div>
                                 </div>
                             </div>
                             </div>
+                            <div ng-if="phantomasResults.metrics.cssRedundantChildNodesSelectors">
+                                <div class="label">Redundant tags selectors</div>
+                                <div class="result">
+                                    {{phantomasResults.metrics.cssRedundantChildNodesSelectors}}
+                                    <show-offenders modal-title="Redundant tags selectors" metric-name="cssRedundantChildNodesSelectors" phantomas-results="phantomasResults"></show-offenders>
+                                </div>
+                                <div class="info">
+                                    <div class="icon-question" ng-click="cssRedundantChildNodesSelectorsTooltip = true"></div>
+                                    <modal-dialog show="cssRedundantChildNodesSelectorsTooltip" dialog-title="Useless redundant selectors">
+                                        <p>Some tags included inside other tags are obvious. For example, when "ul li" is specified in a rule, "ul" can be removed because the "li" element is <b>always</b> inside a "ul". Same thing for "tr td", "select option", ...</p>
+                                        <p>Lowering compexity in CSS selectors can make the page load a little faster.</p>
+                                    </modal-dialog>
+                                </div>
+                            </div>
                         </div>
                         </div>
                     </div>
                     </div>
                 </div>
                 </div>

+ 5 - 4
app/public/scripts/resultsCtrl.js

@@ -263,7 +263,7 @@ app.controller('ResultsCtrl', function ($scope) {
         var note = 'A';
         var note = 'A';
         var score = $scope.phantomasResults.metrics.cssRules +
         var score = $scope.phantomasResults.metrics.cssRules +
                     $scope.phantomasResults.metrics.cssComplexSelectors * 5 +
                     $scope.phantomasResults.metrics.cssComplexSelectors * 5 +
-                    $scope.phantomasResults.metrics.cssComplexSelectorsByAttribute * 15;
+                    $scope.phantomasResults.metrics.cssComplexSelectorsByAttribute * 10;
         if (score > 500) {
         if (score > 500) {
             note = 'B';
             note = 'B';
         }
         }
@@ -298,12 +298,13 @@ app.controller('ResultsCtrl', function ($scope) {
                     $scope.phantomasResults.metrics.cssOldIEFixes * 10 +
                     $scope.phantomasResults.metrics.cssOldIEFixes * 10 +
                     $scope.phantomasResults.metrics.cssOldPropertyPrefixes +
                     $scope.phantomasResults.metrics.cssOldPropertyPrefixes +
                     $scope.phantomasResults.metrics.cssUniversalSelectors * 5 +
                     $scope.phantomasResults.metrics.cssUniversalSelectors * 5 +
-                    $scope.phantomasResults.metrics.cssRedundantBodySelectors +
-                    ($scope.phantomasResults.metrics.cssImports || 0) * 50;
+                    $scope.phantomasResults.metrics.cssRedundantBodySelectors * 0.5 +
+                    $scope.phantomasResults.metrics.cssRedundantChildNodesSelectors * 0.5 +
+                    $scope.phantomasResults.metrics.cssImports * 50;
         if (score > 50) {
         if (score > 50) {
             note = 'B';
             note = 'B';
         }
         }
-        if (score > 10) {
+        if (score > 100) {
             note = 'C';
             note = 'C';
         }
         }
         if (score > 200) {
         if (score > 200) {