| @@ -1,267 +1,28 @@ | ||
| 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 | + // languages form | |
| 3 | + // fills the fields based on the language dropdown list choice | |
| 4 | + $('#lang_list').change(function() { | |
| 5 | + value = $(this).val().split('-'); | |
| 6 | + selected = $("select option:selected").text().split(' - '); | |
| 7 | + $('#lang_slug').val(value[0]); | |
| 8 | + $('#lang_locale').val(value[1]); | |
| 9 | + $('input[name="rtl"]').val([value[2]]); | |
| 10 | + $('#lang_name').val(selected[0]); | |
| 11 | + }); | |
| 12 | + | |
| 13 | + // settings page | |
| 14 | + // manages visibility of fields | |
| 15 | + $("input[name='force_lang']").change(function() { | |
| 16 | + function pll_toggle(a, test) { | |
| 17 | + test ? a.show() : a.hide(); | |
| 18 | + } | |
| 19 | + | |
| 20 | + var value = $(this).val(); | |
| 21 | + pll_toggle($('#pll-domains-table'), 3 == value); | |
| 22 | + pll_toggle($("#pll-hide-default"), 3 > value); | |
| 23 | + pll_toggle($("#pll-detect-browser"), 3 > value); | |
| 24 | + pll_toggle($("#pll-rewrite"), 2 > value); | |
| 25 | + | |
| 26 | + pll_toggle($("#pll-url-complements"), 3 > value || $("input[name='redirect_lang']").size()); | |
| 27 | + }); | |
| 28 | +}); | |