]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/js/media.js
WordPress 3.9
[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                 $( '#find-posts-submit' ).click( function( event ) {
76                         if ( ! $( '#find-posts-response input[type="radio"]:checked' ).length )
77                                 event.preventDefault();
78                 });
79                 $( '#find-posts .find-box-search :input' ).keypress( function( event ) {
80                         if ( 13 == event.which ) {
81                                 findPosts.send();
82                                 return false;
83                         }
84                 });
85                 $( '#find-posts-search' ).click( findPosts.send );
86                 $( '#find-posts-close' ).click( findPosts.close );
87                 $( '#doaction, #doaction2' ).click( function( event ) {
88                         $( 'select[name^="action"]' ).each( function() {
89                                 if ( $(this).val() === 'attach' ) {
90                                         event.preventDefault();
91                                         findPosts.open();
92                                 }
93                         });
94                 });
95
96                 // Enable whole row to be clicked
97                 $( '.find-box-inside' ).on( 'click', 'tr', function() {
98                         $( this ).find( '.found-radio input' ).prop( 'checked', true );
99                 });
100         });
101 })( jQuery );