PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/Project/faci-qsoft/wp-content/plugins/polylang/js/admin.js

https://gitlab.com/hop23typhu/list-theme
JavaScript | 166 lines | 118 code | 24 blank | 24 comment | 8 complexity | 38685a36500dccb9c5840af6bc9a0755 MD5 | raw file
  1. jQuery( document ).ready(function( $ ) {
  2. var transitionTimeout;
  3. // languages list table
  4. // accessibility to row actions on focus
  5. // mainly copy paste of WP code from common.js
  6. $( 'table.languages' ).on({ // restricted to languages list table
  7. focusin: function() {
  8. clearTimeout( transitionTimeout );
  9. focusedRowActions = $( this ).find( '.row-actions' );
  10. // transitionTimeout is necessary for Firefox, but Chrome won't remove the CSS class without a little help.
  11. $( '.row-actions' ).not( this ).removeClass( 'visible' );
  12. focusedRowActions.addClass( 'visible' );
  13. },
  14. focusout: function() {
  15. // Tabbing between post title and .row-actions links needs a brief pause, otherwise
  16. // the .row-actions div gets hidden in transit in some browsers ( ahem, Firefox ).
  17. transitionTimeout = setTimeout(function() {
  18. focusedRowActions.removeClass( 'visible' );
  19. }, 30 );
  20. }
  21. }, 'tr' ); // acts on the whole tr instead of single td as we have actions links in several columns
  22. // extends selectmenu to add flags in menu items
  23. $.widget( "custom.iconselectmenu", $.ui.selectmenu, {
  24. _renderItem: function( ul, item ) {
  25. var li = $( "<li>", { text: item.label } );
  26. if ( item.value ) {
  27. $( "<img>", {
  28. src: pll_flag_base_url + item.value + '.png',
  29. "class": "ui-icon"
  30. }).appendTo( li );
  31. }
  32. return li.appendTo( ul );
  33. }
  34. });
  35. // allows to display the flag for the selected menu item
  36. function add_icon( event, ui ) {
  37. var value = $( this ).val();
  38. if ( value ) {
  39. var txt = $( this ).iconselectmenu( "widget" ).children( ":last" );
  40. var img = $( '<img class="ui-icon" >' ).appendTo( txt );
  41. img.attr( "src", pll_flag_base_url + value + '.png' );
  42. }
  43. }
  44. // overrides the flag dropdown list with our customized jquery ui selectmenu
  45. $( "#flag_list" ).iconselectmenu({
  46. create: add_icon,
  47. select: add_icon,
  48. });
  49. // languages form
  50. // fills the fields based on the language dropdown list choice
  51. $( '#lang_list' ).change(function() {
  52. value = $( this ).val().split( '-' );
  53. selected = $( "select option:selected" ).text().split( ' - ' );
  54. $( '#lang_slug' ).val( value[0] );
  55. $( '#lang_locale' ).val( value[1] );
  56. $( 'input[name="rtl"]' ).val( [value[2]] );
  57. $( '#lang_name' ).val( selected[0] );
  58. $( '#flag_list option[value="' + value[3] + '"]' ).attr( 'selected', 'selected' );
  59. // recreate the jquery ui selectmenu
  60. $( "#flag_list" ).iconselectmenu( 'destroy' ).iconselectmenu({
  61. create: add_icon,
  62. select: add_icon,
  63. })
  64. });
  65. // strings translations
  66. // save translations when pressing enter
  67. $( '.translation input' ).keypress(function( event ){
  68. if ( 13 === event.keyCode ) {
  69. event.preventDefault();
  70. $( '#submit' ).click();
  71. }
  72. });
  73. // settings page
  74. // click on configure link
  75. $( '#the-list' ).on( 'click', '.configure>a', function(){
  76. $( '.pll-configure' ).hide().prev().show();
  77. $( this ).closest( 'tr' ).hide().next().show();
  78. return false;
  79. });
  80. // cancel
  81. $( '#the-list' ).on( 'click', '.cancel', function(){
  82. $( this ).closest( 'tr' ).hide().prev().show();
  83. });
  84. // save settings
  85. $( '#the-list' ).on( 'click', '.save', function(){
  86. var tr = $( this ).closest( 'tr' );
  87. var parts = tr.attr( 'id' ).split( '-' );
  88. var data = {
  89. action: 'pll_save_options',
  90. module: parts[parts.length - 1],
  91. _pll_nonce: $( '#_pll_nonce' ).val()
  92. }
  93. data = tr.find( ':input' ).serialize() + '&' + $.param( data );
  94. $.post( ajaxurl, data , function( response ) {
  95. if ( response.success ) {
  96. tr.hide().prev().show(); // close only if there is no error
  97. }
  98. $( '.settings-error' ).remove(); // remove previous messages if any
  99. $( '.nav-tab-wrapper' ).after( response.data );
  100. // Make notices dismissible
  101. // copy paste of common.js from WP 4.2.2
  102. $( '.notice.is-dismissible' ).each(function() {
  103. var $this = $( this ),
  104. $button = $( '<button type="button" class="notice-dismiss"><span class="screen-reader-text"></span></button>' ),
  105. btnText = commonL10n.dismiss || '';
  106. // Ensure plain text
  107. $button.find( '.screen-reader-text' ).text( btnText );
  108. $this.append( $button );
  109. $button.on( 'click.wp-dismiss-notice', function( event ) {
  110. event.preventDefault();
  111. $this.fadeTo( 100 , 0, function() {
  112. $( this ).slideUp( 100, function() {
  113. $( this ).remove();
  114. });
  115. });
  116. });
  117. });
  118. });
  119. });
  120. // act when pressing enter or esc in configurations
  121. $( '.pll-configure' ).keypress(function( event ){
  122. if ( 13 === event.keyCode ) {
  123. event.preventDefault();
  124. $( this ).find( '.save' ).click();
  125. }
  126. if ( 27 === event.keyCode ) {
  127. event.preventDefault();
  128. $( this ).find( '.cancel' ).click();
  129. }
  130. });
  131. // settings URL modifications
  132. // manages visibility of fields
  133. $( "input[name='force_lang']" ).change(function() {
  134. function pll_toggle( a, test ) {
  135. test ? a.show() : a.hide();
  136. }
  137. var value = $( this ).val();
  138. pll_toggle( $( '#pll-domains-table' ), 3 == value );
  139. pll_toggle( $( "#pll-hide-default" ), 3 > value );
  140. pll_toggle( $( "#pll-rewrite" ), 2 > value );
  141. });
  142. });