Skip to content

Instantly share code, notes, and snippets.

@JasonOffutt
Created December 6, 2012 23:03
Show Gist options
  • Save JasonOffutt/4229291 to your computer and use it in GitHub Desktop.
Save JasonOffutt/4229291 to your computer and use it in GitHub Desktop.
JS Event-Driven Block Disabling
$(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