woocommerce/assets/js/admin/settings.js

93 lines
2.4 KiB
JavaScript
Raw Normal View History

2015-04-30 21:43:01 +00:00
/* global woocommerce_settings_params */
jQuery( window ).load( function() {
2013-07-26 14:36:28 +00:00
// Countries
2015-04-30 21:43:01 +00:00
jQuery( 'select#woocommerce_allowed_countries, select#woocommerce_ship_to_countries' ).change( function() {
if ( jQuery( this ).val() === 'specific' ) {
jQuery( this ).parent().parent().next( 'tr' ).show();
2013-07-26 14:36:28 +00:00
} else {
2015-04-30 21:43:01 +00:00
jQuery( this ).parent().parent().next( 'tr' ).hide();
2013-07-26 14:36:28 +00:00
}
}).change();
// Color picker
2015-04-30 21:43:01 +00:00
jQuery( '.colorpick' ).iris({
change: function( event, ui ) {
jQuery( this ).css({ backgroundColor: ui.color.toString() });
2013-07-26 14:36:28 +00:00
},
hide: true,
border: true
2015-04-30 21:43:01 +00:00
}).each( function() {
jQuery( this ).css({ backgroundColor: jQuery( this ).val() });
}).click( function() {
jQuery( '.iris-picker' ).hide();
jQuery( this ).closest( '.color_box, td' ).find( '.iris-picker' ).show();
2013-07-26 14:36:28 +00:00
});
2015-04-30 21:43:01 +00:00
jQuery( 'body' ).click( function() {
jQuery( '.iris-picker' ).hide();
2013-07-26 14:36:28 +00:00
});
2015-04-30 21:43:01 +00:00
jQuery( '.color_box, .colorpick' ).click( function( event ) {
event.stopPropagation();
2013-07-26 14:36:28 +00:00
});
// Edit prompt
2015-04-30 21:43:01 +00:00
jQuery( function() {
2013-07-26 14:36:28 +00:00
var changed = false;
2015-04-30 21:43:01 +00:00
jQuery( 'input, textarea, select, checkbox' ).change( function() {
2013-07-26 14:36:28 +00:00
changed = true;
});
2015-04-30 21:43:01 +00:00
jQuery( '.woo-nav-tab-wrapper a' ).click( function() {
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 = '';
}
});
2015-04-30 21:43:01 +00:00
jQuery( '.submit input' ).click( function() {
2013-07-26 14:36:28 +00:00
window.onbeforeunload = '';
});
});
// Sorting
2015-04-30 21:43:01 +00:00
jQuery( 'table.wc_gateways tbody, table.wc_shipping tbody' ).sortable({
items: 'tr',
cursor: 'move',
axis: 'y',
handle: 'td.sort',
2015-04-30 21:43:01 +00:00
scrollSensitivity: 40,
helper: function( event, ui ) {
ui.children().each( function() {
jQuery( this ).width( jQuery( 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
jQuery( '.woocommerce' ).on( 'click', '.select_all', function() {
2015-04-30 21:43:01 +00:00
jQuery( this ).closest( 'td' ).find( 'select option' ).attr( 'selected', 'selected' );
jQuery( this ).closest( 'td' ).find( 'select' ).trigger( 'change' );
2013-07-26 14:36:28 +00:00
return false;
});
jQuery( '.woocommerce' ).on( 'click', '.select_none', function() {
2015-04-30 21:43:01 +00:00
jQuery( this ).closest( 'td' ).find( 'select option' ).removeAttr( 'selected' );
jQuery( this ).closest( 'td' ).find( 'select' ).trigger( 'change' );
2013-07-26 14:36:28 +00:00
return false;
});
2015-04-30 21:43:01 +00:00
});