2013-11-14 06:40:11 +01:00
|
|
|
/* global isRtl */
|
2017-12-11 17:27:51 +01:00
|
|
|
|
|
|
|
/**
|
2017-12-18 15:14:53 +01:00
|
|
|
* Initializes the custom header selection page.
|
2017-12-11 17:27:51 +01:00
|
|
|
*
|
|
|
|
* @since 3.5.0
|
|
|
|
*
|
|
|
|
* @deprecated 4.1.0 The page this is used on is never linked to from the UI.
|
|
|
|
* Setting a custom header is completely handled by the Customizer.
|
|
|
|
*/
|
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() {
|
2017-12-11 17:27:51 +01:00
|
|
|
// Fetch available headers.
|
2012-11-09 12:55:20 +01:00
|
|
|
var $headers = $('.available-headers');
|
2012-10-14 19:05:16 +02:00
|
|
|
|
2017-12-11 17:27:51 +01:00
|
|
|
// Apply jQuery.masonry once the images have loaded.
|
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
|
|
|
|
2017-12-11 17:27:51 +01:00
|
|
|
/**
|
2017-12-18 15:14:53 +01:00
|
|
|
* Opens the 'choose from library' frame and creates it if it doesn't exist.
|
2017-12-11 17:27:51 +01:00
|
|
|
*
|
|
|
|
* @since 3.5.0
|
|
|
|
* @deprecated 4.1.0
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2012-11-09 12:59:05 +01:00
|
|
|
$('#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
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-12-11 17:27:51 +01:00
|
|
|
/**
|
2017-12-18 15:14:53 +01:00
|
|
|
* Updates the window location to include the selected attachment.
|
2017-12-11 17:27:51 +01:00
|
|
|
*
|
|
|
|
* @since 3.5.0
|
|
|
|
* @deprecated 4.1.0
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2012-12-04 17:21:57 +01:00
|
|
|
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));
|