2010-05-02 23:33:17 +00:00
|
|
|
$(document).ready(function() {
|
2010-07-23 20:20:09 +00:00
|
|
|
|
|
|
|
// open / close folder
|
|
|
|
$('#pages-list ul.folder img.toggler').click(function(e) {
|
|
|
|
var toggler = $(this);
|
|
|
|
var children = toggler.parent().find('> ul.folder');
|
|
|
|
if (children.is(':visible')) {
|
|
|
|
children.slideUp('fast', function() {
|
|
|
|
toggler.attr('src', toggler.attr('src').replace('open', 'closed'));
|
|
|
|
$.cookie(children.attr('id'), 'none');
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
children.slideDown('fast', function() {
|
|
|
|
toggler.attr('src', toggler.attr('src').replace('closed', 'open'));
|
|
|
|
$.cookie(children.attr('id'), 'block');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// sortable folder items
|
|
|
|
$('#pages-list ul.folder').sortable({
|
|
|
|
'handle': 'em',
|
|
|
|
'axis': 'y',
|
|
|
|
'update': function(event, ui) {
|
|
|
|
var params = $(this).sortable('serialize', { 'key': 'children[]' });
|
|
|
|
params += '&_method=put';
|
2011-06-25 16:25:31 +00:00
|
|
|
params += '&' + $('meta[name=csrf-param]').attr('content') + '=' + $('meta[name=csrf-token]').attr('content');
|
2010-07-23 20:20:09 +00:00
|
|
|
|
2011-06-26 00:01:11 +00:00
|
|
|
$.post($(this).attr('data-url'), params, function(data) {
|
2011-01-10 13:57:44 +00:00
|
|
|
var error = typeof(data.error) != 'undefined';
|
|
|
|
$.growl((error ? 'error' : 'success'), (error ? data.error : data.notice));
|
2010-07-23 20:20:09 +00:00
|
|
|
}, 'json');
|
|
|
|
}
|
|
|
|
});
|
2011-06-21 13:40:01 +00:00
|
|
|
|
2010-07-23 20:20:09 +00:00
|
|
|
// templatized feature
|
|
|
|
|
|
|
|
$.subscribe('toggle.page_templatized.checked', function(event, data) {
|
|
|
|
$('#page_slug_input').hide();
|
2011-01-06 14:48:41 +00:00
|
|
|
$('#page_redirect').parent('li').hide();
|
2011-02-01 08:08:06 +00:00
|
|
|
$('#page_listed').parent('li').hide();
|
2010-07-23 20:20:09 +00:00
|
|
|
$('#page_content_type_id_input').show();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
$.subscribe('toggle.page_templatized.unchecked', function(event, data) {
|
|
|
|
$('#page_slug_input').show();
|
2011-01-06 14:48:41 +00:00
|
|
|
$('#page_redirect').parent('li').show();
|
2011-02-01 08:08:06 +00:00
|
|
|
$('#page_listed').parent('li').show();
|
2010-07-23 20:20:09 +00:00
|
|
|
$('#page_slug').val(makeSlug($('#page_title').val())).addClass('touched');
|
|
|
|
$('#page_content_type_id_input').hide();
|
|
|
|
}, []);
|
|
|
|
|
2011-01-06 14:48:41 +00:00
|
|
|
// redirect feature
|
|
|
|
|
|
|
|
$.subscribe('toggle.page_redirect.checked', function(event, data) {
|
|
|
|
$('#page_templatized').parent('li').hide();
|
|
|
|
$('#page_cache_strategy_input').hide();
|
|
|
|
$('#page_redirect_url_input').show();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
$.subscribe('toggle.page_redirect.unchecked', function(event, data) {
|
|
|
|
$('#page_templatized').parent('li').show();
|
|
|
|
$('#page_cache_strategy_input').show();
|
|
|
|
$('#page_redirect_url_input').hide();
|
|
|
|
}, []);
|
|
|
|
|
2010-07-23 20:20:09 +00:00
|
|
|
// automatic slug from page title
|
|
|
|
$('#page_title').keypress(function() {
|
|
|
|
var input = $(this);
|
|
|
|
var slug = $('#page_slug');
|
|
|
|
|
|
|
|
if (!slug.hasClass('filled')) {
|
|
|
|
setTimeout(function() {
|
|
|
|
slug.val(makeSlug(input.val())).addClass('touched');
|
|
|
|
}, 50);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#page_slug').keypress(function() {
|
|
|
|
$(this).addClass('filled').addClass('touched');
|
|
|
|
});
|
|
|
|
|
|
|
|
var lookForSlugAndUrl = function() {
|
|
|
|
params = 'parent_id=' + $('#page_parent_id').val() + "&slug=" + $('#page_slug').val();
|
2011-06-26 00:01:11 +00:00
|
|
|
$.get($('#page_slug').attr('data-url'), params, function(data) {
|
2010-07-23 20:20:09 +00:00
|
|
|
$('#page_slug_input .inline-hints').html(data.url).effect('highlight');
|
|
|
|
}, 'json');
|
|
|
|
};
|
|
|
|
|
|
|
|
$('#page_parent_id').change(lookForSlugAndUrl);
|
|
|
|
|
|
|
|
setInterval(function() {
|
|
|
|
var slug = $('#page_slug');
|
|
|
|
if (slug.hasClass('touched')) {
|
|
|
|
slug.removeClass('touched');
|
|
|
|
lookForSlugAndUrl();
|
|
|
|
}
|
|
|
|
}, 2000);
|
|
|
|
|
2010-09-15 00:19:34 +00:00
|
|
|
if (typeof $.fn.imagepicker != 'undefined')
|
|
|
|
$('a#image-picker-link').imagepicker({
|
|
|
|
insertFn: function(link) {
|
2011-06-21 13:40:01 +00:00
|
|
|
return "{{ '/" + link.attr('data-local-path') + "' | theme_image_url }}";
|
2010-09-15 00:19:34 +00:00
|
|
|
}
|
|
|
|
});
|
2010-08-28 00:00:05 +00:00
|
|
|
|
2010-07-23 20:20:09 +00:00
|
|
|
});
|