static-quick-view.js
50 lines
| 1 | ( function ( $ ) { |
| 2 | 'use strict'; |
| 3 | $( document ).ready( function () { |
| 4 | $( document ).on( 'click', '.sp-quick-view', function () { |
| 5 | var $this = $( this ), |
| 6 | $wrap = $this.closest( '.sp-quick-view' ), |
| 7 | $id = $wrap.data( 'product_id' ); |
| 8 | |
| 9 | $this.addClass( 'loading' ); |
| 10 | $wrap.css( 'opacity', '0.5' ); |
| 11 | |
| 12 | $.ajax( { |
| 13 | type: 'POST', |
| 14 | url: shoppress_frontend.ajax.url, |
| 15 | data: { |
| 16 | action: 'quick_view_ajax', |
| 17 | nonce: shoppress_frontend.ajax.nonce, |
| 18 | product_id: $id, |
| 19 | }, |
| 20 | success: function ( data ) { |
| 21 | if ( data.content ) { |
| 22 | $( '#sp-quick-view-html' ).html( data.content ); |
| 23 | } else { |
| 24 | $( '#sp-quick-view-html' ).html( data ); |
| 25 | } |
| 26 | |
| 27 | $( '#sp-quick-view-overlay' ).fadeIn(); |
| 28 | |
| 29 | $this.removeClass( 'loading' ); |
| 30 | $wrap.css( 'opacity', '' ); |
| 31 | |
| 32 | $( document ).trigger( 'quick_view_loaded' ); |
| 33 | }, |
| 34 | error: function ( data ) { |
| 35 | console.log( data ); |
| 36 | $this.removeClass( 'loading' ); |
| 37 | }, |
| 38 | } ); |
| 39 | } ); |
| 40 | |
| 41 | $( document ).on( 'click', '#sp-close-quick-view', function () { |
| 42 | $( '#sp-quick-view-overlay' ).fadeOut(); |
| 43 | $( this ) |
| 44 | .closest( '#sp-quick-view-content' ) |
| 45 | .find( '#sp-quick-view-html' ) |
| 46 | .html( '' ); |
| 47 | } ); |
| 48 | } ); |
| 49 | } )( jQuery ); |
| 50 |