]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/js/media.js
WordPress 3.8-scripts
[autoinstalls/wordpress.git] / wp-admin / js / media.js
1 /* global ajaxurl, wpAjax */
2
3 var findPosts;
4 (function($){
5         findPosts = {
6                 open : function(af_name, af_val) {
7                         var st = document.documentElement.scrollTop || $(document).scrollTop(),
8                                 overlay = $( '.ui-find-overlay' );
9
10                         if ( overlay.length === 0 ) {
11                                 $( 'body' ).append( '<div class="ui-find-overlay"></div>' );
12                                 findPosts.overlay();
13                         }
14
15                         overlay.show();
16
17                         if ( af_name && af_val ) {
18                                 $('#affected').attr('name', af_name).val(af_val);
19                         }
20                         $('#find-posts').show().draggable({
21                                 handle: '#find-posts-head'
22                         }).css({'top':st + 50 + 'px','left':'50%','marginLeft':'-328px'});
23
24                         $('#find-posts-input').focus().keyup(function(e){
25                                 if (e.which == 27) { findPosts.close(); } // 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').draggable('destroy').hide();
37                         $( '.ui-find-overlay' ).hide();
38                 },
39
40                 overlay : function() {
41                         $( '.ui-find-overlay' ).css(
42                                 { 'z-index': '999', 'width': $( document ).width() + 'px', 'height': $( document ).height() + 'px' }
43                         ).on('click', function () {
44                                 findPosts.close();
45                         });
46                 },
47
48                 send : function() {
49                         var post = {
50                                         ps: $('#find-posts-input').val(),
51                                         action: 'find_posts',
52                                         _ajax_nonce: $('#_ajax_nonce').val()
53                                 },
54                                 spinner = $( '.find-box-search .spinner' );
55
56                         spinner.show();
57
58                         $.ajax({
59                                 type : 'POST',
60                                 url : ajaxurl,
61                                 data : post,
62                                 success : function(x) { findPosts.show(x); spinner.hide(); },
63                                 error : function(r) { findPosts.error(r); spinner.hide(); }
64                         });
65                 },
66
67                 show : function(x) {
68
69                         if ( typeof(x) == 'string' ) {
70                                 this.error({'responseText': x});
71                                 return;
72                         }
73
74                         var r = wpAjax.parseAjaxResponse(x);
75
76                         if ( r.errors ) {
77                                 this.error({'responseText': wpAjax.broken});
78                         }
79                         r = r.responses[0];
80                         $('#find-posts-response').html(r.data);
81
82                         // Enable whole row to be clicked
83                         $( '.found-posts td' ).on( 'click', function () {
84                                 $( this ).parent().find( '.found-radio input' ).prop( 'checked', true );
85                         });
86                 },
87
88                 error : function(r) {
89                         var er = r.statusText;
90
91                         if ( r.responseText ) {
92                                 er = r.responseText.replace( /<.[^<>]*?>/g, '' );
93                         }
94                         if ( er ) {
95                                 $('#find-posts-response').html(er);
96                         }
97                 }
98         };
99
100         $(document).ready(function() {
101                 $('#find-posts-submit').click(function(e) {
102                         if ( '' === $('#find-posts-response').html() )
103                                 e.preventDefault();
104                 });
105                 $( '#find-posts .find-box-search :input' ).keypress( function( event ) {
106                         if ( 13 == event.which ) {
107                                 findPosts.send();
108                                 return false;
109                         }
110                 } );
111                 $( '#find-posts-search' ).click( findPosts.send );
112                 $( '#find-posts-close' ).click( findPosts.close );
113                 $('#doaction, #doaction2').click(function(e){
114                         $('select[name^="action"]').each(function(){
115                                 if ( $(this).val() == 'attach' ) {
116                                         e.preventDefault();
117                                         findPosts.open();
118                                 }
119                         });
120                 });
121         });
122         $(window).resize(function() {
123                 findPosts.overlay();
124         });
125 })(jQuery);