]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/js/media.js
WordPress 4.1.1
[autoinstalls/wordpress.git] / wp-admin / js / media.js
1 /* global ajaxurl, attachMediaBoxL10n */
2
3 var findPosts;
4 ( function( $ ){
5         findPosts = {
6                 open: function( af_name, af_val ) {
7                         var overlay = $( '.ui-find-overlay' );
8
9                         if ( overlay.length === 0 ) {
10                                 $( 'body' ).append( '<div class="ui-find-overlay"></div>' );
11                                 findPosts.overlay();
12                         }
13
14                         overlay.show();
15
16                         if ( af_name && af_val ) {
17                                 $( '#affected' ).attr( 'name', af_name ).val( af_val );
18                         }
19
20                         $( '#find-posts' ).show();
21
22                         $('#find-posts-input').focus().keyup( function( event ){
23                                 if ( event.which == 27 ) {
24                                         findPosts.close();
25                                 } // close on Escape
26                         });
27
28                         // Pull some results up by default
29                         findPosts.send();
30
31                         return false;
32                 },
33
34                 close: function() {
35                         $('#find-posts-response').html('');
36                         $('#find-posts').hide();
37                         $( '.ui-find-overlay' ).hide();
38                 },
39
40                 overlay: function() {
41                         $( '.ui-find-overlay' ).on( 'click', function () {
42                                 findPosts.close();
43                         });
44                 },
45
46                 send: function() {
47                         var post = {
48                                         ps: $( '#find-posts-input' ).val(),
49                                         action: 'find_posts',
50                                         _ajax_nonce: $('#_ajax_nonce').val()
51                                 },
52                                 spinner = $( '.find-box-search .spinner' );
53
54                         spinner.show();
55
56                         $.ajax( ajaxurl, {
57                                 type: 'POST',
58                                 data: post,
59                                 dataType: 'json'
60                         }).always( function() {
61                                 spinner.hide();
62                         }).done( function( x ) {
63                                 if ( ! x.success ) {
64                                         $( '#find-posts-response' ).text( attachMediaBoxL10n.error );
65                                 }
66
67                                 $( '#find-posts-response' ).html( x.data );
68                         }).fail( function() {
69                                 $( '#find-posts-response' ).text( attachMediaBoxL10n.error );
70                         });
71                 }
72         };
73
74         $( document ).ready( function() {
75                 var $mediaGridWrap = $( '#wp-media-grid' );
76
77                 // Open up a manage media frame into the grid.
78                 if ( $mediaGridWrap.length && window.wp && window.wp.media ) {
79                         window.wp.media({
80                                 frame: 'manage',
81                                 container: $mediaGridWrap
82                         }).open();
83                 }
84
85                 $( '#find-posts-submit' ).click( function( event ) {
86                         if ( ! $( '#find-posts-response input[type="radio"]:checked' ).length )
87                                 event.preventDefault();
88                 });
89                 $( '#find-posts .find-box-search :input' ).keypress( function( event ) {
90                         if ( 13 == event.which ) {
91                                 findPosts.send();
92                                 return false;
93                         }
94                 });
95                 $( '#find-posts-search' ).click( findPosts.send );
96                 $( '#find-posts-close' ).click( findPosts.close );
97                 $( '#doaction, #doaction2' ).click( function( event ) {
98                         $( 'select[name^="action"]' ).each( function() {
99                                 if ( $(this).val() === 'attach' ) {
100                                         event.preventDefault();
101                                         findPosts.open();
102                                 }
103                         });
104                 });
105
106                 // Enable whole row to be clicked
107                 $( '.find-box-inside' ).on( 'click', 'tr', function() {
108                         $( this ).find( '.found-radio input' ).prop( 'checked', true );
109                 });
110         });
111 })( jQuery );