|
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 - 100 + 'px','left':'50%','marginLeft':'-70px'}); // xili place new |
|
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 choose : function() { // xili |
|
28 lang = $('#affected').val(); |
|
29 linked = $('input[name="found_post_id"]:checked').val(); |
|
30 $('#xili_language_lang-'+lang).val( linked ); |
|
31 $('#find-posts').draggable('destroy').hide(); |
|
32 }, |
|
33 |
|
34 send : function() { |
|
35 var post = { |
|
36 ps: $('#find-posts-input').val(), |
|
37 action: 'find_posts', |
|
38 _ajax_nonce: $('#_ajax_nonce').val() |
|
39 }; |
|
40 |
|
41 var selectedItem; |
|
42 //xili - $("input[@name='itemSelect[]']:checked").each(function() { selectedItem = $(this).val() }); |
|
43 post['post_type'] = $('#find-posts-what').val(); //selectedItem; |
|
44 |
|
45 $.ajax({ |
|
46 type : 'POST', |
|
47 url : ajaxurl, |
|
48 data : post, |
|
49 success : function(x) { findPosts.show(x); }, |
|
50 error : function(r) { findPosts.error(r); } |
|
51 }); |
|
52 }, |
|
53 |
|
54 show : function(x) { |
|
55 |
|
56 if ( typeof(x) == 'string' ) { |
|
57 this.error({'responseText': x}); |
|
58 return; |
|
59 } |
|
60 |
|
61 var r = wpAjax.parseAjaxResponse(x); |
|
62 |
|
63 if ( r.errors ) { |
|
64 this.error({'responseText': wpAjax.broken}); |
|
65 } |
|
66 r = r.responses[0]; |
|
67 $('#find-posts-response').html(r.data); |
|
68 }, |
|
69 |
|
70 error : function(r) { |
|
71 var er = r.statusText; |
|
72 |
|
73 if ( r.responseText ) { |
|
74 er = r.responseText.replace( /<.[^<>]*?>/g, '' ); |
|
75 } |
|
76 if ( er ) { |
|
77 $('#find-posts-response').html(er); |
|
78 } |
|
79 } |
|
80 }; |
|
81 |
|
82 $(document).ready(function() { |
|
83 $('#find-posts-submit').click(function(e) { |
|
84 // if ( '' != $('#find-posts-response').html() ) |
|
85 e.preventDefault(); // no resave only fill input |
|
86 findPosts.choose(); // xili |
|
87 }); |
|
88 $( '#find-posts .find-box-search :input' ).keypress( function( event ) { |
|
89 if ( 13 == event.which ) { |
|
90 findPosts.send(); |
|
91 return false; |
|
92 } |
|
93 } ); |
|
94 $( '#find-posts-search' ).click( findPosts.send ); |
|
95 $( '#find-posts-close' ).click( findPosts.close ); |
|
96 $('#doaction, #doaction2').click(function(e){ |
|
97 $('select[name^="action"]').each(function(){ |
|
98 if ( $(this).val() == 'attach' ) { |
|
99 e.preventDefault(); |
|
100 findPosts.open(); |
|
101 } |
|
102 }); |
|
103 }); |
|
104 }); |
|
105 })(jQuery); |