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() { // Hook our Browse button jQuery('a.browse-attachments').click(function() { jQuery.get(attachments_base + '/media.php', function(data) { attachments_media = data; Shadowbox.open({ title: 'Attachments', player: 'html', content: '

Available attachments are listed from your Media Library. If you need to upload a new attachment, please close this dialog and use the available Add New button.

Select an attachment by clicking its thumbnail. When you\'re done adding attachments, click Apply

Apply

' + data + '

Apply

', width:640, height:444 }); }); return false; }); // 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-file-details li 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_location = jQuery(this).find('span.attachment-file-location').text(); attachment_mime = jQuery(this).find('span.attachment-file-mime').text(); attachment_id = jQuery(this).find('span.attachment-file-id').text(); attachment_thumbnail = jQuery(this).find('span.attachments-thumbnail').html(); attachment_index++; new_attachments += '
  • '; new_attachments += '

    Drag' + attachment_name + 'Delete

    '; new_attachments += '
    '; new_attachments += '
    '; new_attachments += '
    '; new_attachments += '
    '; new_attachments += '
    '; new_attachments += ''; new_attachments += ''; new_attachments += ''; new_attachments += ''; new_attachments += ''; new_attachments += '
    '; new_attachments += '
    '; new_attachments += attachment_thumbnail; new_attachments += '
    '; new_attachments += '
  • '; }); jQuery('div#attachments-list ul').append(new_attachments); Shadowbox.close(); if(jQuery('#attachments-list li').length > 0) { // We've got some attachments jQuery('#attachments-list').show(); // Cleanup jQuery('div#attachments-list ul').sortable('destroy'); // Init sortable init_attachments_sortable(); } }); });