1 |
|
---|
2 | var findPosts;
|
---|
3 | (function($){
|
---|
4 | findPosts = {
|
---|
5 | open : function(af_name, af_val) {
|
---|
6 | var st = document.documentElement.scrollTop || $(document).scrollTop();
|
---|
7 |
|
---|
8 | if ( af_name && af_val ) {
|
---|
9 | $('#affected').attr('name', af_name).val(af_val);
|
---|
10 | }
|
---|
11 | $('#find-posts').show().draggable({
|
---|
12 | handle: '#find-posts-head'
|
---|
13 | }).css({'top':st + 50 + 'px','left':'50%','marginLeft':'-250px'});
|
---|
14 |
|
---|
15 | $('#find-posts-input').focus().keyup(function(e){
|
---|
16 | if (e.which == 27) { findPosts.close(); } // close on Escape
|
---|
17 | });
|
---|
18 |
|
---|
19 | return false;
|
---|
20 | },
|
---|
21 |
|
---|
22 | close : function() {
|
---|
23 | $('#find-posts-response').html('');
|
---|
24 | $('#find-posts').draggable('destroy').hide();
|
---|
25 | },
|
---|
26 |
|
---|
27 | send : function() {
|
---|
28 | var post = {
|
---|
29 | ps: $('#find-posts-input').val(),
|
---|
30 | action: 'find_posts',
|
---|
31 | _ajax_nonce: $('#_ajax_nonce').val()
|
---|
32 | };
|
---|
33 |
|
---|
34 | if ( $('#find-posts-pages:checked').val() ) {
|
---|
35 | post['pages'] = 1;
|
---|
36 | } else {
|
---|
37 | post['posts'] = 1;
|
---|
38 | }
|
---|
39 | $.ajax({
|
---|
40 | type : 'POST',
|
---|
41 | url : ajaxurl,
|
---|
42 | data : post,
|
---|
43 | success : function(x) { findPosts.show(x); },
|
---|
44 | error : function(r) { findPosts.error(r); }
|
---|
45 | });
|
---|
46 | },
|
---|
47 |
|
---|
48 | show : function(x) {
|
---|
49 |
|
---|
50 | if ( typeof(x) == 'string' ) {
|
---|
51 | this.error({'responseText': x});
|
---|
52 | return;
|
---|
53 | }
|
---|
54 |
|
---|
55 | var r = wpAjax.parseAjaxResponse(x);
|
---|
56 |
|
---|
57 | if ( r.errors ) {
|
---|
58 | this.error({'responseText': wpAjax.broken});
|
---|
59 | }
|
---|
60 | r = r.responses[0];
|
---|
61 | $('#find-posts-response').html(r.data);
|
---|
62 | },
|
---|
63 |
|
---|
64 | error : function(r) {
|
---|
65 | var er = r.statusText;
|
---|
66 |
|
---|
67 | if ( r.responseText ) {
|
---|
68 | er = r.responseText.replace( /<.[^<>]*?>/g, '' );
|
---|
69 | }
|
---|
70 | if ( er ) {
|
---|
71 | $('#find-posts-response').html(er);
|
---|
72 | }
|
---|
73 | }
|
---|
74 | };
|
---|
75 |
|
---|
76 | $(document).ready(function() {
|
---|
77 | $('#find-posts-submit').click(function(e) {
|
---|
78 | if ( '' == $('#find-posts-response').html() )
|
---|
79 | e.preventDefault();
|
---|
80 | });
|
---|
81 | $('#doaction, #doaction2').click(function(e){
|
---|
82 | $('select[name^="action"]').each(function(){
|
---|
83 | if ( $(this).val() == 'attach' ) {
|
---|
84 | e.preventDefault();
|
---|
85 | findPosts.open();
|
---|
86 | }
|
---|
87 | });
|
---|
88 | });
|
---|
89 | });
|
---|
90 | })(jQuery);
|
---|