Commits

Gora Khargosh committed d60f15d

Handles events in JavaScript instead of in HTML.

  • Participants
  • Parent commits f7eaa94

Comments (0)

Files changed (2)

File coverage/htmlfiles/coverage_html.js

 
     coverage.assign_shortkeys();
     coverage.wire_up_help_panel();
+
+    // Toolbar buttons
+    var elements = {
+        button_stats_run: $('#button-stats-run'),
+        button_stats_missing: $('#button-stats-missing'),
+        button_stats_excluded: $('#button-stats-excluded'),
+        button_stats_par: $('#button-stats-par'),
+        source_run: $('#source .run'),
+        source_missing: $('#source .mis'),
+        source_excluded: $('#source .exc'),
+        source_par: $('#source .par')
+    };
+    var map_button_to_context = {
+        "button-stats-run": {
+            source_code: elements.source_run,
+            hide_class_name: 'hide_run'
+        },
+        "button-stats-missing": {
+            source_code: elements.source_missing,
+            hide_class_name: 'hide_mis'
+        },
+        "button-stats-excluded": {
+            source_code: elements.source_excluded,
+            hide_class_name: 'hide_exc'
+        },
+        "button-stats-par": {
+            source_code: elements.source_par,
+            hide_class_name: 'hide_par'
+        }
+    };
+    // Handle toolbar events.
+    var when_button_stats_clicked = function(event){
+        var elem = $(this),
+            context = map_button_to_context[elem.attr('id')];
+        coverage.toggle_lines(elem, context);
+    };
+    elements.button_stats_run.click(when_button_stats_clicked);
+    elements.button_stats_missing.click(when_button_stats_clicked);
+    elements.button_stats_excluded.click(when_button_stats_clicked);
+    elements.button_stats_par.click(when_button_stats_clicked);
+
+    // TODO: Show missing parts by default using JavaScript.
+    //elements.button_stats_missing.click();
 };
 
-coverage.toggle_lines = function (btn, cls) {
-    btn = $(btn);
-    var hide = "hide_"+cls;
+coverage.toggle_lines = function (btn, context) {
+    var hide = context.hide_class_name;
+    var source_code = context.source_code;
+
     if (btn.hasClass(hide)) {
-        $("#source ."+cls).removeClass(hide);
+        source_code.removeClass(hide);
         btn.removeClass(hide);
     }
     else {
-        $("#source ."+cls).addClass(hide);
+        source_code.addClass(hide);
         btn.addClass(hide);
     }
 };

File coverage/htmlfiles/pyfile.html

         <img id='keyboard_icon' src='keybd_closed.png'>
         <h2 class='stats'>
             {{nums.n_statements}} statements
-            <span class='{{c_run}} shortkey_r' onclick='coverage.toggle_lines(this, "run")'>{{nums.n_executed}} run</span>
-            <span class='{{c_mis}} shortkey_m' onclick='coverage.toggle_lines(this, "mis")'>{{nums.n_missing}} missing</span>
-            <span class='{{c_exc}} shortkey_x' onclick='coverage.toggle_lines(this, "exc")'>{{nums.n_excluded}} excluded</span>
+            <span id="button-stats-run" class='{{c_run}} shortkey_r'>{{nums.n_executed}} run</span>
+            <span id="button-stats-missing" class='{{c_mis}} shortkey_m'>{{nums.n_missing}} missing</span>
+            <span id="button-stats-excluded" class='{{c_exc}} shortkey_x'>{{nums.n_excluded}} excluded</span>
             {% if arcs %}
-                <span class='{{c_par}} shortkey_p' onclick='coverage.toggle_lines(this, "par")'>{{n_par}} partial</span>
+                <span id="button-stats-par" class='{{c_par}} shortkey_p'>{{n_par}} partial</span>
             {% endif %}
         </h2>
     </div>