From 5d66b8b589c1e069bfdf39b36dcd5794ae491406 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 2 Nov 2009 22:21:53 -0500 Subject: [PATCH] switch to prototype --- addons/Core/Core.inc | 4 ++-- js/Storyline.js | 39 ++++++++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/addons/Core/Core.inc b/addons/Core/Core.inc index a9bb0ee..9509c34 100644 --- a/addons/Core/Core.inc +++ b/addons/Core/Core.inc @@ -204,7 +204,7 @@ class ComicPressAddonCore extends ComicPressAddon { if ($plugin_page == 'comicpress/render_admin') { wp_enqueue_style('cp-admin', get_stylesheet_directory_uri() . '/css/cp-admin.css'); - wp_enqueue_script('cp-admin', get_stylesheet_directory_uri() . '/js/Storyline.js', array('jquery', 'jquery-ui-sortable')); + wp_enqueue_script('cp-admin', get_stylesheet_directory_uri() . '/js/Storyline.js', array('prototype', 'scriptaculous')); } if (strpos($pagenow, "media-upload") === 0) { @@ -315,7 +315,7 @@ class ComicPressAddonCore extends ComicPressAddon { function _render_admin_storyline_tree($node, $parent_id = "0") { foreach ($node as $category_id => $children) { $category = get_category($category_id); - echo '
'; + echo '
'; echo '' . $category->name . ''; if (is_array($children)) { echo '
'; diff --git a/js/Storyline.js b/js/Storyline.js index 47e27c0..07205dd 100644 --- a/js/Storyline.js +++ b/js/Storyline.js @@ -2,24 +2,33 @@ var Storyline = {}; Storyline.get_order = function() { var order = [] - jQuery('#storyline-sorter .cp-category-info').each(function() { - var matches = this.className.match(/category-([0-9\/]+)/); + $$('#storyline-sorter .cp-category-info').each(function(info) { + var matches = info.id.match(/category_([0-9\/]+)/); if (matches) { order.push(matches[1]); } }); - jQuery('input[name=cp[storyline_order]]').attr('value', order.join(',')); + $$('input[name*=storyline_order]').pop().value = order.join(','); }; Storyline.setup = function() { - jQuery('.cp-children').sortable({ - handle: 'span', - cursor: 'move', - placeholder: 'placeholder', - forcePlaceholderSize: true, - opacity: 0.4, - stop: function(e, ui) { - Storyline.get_order(); - } - }); -}; + var i = 0; + var depths = {}; + $$('#storyline-sorter .cp-children').each(function(ch) { + ch.id = 'children-' + i; + var depth = ch.ancestors().length; + if (!depths[depth]) { depths[depth] = []; } + depths[depth].push(ch); + ++i; + }); -jQuery(function() { Storyline.get_order(); }); \ No newline at end of file + depths = $H(depths); + + depths.keys().sort(function(a,b) { return b - a; }).each(function(depth) { + depths.get(depth).each(function(ch) { + Sortable.create(ch.id, { + tag: 'div', + handle: 'span', + onUpdate: Storyline.get_order + }); + }); + }); +};