PluginProbe
Polylang / 0.7
Polylang v0.7
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 / admin.js

admin.js in Polylang 0.7, at js/admin.js

181 lines 5.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery(document).ready(function($) {
2
3 // collect taxonomies - code partly copied from WordPress
4 var taxonomies = new Array();
5 $('.categorydiv').each( function(){
6 var this_id = $(this).attr('id'), taxonomyParts, taxonomy;
7
8 taxonomyParts = this_id.split('-');
9 taxonomyParts.shift();
10 taxonomy = taxonomyParts.join('-');
11 taxonomies.push(taxonomy); // store the taxonomy for future use
12
13 // add our hidden field in the new category form - for each hierarchical taxonomy
14 jQuery('#' + taxonomy + '-add-submit').before($('<input />')
15 .attr('type', 'hidden')
16 .attr('id', taxonomy + '-lang')
17 .attr('name', 'term_lang_choice')
18 .attr('value', jQuery('#post_lang_choice').attr('value'))
19 );
20 });
21
22 // ajax for post metabox
23 jQuery('#post_lang_choice').change( function() {
24 var data = {
25 action: 'post_lang_choice',
26 lang: jQuery(this).attr('value'),
27 taxonomies: taxonomies,
28 post_id: jQuery('#post_ID').attr('value')
29 }
30
31 jQuery.post(ajaxurl, data , function(response) {
32 var res = wpAjax.parseAjaxResponse(response, 'ajax-response');
33 $.each(res.responses, function() {
34 switch (this.what) {
35 case 'translations': // translations fields
36 jQuery('#post-translations').html(this.data);
37 break;
38 case 'taxonomy': // categories metabox for posts
39 var tax = this.data;
40 jQuery('#' + tax + 'checklist').html(this.supplemental.all);
41 jQuery('#' + tax + 'checklist-pop').html(this.supplemental.populars);
42 jQuery('#new' + tax + '_parent').replaceWith(this.supplemental.dropdown);
43 jQuery('#' + tax + '-lang').val(jQuery('#post_lang_choice').attr('value')); // hidden field
44 break;
45 case 'pages': // parent dropdown list for pages
46 jQuery('#parent_id').replaceWith(this.data);
47 break;
48 default:
49 break;
50 }
51 });
52
53 // modifies the language in the tag cloud
54 jQuery('.polylang-tagcloud-link').each(function() {
55 var id = $(this).attr('id');
56 pll_tagbox(id, 0);
57 });
58
59 // modifies the language in the tags suggestion input
60 pll_suggest();
61 });
62 });
63
64 // replace WP class by our own
65 jQuery('a.tagcloud-link').addClass('polylang-tagcloud-link');
66 jQuery('a.tagcloud-link').removeClass('tagcloud-link');
67
68 // copy paste WP code and just call our pll_tagbox instead of tagbox.get
69 jQuery('.polylang-tagcloud-link').click( function() {
70 var id = $(this).attr('id');
71 pll_tagbox(id, 1);
72
73 $(this).unbind().click(function(){
74 $(this).siblings('.the-tagcloud').toggle();
75 return false;
76 });
77 return false;
78 });
79
80 // now copy paste WP code
81 // add the language in the $_POST variable
82 // add an if else condition to allow modifying the tags outputed when switching the language
83 function pll_tagbox(id, a) {
84 var tax = id.substr(id.indexOf('-')+1);
85
86 var data = {
87 action: 'get-tagcloud',
88 lang: jQuery('#post_lang_choice').attr('value'),
89 tax: tax
90 }
91
92 $.post(ajaxurl, data, function(r, stat) {
93 if ( 0 == r || 'success' != stat )
94 r = wpAjax.broken;
95
96 r = $('<p id="tagcloud-'+tax+'" class="the-tagcloud">'+r+'</p>');
97 $('a', r).click(function(){
98 tagBox.flushTags( $(this).closest('.inside').children('.tagsdiv'), this);
99 return false;
100 });
101
102 if (a == 1)
103 $('#'+id).after(r);
104 else {
105 v = $('.the-tagcloud').css('display');
106 $('.the-tagcloud').replaceWith(r);
107 $('.the-tagcloud').css('display', v);
108 }
109 });
110 }
111
112 // replace WP class by our own
113 jQuery('input.newtag').addClass('polylang-newtag');
114 jQuery('input.newtag').removeClass('newtag');
115 pll_suggest();
116
117 // now copy paste WP code
118 // add the language in the $_GET variable
119 // add the unbind function to allow calling the function when the language is modified
120 function pll_suggest() {
121 ajaxtag = $('div.ajaxtag');
122 $('input.polylang-newtag', ajaxtag).unbind().blur(function() {
123 if ( this.value == '' )
124 $(this).parent().siblings('.taghint').css('visibility', '');
125 }).focus(function(){
126 $(this).parent().siblings('.taghint').css('visibility', 'hidden');
127 }).keyup(function(e){
128 if ( 13 == e.which ) {
129 tagBox.flushTags( $(this).closest('.tagsdiv') );
130 return false;
131 }
132 }).keypress(function(e){
133 if ( 13 == e.which ) {
134 e.preventDefault();
135 return false;
136 }
137 }).each(function(){
138 var lang = jQuery('#post_lang_choice').attr('value');
139 var tax = $(this).closest('div.tagsdiv').attr('id');
140 $(this).suggest( ajaxurl + '?action=polylang-ajax-tag-search&lang=' + lang + '&tax=' + tax, { delay: 500, minchars: 2, multiple: true, multipleSep: "," } );
141 });
142 }
143
144 // ajax for term edit
145 jQuery('#term_lang_choice').change(function() {
146 var data = {
147 action: 'term_lang_choice',
148 lang: jQuery(this).attr('value'),
149 term_id: jQuery("input[name='tag_ID']").attr('value'),
150 taxonomy: jQuery("input[name='taxonomy']").attr('value')
151 }
152
153 jQuery.post(ajaxurl, data, function(response) {
154 var res = wpAjax.parseAjaxResponse(response, 'ajax-response');
155 $.each(res.responses, function() {
156 switch (this.what) {
157 case 'translations': // translations fields
158 jQuery("#term-translations").html(this.data);
159 break;
160 case 'parent': // parent dropdown list for hierarchical taxonomies
161 jQuery('#parent').replaceWith(this.data);
162 break;
163 default:
164 break;
165 }
166 });
167 });
168 });
169
170 // languages form
171 // fills the fields based on dropdown list choice
172 jQuery('#lang_list').change(function() {
173 value = jQuery(this).attr('value').split('-');
174 jQuery('input[name="slug"]').val(value[0]);
175 jQuery('input[name="description"]').val(value[1]);
176 jQuery('input[name="rtl"]').val([value[2]]);
177 jQuery('input[name="name"]').val($("select option:selected").text());
178 });
179
180 });
181