web/wp-admin/js/media.js
changeset 204 09a1c134465b
parent 194 32102edaa81b
equal deleted inserted replaced
203:f507feede89a 204:09a1c134465b
     1 var findPosts;(function(a){findPosts={open:function(d,c){var b=document.documentElement.scrollTop||a(document).scrollTop();if(d&&c){a("#affected").attr("name",d).val(c)}a("#find-posts").show().draggable({handle:"#find-posts-head"}).css({top:b+50+"px",left:"50%",marginLeft:"-250px"});a("#find-posts-input").focus().keyup(function(f){if(f.which==27){findPosts.close()}});return false},close:function(){a("#find-posts-response").html("");a("#find-posts").draggable("destroy").hide()},send:function(){var b={ps:a("#find-posts-input").val(),action:"find_posts",_ajax_nonce:a("#_ajax_nonce").val(),post_type:a('input[name="find-posts-what"]:checked').val()};a.ajax({type:"POST",url:ajaxurl,data:b,success:function(c){findPosts.show(c)},error:function(c){findPosts.error(c)}})},show:function(b){if(typeof(b)=="string"){this.error({responseText:b});return}var c=wpAjax.parseAjaxResponse(b);if(c.errors){this.error({responseText:wpAjax.broken})}c=c.responses[0];a("#find-posts-response").html(c.data)},error:function(b){var c=b.statusText;if(b.responseText){c=b.responseText.replace(/<.[^<>]*?>/g,"")}if(c){a("#find-posts-response").html(c)}}};a(document).ready(function(){a("#find-posts-submit").click(function(b){if(""==a("#find-posts-response").html()){b.preventDefault()}});a("#find-posts .find-box-search :input").keypress(function(b){if(13==b.which){findPosts.send();return false}});a("#find-posts-search").click(findPosts.send);a("#find-posts-close").click(findPosts.close);a("#doaction, #doaction2").click(function(b){a('select[name^="action"]').each(function(){if(a(this).val()=="attach"){b.preventDefault();findPosts.open()}})})})})(jQuery);
     1 
       
     2 var findPosts;
       
     3 (function($){
       
     4 	findPosts = {
       
     5 		open : function(af_name, af_val) {
       
     6 			var st = document.documentElement.scrollTop || $(document).scrollTop(),
       
     7 				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 			$('#find-posts').show().draggable({
       
    20 				handle: '#find-posts-head'
       
    21 			}).css({'top':st + 50 + 'px','left':'50%','marginLeft':'-328px'});
       
    22 
       
    23 			$('#find-posts-input').focus().keyup(function(e){
       
    24 				if (e.which == 27) { findPosts.close(); } // close on Escape
       
    25 			});
       
    26 
       
    27 			// Pull some results up by default
       
    28 			findPosts.send();
       
    29 
       
    30 			return false;
       
    31 		},
       
    32 
       
    33 		close : function() {
       
    34 			$('#find-posts-response').html('');
       
    35 			$('#find-posts').draggable('destroy').hide();
       
    36 			$( '.ui-find-overlay' ).hide();
       
    37 		},
       
    38 
       
    39 		overlay : function() {
       
    40 			$( '.ui-find-overlay' ).css(
       
    41 				{ 'z-index': '999', 'width': $( document ).width() + 'px', 'height': $( document ).height() + 'px' }
       
    42 			).on('click', function () {
       
    43 				findPosts.close();
       
    44 			});
       
    45 		},
       
    46 
       
    47 		send : function() {
       
    48 			var post = {
       
    49 					ps: $('#find-posts-input').val(),
       
    50 					action: 'find_posts',
       
    51 					_ajax_nonce: $('#_ajax_nonce').val()
       
    52 				},
       
    53 				spinner = $( '.find-box-search .spinner' );
       
    54 
       
    55 			spinner.show();
       
    56 
       
    57 			$.ajax({
       
    58 				type : 'POST',
       
    59 				url : ajaxurl,
       
    60 				data : post,
       
    61 				success : function(x) { findPosts.show(x); spinner.hide(); },
       
    62 				error : function(r) { findPosts.error(r); spinner.hide(); }
       
    63 			});
       
    64 		},
       
    65 
       
    66 		show : function(x) {
       
    67 
       
    68 			if ( typeof(x) == 'string' ) {
       
    69 				this.error({'responseText': x});
       
    70 				return;
       
    71 			}
       
    72 
       
    73 			var r = wpAjax.parseAjaxResponse(x);
       
    74 
       
    75 			if ( r.errors ) {
       
    76 				this.error({'responseText': wpAjax.broken});
       
    77 			}
       
    78 			r = r.responses[0];
       
    79 			$('#find-posts-response').html(r.data);
       
    80 
       
    81 			// Enable whole row to be clicked
       
    82 			$( '.found-posts td' ).on( 'click', function () {
       
    83 				$( this ).parent().find( '.found-radio input' ).prop( 'checked', true );
       
    84 			});
       
    85 		},
       
    86 
       
    87 		error : function(r) {
       
    88 			var er = r.statusText;
       
    89 
       
    90 			if ( r.responseText ) {
       
    91 				er = r.responseText.replace( /<.[^<>]*?>/g, '' );
       
    92 			}
       
    93 			if ( er ) {
       
    94 				$('#find-posts-response').html(er);
       
    95 			}
       
    96 		}
       
    97 	};
       
    98 
       
    99 	$(document).ready(function() {
       
   100 		$('#find-posts-submit').click(function(e) {
       
   101 			if ( '' == $('#find-posts-response').html() )
       
   102 				e.preventDefault();
       
   103 		});
       
   104 		$( '#find-posts .find-box-search :input' ).keypress( function( event ) {
       
   105 			if ( 13 == event.which ) {
       
   106 				findPosts.send();
       
   107 				return false;
       
   108 			}
       
   109 		} );
       
   110 		$( '#find-posts-search' ).click( findPosts.send );
       
   111 		$( '#find-posts-close' ).click( findPosts.close );
       
   112 		$('#doaction, #doaction2').click(function(e){
       
   113 			$('select[name^="action"]').each(function(){
       
   114 				if ( $(this).val() == 'attach' ) {
       
   115 					e.preventDefault();
       
   116 					findPosts.open();
       
   117 				}
       
   118 			});
       
   119 		});
       
   120 	});
       
   121 	$(window).resize(function() {
       
   122 		findPosts.overlay();
       
   123 	});
       
   124 })(jQuery);