| @@ -1,409 +1,191 @@ | ||
| 1 | -/** | |
| 2 | - * @package Polylang | |
| 3 | - */ | |
| 1 | +jQuery( document ).ready(function( $ ) { | |
| 2 | + var transitionTimeout; | |
| 4 | 3 | |
| 5 | -jQuery( | |
| 6 | - function( $ ) { | |
| 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 | |
| 7 | 23 | |
| 8 | - // languages list table | |
| 9 | - // accessibility to row actions on focus | |
| 10 | - // mainly copy paste of WP code from common.js | |
| 11 | - var transitionTimeout; | |
| 12 | - $( 'table.languages' ).on( | |
| 13 | - { // restricted to languages list table | |
| 14 | - focusin: function() { | |
| 15 | - clearTimeout( transitionTimeout ); | |
| 16 | - var focusedRowActions = $( this ).find( '.row-actions' ); | |
| 17 | - // transitionTimeout is necessary for Firefox, but Chrome won't remove the CSS class without a little help. | |
| 18 | - $( '.row-actions' ).not( this ).removeClass( 'visible' ); | |
| 19 | - focusedRowActions.addClass( 'visible' ); | |
| 20 | - }, | |
| 21 | - focusout: function() { | |
| 22 | - // Tabbing between post title and .row-actions links needs a brief pause, otherwise | |
| 23 | - // the .row-actions div gets hidden in transit in some browsers ( ahem, Firefox ). | |
| 24 | - transitionTimeout = setTimeout( | |
| 25 | - function() { | |
| 26 | - focusedRowActions.removeClass( 'visible' ); | |
| 27 | - }, | |
| 28 | - 30 | |
| 29 | - ); | |
| 30 | - } | |
| 31 | - }, | |
| 32 | - 'tr' | |
| 33 | - ); // acts on the whole tr instead of single td as we have actions links in several columns | |
| 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 } ); | |
| 34 | 28 | |
| 35 | - /** | |
| 36 | - * Common functions and variables for overriding languages and flags dropdown list by a jQuery UI selectmenu widget. | |
| 37 | - */ | |
| 38 | - | |
| 39 | - // Add a boolean variable to be able to check jQuery UI >= 1.12 which is introduced in WP 5.6. | |
| 40 | - // Backward compatibility WP < 5.6 | |
| 41 | - var isJqueryUImin112 = $.ui.version >= '1.12.0'; | |
| 42 | - // Allow to check if a flag list dropdown is present. Not present in the Wizard steps or other settings page. | |
| 43 | - var flagListExist = $( "#flag_list" ).length; | |
| 44 | - // Allow to check if a language list dropdown is present. Not present in other settings page. | |
| 45 | - var langListExist = $( "#lang_list" ).length; | |
| 46 | - // jQuery UI selectmenu widget width option | |
| 47 | - var defaultSelectmenuWidth = '95%'; | |
| 48 | - var wizardSelectmenuWidth = '100%'; | |
| 49 | - | |
| 50 | - // Inject flag image when jQuery UI selectmenu is created or an item is selected. | |
| 51 | - // jQuery UI 1.12 introduce a wrapper inside de li tag which is necessary to selectmenu widget to work correctly. | |
| 52 | - // Mainly copy from the orginal jQuery UI 1.12 selectmenu widget _renderItem method. | |
| 53 | - // Note this code works fine with jQuery UI 1.11.4 too. | |
| 54 | - var selectmenuRenderItem = function( ul, item ) { | |
| 55 | - var li = $( '<li>' ); | |
| 56 | - var wrapper = $( '<div>'); | |
| 57 | - | |
| 58 | - if ( item.disabled ) { | |
| 59 | - this._addClass( li, null, "ui-state-disabled" ); | |
| 29 | + if ( item.value ) { | |
| 30 | + $( "<img>", { | |
| 31 | + src: pll_flag_base_url + item.value + '.png', | |
| 32 | + "class": "ui-icon" | |
| 33 | + }).appendTo( li ); | |
| 60 | 34 | } |
| 61 | - this._setText( wrapper, item.label ); | |
| 62 | 35 | |
| 63 | - // Add the flag from the data attribute in the selected element. | |
| 64 | - wrapper.prepend( $( item.element ).data( 'flag-html' ) ); | |
| 65 | - wrapper.children( 'img' ).addClass( 'ui-icon' ); | |
| 66 | - | |
| 67 | - return li.append( wrapper ).appendTo( ul ); | |
| 68 | - }; | |
| 69 | - // Override selected item to inject flag for jQuery UI less than 1.12. | |
| 70 | - var selectmenuRefreshButtonText = function( selectElement ) { | |
| 71 | - var buttonText = $( selectElement ).selectmenu( 'instance' ).buttonText; | |
| 72 | - buttonText.prepend( $( selectElement ).children( ':selected' ).data( 'flag-html' ) ); | |
| 73 | - buttonText.children( 'img' ).addClass( 'ui-icon' ); | |
| 74 | - }; | |
| 75 | - // Override selected item since jQuery UI 1.12 which introduces extension point method _renderButtonItem. | |
| 76 | - // @see https://api.jqueryui.com/1.12/selectmenu/#method-_renderButtonItem _renderButtonItem documentation. | |
| 77 | - var selectmenuRenderButtonItem = function ( selectElement ) { | |
| 78 | - var buttonItem = $( '<span>' ); | |
| 79 | - this._setText( buttonItem, selectElement.label ); | |
| 80 | - this._addClass( buttonItem, "ui-selectmenu-text" ); | |
| 81 | - | |
| 82 | - // Add the flag from the data attribute in the selected element. | |
| 83 | - buttonItem.prepend( $( selectElement.element ).data( 'flag-html' ) ); | |
| 84 | - buttonItem.children( 'img' ).addClass( 'ui-icon' ); | |
| 85 | - | |
| 86 | - return buttonItem; | |
| 36 | + return li.appendTo( ul ); | |
| 87 | 37 | } |
| 38 | + }); | |
| 88 | 39 | |
| 89 | - /** | |
| 90 | - * Initialize a jQuery UI selectmenu widget on a DOM element | |
| 91 | - * | |
| 92 | - * @param {*} element - The jQuery object representing the DOM element to attach the widget with. | |
| 93 | - * @param {*} config - All the parameters - options and callbacks - necessary to configure the jQuery UI selectmenu widget. | |
| 94 | - * @return {Object} - The jQuery UI selectmenu widget object instance. | |
| 95 | - */ | |
| 96 | - function initializeSelectmenuWidget( element, config ) { | |
| 97 | - // Create the jQuery UI selectmenu widget for flags list dropdown and return its instance. | |
| 98 | - var selectmenuWidgetInstance = element.selectmenu( config ).selectmenu( 'instance' ); | |
| 99 | - // Overrides each item in the jQuery UI selectmenu list by injecting flag image. | |
| 100 | - selectmenuWidgetInstance._renderItem = selectmenuRenderItem; | |
| 101 | - // Override the selected item rendering for jQuery UI 1.12 | |
| 102 | - if ( isJqueryUImin112 ) { | |
| 103 | - selectmenuWidgetInstance._renderButtonItem = selectmenuRenderButtonItem; | |
| 104 | - // Need to refresh to take in account the new button item rendering method after the selectmenu widget instanciaion. | |
| 105 | - selectmenuWidgetInstance.refresh(); | |
| 106 | - } | |
| 107 | - return selectmenuWidgetInstance | |
| 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' ); | |
| 108 | 47 | } |
| 109 | - /** | |
| 110 | - * Selectmenu widget common parameters for its configuration: options and callbacks. | |
| 111 | - */ | |
| 48 | + } | |
| 112 | 49 | |
| 113 | - // Selectmenu widget options | |
| 114 | - var selectmenuOptions = { width: defaultSelectmenuWidth }; | |
| 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 | + }); | |
| 115 | 55 | |
| 116 | - // Selectmenu widget callbacks | |
| 117 | - var selectmenuFlagListCallbacks = {}; | |
| 118 | - // Callbacks when Selectmenu widget create or select event is triggered. | |
| 119 | - var createSelectCallback = function( event, ui ) { | |
| 120 | - selectmenuRefreshButtonText( event.target ); | |
| 121 | - } | |
| 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' ); | |
| 122 | 66 | |
| 123 | - /** | |
| 124 | - * Overrides the flag dropdown list with our customized jquery ui selectmenu. | |
| 125 | - */ | |
| 67 | + // recreate the jquery ui selectmenu | |
| 68 | + $( "#flag_list" ).iconselectmenu( 'destroy' ).iconselectmenu({ | |
| 69 | + create: add_icon, | |
| 70 | + select: add_icon, | |
| 71 | + }) | |
| 72 | + }); | |
| 126 | 73 | |
| 127 | - // Callbacks when Selectmenu widget change or open event is triggered. | |
| 128 | - // Needed to correctly refresh the selected element in the list when editing an existing language or when the value change is triggered by the language choice. | |
| 129 | - // jQuery UI 1.11 callback version. | |
| 130 | - var changeOpenCallback = function( event, ui ){ | |
| 131 | - selectmenuRefreshButtonText( $( event.target ).selectmenu( 'refresh' ) ); | |
| 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(); | |
| 132 | 80 | } |
| 133 | - // jQueryUI 1.12 callback version. | |
| 134 | - var changeOpenCallbackjQueryUI112 = function( event, ui ){ | |
| 135 | - // Just a refresh of the menu is needed with jQuery UI 1.12 because _renderButtonItem is triggered and then inject correctly the flag. | |
| 136 | - $( event.target ).selectmenu( 'refresh' ); | |
| 137 | - } | |
| 138 | - // There is no need of create and select callbacks with jQuery UI 1.12 because overriding _renderButtonItem method do the job. | |
| 139 | - if ( isJqueryUImin112 ) { | |
| 140 | - selectmenuFlagListCallbacks = | |
| 141 | - { | |
| 142 | - change: changeOpenCallbackjQueryUI112, | |
| 143 | - open: changeOpenCallbackjQueryUI112, | |
| 144 | - }; | |
| 145 | - } else { | |
| 146 | - selectmenuFlagListCallbacks = { | |
| 147 | - create: createSelectCallback, | |
| 148 | - select: createSelectCallback, | |
| 149 | - change: changeOpenCallback, | |
| 150 | - open: changeOpenCallback, | |
| 151 | - }; | |
| 152 | - } | |
| 81 | + }); | |
| 153 | 82 | |
| 154 | - // Create the selectmenu widget only if the field is present. | |
| 155 | - if ( flagListExist ) { | |
| 156 | - // Create the jQuery UI selectmenu widget for flags list dropdown and return its instance. | |
| 157 | - var selectmenuFlagList = initializeSelectmenuWidget( $( '#flag_list' ), Object.assign( {}, selectmenuOptions, selectmenuFlagListCallbacks ) ); | |
| 158 | - $( '#lang_list' ).on( | |
| 159 | - 'languageChanged', | |
| 160 | - function( event, flag ) { | |
| 161 | - // Refresh the flag field | |
| 162 | - selectmenuFlagList.element.val( flag ); | |
| 163 | - selectmenuFlagList._trigger( 'change' ); | |
| 164 | - } | |
| 165 | - ); | |
| 166 | - } | |
| 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 | + }); | |
| 167 | 90 | |
| 168 | - /** | |
| 169 | - * Language choice in predefined languages in Polylang Languages settings page and wizard. | |
| 170 | - * Overrides the predefined language dropdown list with our customized jQuery ui selectmenu widget. | |
| 171 | - */ | |
| 91 | + // cancel | |
| 92 | + $( '#the-list' ).on( 'click', '.cancel', function(){ | |
| 93 | + $( this ).closest( 'tr' ).hide().prev().show(); | |
| 94 | + }); | |
| 172 | 95 | |
| 173 | - /** | |
| 174 | - * Fill the other language form fields from the language element selected in the language list dropdown. | |
| 175 | - * | |
| 176 | - * @param {Object} language - language object of the selected element in the language list dropdown. | |
| 177 | - */ | |
| 178 | - function fillLanguageFields( language ) { | |
| 179 | - $( '#lang_slug' ).val( language.slug ); | |
| 180 | - $( '#lang_locale' ).val( language.locale ); | |
| 181 | - $( 'input[name="rtl"]' ).val( language.rtl ); | |
| 182 | - $( '#lang_name' ).val( language.name ); | |
| 183 | - } | |
| 96 | + // save settings | |
| 97 | + $( '#the-list' ).on( 'click', '.save', function(){ | |
| 98 | + var tr = $( this ).closest( 'tr' ); | |
| 99 | + var parts = tr.attr( 'id' ).split( '-' ); | |
| 184 | 100 | |
| 185 | - /** | |
| 186 | - * Parse selected language element in the language list dropdown. | |
| 187 | - * | |
| 188 | - * @param {object} event - jQuery triggered event. | |
| 189 | - * @return {object} The language object with its named properties. | |
| 190 | - */ | |
| 191 | - function parseSelectedLanguage( event ) { | |
| 192 | - var selectedElement = $('option:selected', event.target); | |
| 193 | - var values = selectedElement.val().split(':') | |
| 194 | - return { | |
| 195 | - slug: values[0], | |
| 196 | - locale: values[1], | |
| 197 | - rtl: [values[2]], | |
| 198 | - flag: values[3], | |
| 199 | - name: selectedElement.text().split(' - ')[0] // At the moment there is no need of the 2nd part because it corresponds on the locale which is already known by splitting the selected element value | |
| 200 | - }; | |
| 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() | |
| 201 | 106 | } |
| 202 | 107 | |
| 203 | - // Callback when selectmenu widget change event is triggered. | |
| 204 | - var changeCallback = function( event, ui ) { | |
| 205 | - var language = parseSelectedLanguage( event ); | |
| 108 | + data = tr.find( ':input' ).serialize() + '&' + $.param( data ); | |
| 206 | 109 | |
| 207 | - fillLanguageFields( language ); | |
| 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 ); | |
| 208 | 122 | |
| 209 | - $( event.target ).trigger( 'languageChanged', language.flag ); | |
| 210 | - }; | |
| 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 || ''; | |
| 211 | 129 | |
| 212 | - // Create the jQuery UI selectmenu widget languages list dropdown and return its instance. | |
| 213 | - var selectmenuLangListCallbacks = {}; | |
| 214 | - // For the wizard we need a 100% width. So we override the previous defined value of selectmenuOptions. | |
| 215 | - if( $( '#lang_list' ).closest( '.pll-wizard-content' ).length > 0 ) { | |
| 216 | - selectmenuOptions = Object.assign( selectmenuOptions, { width: wizardSelectmenuWidth } ); | |
| 217 | - } | |
| 130 | + // Ensure plain text | |
| 131 | + $button.find( '.screen-reader-text' ).text( btnText ); | |
| 218 | 132 | |
| 219 | - // There is no need of create and select callbacks with jQuery UI 1.12 because overrinding _renderButtonItem method do the job. | |
| 220 | - if ( isJqueryUImin112 ) { | |
| 221 | - selectmenuLangListCallbacks = { | |
| 222 | - change: changeCallback, | |
| 223 | - }; | |
| 224 | - } else { | |
| 225 | - selectmenuLangListCallbacks = { | |
| 226 | - create: createSelectCallback, | |
| 227 | - select: createSelectCallback, | |
| 228 | - change: changeCallback, | |
| 229 | - }; | |
| 230 | - } | |
| 231 | - if ( langListExist ) { | |
| 232 | - initializeSelectmenuWidget( $( '#lang_list' ), Object.assign( {}, selectmenuOptions, selectmenuLangListCallbacks ) ); | |
| 233 | - } | |
| 133 | + $this.append( $button ); | |
| 234 | 134 | |
| 235 | - // strings translations | |
| 236 | - // save translations when pressing enter | |
| 237 | - $( '.translation input' ).on( | |
| 238 | - 'keydown', | |
| 239 | - function( event ){ | |
| 240 | - if ( 'Enter' === event.key ) { | |
| 241 | - event.preventDefault(); | |
| 242 | - $( '#submit' ).trigger( 'click' ); | |
| 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; | |
| 243 | 145 | } |
| 244 | - } | |
| 245 | - ); | |
| 146 | + }); | |
| 147 | + }); | |
| 148 | + }); | |
| 246 | 149 | |
| 247 | - // settings page | |
| 248 | - // click on configure link | |
| 249 | - $( '#the-list' ).on( | |
| 250 | - 'click', | |
| 251 | - '.configure>a', | |
| 252 | - function(){ | |
| 253 | - $( '.pll-configure' ).hide().prev().show(); | |
| 254 | - $( this ).closest( 'tr' ).hide().next().show(); | |
| 255 | - return false; | |
| 256 | - } | |
| 257 | - ); | |
| 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 | + } | |
| 258 | 156 | |
| 259 | - // cancel | |
| 260 | - $( '#the-list' ).on( | |
| 261 | - 'click', | |
| 262 | - '.cancel', | |
| 263 | - function(){ | |
| 264 | - $( this ).closest( 'tr' ).hide().prev().show(); | |
| 265 | - } | |
| 266 | - ); | |
| 157 | + if ( 27 === event.keyCode ) { | |
| 158 | + event.preventDefault(); | |
| 159 | + $( this ).find( '.cancel' ).click(); | |
| 160 | + } | |
| 161 | + }); | |
| 267 | 162 | |
| 268 | - // save settings | |
| 269 | - $( '#the-list' ).on( | |
| 270 | - 'click', | |
| 271 | - '.save', | |
| 272 | - function(){ | |
| 273 | - var tr = $( this ).closest( 'tr' ); | |
| 274 | - var parts = tr.attr( 'id' ).split( '-' ); | |
| 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 | + } | |
| 275 | 169 | |
| 276 | - var data = { | |
| 277 | - action: 'pll_save_options', | |
| 278 | - pll_ajax_settings: true, | |
| 279 | - module: parts[parts.length - 1], | |
| 280 | - _pll_nonce: $( '#_pll_nonce' ).val() | |
| 281 | - }; | |
| 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 | + }); | |
| 282 | 176 | |
| 283 | - data = tr.find( ':input' ).serialize() + '&' + $.param( data ); | |
| 284 | - | |
| 285 | - $.post( | |
| 286 | - ajaxurl, | |
| 287 | - data, | |
| 288 | - function( response ) { | |
| 289 | - var res = wpAjax.parseAjaxResponse( response, 'ajax-response' ); | |
| 290 | - $.each( | |
| 291 | - res.responses, | |
| 292 | - function() { | |
| 293 | - switch ( this.what ) { | |
| 294 | - case 'license-update': | |
| 295 | - $( '#pll-license-' + this.data ).replaceWith( this.supplemental.html ); | |
| 296 | - break; | |
| 297 | - case 'success': | |
| 298 | - tr.hide().prev().show(); // close only if there is no error | |
| 299 | - case 'error': | |
| 300 | - $( '.settings-error' ).remove(); // remove previous messages if any | |
| 301 | - $( 'h1' ).after( this.data ); | |
| 302 | - | |
| 303 | - // Make notices dismissible | |
| 304 | - // copy paste of common.js from WP 4.2.2 | |
| 305 | - $( '.notice.is-dismissible' ).each( | |
| 306 | - function() { | |
| 307 | - var $this = $( this ), | |
| 308 | - $button = $( '<button type="button" class="notice-dismiss"><span class="screen-reader-text"></span></button>' ), | |
| 309 | - btnText = pll_dismiss_notice || ''; | |
| 310 | - | |
| 311 | - // Ensure plain text | |
| 312 | - $button.find( '.screen-reader-text' ).text( btnText ); | |
| 313 | - | |
| 314 | - // Whitelist because of how the button is built. See above | |
| 315 | - $this.append( $button ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.append | |
| 316 | - | |
| 317 | - $button.on( | |
| 318 | - 'click.wp-dismiss-notice', | |
| 319 | - function( event ) { | |
| 320 | - event.preventDefault(); | |
| 321 | - $this.fadeTo( | |
| 322 | - 100, | |
| 323 | - 0, | |
| 324 | - function() { | |
| 325 | - $( this ).slideUp( | |
| 326 | - 100, | |
| 327 | - function() { | |
| 328 | - $( this ).remove(); | |
| 329 | - } | |
| 330 | - ); | |
| 331 | - } | |
| 332 | - ); | |
| 333 | - } | |
| 334 | - ); | |
| 335 | - } | |
| 336 | - ); | |
| 337 | - break; | |
| 338 | - } | |
| 339 | - } | |
| 340 | - ); | |
| 341 | - } | |
| 342 | - ); | |
| 343 | - } | |
| 344 | - ); | |
| 345 | - | |
| 346 | - // act when pressing enter or esc in configurations | |
| 347 | - $( '.pll-configure' ).on( | |
| 348 | - 'keydown', | |
| 349 | - function( event ){ | |
| 350 | - if ( 'Enter' === event.key ) { | |
| 351 | - event.preventDefault(); | |
| 352 | - $( this ).find( '.save' ).trigger( 'click' ); | |
| 353 | - } | |
| 354 | - | |
| 355 | - if ( 'Escape' === event.key ) { | |
| 356 | - event.preventDefault(); | |
| 357 | - $( this ).find( '.cancel' ).trigger( 'click' ); | |
| 358 | - } | |
| 359 | - } | |
| 360 | - ); | |
| 361 | - | |
| 362 | - // settings URL modifications | |
| 363 | - // manages visibility of fields | |
| 364 | - $( "input[name='force_lang']" ).on( | |
| 365 | - 'change', | |
| 366 | - function() { | |
| 367 | - function pll_toggle( a, test ) { | |
| 368 | - test ? a.show() : a.hide(); | |
| 369 | - } | |
| 370 | - | |
| 371 | - var value = $( this ).val(); | |
| 372 | - pll_toggle( $( '#pll-domains-table' ), 3 == value ); | |
| 373 | - pll_toggle( $( "#pll-hide-default" ), 3 > value ); | |
| 374 | - pll_toggle( $( "#pll-rewrite" ), 2 > value ); | |
| 375 | - pll_toggle( $( "#pll-redirect-lang" ), 2 > value ); | |
| 376 | - } | |
| 377 | - ); | |
| 378 | - | |
| 379 | - // settings license | |
| 380 | - // deactivate button | |
| 381 | - $( '.pll-deactivate-license' ).on( | |
| 382 | - 'click', | |
| 383 | - function() { | |
| 384 | - var data = { | |
| 385 | - action: 'pll_deactivate_license', | |
| 386 | - pll_ajax_settings: true, | |
| 387 | - id: $( this ).attr( 'id' ), | |
| 388 | - _pll_nonce: $( '#_pll_nonce' ).val() | |
| 389 | - }; | |
| 390 | - $.post( | |
| 391 | - ajaxurl, | |
| 392 | - data, | |
| 393 | - function( response ){ | |
| 394 | - $( '#pll-license-' + response.id ).replaceWith( response.html ); | |
| 395 | - } | |
| 396 | - ); | |
| 397 | - } | |
| 398 | - ); | |
| 399 | - | |
| 400 | - // Manage closing the metabox. | |
| 401 | - // close postboxes that should be closed | |
| 402 | - $( '.if-js-closed' ).removeClass( 'if-js-closed' ).addClass( 'closed' ); | |
| 403 | - // postboxes setup | |
| 404 | - if ( 'undefined' !== typeof postboxes ) { | |
| 405 | - postboxes.add_postbox_toggles( pagenow ); | |
| 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() | |
| 406 | 185 | } |
| 407 | - } | |
| 408 | -); | |
| 186 | + $.post( ajaxurl, data , function( response ){ | |
| 187 | + $( '#pll-license-' + response.id ).replaceWith( response.html ); | |
| 188 | + }); | |
| 189 | + }); | |
| 409 | 190 | |
| 191 | +}); | |