comicpress-core/js/Storyline.js

120 lines
2.9 KiB
JavaScript
Raw Permalink Normal View History

2009-11-01 18:15:59 +00:00
var Storyline = {};
2009-11-13 12:51:40 +00:00
var ComicImageTypes = {};
2010-01-31 21:40:27 +00:00
var CategoryGroupings = {};
2009-11-01 18:15:59 +00:00
2010-02-06 23:50:17 +00:00
(function($) {
$.fn.setupAjax = function(action, nonce, target, onLoad) {
$(this).click(function() {
$.post(
ComicPressAdmin.ajax_uri,
{
'cp[_nonce]': ComicPressAdmin.nonce,
'cp[action]': action,
'cp[_action_nonce]': nonce
},
function(data) {
var type = $(data).hide();
$(target).append(type);
type.slideDown(250);
if (onLoad) { onLoad(); }
}
);
return false;
2009-11-13 12:51:40 +00:00
});
2010-02-06 23:50:17 +00:00
return this;
2009-11-13 12:51:40 +00:00
};
2009-11-01 18:15:59 +00:00
2010-02-06 23:50:17 +00:00
$.fn.setupRemover = function(message, parentSearch) {
$(this).unbind('click')
.click(function() {
if (confirm(message)) {
$(this).parents(parentSearch).slideUp(250, function() { $(this).remove(); });
}
return false;
2009-11-13 12:51:40 +00:00
});
2009-11-01 18:15:59 +00:00
2010-02-06 23:50:17 +00:00
return this;
};
2009-11-03 03:21:53 +00:00
2010-02-06 23:50:17 +00:00
Storyline.get_order = function() {
var order = [];
$('.cp-category-info').each(function() {
order.push(
$(this)
.attr('id')
.replace('category_', '')
.replace(/\-/g,'/')
);
2009-11-13 12:51:40 +00:00
});
2010-02-06 23:50:17 +00:00
$('input[name*=storyline_order]').val(order.join(','));
};
Storyline.setup = function() {
$('.cp-children').sortable({
axis: 'y',
stop: Storyline.get_order
}).disableSelection();
2009-11-13 19:45:28 +00:00
Storyline.get_order();
};
2010-02-06 23:50:17 +00:00
ComicImageTypes.setup_editors = function() {
$('.delete-image-type').setupRemover(
'Are you sure? Your templates may break after deleting this image type.',
'.image-type-holder'
);
2009-11-13 12:51:40 +00:00
};
ComicImageTypes.setup = function() {
2010-02-06 23:50:17 +00:00
ComicImageTypes.setup_editors();
$('#add-new-image-type').setupAjax(
'get-new-image-type-editor',
ComicPressAdmin.image_type_editor_nonce,
'#image-type-container',
ComicImageTypes.setup_editors
);
2009-11-13 12:51:40 +00:00
};
2010-01-31 21:40:27 +00:00
CategoryGroupings.highlight_child_levels = function(e) {
2010-02-06 23:50:17 +00:00
$('.category-group-holder input[type=checkbox]').attr('disabled', false);
$('.category-group-holder li')
.removeClass('selected')
.each(function() {
if ($(this).find('input[type=checkbox]:first').is('*:checked')) {
$(this).addClass('selected').find('input[type=checkbox]').not("*:first").attr('disabled', true);
}
});
$('.category-group-holder').each(function() {
$(this).find('.empty-group-warning')[($(this).find('input:checked').length == 0) ? 'show' : 'hide'](250);
});
2010-01-31 21:40:27 +00:00
}
CategoryGroupings.setup_editors = function() {
2010-02-06 23:50:17 +00:00
$('.category-group-holder input[type=checkbox], .category-group-holder label')
.unbind('click')
.click(CategoryGroupings.highlight_child_levels);
$('.delete-category-group-holder').setupRemover(
'Are you sure?',
'.category-group-holder'
);
2010-01-31 21:40:27 +00:00
}
CategoryGroupings.setup = function() {
CategoryGroupings.setup_editors();
CategoryGroupings.highlight_child_levels();
2010-02-06 23:50:17 +00:00
$('#add-new-category-group').setupAjax(
'get-new-category-group-editor',
ComicPressAdmin.category_group_editor_nonce,
'#category-groups-holder',
CategoryGroupings.setup_editors
);
2010-01-31 21:40:27 +00:00
}
2010-02-06 23:50:17 +00:00
}(jQuery))