var FusionPageBuilder = FusionPageBuilder || {}; ( function () { jQuery( document ).ready( function () { // Post Card Cart Component View. FusionPageBuilder.fusion_post_card_cart = FusionPageBuilder.ElementView.extend( { onInit: function() { var params = this.model.get( 'params' ); // Check for newer margin params. If unset but regular is, copy from there. if ( 'object' === typeof params ) { // Split border width into 4. if ( 'undefined' === typeof params.button_border_top && 'undefined' !== typeof params.button_border_width && '' !== params.button_border_width ) { params.button_border_top = parseInt( params.button_border_width ) + 'px'; params.button_border_right = params.button_border_top; params.button_border_bottom = params.button_border_top; params.button_border_left = params.button_border_top; delete params.button_border_width; } // Split border width into 4. if ( 'undefined' === typeof params.button_details_border_top && 'undefined' !== typeof params.button_details_border_width && '' !== params.button_details_border_width ) { params.button_details_border_top = parseInt( params.button_details_border_width ) + 'px'; params.button_details_border_right = params.button_details_border_top; params.button_details_border_bottom = params.button_details_border_top; params.button_details_border_left = params.button_details_border_top; delete params.button_details_border_width; } this.model.set( 'params', params ); } }, afterPatch: function () { var $quantityBoxes = this.$el.find( 'div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)' ).find( '.qty' ), $form = jQuery( '#fb-preview' )[ 0 ].contentWindow.jQuery( this.$el.find( '.variations_form' ) ); if ( $quantityBoxes.length && 'function' === typeof jQuery( '#fb-preview' )[ 0 ].contentWindow.avadaAddQuantityBoxes ) { jQuery( '#fb-preview' )[ 0 ].contentWindow.avadaAddQuantityBoxes( '.qty', $quantityBoxes ); } if ( $form.length && 'function' === typeof $form.wc_variation_form ) { $form.wc_variation_form(); $form.on( 'hide_variation', function( e ) { jQuery( '#fb-preview' )[ 0 ].contentWindow.jQuery( e.currentTarget ).find( '.avada-variation' ).closest( 'tr' ).addClass( 'awb-hide-element' ); } ).on( 'found_variation.wc-variation-form', function( e ) { if ( jQuery.trim( jQuery( '#fb-preview' )[ 0 ].contentWindow.jQuery( e.currentTarget ).find( '.avada-variation' ).text() ).length ) { jQuery( '#fb-preview' )[ 0 ].contentWindow.jQuery( e.currentTarget ).find( '.avada-variation' ).closest( 'tr' ).removeClass( 'awb-hide-element' ); } } ); this.$el.find( '.awb-post-card-cart-cart-wrapper' ).appendTo( $form ); } }, /** * Modify template attributes. * * @since 3.3 * @param {Object} atts - The attributes. * @return {Object} */ filterTemplateAtts: function ( atts ) { var attributes = {}; this.values = atts.values; this.extras = atts.extras; this.query_data = atts.query_data; this.setIconDefaults(); // Validate values. this.validateArgs(); // Any extras that need passed on. attributes.cid = this.model.get( 'cid' ); attributes.wrapperAttr = this.buildAttr( atts.values ); attributes.output = this.buildOutput( atts ); return attributes; }, /** * Modify template attributes. * * @since 3.5 * @return {void} */ validateArgs: function() { this.values.button_icon = this.values.button_icon.replace( 'fusion-prefix-', '' ); }, /** * Set default icons for text links * * @since 3.3 */ setIconDefaults: function() { if ( 'custom' !== this.values.button_style ) { this.values.icon_position = 'left'; this.values.button_icon = 'fa-shopping-cart fas'; } if ( 'custom' !== this.values.product_link_style ) { this.values.icon_details_position = 'left'; this.values.button_details_icon = 'fa-list-ul fas'; } }, /** * Builds attributes. * * @since 3.3 * @param {Object} values - The values object. * @return {Object} */ buildAttr: function ( values ) { var attr = _.fusionVisibilityAtts( values.hide_on_mobile, { class: 'fusion-woo-cart fusion-post-card-cart', style: this.getStyleVars() } ); if ( '' !== values[ 'class' ] ) { attr[ 'class' ] += ' ' + values[ 'class' ]; } attr[ 'class' ] += ' awb-variation-layout-' + this.values.variation_layout; attr[ 'class' ] += ' awb-variation-clear-' + this.values.variation_clear; attr[ 'class' ] += ' awb-label-' + this.values.show_label; if ( '' !== values.variation_text_align ) { attr[ 'class' ] += ' awb-variation-text-align-' + values.variation_text_align; } attr[ 'class' ] += ' awb-add-to-cart-style-' + ( '' === this.values.button_style ? 'link' : 'button' ); attr[ 'class' ] += ' awb-product-style-' + ( '' === this.values.product_link_style ? 'link' : 'button' ); if ( '' !== values.id ) { attr.id = values.id; } attr = _.fusionAnimations( values, attr ); return attr; }, /** * Builds output. * * @since 3.3 * @param {Object} values - The values object. * @return {String} */ buildOutput: function ( atts ) { var quantity = '', buttons = '', output = ''; if ( 'yes' === atts.values.show_variations && 'variable' === this.getProductType() && 'undefined' !== typeof atts.query_data && 'undefined' !== typeof atts.query_data.fusion_post_card_cart ) { output = atts.query_data.fusion_post_card_cart; } if ( 'yes' === atts.values.show_add_to_cart_button ) { buttons += this.buildAddToCart( ); } if ( 'yes' === atts.values.show_product_link_button ) { buttons += this.buildProductDetails( ); } if ( 'yes' === atts.values.show_quantity_input ) { quantity = this.buildQuantity( ); } // Add wrapper. if ( 'yes' === atts.values.show_variations && 'variable' === this.getProductType() ) { quantity = '