Skip to content

Commit 2499226

Browse files
committed
Switch to event delegation for home.js+main.js
Due to 5f3cd13 adding scroll capabilities to all anchor links, this causes the toggle buttons to jump around on the homepage. stopPropagation will stop the event from bubbling and means that we can keep the behaviour from 5f3cd13 without breaking the home page. For stopPropagation to work effectively, both home.js and main.js need to use event delegation - so that propagation bubbles effectively. This also offers the side benefit that there are loads less events to bind now :)
1 parent ac1263e commit 2499226

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

js/home.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ $(function () {
22

33
var lastInstall = '#node'
44
, allowToggle = true;
5-
$('.install a.toggle').click(function (e) {
5+
$('.install').on('click', 'a.toggle', function (e) {
66
e.preventDefault();
7+
e.stopPropagation();
78
if (!allowToggle) return;
89
var which = $(this).attr('href');
910
allowToggle = false;

js/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
$(function () {
22

3-
$('a[href^="#"]').click(function (e) {
3+
$('body').on('click', 'a[href^="#"]', function (e) {
44
e.preventDefault();
55

66
var section = $(this).attr('href')

0 commit comments

Comments
 (0)