2013-11-14 00:40:11 -05:00
|
|
|
/* global isRtl */
|
2017-12-11 11:27:51 -05:00
|
|
|
|
|
|
|
/**
|
2017-12-18 09:14:53 -05:00
|
|
|
* Initializes the custom header selection page.
|
2017-12-11 11:27:51 -05: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 13:05:16 -04:00
|
|
|
(function($) {
|
2012-11-09 06:59:05 -05:00
|
|
|
var frame;
|
|
|
|
|
2012-11-09 06:55:20 -05:00
|
|
|
$( function() {
|
2017-12-11 11:27:51 -05:00
|
|
|
// Fetch available headers.
|
2012-11-09 06:55:20 -05:00
|
|
|
var $headers = $('.available-headers');
|
2012-10-14 13:05:16 -04:00
|
|
|
|
2017-12-11 11:27:51 -05:00
|
|
|
// Apply jQuery.masonry once the images have loaded.
|
2012-11-09 06:55:20 -05:00
|
|
|
$headers.imagesLoaded( function() {
|
|
|
|
$headers.masonry({
|
2012-12-03 23:08:32 -05:00
|
|
|
itemSelector: '.default-header',
|
|
|
|
isRTL: !! ( 'undefined' != typeof isRtl && isRtl )
|
2012-11-09 06:55:20 -05:00
|
|
|
});
|
2012-10-14 13:05:16 -04:00
|
|
|
});
|
2012-11-09 06:59:05 -05:00
|
|
|
|
2017-12-11 11:27:51 -05:00
|
|
|
/**
|
2017-12-18 09:14:53 -05:00
|
|
|
* Opens the 'choose from library' frame and creates it if it doesn't exist.
|
2017-12-11 11:27:51 -05:00
|
|
|
*
|
|
|
|
* @since 3.5.0
|
|
|
|
* @deprecated 4.1.0
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2012-11-09 06:59:05 -05:00
|
|
|
$('#choose-from-library-link').click( function( event ) {
|
|
|
|
var $el = $(this);
|
|
|
|
event.preventDefault();
|
|
|
|
|
2012-12-06 00:06:49 -05:00
|
|
|
// If the media frame already exists, reopen it.
|
|
|
|
if ( frame ) {
|
|
|
|
frame.open();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-04 11:21:57 -05:00
|
|
|
// Create the media frame.
|
2012-12-06 00:06:49 -05:00
|
|
|
frame = wp.media.frames.customHeader = wp.media({
|
2012-12-04 11:21:57 -05:00
|
|
|
// Set the title of the modal.
|
|
|
|
title: $el.data('choose'),
|
|
|
|
|
|
|
|
// Tell the modal to show only images.
|
|
|
|
library: {
|
2012-11-09 06:59:05 -05:00
|
|
|
type: 'image'
|
2012-12-04 11:21:57 -05: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 06:59:05 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-12-11 11:27:51 -05:00
|
|
|
/**
|
2017-12-18 09:14:53 -05:00
|
|
|
* Updates the window location to include the selected attachment.
|
2017-12-11 11:27:51 -05:00
|
|
|
*
|
|
|
|
* @since 3.5.0
|
|
|
|
* @deprecated 4.1.0
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2012-12-04 11:21:57 -05:00
|
|
|
frame.on( 'select', function() {
|
|
|
|
// Grab the selected attachment.
|
|
|
|
var attachment = frame.state().get('selection').first(),
|
|
|
|
link = $el.data('updateLink');
|
2012-11-09 06:59:05 -05:00
|
|
|
|
2012-12-04 11:21:57 -05:00
|
|
|
// Tell the browser to navigate to the crop step.
|
|
|
|
window.location = link + '&file=' + attachment.id;
|
2012-11-09 06:59:05 -05:00
|
|
|
});
|
|
|
|
|
2012-12-04 11:21:57 -05:00
|
|
|
frame.open();
|
2012-11-09 06:59:05 -05:00
|
|
|
});
|
2012-10-14 13:05:16 -04:00
|
|
|
});
|
2012-11-09 06:55:20 -05:00
|
|
|
}(jQuery));
|