Nenhuma Descrição

woocommerce.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* global Cookies */
  2. jQuery( function( $ ) {
  3. // Orderby
  4. $( '.woocommerce-ordering' ).on( 'change', 'select.orderby', function() {
  5. $( this ).closest( 'form' ).trigger( 'submit' );
  6. });
  7. // Target quantity inputs on product pages
  8. $( 'input.qty:not(.product-quantity input.qty)' ).each( function() {
  9. var min = parseFloat( $( this ).attr( 'min' ) );
  10. if ( min >= 0 && parseFloat( $( this ).val() ) < min ) {
  11. $( this ).val( min );
  12. }
  13. });
  14. var noticeID = $( '.woocommerce-store-notice' ).data( 'noticeId' ) || '',
  15. cookieName = 'store_notice' + noticeID;
  16. // Check the value of that cookie and show/hide the notice accordingly
  17. if ( 'hidden' === Cookies.get( cookieName ) ) {
  18. $( '.woocommerce-store-notice' ).hide();
  19. } else {
  20. $( '.woocommerce-store-notice' ).show();
  21. }
  22. // Set a cookie and hide the store notice when the dismiss button is clicked
  23. $( '.woocommerce-store-notice__dismiss-link' ).on( 'click', function( event ) {
  24. Cookies.set( cookieName, 'hidden', { path: '/' } );
  25. $( '.woocommerce-store-notice' ).hide();
  26. event.preventDefault();
  27. });
  28. // Make form field descriptions toggle on focus.
  29. if ( $( '.woocommerce-input-wrapper span.description' ).length ) {
  30. $( document.body ).on( 'click', function() {
  31. $( '.woocommerce-input-wrapper span.description:visible' ).prop( 'aria-hidden', true ).slideUp( 250 );
  32. } );
  33. }
  34. $( '.woocommerce-input-wrapper' ).on( 'click', function( event ) {
  35. event.stopPropagation();
  36. } );
  37. $( '.woocommerce-input-wrapper :input' )
  38. .on( 'keydown', function( event ) {
  39. var input = $( this ),
  40. parent = input.parent(),
  41. description = parent.find( 'span.description' );
  42. if ( 27 === event.which && description.length && description.is( ':visible' ) ) {
  43. description.prop( 'aria-hidden', true ).slideUp( 250 );
  44. event.preventDefault();
  45. return false;
  46. }
  47. } )
  48. .on( 'click focus', function() {
  49. var input = $( this ),
  50. parent = input.parent(),
  51. description = parent.find( 'span.description' );
  52. parent.addClass( 'currentTarget' );
  53. $( '.woocommerce-input-wrapper:not(.currentTarget) span.description:visible' ).prop( 'aria-hidden', true ).slideUp( 250 );
  54. if ( description.length && description.is( ':hidden' ) ) {
  55. description.prop( 'aria-hidden', false ).slideDown( 250 );
  56. }
  57. parent.removeClass( 'currentTarget' );
  58. } );
  59. // Common scroll to element code.
  60. $.scroll_to_notices = function( scrollElement ) {
  61. if ( scrollElement.length ) {
  62. $( 'html, body' ).animate( {
  63. scrollTop: ( scrollElement.offset().top - 100 )
  64. }, 1000 );
  65. }
  66. };
  67. // Show password visiblity hover icon on woocommerce forms
  68. $( '.woocommerce form .woocommerce-Input[type="password"]' ).wrap( '<span class="password-input"></span>' );
  69. // Add 'password-input' class to the password wrapper in checkout page.
  70. $( '.woocommerce form input' ).filter(':password').parent('span').addClass('password-input');
  71. $( '.password-input' ).append( '<span class="show-password-input"></span>' );
  72. $( '.show-password-input' ).on( 'click',
  73. function() {
  74. if ( $( this ).hasClass( 'display-password' ) ) {
  75. $( this ).removeClass( 'display-password' );
  76. } else {
  77. $( this ).addClass( 'display-password' );
  78. }
  79. if ( $( this ).hasClass( 'display-password' ) ) {
  80. $( this ).siblings( ['input[type="password"]'] ).prop( 'type', 'text' );
  81. } else {
  82. $( this ).siblings( 'input[type="text"]' ).prop( 'type', 'password' );
  83. }
  84. }
  85. );
  86. });