Created
December 6, 2012 23:03
-
-
Save JasonOffutt/4229291 to your computer and use it in GitHub Desktop.
JS Event-Driven Block Disabling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function () { | |
$('.disable-on-edit').click(function () { | |
var id = $(this).parents('.block-instance').attr('id'); | |
$(document).trigger('EDIT_CLICKED', id); | |
}); | |
$('.save').click(function () { | |
$(document).trigger('EDIT_COMPLETE'); | |
}); | |
$(document).bind('EDIT_CLICKED', function (id) { | |
var $blocks = $('.block-instance'); | |
$blocks.each(function (index, value) { | |
var $el = $(this); | |
if ($el.attr('id') !== id) { | |
$el.addClass('disabled'); | |
$el.bind('click', function (e) { | |
e.preventDefault(); | |
e.stopPropogation(); | |
return false; | |
}); | |
} | |
}) | |
}); | |
$(document).bind('EDIT_COMPLETE', function () { | |
$('.block-instance').removeClass('disabled').unbind('click'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment