From 8f2a589e219e68232100238ea28d416053eca017 Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 21 May 2008 18:29:46 +0000 Subject: [PATCH] Add sorting to gallery. Props AaronCampbell. fixes #6988 git-svn-id: http://svn.automattic.com/wordpress/trunk@7974 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/css/colors-classic.css | 2 +- wp-admin/css/colors-fresh.css | 2 +- wp-admin/css/media.css | 1 + wp-admin/includes/media.php | 7 +++++++ wp-admin/js/gallery.js | 20 ++++++++++++++++++++ 5 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 wp-admin/js/gallery.js diff --git a/wp-admin/css/colors-classic.css b/wp-admin/css/colors-classic.css index cf6579e5c1..7032f2b57a 100644 --- a/wp-admin/css/colors-classic.css +++ b/wp-admin/css/colors-classic.css @@ -63,7 +63,7 @@ ul#widget-list li.widget-list-item h4.widget-title { color: #000; } -ul.widget-control-list .sorthelper { +.sorthelper { background-color: #ccf3fa; } diff --git a/wp-admin/css/colors-fresh.css b/wp-admin/css/colors-fresh.css index 982f7bbf28..1da5a53da0 100644 --- a/wp-admin/css/colors-fresh.css +++ b/wp-admin/css/colors-fresh.css @@ -63,7 +63,7 @@ ul#widget-list li.widget-list-item h4.widget-title { color: #000; } -ul.widget-control-list .sorthelper { +.sorthelper { background-color: #ccf3fa; } diff --git a/wp-admin/css/media.css b/wp-admin/css/media.css index 7d46c1c9f4..eabc477582 100644 --- a/wp-admin/css/media.css +++ b/wp-admin/css/media.css @@ -216,6 +216,7 @@ abbr.required { } #media-upload .media-item { + cursor:move; position: relative; border-bottom-width: 1px; border-bottom-style: solid; diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index 7ec57c1bce..afe0c000d5 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -199,6 +199,8 @@ function media_upload_form_handler() { $post['post_title'] = $attachment['post_title']; if ( isset($attachment['post_excerpt']) ) $post['post_excerpt'] = $attachment['post_excerpt']; + if ( isset($attachment['menu_order']) ) + $post['menu_order'] = $attachment['menu_order']; $post = apply_filters('attachment_fields_to_save', $post, $attachment); @@ -399,6 +401,7 @@ function media_upload_gallery() { $errors = $return; } + wp_enqueue_script('admin-gallery'); return wp_iframe( 'media_upload_gallery_form', $errors ); } @@ -535,6 +538,10 @@ function get_attachment_fields_to_edit($post, $errors = null) { \n", 'helps' => __('Enter a link URL or click above for presets.'), ), + 'menu_order' => array( + 'label' => __('Order'), + 'value' => $edit_post->menu_order + ), ); foreach ( get_attachment_taxonomies($post) as $taxonomy ) { diff --git a/wp-admin/js/gallery.js b/wp-admin/js/gallery.js new file mode 100644 index 0000000000..aae02217c0 --- /dev/null +++ b/wp-admin/js/gallery.js @@ -0,0 +1,20 @@ +jQuery(function($) { + var gallerySortable; + var gallerySortableInit = function() { + gallerySortable = $('#media-items').sortable( { + items: '.media-item', + placeholder: 'sorthelper', + update: galleryReorder + } ); + } + + // When an update has occurred, adjust the order for each item + var galleryReorder = function(e, sort) { + jQuery.each(sort['instance'].toArray(), function(i, id) { + jQuery('#' + id + ' .menu_order input')[0].value = i; + }); + } + + // initialize sortable + gallerySortableInit(); +});