custom-header.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * @output wp-admin/js/custom-header.js
  3. */
  4. /* global isRtl */
  5. /**
  6. * Initializes the custom header selection page.
  7. *
  8. * @since 3.5.0
  9. *
  10. * @deprecated 4.1.0 The page this is used on is never linked to from the UI.
  11. * Setting a custom header is completely handled by the Customizer.
  12. */
  13. (function($) {
  14. var frame;
  15. $( function() {
  16. // Fetch available headers.
  17. var $headers = $('.available-headers');
  18. // Apply jQuery.masonry once the images have loaded.
  19. $headers.imagesLoaded( function() {
  20. $headers.masonry({
  21. itemSelector: '.default-header',
  22. isRTL: !! ( 'undefined' != typeof isRtl && isRtl )
  23. });
  24. });
  25. /**
  26. * Opens the 'choose from library' frame and creates it if it doesn't exist.
  27. *
  28. * @since 3.5.0
  29. * @deprecated 4.1.0
  30. *
  31. * @return {void}
  32. */
  33. $('#choose-from-library-link').on( 'click', function( event ) {
  34. var $el = $(this);
  35. event.preventDefault();
  36. // If the media frame already exists, reopen it.
  37. if ( frame ) {
  38. frame.open();
  39. return;
  40. }
  41. // Create the media frame.
  42. frame = wp.media.frames.customHeader = wp.media({
  43. // Set the title of the modal.
  44. title: $el.data('choose'),
  45. // Tell the modal to show only images.
  46. library: {
  47. type: 'image'
  48. },
  49. // Customize the submit button.
  50. button: {
  51. // Set the text of the button.
  52. text: $el.data('update'),
  53. // Tell the button not to close the modal, since we're
  54. // going to refresh the page when the image is selected.
  55. close: false
  56. }
  57. });
  58. /**
  59. * Updates the window location to include the selected attachment.
  60. *
  61. * @since 3.5.0
  62. * @deprecated 4.1.0
  63. *
  64. * @return {void}
  65. */
  66. frame.on( 'select', function() {
  67. // Grab the selected attachment.
  68. var attachment = frame.state().get('selection').first(),
  69. link = $el.data('updateLink');
  70. // Tell the browser to navigate to the crop step.
  71. window.location = link + '&file=' + attachment.id;
  72. });
  73. frame.open();
  74. });
  75. });
  76. }(jQuery));