var DocFiles = { init: false, init: function() { if (this.initialized) return; this.initialized = true; this.lists(); }, lists: function() { this.lists_sortable(); this.lists_del_item(); this.lists_add(); }, lists_update: function() { this.lists_maxid(); this.lists_del_item(); AveAdmin.tooltip(); }, lists_maxid: function(id) { var maxid = 1; $('#doc_files_' + id).children('.doc_file').each(function() { maxid = Math.max(maxid, parseInt($(this).attr("data-id")) + 1); }); return maxid; }, lists_del_item: function() { $('.doc_file .DelButton').on('click', function(event) { event.preventDefault(); var id = $(this).attr('data-id'); jConfirm( links_del_conf, links_del_head, function(b) { if (b) { $('#link_' + id).remove(); } } ); }); }, lists_add: function() { $('.doc_files .AddButton').on('click', function(event) { event.preventDefault(); c_id = $(this).parent().parent().parent('.doc_files').attr("data-id"); iid = DocFiles.lists_maxid(c_id); $('#doc_files_' + c_id + ':last').append( '' ); DocFiles.lists_update(); }); }, lists_sortable: function() { $('.doc_files').sortable({ handle: ".handle", placeholder: "ui-state-highlight grey_bg" }); } } $(document).ready(function() { DocFiles.init(); });