settings.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* global woocommerce_settings_params */
  2. ( function( $ ) {
  3. // Sell Countries
  4. $( 'select#woocommerce_allowed_countries' ).change( function() {
  5. if ( 'specific' === $( this ).val() ) {
  6. $( this ).closest('tr').next( 'tr' ).hide();
  7. $( this ).closest('tr').next().next( 'tr' ).show();
  8. } else if ( 'all_except' === $( this ).val() ) {
  9. $( this ).closest('tr').next( 'tr' ).show();
  10. $( this ).closest('tr').next().next( 'tr' ).hide();
  11. } else {
  12. $( this ).closest('tr').next( 'tr' ).hide();
  13. $( this ).closest('tr').next().next( 'tr' ).hide();
  14. }
  15. }).change();
  16. // Ship Countries
  17. $( 'select#woocommerce_ship_to_countries' ).change( function() {
  18. if ( 'specific' === $( this ).val() ) {
  19. $( this ).closest('tr').next( 'tr' ).show();
  20. } else {
  21. $( this ).closest('tr').next( 'tr' ).hide();
  22. }
  23. }).change();
  24. // Stock management
  25. $( 'input#woocommerce_manage_stock' ).change( function() {
  26. if ( $( this ).is(':checked') ) {
  27. $( this ).closest('tbody').find( '.manage_stock_field' ).closest( 'tr' ).show();
  28. } else {
  29. $( this ).closest('tbody').find( '.manage_stock_field' ).closest( 'tr' ).hide();
  30. }
  31. }).change();
  32. // Color picker
  33. $( '.colorpick' )
  34. .iris({
  35. change: function( event, ui ) {
  36. $( this ).parent().find( '.colorpickpreview' ).css({ backgroundColor: ui.color.toString() });
  37. },
  38. hide: true,
  39. border: true
  40. })
  41. .on( 'click focus', function( event ) {
  42. event.stopPropagation();
  43. $( '.iris-picker' ).hide();
  44. $( this ).closest( 'td' ).find( '.iris-picker' ).show();
  45. $( this ).data( 'original-value', $( this ).val() );
  46. })
  47. .on( 'change', function() {
  48. if ( $( this ).is( '.iris-error' ) ) {
  49. var original_value = $( this ).data( 'original-value' );
  50. if ( original_value.match( /^\#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/ ) ) {
  51. $( this ).val( $( this ).data( 'original-value' ) ).change();
  52. } else {
  53. $( this ).val( '' ).change();
  54. }
  55. }
  56. });
  57. $( 'body' ).on( 'click', function() {
  58. $( '.iris-picker' ).hide();
  59. });
  60. // Edit prompt
  61. $( function() {
  62. var changed = false;
  63. $( 'input, textarea, select, checkbox' ).change( function() {
  64. changed = true;
  65. });
  66. $( '.woo-nav-tab-wrapper a' ).click( function() {
  67. if ( changed ) {
  68. window.onbeforeunload = function() {
  69. return woocommerce_settings_params.i18n_nav_warning;
  70. };
  71. } else {
  72. window.onbeforeunload = '';
  73. }
  74. });
  75. $( '.submit :input' ).click( function() {
  76. window.onbeforeunload = '';
  77. });
  78. });
  79. // Sorting
  80. $( 'table.wc_gateways tbody, table.wc_shipping tbody' ).sortable({
  81. items: 'tr',
  82. cursor: 'move',
  83. axis: 'y',
  84. handle: 'td.sort',
  85. scrollSensitivity: 40,
  86. helper: function( event, ui ) {
  87. ui.children().each( function() {
  88. $( this ).width( $( this ).width() );
  89. });
  90. ui.css( 'left', '0' );
  91. return ui;
  92. },
  93. start: function( event, ui ) {
  94. ui.item.css( 'background-color', '#f6f6f6' );
  95. },
  96. stop: function( event, ui ) {
  97. ui.item.removeAttr( 'style' );
  98. }
  99. });
  100. // Select all/none
  101. $( '.woocommerce' ).on( 'click', '.select_all', function() {
  102. $( this ).closest( 'td' ).find( 'select option' ).attr( 'selected', 'selected' );
  103. $( this ).closest( 'td' ).find( 'select' ).trigger( 'change' );
  104. return false;
  105. });
  106. $( '.woocommerce' ).on( 'click', '.select_none', function() {
  107. $( this ).closest( 'td' ).find( 'select option' ).removeAttr( 'selected' );
  108. $( this ).closest( 'td' ).find( 'select' ).trigger( 'change' );
  109. return false;
  110. });
  111. })( jQuery );