2014-07-16 18:11:48 +00:00
|
|
|
/*global woocommerce_admin_meta_boxes */
|
|
|
|
jQuery( function ( $ ) {
|
|
|
|
|
2014-07-08 13:14:41 +00:00
|
|
|
// run tip tip
|
|
|
|
function runTipTip() {
|
|
|
|
// remove any lingering tooltips
|
|
|
|
$( '#tiptip_holder' ).removeAttr( 'style' );
|
|
|
|
$( '#tiptip_arrow' ).removeAttr( 'style' );
|
|
|
|
$( '.tips' ).tipTip({
|
|
|
|
'attribute': 'data-tip',
|
|
|
|
'fadeIn': 50,
|
|
|
|
'fadeOut': 50,
|
|
|
|
'delay': 200
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
runTipTip();
|
|
|
|
|
|
|
|
// Allow tabbing
|
|
|
|
$('#titlediv #title').keyup(function( event ) {
|
|
|
|
var code = event.keyCode || event.which;
|
|
|
|
|
2014-07-16 18:11:48 +00:00
|
|
|
if ( code == '9' && $('#woocommerce-coupon-description').size() > 0 ) {
|
|
|
|
event.stopPropagation();
|
|
|
|
$('#woocommerce-coupon-description').focus();
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-08 13:14:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$(function(){
|
|
|
|
jQuery('.wc-metabox > h3').click( function(event){
|
|
|
|
$( this ).parent( '.wc-metabox' ).toggleClass( 'closed' ).toggleClass( 'open' );
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// TABS
|
|
|
|
$('ul.wc-tabs').show();
|
|
|
|
$('div.panel-wrap').each(function(){
|
|
|
|
$(this).find('div.panel:not(:first)').hide();
|
|
|
|
});
|
|
|
|
$('ul.wc-tabs a').click(function(){
|
|
|
|
var panel_wrap = $(this).closest('div.panel-wrap');
|
|
|
|
$('ul.wc-tabs li', panel_wrap).removeClass('active');
|
|
|
|
$(this).parent().addClass('active');
|
|
|
|
$('div.panel', panel_wrap).hide();
|
|
|
|
$( $(this).attr('href') ).show();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
$('ul.wc-tabs li:visible').eq(0).find('a').click();
|
|
|
|
|
|
|
|
// Chosen selects
|
|
|
|
jQuery("select.chosen_select").chosen();
|
|
|
|
|
|
|
|
jQuery("select.chosen_select_nostd").chosen({
|
|
|
|
allow_single_deselect: 'true'
|
|
|
|
});
|
|
|
|
|
|
|
|
// Ajax Chosen Product Selectors
|
|
|
|
jQuery("select.ajax_chosen_select_products").ajaxChosen({
|
2014-07-16 18:11:48 +00:00
|
|
|
method: 'GET',
|
|
|
|
url: woocommerce_admin_meta_boxes.ajax_url,
|
|
|
|
dataType: 'json',
|
|
|
|
afterTypeDelay: 100,
|
|
|
|
data: {
|
|
|
|
action: 'woocommerce_json_search_products',
|
2014-07-08 13:14:41 +00:00
|
|
|
security: woocommerce_admin_meta_boxes.search_products_nonce
|
2014-07-16 18:11:48 +00:00
|
|
|
}
|
2014-07-08 13:14:41 +00:00
|
|
|
}, function (data) {
|
|
|
|
var terms = {};
|
|
|
|
|
2014-07-16 18:11:48 +00:00
|
|
|
$.each(data, function (i, val) {
|
|
|
|
terms[i] = val;
|
|
|
|
});
|
2014-07-08 13:14:41 +00:00
|
|
|
|
2014-07-16 18:11:48 +00:00
|
|
|
return terms;
|
2014-07-08 13:14:41 +00:00
|
|
|
});
|
|
|
|
|
2014-07-16 18:11:48 +00:00
|
|
|
/**
|
|
|
|
* Load Chosen for select products and variations
|
|
|
|
*
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
function loadSelectProductAndVariation() {
|
|
|
|
$( 'select.ajax_chosen_select_products_and_variations' ).ajaxChosen({
|
|
|
|
method: 'GET',
|
|
|
|
url: woocommerce_admin_meta_boxes.ajax_url,
|
|
|
|
dataType: 'json',
|
|
|
|
afterTypeDelay: 100,
|
|
|
|
data: {
|
|
|
|
action: 'woocommerce_json_search_products_and_variations',
|
|
|
|
security: woocommerce_admin_meta_boxes.search_products_nonce
|
|
|
|
}
|
|
|
|
},
|
|
|
|
function ( data ) {
|
|
|
|
var terms = {};
|
|
|
|
|
|
|
|
$.each(data, function ( i, val ) {
|
|
|
|
terms[i] = val;
|
|
|
|
});
|
|
|
|
|
|
|
|
return terms;
|
|
|
|
});
|
|
|
|
}
|
2014-07-08 13:14:41 +00:00
|
|
|
|
2014-07-16 18:11:48 +00:00
|
|
|
// Run on document load
|
|
|
|
loadSelectProductAndVariation();
|
2014-07-08 13:14:41 +00:00
|
|
|
|
2014-07-16 18:11:48 +00:00
|
|
|
// Load chosen inside WC Backbone Modal
|
|
|
|
$( 'body' ).on( 'wc_backbone_modal_loaded', function ( e, target ) {
|
|
|
|
if ( '#wc-modal-add-products' === target ) {
|
|
|
|
loadSelectProductAndVariation();
|
|
|
|
}
|
2014-07-08 13:14:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
jQuery("select.ajax_chosen_select_downloadable_products_and_variations").ajaxChosen({
|
2014-07-16 18:11:48 +00:00
|
|
|
method: 'GET',
|
|
|
|
url: woocommerce_admin_meta_boxes.ajax_url,
|
|
|
|
dataType: 'json',
|
|
|
|
afterTypeDelay: 100,
|
|
|
|
data: {
|
|
|
|
action: 'woocommerce_json_search_downloadable_products_and_variations',
|
2014-07-08 13:14:41 +00:00
|
|
|
security: woocommerce_admin_meta_boxes.search_products_nonce
|
2014-07-16 18:11:48 +00:00
|
|
|
}
|
2014-07-08 13:14:41 +00:00
|
|
|
}, function (data) {
|
|
|
|
|
|
|
|
var terms = {};
|
|
|
|
|
2014-07-16 18:11:48 +00:00
|
|
|
$.each(data, function (i, val) {
|
|
|
|
terms[i] = val;
|
|
|
|
});
|
2014-07-08 13:14:41 +00:00
|
|
|
|
2014-07-16 18:11:48 +00:00
|
|
|
return terms;
|
2014-07-08 13:14:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$( ".date-picker" ).datepicker({
|
|
|
|
dateFormat: "yy-mm-dd",
|
|
|
|
numberOfMonths: 1,
|
|
|
|
showButtonPanel: true,
|
|
|
|
showOn: "button",
|
|
|
|
buttonImage: woocommerce_admin_meta_boxes.calendar_image,
|
|
|
|
buttonImageOnly: true
|
|
|
|
});
|
|
|
|
|
|
|
|
$( ".date-picker-field" ).datepicker({
|
|
|
|
dateFormat: "yy-mm-dd",
|
|
|
|
numberOfMonths: 1,
|
|
|
|
showButtonPanel: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
// META BOXES - Open/close
|
|
|
|
jQuery('.wc-metaboxes-wrapper').on('click', '.wc-metabox h3', function(event){
|
|
|
|
// If the user clicks on some form input inside the h3, like a select list (for variations), the box should not be toggled
|
|
|
|
if ($(event.target).filter(':input, option').length) return;
|
|
|
|
|
2014-10-17 13:42:15 +00:00
|
|
|
jQuery(this).next('.wc-metabox-content').stop().slideToggle();
|
2014-07-08 13:14:41 +00:00
|
|
|
})
|
|
|
|
.on('click', '.expand_all', function(event){
|
2014-10-17 13:42:15 +00:00
|
|
|
jQuery(this).closest('.wc-metaboxes-wrapper').find('.wc-metabox > .wc-metabox-content').show();
|
2014-07-08 13:14:41 +00:00
|
|
|
return false;
|
|
|
|
})
|
|
|
|
.on('click', '.close_all', function(event){
|
2014-10-17 13:42:15 +00:00
|
|
|
jQuery(this).closest('.wc-metaboxes-wrapper').find('.wc-metabox > .wc-metabox-content').hide();
|
2014-07-08 13:14:41 +00:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
jQuery('.wc-metabox.closed').each(function(){
|
|
|
|
jQuery(this).find('.wc-metabox-content').hide();
|
|
|
|
});
|
|
|
|
|
2014-07-16 18:11:48 +00:00
|
|
|
});
|