PluginProbe
Polylang / 2.2.5
Polylang v2.2.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 / admin.js

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

192 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery( document ).ready(function( $ ) {
2 var transitionTimeout;
3
4 // languages list table
5 // accessibility to row actions on focus
6 // mainly copy paste of WP code from common.js
7 $( 'table.languages' ).on({ // restricted to languages list table
8 focusin: function() {
9 clearTimeout( transitionTimeout );
10 focusedRowActions = $( this ).find( '.row-actions' );
11 // transitionTimeout is necessary for Firefox, but Chrome won't remove the CSS class without a little help.
12 $( '.row-actions' ).not( this ).removeClass( 'visible' );
13 focusedRowActions.addClass( 'visible' );
14 },
15 focusout: function() {
16 // Tabbing between post title and .row-actions links needs a brief pause, otherwise
17 // the .row-actions div gets hidden in transit in some browsers ( ahem, Firefox ).
18 transitionTimeout = setTimeout(function() {
19 focusedRowActions.removeClass( 'visible' );
20 }, 30 );
21 }
22 }, 'tr' ); // acts on the whole tr instead of single td as we have actions links in several columns
23
24 // extends selectmenu to add flags in menu items
25 $.widget( "custom.iconselectmenu", $.ui.selectmenu, {
26 _renderItem: function( ul, item ) {
27 var li = $( "<li>", { text: item.label } );
28
29 if ( item.value ) {
30 $( "<img>", {
31 src: pll_flag_base_url + item.value + '.png',
32 "class": "ui-icon"
33 }).appendTo( li );
34 }
35
36 return li.appendTo( ul );
37 }
38 });
39
40 // allows to display the flag for the selected menu item
41 function add_icon( event, ui ) {
42 var value = $( this ).val();
43 if ( value ) {
44 var txt = $( this ).iconselectmenu( "widget" ).children( ":last" );
45 var img = $( '<img class="ui-icon" >' ).appendTo( txt );
46 img.attr( "src", pll_flag_base_url + value + '.png' );
47 }
48 }
49
50 // overrides the flag dropdown list with our customized jquery ui selectmenu
51 $( "#flag_list" ).iconselectmenu({
52 create: add_icon,
53 select: add_icon,
54 });
55
56 // languages form
57 // fills the fields based on the language dropdown list choice
58 $( '#lang_list' ).change(function() {
59 var value = $( this ).val().split( ':' );
60 var selected = $( "select option:selected" ).text().split( ' - ' );
61 $( '#lang_slug' ).val( value[0] );
62 $( '#lang_locale' ).val( value[1] );
63 $( 'input[name="rtl"]' ).val( [value[2]] );
64 $( '#lang_name' ).val( selected[0] );
65 $( '#flag_list option[value="' + value[3] + '"]' ).attr( 'selected', 'selected' );
66
67 // recreate the jquery ui selectmenu
68 $( "#flag_list" ).iconselectmenu( 'destroy' ).iconselectmenu({
69 create: add_icon,
70 select: add_icon,
71 })
72 });
73
74 // strings translations
75 // save translations when pressing enter
76 $( '.translation input' ).keypress(function( event ){
77 if ( 13 === event.keyCode ) {
78 event.preventDefault();
79 $( '#submit' ).click();
80 }
81 });
82
83 // settings page
84 // click on configure link
85 $( '#the-list' ).on( 'click', '.configure>a', function(){
86 $( '.pll-configure' ).hide().prev().show();
87 $( this ).closest( 'tr' ).hide().next().show();
88 return false;
89 });
90
91 // cancel
92 $( '#the-list' ).on( 'click', '.cancel', function(){
93 $( this ).closest( 'tr' ).hide().prev().show();
94 });
95
96 // save settings
97 $( '#the-list' ).on( 'click', '.save', function(){
98 var tr = $( this ).closest( 'tr' );
99 var parts = tr.attr( 'id' ).split( '-' );
100
101 var data = {
102 action: 'pll_save_options',
103 pll_ajax_settings: true,
104 module: parts[parts.length - 1],
105 _pll_nonce: $( '#_pll_nonce' ).val()
106 }
107
108 data = tr.find( ':input' ).serialize() + '&' + $.param( data );
109
110 $.post( ajaxurl, data, function( response ) {
111 var res = wpAjax.parseAjaxResponse( response, 'ajax-response' );
112 $.each( res.responses, function() {
113 switch ( this.what ) {
114 case 'license-update':
115 $( '#pll-license-' + this.data ).replaceWith( this.supplemental.html );
116 break;
117 case 'success':
118 tr.hide().prev().show(); // close only if there is no error
119 case 'error':
120 $( '.settings-error' ).remove(); // remove previous messages if any
121 $( 'h1' ).after( this.data );
122
123 // Make notices dismissible
124 // copy paste of common.js from WP 4.2.2
125 $( '.notice.is-dismissible' ).each(function() {
126 var $this = $( this ),
127 $button = $( '<button type="button" class="notice-dismiss"><span class="screen-reader-text"></span></button>' ),
128 btnText = commonL10n.dismiss || '';
129
130 // Ensure plain text
131 $button.find( '.screen-reader-text' ).text( btnText );
132
133 $this.append( $button );
134
135 $button.on( 'click.wp-dismiss-notice', function( event ) {
136 event.preventDefault();
137 $this.fadeTo( 100 , 0, function() {
138 $( this ).slideUp( 100, function() {
139 $( this ).remove();
140 });
141 });
142 });
143 });
144 break;
145 }
146 });
147 });
148 });
149
150 // act when pressing enter or esc in configurations
151 $( '.pll-configure' ).keypress(function( event ){
152 if ( 13 === event.keyCode ) {
153 event.preventDefault();
154 $( this ).find( '.save' ).click();
155 }
156
157 if ( 27 === event.keyCode ) {
158 event.preventDefault();
159 $( this ).find( '.cancel' ).click();
160 }
161 });
162
163 // settings URL modifications
164 // manages visibility of fields
165 $( "input[name='force_lang']" ).change(function() {
166 function pll_toggle( a, test ) {
167 test ? a.show() : a.hide();
168 }
169
170 var value = $( this ).val();
171 pll_toggle( $( '#pll-domains-table' ), 3 == value );
172 pll_toggle( $( "#pll-hide-default" ), 3 > value );
173 pll_toggle( $( "#pll-rewrite" ), 2 > value );
174 pll_toggle( $( "#pll-redirect-lang" ), 2 > value );
175 });
176
177 // settings license
178 // deactivate button
179 $( '.pll-deactivate-license' ).on( 'click', function() {
180 var data = {
181 action: 'pll_deactivate_license',
182 pll_ajax_settings: true,
183 id: $( this ).attr( 'id' ),
184 _pll_nonce: $( '#_pll_nonce' ).val()
185 }
186 $.post( ajaxurl, data , function( response ){
187 $( '#pll-license-' + response.id ).replaceWith( response.html );
188 });
189 });
190
191 });
192