Selaa lähdekoodia

Listing 3.18: removing an event handler.

Frederic G. MARAND 8 vuotta sitten
vanhempi
säilyke
af79817a7b
1 muutettua tiedostoa jossa 15 lisäystä ja 3 poistoa
  1. 15 3
      Chapter 3/03.js

+ 15 - 3
Chapter 3/03.js

@@ -8,6 +8,20 @@ $(document).ready(function () {
   });
 });
 
+$(document).ready(function () {
+  'use strict';
+
+  $('#switcher').click(function(event) {
+    if (!$(event.target).is('button')) {
+      $('#switcher button').toggleClass('hidden');
+    }
+  });
+
+  $('#switcher-narrow, #switcher-large').click(function () {
+    $('#switcher').off('click');
+  });
+});
+
 $(document).ready(function () {
   'use strict';
 
@@ -21,8 +35,6 @@ $(document).ready(function () {
 
       $('#switcher button').removeClass('selected');
         $(event.target).addClass('selected');
-    } else {
-      $('#switcher button').toggleClass('hidden');
-    }
+    } 
   });
 });