From f578f1c49ee5b01c115230a4e06568fdd14c3b0d Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 3 Nov 2009 07:55:08 -0500 Subject: [PATCH] work on comic image ordering and zooming --- addons/Core/Core.inc | 64 +++++++++++++++---- .../Core/partials/_comic-image-ordering.inc | 43 +++++++++++++ css/cp-admin.css | 30 ++++++--- js/ComicImageOrdering.js | 0 4 files changed, 115 insertions(+), 22 deletions(-) create mode 100644 addons/Core/partials/_comic-image-ordering.inc create mode 100644 js/ComicImageOrdering.js diff --git a/addons/Core/Core.inc b/addons/Core/Core.inc index f35ce3b..f6a8b30 100644 --- a/addons/Core/Core.inc +++ b/addons/Core/Core.inc @@ -12,7 +12,7 @@ class ComicPressAddonCore extends ComicPressAddon { function init() { $this->comicpress = &ComicPress::get_instance(); - add_action('admin_menu', array(&$this, 'setup_admin_interface')); + add_action('admin_menu', array(&$this, 'admin_menu')); add_filter('attachment_fields_to_edit', array(&$this, 'setup_comic_metadata_buttons'), 10, 2); add_action('show_comic', array(&$this, 'show_comic'), 1, 1); add_action('show_archive', array(&$this, 'show_archive'), 1, 1); @@ -191,15 +191,17 @@ class ComicPressAddonCore extends ComicPressAddon { /** * Set up the admin interface and meta boxes. */ - function setup_admin_interface() { + function admin_menu() { global $plugin_page, $pagenow, $post; add_theme_page(__("ComicPress Core", 'comicpress'), __('ComicPress Core', 'comicpress'), 'edit_themes', 'comicpress/render_admin', array(&$this, 'render_admin')); add_theme_page(__("Edit Partials", 'comicpress'), __('Edit Partials', 'comicpress'), 'edit_themes', 'comicpress/edit_partials', array(&$this, 'render_edit_partials')); - if (strpos($page, "edit") === 0) { - var_dump($post); + if (strpos($pagenow, "post") === 0) { add_meta_box("comic-image-ordering", __("Comic Image Ordering", 'comicpress'), array(&$this, 'render_comic_image_ordering'), "post", "normal", "low"); + wp_enqueue_script('cp-ordering', get_stylesheet_directory_uri() . '/js/ComicImageOrdering.js', array('scriptaculous-slider')); + wp_enqueue_style('cp-admin', get_stylesheet_directory_uri() . '/css/cp-admin.css'); + add_action('admin_footer', array(&$this, 'admin_footer')); } if ($plugin_page == 'comicpress/render_admin') { @@ -211,6 +213,16 @@ class ComicPressAddonCore extends ComicPressAddon { wp_enqueue_script('cp-media', get_stylesheet_directory_uri() . '/js/MediaUpload.js', array('prototype')); } } + + function admin_footer() { + $nonce = wp_create_nonce('comicpress'); + ?> + comicpress); + $comic_post = new ComicPressComicPost(get_post($_REQUEST['post'])); $ordering = $comic_post->normalize_comic_image_ordering(); - echo ''; + if (is_array($ordering)) { - foreach ($ordering as $type => $attachment_ids) { - echo '

' . $this->comic_image_types[$type] . '

'; - $index = 1; - foreach ($attachment_ids as $attachment_id) { - echo ''; - echo ''; - ++$index; + $nonce = wp_create_nonce('comicpress'); + $zoom_level = 40; + $current_user = wp_get_current_user(); + if (!empty($current_user)) { + $comicpress_meta = get_usermeta($current_user->ID, 'comicpress-settings'); + if (is_array($comicpress_meta)) { + if (isset($comicpress_meta['zoom_level'])) { + $zoom_level = floor($comicpress_meta['zoom_level']); + } } } - } + + include(dirname(__FILE__) . '/partials/_comic-image-ordering.inc'); + } } } @@ -527,6 +543,21 @@ class ComicPressAddonCore extends ComicPressAddon { } } + function handle_update_zoom_slider($info) { + $this->is_ajax = true; + + $current_user = wp_get_current_user(); + if (!empty($current_user)) { + $comicpress_meta = get_usermeta($current_user->ID, 'comicpress-settings'); + if (!is_array($comicpress_meta)) { $comicpress_meta = array(); } + $comicpress_meta['zoom_level'] = $info['zoom_level']; + update_usermeta($current_user->ID, 'comicpress-settings', $comicpress_meta); + exit(0); + } + header('HTTP/1.1 500 Internal Server Error'); + exit(0); + } + /** * Handle an update. */ @@ -534,6 +565,11 @@ class ComicPressAddonCore extends ComicPressAddon { if (isset($_POST['attachments'])) { //coming from media editor $this->handle_update_attachments(); + } else if (isset($info['action'])) { + $method = 'handle_update_' . strtolower(str_replace('-', '_', $info['action'])); + if (method_exists($this, $method)) { + $this->{$method}($info); + } } else if (is_array($info['ordering'])) { // comic ordering diff --git a/addons/Core/partials/_comic-image-ordering.inc b/addons/Core/partials/_comic-image-ordering.inc new file mode 100644 index 0000000..c1f91ea --- /dev/null +++ b/addons/Core/partials/_comic-image-ordering.inc @@ -0,0 +1,43 @@ + +
+
+
+
+
+ +
+ $attachment_ids) { ?> +

comic_image_types[$type] ?>

+
+ +
+ +
+ +
+ +
+ + diff --git a/css/cp-admin.css b/css/cp-admin.css index 708c355..229cd46 100644 --- a/css/cp-admin.css +++ b/css/cp-admin.css @@ -2,16 +2,30 @@ padding-left: 20px } -.ui-draggable { - border: solid black 1px; - background-color: #ddd -} - .cp-category-info span { cursor: move; color: #004 } -.placeholder { - border: dashed #ddd 2px -} \ No newline at end of file +#ordering-zoom-slider-holder { + width: 30px; +} + +#ordering-zoom-slider { + height: 150px; + width: 6px; + border: solid #ccc 1px; + background-color: #ddd; + position: relative; + margin-left: 12px +} + +#ordering-zoom-handle { + height: 4px; + width: 16px; + border: solid #999 1px; + background-color: #aaa; + position: absolute; + cursor: move; + margin-left: -6px +} diff --git a/js/ComicImageOrdering.js b/js/ComicImageOrdering.js new file mode 100644 index 0000000..e69de29