Use event delegation.

This way, we avoid binding the event handler to all lines. Instead, we
bind to the container and simply pass on control to the targeted frame.
This commit is contained in:
Franz Liedke
2014-02-16 15:26:32 +01:00
parent 9a7df7fb48
commit fda2b8ea1b
+1 -2
View File
@@ -3,7 +3,6 @@ Zepto(function($) {
var $frameContainer = $('.frames-container');
var $container = $('.details-container');
var $frameLines = $frameContainer.find('.frame');
var $activeLine = $frameContainer.find('.frame.active');
var $activeFrame = $container.find('.frame-code.active');
var headerHeight = $('header').height();
@@ -22,7 +21,7 @@ Zepto(function($) {
// Highlight the active for the first frame:
highlightCurrentLine();
$frameLines.click(function() {
$frameContainer.delegate('.frame', 'click', function() {
var $this = $(this);
var id = /frame\-line\-([\d]*)/.exec($this.attr('id'))[1];
var $codeFrame = $('#frame-code-' + id);