PluginProbe
Polylang / 1.5
Polylang v1.5
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
polylang / js / post.js

post.js in Polylang 1.5, at js/post.js

245 lines 7.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1
2 // overrides tagBox but mainly copy paste of WP code
3 (function($){
4 // overrides function to add the language
5 tagBox.get = function(id, a) {
6 var tax = id.substr(id.indexOf('-')+1);
7
8 // add the language in the $_POST variable
9 var data = {
10 action: 'get-tagcloud',
11 lang: $('#post_lang_choice').val(),
12 tax: tax
13 }
14
15 $.post(ajaxurl, data, function(r, stat) {
16 if ( 0 == r || 'success' != stat )
17 r = wpAjax.broken;
18
19 r = $('<p id="tagcloud-'+tax+'" class="the-tagcloud">'+r+'</p>');
20 $('a', r).click(function(){
21 tagBox.flushTags( $(this).closest('.inside').children('.tagsdiv'), this);
22 return false;
23 });
24
25 // add an if else condition to allow modifying the tags outputed when switching the language
26 if (a == 1)
27 $('#'+id).after(r);
28 else {
29 v = $('.the-tagcloud').css('display');
30 $('.the-tagcloud').replaceWith(r);
31 $('.the-tagcloud').css('display', v);
32 }
33 });
34 },
35
36 // creates the function to be reused
37 tagBox.suggest = function() {
38 ajaxtag = $('div.ajaxtag');
39 // add the unbind function to allow calling the function when the language is modified
40 $('input.newtag', ajaxtag).unbind().blur(function() {
41 if ( this.value == '' )
42 $(this).parent().siblings('.taghint').css('visibility', '');
43 }).focus(function(){
44 $(this).parent().siblings('.taghint').css('visibility', 'hidden');
45 }).keyup(function(e){
46 if ( 13 == e.which ) {
47 tagBox.flushTags( $(this).closest('.tagsdiv') );
48 return false;
49 }
50 }).keypress(function(e){
51 if ( 13 == e.which ) {
52 e.preventDefault();
53 return false;
54 }
55 }).each(function(){
56 // add the language in the $_GET variable
57 var lang = $('#post_lang_choice').val();
58 var tax = $(this).closest('div.tagsdiv').attr('id');
59 // change action name for backward compatibility WP < 3.7
60 $(this).suggest( ajaxurl + '?action=polylang-ajax-tag-search&lang=' + lang + '&tax=' + tax, { delay: 500, minchars: 2, multiple: true, multipleSep: "," } );
61 });
62 }
63
64 // overrides function to add language (in tagBox.suggest)
65 tagBox.init = function() {
66 var t = this, ajaxtag = $('div.ajaxtag');
67
68 $('.tagsdiv').each( function() {
69 tagBox.quickClicks(this);
70 });
71
72 $('input.tagadd', ajaxtag).click(function(){
73 t.flushTags( $(this).closest('.tagsdiv') );
74 });
75
76 $('div.taghint', ajaxtag).click(function(){
77 $(this).css('visibility', 'hidden').parent().siblings('.newtag').focus();
78 });
79
80 tagBox.suggest();
81
82 // save tags on post save/publish
83 $('#post').submit(function(){
84 $('div.tagsdiv').each( function() {
85 tagBox.flushTags(this, false, 1);
86 });
87 });
88
89 // tag cloud
90 $('a.tagcloud-link').click(function(){
91 tagBox.get( $(this).attr('id'), 1 );
92 $(this).unbind().click(function(){
93 $(this).siblings('.the-tagcloud').toggle();
94 return false;
95 });
96 return false;
97 });
98 }
99 })(jQuery);
100
101 // quick edit
102 // thanks to WP Dreamer http://wpdreamer.com/2012/03/manage-wordpress-posts-using-bulk-edit-and-quick-edit/
103 (function($) {
104 var $wp_inline_edit = inlineEditPost.edit;
105
106 inlineEditPost.edit = function( id ) {
107 $wp_inline_edit.apply( this, arguments );
108 var $post_id = 0;
109 if ( typeof( id ) == 'object' )
110 $post_id = parseInt( this.getId( id ) );
111
112 if ( $post_id > 0 ) {
113 var $edit_row = $( '#edit-' + $post_id );
114 var $select = $edit_row.find(':input[name="inline_lang_choice"]');
115 $select.find('option:selected').removeProp('selected');
116 var lang = $('#lang_' + $post_id).html();
117 $("input[name='old_lang']").val(lang);
118 $select.find('option[value="'+lang+'"]').prop('selected', true);
119 }
120 }
121 })(jQuery);
122
123 jQuery(document).ready(function($) {
124 // collect taxonomies - code partly copied from WordPress
125 var taxonomies = new Array();
126 $('.categorydiv').each( function(){
127 var this_id = $(this).attr('id'), taxonomyParts, taxonomy;
128
129 taxonomyParts = this_id.split('-');
130 taxonomyParts.shift();
131 taxonomy = taxonomyParts.join('-');
132 taxonomies.push(taxonomy); // store the taxonomy for future use
133
134 // add our hidden field in the new category form - for each hierarchical taxonomy
135 // to set the language when creating a new category
136 $('#' + taxonomy + '-add-submit').before($('<input />')
137 .attr('type', 'hidden')
138 .attr('id', taxonomy + '-lang')
139 .attr('name', 'term_lang_choice')
140 .attr('value', $('#post_lang_choice').val())
141 );
142 });
143
144 // ajax for changing the post's language in the languages metabox
145 $('#post_lang_choice').change( function() {
146 var data = {
147 action: 'post_lang_choice',
148 lang: $(this).val(),
149 taxonomies: taxonomies,
150 post_id: $('#post_ID').val(),
151 _pll_nonce: $('#_pll_nonce').val()
152 }
153
154 $.post(ajaxurl, data , function(response) {
155 var res = wpAjax.parseAjaxResponse(response, 'ajax-response');
156 $.each(res.responses, function() {
157 switch (this.what) {
158 case 'translations': // translations fields
159 $('#post-translations').html(this.data);
160 init_translations();
161 break;
162 case 'taxonomy': // categories metabox for posts
163 var tax = this.data;
164 $('#' + tax + 'checklist').html(this.supplemental.all);
165 $('#' + tax + 'checklist-pop').html(this.supplemental.populars);
166 $('#new' + tax + '_parent').replaceWith(this.supplemental.dropdown);
167 $('#' + tax + '-lang').val($('#post_lang_choice').val()); // hidden field
168 break;
169 case 'pages': // parent dropdown list for pages
170 $('#pageparentdiv > .inside').html(this.data);
171 break;
172 default:
173 break;
174 }
175 });
176
177 // modifies the language in the tag cloud
178 $('.tagcloud-link').each(function() {
179 var id = $(this).attr('id');
180 tagBox.get(id, 0);
181 });
182
183 // modifies the language in the tags suggestion input
184 tagBox.suggest();
185 });
186 });
187
188 // ajax for changing the media's language
189 $('.media_lang_choice').change( function() {
190 var data = {
191 action: 'media_lang_choice',
192 lang: $(this).val(),
193 post_id: $(this).attr('name'),
194 _pll_nonce: $('#_pll_nonce').val()
195 }
196
197 $.post(ajaxurl, data , function(response) {
198 var res = wpAjax.parseAjaxResponse(response, 'ajax-response');
199 $.each(res.responses, function() {
200 switch (this.what) {
201 case 'translations': // translations fields
202 $('.translations').html(this.data);
203 $('.compat-field-translations').html(this.data); // WP 3.5+
204 break;
205 default:
206 break;
207 }
208 });
209 });
210 });
211
212 // translations autocomplete input box
213 function init_translations() {
214 $('.tr_lang').each(function(){
215 var tr_lang = $(this).attr('id').substring(8);
216 var td = $(this).parent().siblings('.pll-edit-column');
217
218 $(this).autocomplete({
219 minLength: 0,
220
221 source: ajaxurl + '?action=pll_posts_not_translated&post_language=' + $('#post_lang_choice').val() +
222 '&translation_language=' + tr_lang + '&post_type=' + $('#post_type').val() +
223 '&_pll_nonce=' + $('#_pll_nonce').val(),
224
225 select: function(event, ui) {
226 $('#htr_lang_'+tr_lang).val(ui.item.id);
227 td.html(ui.item.link);
228 },
229 });
230
231 // when the input box is emptied
232 $(this).blur(function() {
233 if (!$(this).val()) {
234 $('#htr_lang_'+tr_lang).val(0);
235 td.html(td.siblings('.hidden').children().clone());
236 }
237 });
238
239 });
240 }
241
242 init_translations();
243
244 });
245