installed plugin Easy Digital Downloads
version 3.1.0.3
This commit is contained in:
@ -0,0 +1,13 @@
|
||||
jQuery( document ).ready( function ( $ ) {
|
||||
$( 'body' ).on( 'edd_cart_item_added edd_cart_item_removed', function ( e, response ) {
|
||||
if ( $( '.wp-block-edd-cart' ).length && response.block_cart.length ) {
|
||||
if ( $( '.edd-blocks__cart-mini' ).length ) {
|
||||
$( '.edd-blocks-cart__mini-quantity' ).empty().append( response.quantity_formatted );
|
||||
$( '.edd-blocks-cart__mini-total' ).empty().append( response.total );
|
||||
}
|
||||
if ( $( '.edd-blocks__cart-full' ).length ) {
|
||||
$( '.edd-blocks__cart-full .edd-blocks-form__cart' ).replaceWith( response.block_cart );
|
||||
}
|
||||
}
|
||||
} );
|
||||
} );
|
@ -0,0 +1,23 @@
|
||||
jQuery( document ).ready( function ( $ ) {
|
||||
$( '.edd-blocks__checkout-forms button' ).on( 'click', function ( e ) {
|
||||
e.preventDefault();
|
||||
var button = $( this ),
|
||||
form_id = $( this ).data( 'attr' ),
|
||||
current = $( '.edd-blocks__checkout-forms' ).find( 'button:disabled' );
|
||||
$( '.edd-checkout-block__personal-info' ).empty().append( '<span class=\"edd-loading-ajax edd-loading\"></span>' );
|
||||
$.ajax( {
|
||||
type: 'GET',
|
||||
data: {
|
||||
action: 'edd_blocks_swap_personal_info',
|
||||
form_id: form_id,
|
||||
},
|
||||
url: edd_global_vars.ajaxurl,
|
||||
success: function ( response ) {
|
||||
button.prop( 'disabled', true ).hide();
|
||||
current.prop( 'disabled', false ).show();
|
||||
$( '.edd-checkout-block__personal-info' ).empty();
|
||||
$( '.edd-checkout-block__personal-info' ).html( response.data );
|
||||
},
|
||||
} );
|
||||
} );
|
||||
} );
|
@ -0,0 +1,42 @@
|
||||
jQuery( document ).ready( function ( $ ) {
|
||||
if ( !EDDreCAPTCHA.sitekey ) {
|
||||
return;
|
||||
}
|
||||
var reCAPTCHAinput = document.querySelector( 'input#edd-blocks-recaptcha' );
|
||||
if ( !reCAPTCHAinput ) {
|
||||
return;
|
||||
}
|
||||
EDDreCAPTCHA.action = document.querySelector( 'input[name="edd_action"]' ).value;
|
||||
EDDreCAPTCHA.submit = document.querySelector( 'input[name="edd_submit"]' ).value;
|
||||
reCAPTCHAinput.addEventListener( 'invalid', function () {
|
||||
grecaptcha.execute( EDDreCAPTCHA.sitekey, { action: EDDreCAPTCHA.action } ).then( function ( token ) {
|
||||
$.ajax( {
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'edd_recaptcha_validate',
|
||||
token: token,
|
||||
ip: document.querySelector( '[name="edd_blocks_ip"]' ).value,
|
||||
},
|
||||
url: EDDreCAPTCHA.ajaxurl,
|
||||
success: function ( response ) {
|
||||
var submitButton = document.querySelector( '#' + EDDreCAPTCHA.submit );
|
||||
if ( response.success ) {
|
||||
reCAPTCHAinput.value = token;
|
||||
submitButton.click();
|
||||
} else {
|
||||
reCAPTCHAinput.value = '';
|
||||
var errorNode = document.createElement( 'div' );
|
||||
errorNode.classList.add( 'edd_errors', 'edd-alert', 'edd-alert-error', response.data.error );
|
||||
errorNode.innerHTML = '<p class="edd_error"><strong>' + EDDreCAPTCHA.error + '</strong>: ' + response.data.message + '</p>';
|
||||
submitButton.closest( 'form' ).before( errorNode );
|
||||
}
|
||||
},
|
||||
} ).fail( function ( response ) {
|
||||
reCAPTCHAinput.value = '';
|
||||
if ( window.console && window.console.log ) {
|
||||
console.log( response );
|
||||
}
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
} );
|
@ -0,0 +1,99 @@
|
||||
; ( function ( document, $, undefined ) {
|
||||
'use strict';
|
||||
|
||||
var custom_uploader,
|
||||
targetInputClass = '.upload-image-id',
|
||||
previewClass = 'upload-image-preview',
|
||||
target_input,
|
||||
TermImage = {};
|
||||
|
||||
TermImage.upload = function () {
|
||||
$( '.upload-image' ).on( 'click.upload', _uploadMedia );
|
||||
$( '.delete-image' ).on( 'click.delete', _deleteMedia );
|
||||
$( '#addtag #submit' ).on( 'click.term', _termImages );
|
||||
|
||||
function _uploadMedia ( e ) {
|
||||
e.preventDefault();
|
||||
target_input = $( this ).prev( targetInputClass );
|
||||
|
||||
//If the uploader object has already been created, reopen the dialog
|
||||
if ( custom_uploader ) {
|
||||
custom_uploader.reset();
|
||||
}
|
||||
|
||||
//Extend the wp.media object
|
||||
custom_uploader = wp.media.frames.file_frame = wp.media( {
|
||||
title: ( [ TermImage.params.text ] ),
|
||||
button: {
|
||||
text: ( [ TermImage.params.text ] )
|
||||
},
|
||||
multiple: false,
|
||||
library: { type: 'image' }
|
||||
} );
|
||||
|
||||
//When a file is selected, grab the URL and set it as the text field's value
|
||||
custom_uploader.on( 'select', function () {
|
||||
|
||||
var attachment = custom_uploader.state().get( 'selection' ).first().toJSON(),
|
||||
preview = $( target_input ).prevAll( '.' + previewClass ),
|
||||
deleteButton = $( target_input ).siblings( '.delete-image' ),
|
||||
previewImage = $( '<div />', {
|
||||
class: previewClass
|
||||
} ).append( $( '<img/>', {
|
||||
style: 'max-width:300px;',
|
||||
src: _getImageURL( attachment ),
|
||||
alt: ''
|
||||
} ) );
|
||||
$( target_input ).val( attachment.id );
|
||||
if ( preview.length ) {
|
||||
preview.remove();
|
||||
}
|
||||
$( target_input ).before( previewImage );
|
||||
$( deleteButton ).show();
|
||||
} );
|
||||
|
||||
//Open the uploader dialog
|
||||
custom_uploader.open();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the medium size image, if it exists.
|
||||
* @param image
|
||||
* @return {*}
|
||||
* @private
|
||||
*/
|
||||
function _getImageURL ( image ) {
|
||||
return image.sizes.medium ? image.sizes.medium.url : image.url;
|
||||
}
|
||||
|
||||
function _deleteMedia ( e ) {
|
||||
e.preventDefault();
|
||||
target_input = $( this ).prevAll( targetInputClass );
|
||||
var previewView = $( this ).prevAll( '.' + previewClass );
|
||||
|
||||
$( target_input ).val( '' );
|
||||
$( previewView ).remove();
|
||||
$( this ).hide();
|
||||
}
|
||||
|
||||
function _termImages ( e ) {
|
||||
e.preventDefault();
|
||||
var submitButton = $( this ).parentsUntil( '#addtag' ),
|
||||
previewView = submitButton.siblings( '.term-image-wrap' ).children( '.' + previewClass ),
|
||||
clearInput = submitButton.siblings( '.term-image-wrap' ).children( targetInputClass );
|
||||
|
||||
if ( $( previewView ).length && $( submitButton ).length ) {
|
||||
$( previewView ).delay( 1000 ).fadeOut( 200, function () {
|
||||
$( this ).remove();
|
||||
$( clearInput ).val( '' );
|
||||
} );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TermImage.params = typeof EDDTermImages === 'undefined' ? '' : EDDTermImages;
|
||||
if ( typeof TermImage.params !== 'undefined' ) {
|
||||
TermImage.upload();
|
||||
}
|
||||
|
||||
} )( document, jQuery );
|
Reference in New Issue
Block a user