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
← All changes | js/admin.js +180 -267 2.7.10.7 View file →
@@ -1,267 +1,180 @@
1 -jQuery( document ).ready(
2 - function( $ ) {
3 - var transitionTimeout;
4 -
5 - // languages list table
6 - // accessibility to row actions on focus
7 - // mainly copy paste of WP code from common.js
8 - $( 'table.languages' ).on(
9 - { // restricted to languages list table
10 - focusin: function() {
11 - clearTimeout( transitionTimeout );
12 - focusedRowActions = $( this ).find( '.row-actions' );
13 - // transitionTimeout is necessary for Firefox, but Chrome won't remove the CSS class without a little help.
14 - $( '.row-actions' ).not( this ).removeClass( 'visible' );
15 - focusedRowActions.addClass( 'visible' );
16 - },
17 - focusout: function() {
18 - // Tabbing between post title and .row-actions links needs a brief pause, otherwise
19 - // the .row-actions div gets hidden in transit in some browsers ( ahem, Firefox ).
20 - transitionTimeout = setTimeout(
21 - function() {
22 - focusedRowActions.removeClass( 'visible' );
23 - },
24 - 30
25 - );
26 - }
27 - },
28 - 'tr'
29 - ); // acts on the whole tr instead of single td as we have actions links in several columns
30 -
31 - // Common functions for overriding language and flag dropdown list.
32 - var selectmenuRenderItem = function( wrapper, item ) {
33 - var li = $( '<li>' ).text( item.label ).prepend( $( item.element ).data( 'flag-html' ) );
34 - li.children( 'img' ).addClass( 'ui-icon' );
35 - return li.appendTo( wrapper );
36 - };
37 - var selectmenuRefreshButtonText = function( selectElement ) {
38 - var buttonText = $( selectElement ).selectmenu( 'instance' ).buttonText;
39 - buttonText.prepend( $( selectElement ).children( ':selected' ).data( 'flag-html' ) );
40 - buttonText.children( 'img' ).addClass( 'ui-icon' );
41 - };
42 - // Overrides the flag dropdown list with our customized jquery ui selectmenu.
43 -
44 - // Inject flag image when jQuery UI selectmenu is created or an item is selected.
45 - $( '#flag_list' ).on(
46 - 'selectmenucreate selectmenuselect',
47 - function(){
48 - selectmenuRefreshButtonText( this );
49 - }
50 - );
51 - // Refresh jQuery UI selectmenu when the value is changed programmatically: select another language or edit an existing language.
52 - // For putting the focus in the list on the selected item and injecting the right flag on the selected item.
53 - $( '#flag_list' ).on(
54 - 'selectmenuopen',
55 - function(){
56 - $( this ).selectmenu( 'refresh' ).trigger( 'selectmenuselect' );
57 - }
58 - );
59 - // Create the jQuery UI selectmenu widget
60 - $( '#flag_list' ).selectmenu( { width: '100%' } );
61 - // Overrides each item in the jQuery UI selectmenu list by injecting flag image.
62 - $( '#flag_list' ).selectmenu( 'instance' )._renderItem = selectmenuRenderItem;
63 -
64 - // Language choice in predefined languages in Polylang Languages settings page and wizard.
65 - // Overrides the predefined language dropdown list with our customized jquery ui selectmenu.
66 -
67 - // Inject flag image when jQuery UI selectmenu is created or an item is selected.
68 - $( '#lang_list' ).on(
69 - 'selectmenucreate selectmenuselect',
70 - function() {
71 - selectmenuRefreshButtonText( this );
72 - }
73 - );
74 - // Create the jQuery UI selectmenu widget
75 - $( '#lang_list' ).selectmenu( { width: '100%' } );
76 - // Overrides each element in the jQuery UI selectmenu list by injecting flag image.
77 - $( '#lang_list' ).selectmenu( 'instance' )._renderItem = selectmenuRenderItem;
78 -
79 - // Languages form
80 - // Fills the fields based on the language dropdown list choice
81 - $( '#add-lang #lang_list' ).on(
82 - 'selectmenuchange',
83 - function() {
84 - var value = $( this ).val().split( ':' );
85 - var selected = $( "option:selected", this ).text().split( ' - ' );
86 - $( '#lang_slug' ).val( value[0] );
87 - $( '#lang_locale' ).val( value[1] );
88 - $( 'input[name="rtl"]' ).val( [value[2]] );
89 - $( '#lang_name' ).val( selected[0] );
90 - $( '#flag_list').val( value[3] );
91 -
92 - // Refresh the jQuery UI selectmenu flags list.
93 - $( '#flag_list' ).selectmenu( 'refresh' ).trigger( 'selectmenuselect' );
94 - }
95 - );
96 -
97 - // strings translations
98 - // save translations when pressing enter
99 - $( '.translation input' ).keypress(
100 - function( event ){
101 - if ( 13 === event.keyCode ) {
102 - event.preventDefault();
103 - $( '#submit' ).click();
104 - }
105 - }
106 - );
107 -
108 - // settings page
109 - // click on configure link
110 - $( '#the-list' ).on(
111 - 'click',
112 - '.configure>a',
113 - function(){
114 - $( '.pll-configure' ).hide().prev().show();
115 - $( this ).closest( 'tr' ).hide().next().show();
116 - return false;
117 - }
118 - );
119 -
120 - // cancel
121 - $( '#the-list' ).on(
122 - 'click',
123 - '.cancel',
124 - function(){
125 - $( this ).closest( 'tr' ).hide().prev().show();
126 - }
127 - );
128 -
129 - // save settings
130 - $( '#the-list' ).on(
131 - 'click',
132 - '.save',
133 - function(){
134 - var tr = $( this ).closest( 'tr' );
135 - var parts = tr.attr( 'id' ).split( '-' );
136 -
137 - var data = {
138 - action: 'pll_save_options',
139 - pll_ajax_settings: true,
140 - module: parts[parts.length - 1],
141 - _pll_nonce: $( '#_pll_nonce' ).val()
142 - };
143 -
144 - data = tr.find( ':input' ).serialize() + '&' + $.param( data );
145 -
146 - $.post(
147 - ajaxurl,
148 - data,
149 - function( response ) {
150 - var res = wpAjax.parseAjaxResponse( response, 'ajax-response' );
151 - $.each(
152 - res.responses,
153 - function() {
154 - switch ( this.what ) {
155 - case 'license-update':
156 - $( '#pll-license-' + this.data ).replaceWith( this.supplemental.html );
157 - break;
158 - case 'success':
159 - tr.hide().prev().show(); // close only if there is no error
160 - case 'error':
161 - $( '.settings-error' ).remove(); // remove previous messages if any
162 - $( 'h1' ).after( this.data );
163 -
164 - // Make notices dismissible
165 - // copy paste of common.js from WP 4.2.2
166 - $( '.notice.is-dismissible' ).each(
167 - function() {
168 - var $this = $( this ),
169 - $button = $( '<button type="button" class="notice-dismiss"><span class="screen-reader-text"></span></button>' ),
170 - btnText = commonL10n.dismiss || '';
171 -
172 - // Ensure plain text
173 - $button.find( '.screen-reader-text' ).text( btnText );
174 -
175 - // Whitelist because of how the button is built. See above
176 - $this.append( $button ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.append
177 -
178 - $button.on(
179 - 'click.wp-dismiss-notice',
180 - function( event ) {
181 - event.preventDefault();
182 - $this.fadeTo(
183 - 100,
184 - 0,
185 - function() {
186 - $( this ).slideUp(
187 - 100,
188 - function() {
189 - $( this ).remove();
190 - }
191 - );
192 - }
193 - );
194 - }
195 - );
196 - }
197 - );
198 - break;
199 - }
200 - }
201 - );
202 - }
203 - );
204 - }
205 - );
206 -
207 - // act when pressing enter or esc in configurations
208 - $( '.pll-configure' ).keypress(
209 - function( event ){
210 - if ( 13 === event.keyCode ) {
211 - event.preventDefault();
212 - $( this ).find( '.save' ).click();
213 - }
214 -
215 - if ( 27 === event.keyCode ) {
216 - event.preventDefault();
217 - $( this ).find( '.cancel' ).click();
218 - }
219 - }
220 - );
221 -
222 - // settings URL modifications
223 - // manages visibility of fields
224 - $( "input[name='force_lang']" ).change(
225 - function() {
226 - function pll_toggle( a, test ) {
227 - test ? a.show() : a.hide();
228 - }
229 -
230 - var value = $( this ).val();
231 - pll_toggle( $( '#pll-domains-table' ), 3 == value );
232 - pll_toggle( $( "#pll-hide-default" ), 3 > value );
233 - pll_toggle( $( "#pll-rewrite" ), 2 > value );
234 - pll_toggle( $( "#pll-redirect-lang" ), 2 > value );
235 - }
236 - );
237 -
238 - // settings license
239 - // deactivate button
240 - $( '.pll-deactivate-license' ).on(
241 - 'click',
242 - function() {
243 - var data = {
244 - action: 'pll_deactivate_license',
245 - pll_ajax_settings: true,
246 - id: $( this ).attr( 'id' ),
247 - _pll_nonce: $( '#_pll_nonce' ).val()
248 - };
249 - $.post(
250 - ajaxurl,
251 - data,
252 - function( response ){
253 - $( '#pll-license-' + response.id ).replaceWith( response.html );
254 - }
255 - );
256 - }
257 - );
258 -
259 - // Manage closing the metabox.
260 - // close postboxes that should be closed
261 - $( '.if-js-closed' ).removeClass( 'if-js-closed' ).addClass( 'closed' );
262 - // postboxes setup
263 - if ( 'undefined' !== typeof postboxes ) {
264 - postboxes.add_postbox_toggles( pagenow );
265 - }
266 - }
267 -);
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 +});