wp/wp-admin/js/media.js
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
     8  * @namespace findPosts
     8  * @namespace findPosts
     9  *
     9  *
    10  * @requires jQuery
    10  * @requires jQuery
    11  */
    11  */
    12 
    12 
    13 /* global ajaxurl, attachMediaBoxL10n, _wpMediaGridSettings, showNotice, findPosts */
    13 /* global ajaxurl, _wpMediaGridSettings, showNotice, findPosts */
    14 
    14 
    15 ( function( $ ){
    15 ( function( $ ){
    16 	window.findPosts = {
    16 	window.findPosts = {
    17 		/**
    17 		/**
    18 		 * Opens a dialog to attach media to a post.
    18 		 * Opens a dialog to attach media to a post.
    24 		 * @memberOf findPosts
    24 		 * @memberOf findPosts
    25 		 *
    25 		 *
    26 		 * @param {string} af_name The name of the affected element.
    26 		 * @param {string} af_name The name of the affected element.
    27 		 * @param {string} af_val The value of the affected post element.
    27 		 * @param {string} af_val The value of the affected post element.
    28 		 *
    28 		 *
    29 		 * @returns {boolean} Always returns false.
    29 		 * @return {boolean} Always returns false.
    30 		 */
    30 		 */
    31 		open: function( af_name, af_val ) {
    31 		open: function( af_name, af_val ) {
    32 			var overlay = $( '.ui-find-overlay' );
    32 			var overlay = $( '.ui-find-overlay' );
    33 
    33 
    34 			if ( overlay.length === 0 ) {
    34 			if ( overlay.length === 0 ) {
    63 		 *
    63 		 *
    64 		 * @since 2.7.0
    64 		 * @since 2.7.0
    65 		 *
    65 		 *
    66 		 * @memberOf findPosts
    66 		 * @memberOf findPosts
    67 		 *
    67 		 *
    68 		 * @returns {void}
    68 		 * @return {void}
    69 		 */
    69 		 */
    70 		close: function() {
    70 		close: function() {
    71 			$('#find-posts-response').empty();
    71 			$('#find-posts-response').empty();
    72 			$('#find-posts').hide();
    72 			$('#find-posts').hide();
    73 			$( '.ui-find-overlay' ).hide();
    73 			$( '.ui-find-overlay' ).hide();
    79 		 *
    79 		 *
    80 		 * @since 3.5.0
    80 		 * @since 3.5.0
    81 		 *
    81 		 *
    82 		 * @memberOf findPosts
    82 		 * @memberOf findPosts
    83 		 *
    83 		 *
    84 		 * @returns {void}
    84 		 * @return {void}
    85 		 */
    85 		 */
    86 		overlay: function() {
    86 		overlay: function() {
    87 			$( '.ui-find-overlay' ).on( 'click', function () {
    87 			$( '.ui-find-overlay' ).on( 'click', function () {
    88 				findPosts.close();
    88 				findPosts.close();
    89 			});
    89 			});
    98 		 *
    98 		 *
    99 		 * @since 2.7.0
    99 		 * @since 2.7.0
   100 		 *
   100 		 *
   101 		 * @memberOf findPosts
   101 		 * @memberOf findPosts
   102 		 *
   102 		 *
   103 		 * @returns {void}
   103 		 * @return {void}
   104 		 */
   104 		 */
   105 		send: function() {
   105 		send: function() {
   106 			var post = {
   106 			var post = {
   107 					ps: $( '#find-posts-input' ).val(),
   107 					ps: $( '#find-posts-input' ).val(),
   108 					action: 'find_posts',
   108 					action: 'find_posts',
   122 				dataType: 'json'
   122 				dataType: 'json'
   123 			}).always( function() {
   123 			}).always( function() {
   124 				spinner.removeClass( 'is-active' );
   124 				spinner.removeClass( 'is-active' );
   125 			}).done( function( x ) {
   125 			}).done( function( x ) {
   126 				if ( ! x.success ) {
   126 				if ( ! x.success ) {
   127 					$( '#find-posts-response' ).text( attachMediaBoxL10n.error );
   127 					$( '#find-posts-response' ).text( wp.i18n.__( 'An error has occurred. Please reload the page and try again.' ) );
   128 				}
   128 				}
   129 
   129 
   130 				$( '#find-posts-response' ).html( x.data );
   130 				$( '#find-posts-response' ).html( x.data );
   131 			}).fail( function() {
   131 			}).fail( function() {
   132 				$( '#find-posts-response' ).text( attachMediaBoxL10n.error );
   132 				$( '#find-posts-response' ).text( wp.i18n.__( 'An error has occurred. Please reload the page and try again.' ) );
   133 			});
   133 			});
   134 		}
   134 		}
   135 	};
   135 	};
   136 
   136 
   137 	/**
   137 	/**
   138 	 * Initializes the file once the DOM is fully loaded and attaches events to the
   138 	 * Initializes the file once the DOM is fully loaded and attaches events to the
   139 	 * various form elements.
   139 	 * various form elements.
   140 	 *
   140 	 *
   141 	 * @returns {void}
   141 	 * @return {void}
   142 	 */
   142 	 */
   143 	$( document ).ready( function() {
   143 	$( document ).ready( function() {
   144 		var settings, $mediaGridWrap = $( '#wp-media-grid' );
   144 		var settings, $mediaGridWrap = $( '#wp-media-grid' );
   145 
   145 
   146 		// Opens a manage media frame into the grid.
   146 		// Opens a manage media frame into the grid.
   147 		if ( $mediaGridWrap.length && window.wp && window.wp.media ) {
   147 		if ( $mediaGridWrap.length && window.wp && window.wp.media ) {
   148 			settings = _wpMediaGridSettings;
   148 			settings = _wpMediaGridSettings;
   149 
   149 
   150 			window.wp.media({
   150 			var frame = window.wp.media({
   151 				frame: 'manage',
   151 				frame: 'manage',
   152 				container: $mediaGridWrap,
   152 				container: $mediaGridWrap,
   153 				library: settings.queryVars
   153 				library: settings.queryVars
   154 			}).open();
   154 			}).open();
       
   155 
       
   156 			// Fire a global ready event.
       
   157 			$mediaGridWrap.trigger( 'wp-media-grid-ready', frame );
   155 		}
   158 		}
   156 
   159 
   157 		// Prevents form submission if no post has been selected.
   160 		// Prevents form submission if no post has been selected.
   158 		$( '#find-posts-submit' ).click( function( event ) {
   161 		$( '#find-posts-submit' ).click( function( event ) {
   159 			if ( ! $( '#find-posts-response input[type="radio"]:checked' ).length )
   162 			if ( ! $( '#find-posts-response input[type="radio"]:checked' ).length )
   196 		});
   199 		});
   197 
   200 
   198 		/**
   201 		/**
   199 		 * Enables clicking on the entire table row.
   202 		 * Enables clicking on the entire table row.
   200 		 *
   203 		 *
   201 		 * @returns {void}
   204 		 * @return {void}
   202 		 */
   205 		 */
   203 		$( '.find-box-inside' ).on( 'click', 'tr', function() {
   206 		$( '.find-box-inside' ).on( 'click', 'tr', function() {
   204 			$( this ).find( '.found-radio input' ).prop( 'checked', true );
   207 			$( this ).find( '.found-radio input' ).prop( 'checked', true );
   205 		});
   208 		});
   206 	});
   209 	});