meta-boxes.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. jQuery( function ( $ ) {
  2. // Run tipTip
  3. function runTipTip() {
  4. // Remove any lingering tooltips
  5. $( '#tiptip_holder' ).removeAttr( 'style' );
  6. $( '#tiptip_arrow' ).removeAttr( 'style' );
  7. $( '.tips' ).tipTip({
  8. 'attribute': 'data-tip',
  9. 'fadeIn': 50,
  10. 'fadeOut': 50,
  11. 'delay': 200
  12. });
  13. }
  14. runTipTip();
  15. // Allow Tabbing
  16. $( '#titlediv' ).find( '#title' ).keyup( function( event ) {
  17. var code = event.keyCode || event.which;
  18. // Tab key
  19. if ( code === '9' && $( '#woocommerce-coupon-description' ).length > 0 ) {
  20. event.stopPropagation();
  21. $( '#woocommerce-coupon-description' ).focus();
  22. return false;
  23. }
  24. });
  25. $( '.wc-metaboxes-wrapper' ).on( 'click', '.wc-metabox > h3', function() {
  26. $( this ).parent( '.wc-metabox' ).toggleClass( 'closed' ).toggleClass( 'open' );
  27. });
  28. // Tabbed Panels
  29. $( document.body ).on( 'wc-init-tabbed-panels', function() {
  30. $( 'ul.wc-tabs' ).show();
  31. $( 'ul.wc-tabs a' ).click( function( e ) {
  32. e.preventDefault();
  33. var panel_wrap = $( this ).closest( 'div.panel-wrap' );
  34. $( 'ul.wc-tabs li', panel_wrap ).removeClass( 'active' );
  35. $( this ).parent().addClass( 'active' );
  36. $( 'div.panel', panel_wrap ).hide();
  37. $( $( this ).attr( 'href' ) ).show();
  38. });
  39. $( 'div.panel-wrap' ).each( function() {
  40. $( this ).find( 'ul.wc-tabs li' ).eq( 0 ).find( 'a' ).click();
  41. });
  42. }).trigger( 'wc-init-tabbed-panels' );
  43. // Date Picker
  44. $( document.body ).on( 'wc-init-datepickers', function() {
  45. $( '.date-picker-field, .date-picker' ).datepicker({
  46. dateFormat: 'yy-mm-dd',
  47. numberOfMonths: 1,
  48. showButtonPanel: true
  49. });
  50. }).trigger( 'wc-init-datepickers' );
  51. // Meta-Boxes - Open/close
  52. $( '.wc-metaboxes-wrapper' ).on( 'click', '.wc-metabox h3', function( event ) {
  53. // If the user clicks on some form input inside the h3, like a select list (for variations), the box should not be toggled
  54. if ( $( event.target ).filter( ':input, option, .sort' ).length ) {
  55. return;
  56. }
  57. $( this ).next( '.wc-metabox-content' ).stop().slideToggle();
  58. })
  59. .on( 'click', '.expand_all', function() {
  60. $( this ).closest( '.wc-metaboxes-wrapper' ).find( '.wc-metabox > .wc-metabox-content' ).show();
  61. return false;
  62. })
  63. .on( 'click', '.close_all', function() {
  64. $( this ).closest( '.wc-metaboxes-wrapper' ).find( '.wc-metabox > .wc-metabox-content' ).hide();
  65. return false;
  66. });
  67. $( '.wc-metabox.closed' ).each( function() {
  68. $( this ).find( '.wc-metabox-content' ).hide();
  69. });
  70. });