// Throughout the admin I chose to use slow animations to make it clear that stuff is being hidden or shown depending on settings.
jQuery(document).ready(function() {
jQuery('.show_list').change(function() {
if (jQuery('.show_list:checked').length == 0) {
jQuery('.content_placement').hide('slow');
jQuery('.content_placement input').attr('disabled','disabled');
jQuery('.show_template').attr('checked', 'checked');
} else {
jQuery('.show_template').attr('checked', false);
jQuery('.content_placement').show('slow');
jQuery('.content_placement input').removeAttr('disabled');
}
var postName = 'printfriendly_option[show_on_posts]';
var homeName = 'printfriendly_option[show_on_homepage]';
var optionName = jQuery(this).attr('name');
if (optionName == homeName || optionName == postName){
if(jQuery(this).is(':checked')) {
jQuery('#pf-categories').show('slow');
} else if(!jQuery('input[name="' + homeName + '"]').is(':checked')
&& !jQuery('input[name="' + postName + '"]').is(':checked')) {
jQuery('#pf-categories').hide('slow');
}
}
}).change();
jQuery('.show_template').change(function() {
if(jQuery(this).is(':checked')) {
jQuery('.show_list').attr('checked', false);
jQuery('.show_list').attr('disabled', 'disabled');
jQuery('.content_placement').hide('slow');
jQuery('.content_placement input').attr('disabled','disabled');
jQuery('#pf-categories-metabox').hide('slow');
} else {
jQuery('.show_list').removeAttr('disabled');
jQuery('.content_placement').show('slow');
jQuery('.content_placement input').removeAttr('disabled');
}
}).change();
jQuery('#toggle-categories').click(function() {
if(jQuery('#pf-categories-metabox').is(':visible')) {
jQuery('#pf-categories-metabox').hide('slow');
} else {
jQuery('#pf-categories-metabox').show('slow');
}
});
jQuery(document).mouseup(function (e) {
var container = jQuery("#pf-categories");
if (container.has(e.target).length === 0) {
jQuery('#pf-categories-metabox').hide('slow');
}
});
jQuery('#colorSelector').ColorPicker({
color: jQuery('#text_color').val(),
onShow: function (colpkr) {
jQuery(colpkr).fadeIn(500);
return false;
},
onHide: function (colpkr) {
jQuery(colpkr).fadeOut(500);
return false;
},
onChange: function (hsb, hex, rgb) {
jQuery('#colorSelector div').css('backgroundColor', '#' + hex);
jQuery('#text_color').val('#' + hex);
jQuery('.printfriendly-text2').css('color','#' + hex);
}
});
jQuery('#text_size').change(function(){
size = jQuery('#text_size').val();
jQuery('.printfriendly-text2').css('font-size',parseInt(size));
}).change();
jQuery('#css input').change(function() {
if(jQuery(this).attr('checked')) {
jQuery(this).val('off');
jQuery('#margin, #txt-color, #txt-size').hide('slow');
pf_reset_style();
} else {
jQuery(this).val('on');
jQuery('#margin, #txt-color, #txt-size').show('slow');
pf_apply_style();
}
}).change();
jQuery('#custom_text').change(function(){
pf_custom_text_change();
}).change();
jQuery('#custom_text').keyup(function(){
pf_custom_text_change();
});
function pf_custom_text_change(){
jQuery('#buttongroup3 span:not(.printandpdf)').text( jQuery('#custom_text').val() );
jQuery('#custom span.printfriendly-text2').text( jQuery('#custom_text').val() );
}
function pf_initialize_preview(urlInputSelector, previewSelector) {
var el = jQuery(urlInputSelector);
var imgUrl = jQuery.trim(el.val());
var preview = jQuery(previewSelector + '-preview');
var error = jQuery(previewSelector + '-error');
el.bind('input paste change keyup', function() {
setTimeout(function() {
// ie shows error if we try to merge the two below into a single statement
var img = jQuery('');
var imgUrl = jQuery.trim(el.val());
img.load(function() {
error.html('');
preview.html('').append(img);})
.error(function() {
preview.html('');
if(img.attr('src') != '') {
error.html('
Invalid Image URL