2015-04-30 21:43:01 +00:00
|
|
|
/* global woocommerce_settings_params */
|
2016-04-20 15:38:58 +00:00
|
|
|
( function( $ ) {
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2016-04-28 16:37:30 +00:00
|
|
|
// Sell Countries
|
|
|
|
$( 'select#woocommerce_allowed_countries' ).change( function() {
|
|
|
|
if ( 'specific' === $( this ).val() ) {
|
2016-04-28 17:30:13 +00:00
|
|
|
$( this ).closest('tr').next( 'tr' ).hide();
|
|
|
|
$( this ).closest('tr').next().next( 'tr' ).show();
|
2016-04-28 16:37:30 +00:00
|
|
|
} else if ( 'all_except' === $( this ).val() ) {
|
2016-04-28 17:30:13 +00:00
|
|
|
$( this ).closest('tr').next( 'tr' ).show();
|
|
|
|
$( this ).closest('tr').next().next( 'tr' ).hide();
|
2016-04-28 16:37:30 +00:00
|
|
|
} else {
|
2016-04-28 17:30:13 +00:00
|
|
|
$( this ).closest('tr').next( 'tr' ).hide();
|
|
|
|
$( this ).closest('tr').next().next( 'tr' ).hide();
|
2016-04-28 16:37:30 +00:00
|
|
|
}
|
|
|
|
}).change();
|
|
|
|
|
|
|
|
// Ship Countries
|
|
|
|
$( 'select#woocommerce_ship_to_countries' ).change( function() {
|
|
|
|
if ( 'specific' === $( this ).val() ) {
|
2016-04-28 17:30:13 +00:00
|
|
|
$( this ).closest('tr').next( 'tr' ).show();
|
2016-04-28 16:37:30 +00:00
|
|
|
} else {
|
2016-04-28 17:30:13 +00:00
|
|
|
$( this ).closest('tr').next( 'tr' ).hide();
|
2013-07-26 14:36:28 +00:00
|
|
|
}
|
|
|
|
}).change();
|
|
|
|
|
2016-10-10 21:18:26 +00:00
|
|
|
// Stock management
|
|
|
|
$( 'input#woocommerce_manage_stock' ).change( function() {
|
|
|
|
if ( $( this ).is(':checked') ) {
|
2016-10-11 16:36:34 +00:00
|
|
|
$( this ).closest('tbody').find( '.manage_stock_field' ).closest( 'tr' ).show();
|
2016-10-10 21:18:26 +00:00
|
|
|
} else {
|
2016-10-11 16:36:34 +00:00
|
|
|
$( this ).closest('tbody').find( '.manage_stock_field' ).closest( 'tr' ).hide();
|
2016-10-10 21:18:26 +00:00
|
|
|
}
|
|
|
|
}).change();
|
|
|
|
|
2013-07-26 14:36:28 +00:00
|
|
|
// Color picker
|
2017-11-01 13:47:20 +00:00
|
|
|
$( '.colorpick' )
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2017-11-01 13:47:20 +00:00
|
|
|
.iris({
|
|
|
|
change: function( event, ui ) {
|
|
|
|
$( this ).parent().find( '.colorpickpreview' ).css({ backgroundColor: ui.color.toString() });
|
|
|
|
},
|
|
|
|
hide: true,
|
|
|
|
border: true
|
|
|
|
})
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2017-11-01 13:47:20 +00:00
|
|
|
.on( 'click focus', function( event ) {
|
|
|
|
event.stopPropagation();
|
|
|
|
$( '.iris-picker' ).hide();
|
|
|
|
$( this ).closest( 'td' ).find( '.iris-picker' ).show();
|
2017-11-01 13:52:08 +00:00
|
|
|
$( this ).data( 'original-value', $( this ).val() );
|
|
|
|
})
|
|
|
|
|
|
|
|
.on( 'change', function() {
|
|
|
|
if ( $( this ).is( '.iris-error' ) ) {
|
|
|
|
var original_value = $( this ).data( 'original-value' );
|
|
|
|
|
|
|
|
if ( original_value.match( /^\#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/ ) ) {
|
|
|
|
$( this ).val( $( this ).data( 'original-value' ) ).change();
|
|
|
|
} else {
|
|
|
|
$( this ).val( '' ).change();
|
|
|
|
}
|
|
|
|
}
|
2017-11-01 13:47:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$( 'body' ).on( 'click', function() {
|
|
|
|
$( '.iris-picker' ).hide();
|
2013-07-26 14:36:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Edit prompt
|
2016-04-20 15:38:58 +00:00
|
|
|
$( function() {
|
2013-07-26 14:36:28 +00:00
|
|
|
var changed = false;
|
|
|
|
|
2016-04-20 15:38:58 +00:00
|
|
|
$( 'input, textarea, select, checkbox' ).change( function() {
|
2013-07-26 14:36:28 +00:00
|
|
|
changed = true;
|
|
|
|
});
|
|
|
|
|
2016-04-20 15:38:58 +00:00
|
|
|
$( '.woo-nav-tab-wrapper a' ).click( function() {
|
2015-04-30 21:43:01 +00:00
|
|
|
if ( changed ) {
|
2013-07-26 14:36:28 +00:00
|
|
|
window.onbeforeunload = function() {
|
|
|
|
return woocommerce_settings_params.i18n_nav_warning;
|
2015-04-30 21:43:01 +00:00
|
|
|
};
|
2013-07-26 14:36:28 +00:00
|
|
|
} else {
|
|
|
|
window.onbeforeunload = '';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-04-20 15:38:58 +00:00
|
|
|
$( '.submit input' ).click( function() {
|
2013-07-26 14:36:28 +00:00
|
|
|
window.onbeforeunload = '';
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Sorting
|
2016-04-20 15:38:58 +00:00
|
|
|
$( 'table.wc_gateways tbody, table.wc_shipping tbody' ).sortable({
|
2015-04-30 21:43:01 +00:00
|
|
|
items: 'tr',
|
|
|
|
cursor: 'move',
|
|
|
|
axis: 'y',
|
2015-04-13 14:32:54 +00:00
|
|
|
handle: 'td.sort',
|
2015-04-30 21:43:01 +00:00
|
|
|
scrollSensitivity: 40,
|
|
|
|
helper: function( event, ui ) {
|
|
|
|
ui.children().each( function() {
|
2016-04-20 15:38:58 +00:00
|
|
|
$( this ).width( $( this ).width() );
|
2013-07-26 14:36:28 +00:00
|
|
|
});
|
2015-04-30 21:43:01 +00:00
|
|
|
ui.css( 'left', '0' );
|
2013-07-26 14:36:28 +00:00
|
|
|
return ui;
|
|
|
|
},
|
2015-04-30 21:43:01 +00:00
|
|
|
start: function( event, ui ) {
|
|
|
|
ui.item.css( 'background-color', '#f6f6f6' );
|
2013-07-26 14:36:28 +00:00
|
|
|
},
|
2015-04-30 21:43:01 +00:00
|
|
|
stop: function( event, ui ) {
|
|
|
|
ui.item.removeAttr( 'style' );
|
2013-07-26 14:36:28 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Select all/none
|
2016-04-20 15:38:58 +00:00
|
|
|
$( '.woocommerce' ).on( 'click', '.select_all', function() {
|
|
|
|
$( this ).closest( 'td' ).find( 'select option' ).attr( 'selected', 'selected' );
|
|
|
|
$( this ).closest( 'td' ).find( 'select' ).trigger( 'change' );
|
2013-07-26 14:36:28 +00:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2016-04-20 15:38:58 +00:00
|
|
|
$( '.woocommerce' ).on( 'click', '.select_none', function() {
|
|
|
|
$( this ).closest( 'td' ).find( 'select option' ).removeAttr( 'selected' );
|
|
|
|
$( this ).closest( 'td' ).find( 'select' ).trigger( 'change' );
|
2013-07-26 14:36:28 +00:00
|
|
|
return false;
|
|
|
|
});
|
2017-11-07 18:32:43 +00:00
|
|
|
|
|
|
|
// Thumbnail cropping option updates and preview.
|
|
|
|
$( '.woocommerce-thumbnail-cropping' )
|
2017-11-08 13:40:30 +00:00
|
|
|
.on( 'change input', 'input', function() {
|
2017-11-07 18:32:43 +00:00
|
|
|
var value = $( '.woocommerce-thumbnail-cropping input:checked' ).val(),
|
|
|
|
$preview_images = $( '.woocommerce-thumbnail-preview-block__image' );
|
|
|
|
|
|
|
|
if ( 'custom' === value ) {
|
|
|
|
|
|
|
|
var width_ratio = Math.max( parseInt( $( 'input[name="thumbnail_cropping_aspect_ratio_width"]' ).val(), 10 ), 1 ),
|
|
|
|
height_ratio = Math.max( parseInt( $( 'input[name="thumbnail_cropping_aspect_ratio_height"]' ).val(), 10 ), 1 ),
|
|
|
|
height = ( 90 / width_ratio ) * height_ratio;
|
|
|
|
|
|
|
|
$preview_images.animate( { height: height + 'px' }, 200 );
|
|
|
|
|
|
|
|
$( '.woocommerce-thumbnail-cropping-aspect-ratio' ).slideDown( 200 );
|
|
|
|
|
|
|
|
} else if ( 'uncropped' === value ) {
|
|
|
|
|
|
|
|
var heights = [ '120', '60', '80' ];
|
|
|
|
|
|
|
|
$preview_images.each( function( index, element ) {
|
|
|
|
var height = heights[ index ];
|
|
|
|
$( element ).animate( { height: height + 'px' }, 200 );
|
|
|
|
} );
|
|
|
|
|
|
|
|
$( '.woocommerce-thumbnail-cropping-aspect-ratio' ).hide();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$preview_images.animate( { height: '90px' }, 200 );
|
|
|
|
|
|
|
|
$( '.woocommerce-thumbnail-cropping-aspect-ratio' ).hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
$( '.woocommerce-thumbnail-cropping' ).find( 'input' ).change();
|
|
|
|
|
2016-04-20 15:38:58 +00:00
|
|
|
})( jQuery );
|