| 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 |
case 'flag': // flag in front of the select dropdown |
| 173 |
$('.pll-select-flag').html(this.data); |
| 174 |
break; |
| 175 |
default: |
| 176 |
break; |
| 177 |
} |
| 178 |
}); |
| 179 |
|
| 180 |
// modifies the language in the tag cloud |
| 181 |
$('.tagcloud-link').each(function() { |
| 182 |
var id = $(this).attr('id'); |
| 183 |
tagBox.get(id, 0); |
| 184 |
}); |
| 185 |
|
| 186 |
// modifies the language in the tags suggestion input |
| 187 |
tagBox.suggest(); |
| 188 |
}); |
| 189 |
}); |
| 190 |
|
| 191 |
// ajax for changing the media's language |
| 192 |
$('.media_lang_choice').change( function() { |
| 193 |
var data = { |
| 194 |
action: 'media_lang_choice', |
| 195 |
lang: $(this).val(), |
| 196 |
post_id: $(this).attr('name'), |
| 197 |
_pll_nonce: $('#_pll_nonce').val() |
| 198 |
} |
| 199 |
|
| 200 |
$.post(ajaxurl, data , function(response) { |
| 201 |
var res = wpAjax.parseAjaxResponse(response, 'ajax-response'); |
| 202 |
$.each(res.responses, function() { |
| 203 |
switch (this.what) { |
| 204 |
case 'translations': // translations fields |
| 205 |
$('.translations').html(this.data); |
| 206 |
$('.compat-field-translations').html(this.data); // WP 3.5+ |
| 207 |
break; |
| 208 |
case 'flag': // flag in front of the select dropdown |
| 209 |
$('.pll-select-flag').html(this.data); |
| 210 |
break; |
| 211 |
default: |
| 212 |
break; |
| 213 |
} |
| 214 |
}); |
| 215 |
}); |
| 216 |
}); |
| 217 |
|
| 218 |
// translations autocomplete input box |
| 219 |
function init_translations() { |
| 220 |
$('.tr_lang').each(function(){ |
| 221 |
var tr_lang = $(this).attr('id').substring(8); |
| 222 |
var td = $(this).parent().siblings('.pll-edit-column'); |
| 223 |
|
| 224 |
$(this).autocomplete({ |
| 225 |
minLength: 0, |
| 226 |
|
| 227 |
source: ajaxurl + '?action=pll_posts_not_translated&post_language=' + $('#post_lang_choice').val() + |
| 228 |
'&translation_language=' + tr_lang + '&post_type=' + $('#post_type').val() + |
| 229 |
'&_pll_nonce=' + $('#_pll_nonce').val(), |
| 230 |
|
| 231 |
select: function(event, ui) { |
| 232 |
$('#htr_lang_'+tr_lang).val(ui.item.id); |
| 233 |
td.html(ui.item.link); |
| 234 |
}, |
| 235 |
}); |
| 236 |
|
| 237 |
// when the input box is emptied |
| 238 |
$(this).blur(function() { |
| 239 |
if (!$(this).val()) { |
| 240 |
$('#htr_lang_'+tr_lang).val(0); |
| 241 |
td.html(td.siblings('.hidden').children().clone()); |
| 242 |
} |
| 243 |
}); |
| 244 |
|
| 245 |
}); |
| 246 |
} |
| 247 |
|
| 248 |
init_translations(); |
| 249 |
|
| 250 |
}); |
| 251 |
|