2012-08-23 02:04:18 +02:00
|
|
|
(function($) {
|
|
|
|
$(document).ready(function() {
|
2012-11-09 12:37:24 +01:00
|
|
|
var bgImage = $("#custom-background-image"),
|
|
|
|
frame;
|
2012-09-27 03:57:38 +02:00
|
|
|
|
|
|
|
$('#background-color').wpColorPicker({
|
|
|
|
change: function( event, ui ) {
|
|
|
|
bgImage.css('background-color', ui.color.toString());
|
|
|
|
},
|
|
|
|
clear: function() {
|
|
|
|
bgImage.css('background-color', '');
|
|
|
|
}
|
2012-08-23 02:04:18 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$('input[name="background-position-x"]').change(function() {
|
2012-09-27 03:57:38 +02:00
|
|
|
bgImage.css('background-position', $(this).val() + ' top');
|
2012-08-23 02:04:18 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$('input[name="background-repeat"]').change(function() {
|
2012-09-27 03:57:38 +02:00
|
|
|
bgImage.css('background-repeat', $(this).val());
|
2012-08-23 02:04:18 +02:00
|
|
|
});
|
|
|
|
|
2012-11-09 12:37:24 +01:00
|
|
|
$('#choose-from-library-link').click( function( event ) {
|
|
|
|
var $el = $(this);
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
if ( frame ) {
|
|
|
|
frame.open();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
frame = wp.media({
|
|
|
|
title: $el.data('choose'),
|
|
|
|
library: {
|
|
|
|
type: 'image'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
frame.toolbar.on( 'activate:select', function() {
|
2012-11-12 06:57:12 +01:00
|
|
|
frame.toolbar.view().set({
|
2012-11-09 12:37:24 +01:00
|
|
|
select: {
|
|
|
|
style: 'primary',
|
|
|
|
text: $el.data('update'),
|
|
|
|
|
|
|
|
click: function() {
|
|
|
|
var attachment = frame.state().get('selection').first();
|
|
|
|
$.post( ajaxurl, {
|
|
|
|
action: 'set-background-image',
|
|
|
|
attachment_id: attachment.id,
|
|
|
|
size: 'full'
|
|
|
|
}, function() {
|
|
|
|
window.location.reload();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2012-12-03 03:38:10 +01:00
|
|
|
frame.setState('library').open();
|
2012-11-09 12:37:24 +01:00
|
|
|
});
|
|
|
|
});
|
2012-08-23 02:04:18 +02:00
|
|
|
})(jQuery);
|