var MultiLinks = { 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; $('#multi_links_' + id).children('.multi_link').each(function() { maxid = Math.max(maxid, parseInt($(this).attr("data-id")) + 1); }); return maxid; }, lists_del_item: function() { $('.multi_link .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() { $('.multi_links .AddButton').on('click', function(event) { event.preventDefault(); c_id = $(this).parent().parent('.multi_links').attr("data-id"); iid = MultiLinks.lists_maxid(c_id); $('#multi_links_' + c_id + ':last').append( '
' ); MultiLinks.lists_update(); }); }, lists_sortable: function() { $('.multi_links').sortable({ handle: ".handle", placeholder: "ui-state-highlight grey_bg" }); } } $(document).ready(function() { MultiLinks.init(); });