2013-11-14 06:40:11 +01:00
|
|
|
/* global isRtl */
|
2012-10-14 19:05:16 +02:00
|
|
|
(function($) {
|
2012-11-09 12:59:05 +01:00
|
|
|
var frame;
|
|
|
|
|
2012-11-09 12:55:20 +01:00
|
|
|
$( function() {
|
2012-11-09 12:59:05 +01:00
|
|
|
// Fetch available headers and apply jQuery.masonry
|
|
|
|
// once the images have loaded.
|
2012-11-09 12:55:20 +01:00
|
|
|
var $headers = $('.available-headers');
|
2012-10-14 19:05:16 +02:00
|
|
|
|
2012-11-09 12:55:20 +01:00
|
|
|
$headers.imagesLoaded( function() {
|
|
|
|
$headers.masonry({
|
2012-12-04 05:08:32 +01:00
|
|
|
itemSelector: '.default-header',
|
|
|
|
isRTL: !! ( 'undefined' != typeof isRtl && isRtl )
|
2012-11-09 12:55:20 +01:00
|
|
|
});
|
2012-10-14 19:05:16 +02:00
|
|
|
});
|
2012-11-09 12:59:05 +01:00
|
|
|
|
|
|
|
// Build the choose from library frame.
|
|
|
|
$('#choose-from-library-link').click( function( event ) {
|
|
|
|
var $el = $(this);
|
|
|
|
event.preventDefault();
|
|
|
|
|
2012-12-06 06:06:49 +01:00
|
|
|
// If the media frame already exists, reopen it.
|
|
|
|
if ( frame ) {
|
|
|
|
frame.open();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-04 17:21:57 +01:00
|
|
|
// Create the media frame.
|
2012-12-06 06:06:49 +01:00
|
|
|
frame = wp.media.frames.customHeader = wp.media({
|
2012-12-04 17:21:57 +01:00
|
|
|
// Set the title of the modal.
|
|
|
|
title: $el.data('choose'),
|
|
|
|
|
|
|
|
// Tell the modal to show only images.
|
|
|
|
library: {
|
2012-11-09 12:59:05 +01:00
|
|
|
type: 'image'
|
2012-12-04 17:21:57 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
// Customize the submit button.
|
|
|
|
button: {
|
|
|
|
// Set the text of the button.
|
|
|
|
text: $el.data('update'),
|
|
|
|
// Tell the button not to close the modal, since we're
|
|
|
|
// going to refresh the page when the image is selected.
|
|
|
|
close: false
|
2012-11-09 12:59:05 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-12-04 17:21:57 +01:00
|
|
|
// When an image is selected, run a callback.
|
|
|
|
frame.on( 'select', function() {
|
|
|
|
// Grab the selected attachment.
|
|
|
|
var attachment = frame.state().get('selection').first(),
|
|
|
|
link = $el.data('updateLink');
|
2012-11-09 12:59:05 +01:00
|
|
|
|
2012-12-04 17:21:57 +01:00
|
|
|
// Tell the browser to navigate to the crop step.
|
|
|
|
window.location = link + '&file=' + attachment.id;
|
2012-11-09 12:59:05 +01:00
|
|
|
});
|
|
|
|
|
2012-12-04 17:21:57 +01:00
|
|
|
frame.open();
|
2012-11-09 12:59:05 +01:00
|
|
|
});
|
2012-10-14 19:05:16 +02:00
|
|
|
});
|
2012-11-09 12:55:20 +01:00
|
|
|
}(jQuery));
|