switch to prototype

This commit is contained in:
John Bintz 2009-11-02 22:21:53 -05:00
parent 831b8d80c6
commit 5d66b8b589
2 changed files with 26 additions and 17 deletions

View File

@ -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 '<div class="cp-category-info category-' . $parent_id . '/' . $category_id . '">';
echo '<div id="category_' . $parent_id . '/' . $category_id . '" class="cp-category-info">';
echo '<span>' . $category->name . '</span>';
if (is_array($children)) {
echo '<div class="cp-children">';

View File

@ -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(); });
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
});
});
});
};