5 // Fetch available headers and apply jQuery.masonry
6 // once the images have loaded.
7 var $headers = $('.available-headers');
9 $headers.imagesLoaded( function() {
11 itemSelector: '.default-header',
12 isRTL: !! ( 'undefined' != typeof isRtl && isRtl )
16 // Build the choose from library frame.
17 $('#choose-from-library-link').click( function( event ) {
19 event.preventDefault();
21 // If the media frame already exists, reopen it.
27 // Create the media frame.
28 frame = wp.media.frames.customHeader = wp.media({
29 // Set the title of the modal.
30 title: $el.data('choose'),
32 // Tell the modal to show only images.
37 // Customize the submit button.
39 // Set the text of the button.
40 text: $el.data('update'),
41 // Tell the button not to close the modal, since we're
42 // going to refresh the page when the image is selected.
47 // When an image is selected, run a callback.
48 frame.on( 'select', function() {
49 // Grab the selected attachment.
50 var attachment = frame.state().get('selection').first(),
51 link = $el.data('updateLink');
53 // Tell the browser to navigate to the crop step.
54 window.location = link + '&file=' + attachment.id;