Bez popisu

settings.js 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /* global woocommerce_settings_params, wp */
  2. ( function( $, params, wp ) {
  3. $( function() {
  4. // Sell Countries
  5. $( 'select#woocommerce_allowed_countries' ).on( 'change', function() {
  6. if ( 'specific' === $( this ).val() ) {
  7. $( this ).closest('tr').next( 'tr' ).hide();
  8. $( this ).closest('tr').next().next( 'tr' ).show();
  9. } else if ( 'all_except' === $( this ).val() ) {
  10. $( this ).closest('tr').next( 'tr' ).show();
  11. $( this ).closest('tr').next().next( 'tr' ).hide();
  12. } else {
  13. $( this ).closest('tr').next( 'tr' ).hide();
  14. $( this ).closest('tr').next().next( 'tr' ).hide();
  15. }
  16. }).trigger( 'change' );
  17. // Ship Countries
  18. $( 'select#woocommerce_ship_to_countries' ).on( 'change', function() {
  19. if ( 'specific' === $( this ).val() ) {
  20. $( this ).closest('tr').next( 'tr' ).show();
  21. } else {
  22. $( this ).closest('tr').next( 'tr' ).hide();
  23. }
  24. }).trigger( 'change' );
  25. // Stock management
  26. $( 'input#woocommerce_manage_stock' ).on( 'change', function() {
  27. if ( $( this ).is(':checked') ) {
  28. $( this ).closest('tbody').find( '.manage_stock_field' ).closest( 'tr' ).show();
  29. } else {
  30. $( this ).closest('tbody').find( '.manage_stock_field' ).closest( 'tr' ).hide();
  31. }
  32. }).trigger( 'change' );
  33. // Color picker
  34. $( '.colorpick' )
  35. .iris({
  36. change: function( event, ui ) {
  37. $( this ).parent().find( '.colorpickpreview' ).css({ backgroundColor: ui.color.toString() });
  38. },
  39. hide: true,
  40. border: true
  41. })
  42. .on( 'click focus', function( event ) {
  43. event.stopPropagation();
  44. $( '.iris-picker' ).hide();
  45. $( this ).closest( 'td' ).find( '.iris-picker' ).show();
  46. $( this ).data( 'originalValue', $( this ).val() );
  47. })
  48. .on( 'change', function() {
  49. if ( $( this ).is( '.iris-error' ) ) {
  50. var original_value = $( this ).data( 'originalValue' );
  51. if ( original_value.match( /^\#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/ ) ) {
  52. $( this ).val( $( this ).data( 'originalValue' ) ).trigger( 'change' );
  53. } else {
  54. $( this ).val( '' ).trigger( 'change' );
  55. }
  56. }
  57. });
  58. $( 'body' ).on( 'click', function() {
  59. $( '.iris-picker' ).hide();
  60. });
  61. // Edit prompt
  62. $( function() {
  63. var changed = false;
  64. $( 'input, textarea, select, checkbox' ).on( 'change', function() {
  65. if ( ! changed ) {
  66. window.onbeforeunload = function() {
  67. return params.i18n_nav_warning;
  68. };
  69. changed = true;
  70. }
  71. });
  72. $( '.submit :input' ).on( 'click', function() {
  73. window.onbeforeunload = '';
  74. });
  75. });
  76. // Sorting
  77. $( 'table.wc_gateways tbody, table.wc_shipping tbody' ).sortable({
  78. items: 'tr',
  79. cursor: 'move',
  80. axis: 'y',
  81. handle: 'td.sort',
  82. scrollSensitivity: 40,
  83. helper: function( event, ui ) {
  84. ui.children().each( function() {
  85. $( this ).width( $( this ).width() );
  86. });
  87. ui.css( 'left', '0' );
  88. return ui;
  89. },
  90. start: function( event, ui ) {
  91. ui.item.css( 'background-color', '#f6f6f6' );
  92. },
  93. stop: function( event, ui ) {
  94. ui.item.removeAttr( 'style' );
  95. ui.item.trigger( 'updateMoveButtons' );
  96. }
  97. });
  98. // Select all/none
  99. $( '.woocommerce' ).on( 'click', '.select_all', function() {
  100. $( this ).closest( 'td' ).find( 'select option' ).prop( 'selected', true );
  101. $( this ).closest( 'td' ).find( 'select' ).trigger( 'change' );
  102. return false;
  103. });
  104. $( '.woocommerce' ).on( 'click', '.select_none', function() {
  105. $( this ).closest( 'td' ).find( 'select option' ).prop( 'selected', false );
  106. $( this ).closest( 'td' ).find( 'select' ).trigger( 'change' );
  107. return false;
  108. });
  109. // Re-order buttons.
  110. $( '.wc-item-reorder-nav').find( '.wc-move-up, .wc-move-down' ).on( 'click', function() {
  111. var moveBtn = $( this ),
  112. $row = moveBtn.closest( 'tr' );
  113. moveBtn.trigger( 'focus' );
  114. var isMoveUp = moveBtn.is( '.wc-move-up' ),
  115. isMoveDown = moveBtn.is( '.wc-move-down' );
  116. if ( isMoveUp ) {
  117. var $previewRow = $row.prev( 'tr' );
  118. if ( $previewRow && $previewRow.length ) {
  119. $previewRow.before( $row );
  120. wp.a11y.speak( params.i18n_moved_up );
  121. }
  122. } else if ( isMoveDown ) {
  123. var $nextRow = $row.next( 'tr' );
  124. if ( $nextRow && $nextRow.length ) {
  125. $nextRow.after( $row );
  126. wp.a11y.speak( params.i18n_moved_down );
  127. }
  128. }
  129. moveBtn.trigger( 'focus' ); // Re-focus after the container was moved.
  130. moveBtn.closest( 'table' ).trigger( 'updateMoveButtons' );
  131. } );
  132. $( '.wc-item-reorder-nav').closest( 'table' ).on( 'updateMoveButtons', function() {
  133. var table = $( this ),
  134. lastRow = $( this ).find( 'tbody tr:last' ),
  135. firstRow = $( this ).find( 'tbody tr:first' );
  136. table.find( '.wc-item-reorder-nav .wc-move-disabled' ).removeClass( 'wc-move-disabled' )
  137. .attr( { 'tabindex': '0', 'aria-hidden': 'false' } );
  138. firstRow.find( '.wc-item-reorder-nav .wc-move-up' ).addClass( 'wc-move-disabled' )
  139. .attr( { 'tabindex': '-1', 'aria-hidden': 'true' } );
  140. lastRow.find( '.wc-item-reorder-nav .wc-move-down' ).addClass( 'wc-move-disabled' )
  141. .attr( { 'tabindex': '-1', 'aria-hidden': 'true' } );
  142. } );
  143. $( '.wc-item-reorder-nav').closest( 'table' ).trigger( 'updateMoveButtons' );
  144. $( '.submit button' ).on( 'click', function() {
  145. if (
  146. $( 'select#woocommerce_allowed_countries' ).val() === 'specific' &&
  147. ! $( '[name="woocommerce_specific_allowed_countries[]"]' ).val()
  148. ) {
  149. if ( window.confirm( woocommerce_settings_params.i18n_no_specific_countries_selected ) ) {
  150. return true;
  151. }
  152. return false;
  153. }
  154. } );
  155. });
  156. })( jQuery, woocommerce_settings_params, wp );