2018-04-24 18:25:45 +00:00
|
|
|
/* global woocommerce_settings_params, wp */
|
|
|
|
( function( $, params, wp ) {
|
|
|
|
$( function() {
|
|
|
|
// Sell Countries
|
2021-02-04 17:13:46 +00:00
|
|
|
$( 'select#woocommerce_allowed_countries' ).on( 'change', function() {
|
2018-04-24 18:25:45 +00:00
|
|
|
if ( 'specific' === $( this ).val() ) {
|
|
|
|
$( this ).closest('tr').next( 'tr' ).hide();
|
|
|
|
$( this ).closest('tr').next().next( 'tr' ).show();
|
|
|
|
} else if ( 'all_except' === $( this ).val() ) {
|
|
|
|
$( this ).closest('tr').next( 'tr' ).show();
|
|
|
|
$( this ).closest('tr').next().next( 'tr' ).hide();
|
|
|
|
} else {
|
|
|
|
$( this ).closest('tr').next( 'tr' ).hide();
|
|
|
|
$( this ).closest('tr').next().next( 'tr' ).hide();
|
|
|
|
}
|
2021-01-07 22:08:36 +00:00
|
|
|
}).trigger( 'change' );
|
2018-04-24 18:25:45 +00:00
|
|
|
|
|
|
|
// Ship Countries
|
2021-02-04 17:13:46 +00:00
|
|
|
$( 'select#woocommerce_ship_to_countries' ).on( 'change', function() {
|
2018-04-24 18:25:45 +00:00
|
|
|
if ( 'specific' === $( this ).val() ) {
|
|
|
|
$( this ).closest('tr').next( 'tr' ).show();
|
|
|
|
} else {
|
|
|
|
$( this ).closest('tr').next( 'tr' ).hide();
|
|
|
|
}
|
2021-01-07 22:08:36 +00:00
|
|
|
}).trigger( 'change' );
|
2018-04-24 18:25:45 +00:00
|
|
|
|
|
|
|
// Stock management
|
2021-02-04 17:13:46 +00:00
|
|
|
$( 'input#woocommerce_manage_stock' ).on( 'change', function() {
|
2018-04-24 18:25:45 +00:00
|
|
|
if ( $( this ).is(':checked') ) {
|
|
|
|
$( this ).closest('tbody').find( '.manage_stock_field' ).closest( 'tr' ).show();
|
|
|
|
} else {
|
|
|
|
$( this ).closest('tbody').find( '.manage_stock_field' ).closest( 'tr' ).hide();
|
|
|
|
}
|
2021-01-07 22:08:36 +00:00
|
|
|
}).trigger( 'change' );
|
2018-04-24 18:25:45 +00:00
|
|
|
|
|
|
|
// Color picker
|
|
|
|
$( '.colorpick' )
|
|
|
|
|
|
|
|
.iris({
|
|
|
|
change: function( event, ui ) {
|
|
|
|
$( this ).parent().find( '.colorpickpreview' ).css({ backgroundColor: ui.color.toString() });
|
|
|
|
},
|
|
|
|
hide: true,
|
|
|
|
border: true
|
|
|
|
})
|
|
|
|
|
|
|
|
.on( 'click focus', function( event ) {
|
|
|
|
event.stopPropagation();
|
|
|
|
$( '.iris-picker' ).hide();
|
|
|
|
$( this ).closest( 'td' ).find( '.iris-picker' ).show();
|
2021-03-02 15:17:03 +00:00
|
|
|
$( this ).data( 'originalValue', $( this ).val() );
|
2018-04-24 18:25:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
.on( 'change', function() {
|
|
|
|
if ( $( this ).is( '.iris-error' ) ) {
|
2021-03-02 15:17:03 +00:00
|
|
|
var original_value = $( this ).data( 'originalValue' );
|
2018-04-24 18:25:45 +00:00
|
|
|
|
|
|
|
if ( original_value.match( /^\#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/ ) ) {
|
2021-03-02 15:17:03 +00:00
|
|
|
$( this ).val( $( this ).data( 'originalValue' ) ).trigger( 'change' );
|
2018-04-24 18:25:45 +00:00
|
|
|
} else {
|
2021-01-07 22:08:36 +00:00
|
|
|
$( this ).val( '' ).trigger( 'change' );
|
2018-04-24 18:25:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2018-04-24 18:25:45 +00:00
|
|
|
$( 'body' ).on( 'click', function() {
|
2017-11-01 13:47:20 +00:00
|
|
|
$( '.iris-picker' ).hide();
|
2018-04-24 18:25:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Edit prompt
|
|
|
|
$( function() {
|
|
|
|
var changed = false;
|
2017-11-01 13:52:08 +00:00
|
|
|
|
2021-02-04 17:13:46 +00:00
|
|
|
$( 'input, textarea, select, checkbox' ).on( 'change', function() {
|
2020-06-26 08:52:28 +00:00
|
|
|
if ( ! changed ) {
|
2018-04-24 18:25:45 +00:00
|
|
|
window.onbeforeunload = function() {
|
|
|
|
return params.i18n_nav_warning;
|
|
|
|
};
|
2020-06-26 08:52:28 +00:00
|
|
|
changed = true;
|
2017-11-01 13:52:08 +00:00
|
|
|
}
|
2018-04-24 18:25:45 +00:00
|
|
|
});
|
|
|
|
|
2020-11-18 17:56:30 +00:00
|
|
|
$( '.submit :input' ).on( 'click', function() {
|
2018-04-24 18:25:45 +00:00
|
|
|
window.onbeforeunload = '';
|
|
|
|
});
|
2017-11-01 13:47:20 +00:00
|
|
|
});
|
|
|
|
|
2018-04-24 18:25:45 +00:00
|
|
|
// Sorting
|
|
|
|
$( 'table.wc_gateways tbody, table.wc_shipping tbody' ).sortable({
|
|
|
|
items: 'tr',
|
|
|
|
cursor: 'move',
|
|
|
|
axis: 'y',
|
|
|
|
handle: 'td.sort',
|
|
|
|
scrollSensitivity: 40,
|
|
|
|
helper: function( event, ui ) {
|
|
|
|
ui.children().each( function() {
|
|
|
|
$( this ).width( $( this ).width() );
|
|
|
|
});
|
|
|
|
ui.css( 'left', '0' );
|
|
|
|
return ui;
|
|
|
|
},
|
|
|
|
start: function( event, ui ) {
|
|
|
|
ui.item.css( 'background-color', '#f6f6f6' );
|
|
|
|
},
|
|
|
|
stop: function( event, ui ) {
|
|
|
|
ui.item.removeAttr( 'style' );
|
|
|
|
ui.item.trigger( 'updateMoveButtons' );
|
|
|
|
}
|
|
|
|
});
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2018-04-24 18:25:45 +00:00
|
|
|
// Select all/none
|
|
|
|
$( '.woocommerce' ).on( 'click', '.select_all', function() {
|
2021-05-24 19:55:15 +00:00
|
|
|
$( this ).closest( 'td' ).find( 'select option' ).prop( 'selected', true );
|
2018-04-24 18:25:45 +00:00
|
|
|
$( this ).closest( 'td' ).find( 'select' ).trigger( 'change' );
|
|
|
|
return false;
|
|
|
|
});
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2018-04-24 18:25:45 +00:00
|
|
|
$( '.woocommerce' ).on( 'click', '.select_none', function() {
|
2021-02-04 17:13:46 +00:00
|
|
|
$( this ).closest( 'td' ).find( 'select option' ).prop( 'selected', false );
|
2018-04-24 18:25:45 +00:00
|
|
|
$( this ).closest( 'td' ).find( 'select' ).trigger( 'change' );
|
|
|
|
return false;
|
2013-07-26 14:36:28 +00:00
|
|
|
});
|
|
|
|
|
2018-04-24 18:25:45 +00:00
|
|
|
// Re-order buttons.
|
|
|
|
$( '.wc-item-reorder-nav').find( '.wc-move-up, .wc-move-down' ).on( 'click', function() {
|
|
|
|
var moveBtn = $( this ),
|
|
|
|
$row = moveBtn.closest( 'tr' );
|
|
|
|
|
2021-02-04 17:13:46 +00:00
|
|
|
moveBtn.trigger( 'focus' );
|
2018-04-24 18:25:45 +00:00
|
|
|
|
|
|
|
var isMoveUp = moveBtn.is( '.wc-move-up' ),
|
|
|
|
isMoveDown = moveBtn.is( '.wc-move-down' );
|
|
|
|
|
|
|
|
if ( isMoveUp ) {
|
|
|
|
var $previewRow = $row.prev( 'tr' );
|
|
|
|
|
|
|
|
if ( $previewRow && $previewRow.length ) {
|
|
|
|
$previewRow.before( $row );
|
|
|
|
wp.a11y.speak( params.i18n_moved_up );
|
|
|
|
}
|
|
|
|
} else if ( isMoveDown ) {
|
|
|
|
var $nextRow = $row.next( 'tr' );
|
|
|
|
|
|
|
|
if ( $nextRow && $nextRow.length ) {
|
|
|
|
$nextRow.after( $row );
|
|
|
|
wp.a11y.speak( params.i18n_moved_down );
|
|
|
|
}
|
2013-07-26 14:36:28 +00:00
|
|
|
}
|
|
|
|
|
2021-02-04 17:13:46 +00:00
|
|
|
moveBtn.trigger( 'focus' ); // Re-focus after the container was moved.
|
2018-04-24 18:25:45 +00:00
|
|
|
moveBtn.closest( 'table' ).trigger( 'updateMoveButtons' );
|
|
|
|
} );
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2018-04-24 18:25:45 +00:00
|
|
|
$( '.wc-item-reorder-nav').closest( 'table' ).on( 'updateMoveButtons', function() {
|
|
|
|
var table = $( this ),
|
|
|
|
lastRow = $( this ).find( 'tbody tr:last' ),
|
|
|
|
firstRow = $( this ).find( 'tbody tr:first' );
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2019-05-02 19:22:36 +00:00
|
|
|
table.find( '.wc-item-reorder-nav .wc-move-disabled' ).removeClass( 'wc-move-disabled' )
|
|
|
|
.attr( { 'tabindex': '0', 'aria-hidden': 'false' } );
|
|
|
|
firstRow.find( '.wc-item-reorder-nav .wc-move-up' ).addClass( 'wc-move-disabled' )
|
|
|
|
.attr( { 'tabindex': '-1', 'aria-hidden': 'true' } );
|
|
|
|
lastRow.find( '.wc-item-reorder-nav .wc-move-down' ).addClass( 'wc-move-disabled' )
|
|
|
|
.attr( { 'tabindex': '-1', 'aria-hidden': 'true' } );
|
2018-04-24 18:25:45 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
$( '.wc-item-reorder-nav').closest( 'table' ).trigger( 'updateMoveButtons' );
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2019-05-02 19:26:29 +00:00
|
|
|
|
|
|
|
$( '.submit button' ).on( 'click', function() {
|
2019-05-02 22:20:33 +00:00
|
|
|
if (
|
|
|
|
$( 'select#woocommerce_allowed_countries' ).val() === 'specific' &&
|
|
|
|
! $( '[name="woocommerce_specific_allowed_countries[]"]' ).val()
|
|
|
|
) {
|
2019-05-02 19:26:29 +00:00
|
|
|
if ( window.confirm( woocommerce_settings_params.i18n_no_specific_countries_selected ) ) {
|
|
|
|
return true;
|
2019-05-02 22:20:33 +00:00
|
|
|
}
|
2019-05-02 19:26:29 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2013-07-26 14:36:28 +00:00
|
|
|
});
|
2018-04-24 18:25:45 +00:00
|
|
|
})( jQuery, woocommerce_settings_params, wp );
|