Skip to content

Instantly share code, notes, and snippets.

@iacutone
Created October 13, 2014 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iacutone/10321a7509241c5130cd to your computer and use it in GitHub Desktop.
Save iacutone/10321a7509241c5130cd to your computer and use it in GitHub Desktop.
(function($) {
var options = { show: false };
var $modal = $('#tag-modal');
// Initialize the modal
$modal.modal(options);
$modal.on('hidden', function() {
resetTagModal();
});
$(document).on('click', '.edit-tag', function(click) {
updateTagModalWith(readTagData($(this)));
openTagModal();
return false;
});
function readTagData($button) {
return {
tag_name: $button.data('tag-name'),
tag_id: $button.data('tag-id')
};
}
function updateTagModalWith(data) {
$modal.find('.tag_name').val(data.tag_name);
$modal.find('#tag_id').val(data.tag_id);
}
function resetTagModal() {
$modal.find('.tag_name').val('');
$modal.find('#tag_id').val('');
}
function openTagModal() {
$modal.modal('show');
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment