function attachments_update() { jQuery('div#attachments_file_list').html(attachments_media); } function init_attachments_sortable() { jQuery('div#attachments-list ul').sortable({ containment: 'parent', stop: function(e, ui) { jQuery('#attachments-list ul li').each(function(i, id) { jQuery(this).find('input.attachment_order').val(i+1); }); } }); } jQuery(document).ready(function() { // If there are no attachments, let's hide this thing... if(jQuery('div#attachments-list li').length == 0) { jQuery('#attachments-list').hide(); } else { init_attachments_sortable(); } // Keep track of our browse dialog selections jQuery('.attachments a').live('click', function() { jQuery(this).toggleClass('attachments-selected'); return false; }); // Hook our delete links jQuery('span.attachment-delete a').live('click', function() { attachment_parent = jQuery(this).parent().parent().parent(); attachment_parent.slideUp(function() { attachment_parent.remove(); jQuery('#attachments-list ul li').each(function(i, id) { jQuery(this).find('input.attachment_order').val(i+1); }); if(jQuery('div#attachments-list li').length == 0) { jQuery('#attachments-list').slideUp(function() { jQuery('#attachments-list').hide(); }); } }); return false; }); // Hook the all important Apply button jQuery('a.attachments-apply').live('click', function() { attachment_index = jQuery('li.attachments-file').length; new_attachments = ''; jQuery('a.attachments-selected').each(function() { attachment_name = jQuery(this).find('span.attachment-file-name').text(); attachment_id = jQuery(this).find('span.attachment-file-id').text(); attachment_thumbnail = jQuery(this).find('span.attachments-thumbnail').html(); attachment_index++; new_attachments += '