installed plugin Easy Digital Downloads
version 3.1.0.3
This commit is contained in:
@ -0,0 +1,9 @@
|
||||
/* global jQuery */
|
||||
|
||||
jQuery( document ).ready( function( $ ) {
|
||||
$( '.edd-advanced-filters-button' ).on( 'click', function( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
$( this ).closest( '#edd-advanced-filters' ).toggleClass( 'open' );
|
||||
} );
|
||||
} );
|
@ -0,0 +1,147 @@
|
||||
/* global _ */
|
||||
|
||||
/**
|
||||
* Internal dependencies.
|
||||
*/
|
||||
import { getChosenVars } from 'utils/chosen.js';
|
||||
|
||||
jQuery( document ).ready( function( $ ) {
|
||||
|
||||
// Globally apply to elements on the page.
|
||||
$( '.edd-select-chosen' ).each( function() {
|
||||
const el = $( this );
|
||||
el.chosen( getChosenVars( el ) );
|
||||
} );
|
||||
|
||||
$( '.edd-select-chosen .chosen-search input' ).each( function() {
|
||||
// Bail if placeholder already set
|
||||
if ( $( this ).attr( 'placeholder' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
const selectElem = $( this ).parent().parent().parent().prev( 'select.edd-select-chosen' ),
|
||||
placeholder = selectElem.data( 'search-placeholder' );
|
||||
|
||||
if ( placeholder ) {
|
||||
$( this ).attr( 'placeholder', placeholder );
|
||||
}
|
||||
} );
|
||||
|
||||
// Add placeholders for Chosen input fields
|
||||
$( '.chosen-choices' ).on( 'click', function() {
|
||||
let placeholder = $( this ).parent().prev().data( 'search-placeholder' );
|
||||
if ( typeof placeholder === 'undefined' ) {
|
||||
placeholder = edd_vars.type_to_search;
|
||||
}
|
||||
$( this ).children( 'li' ).children( 'input' ).attr( 'placeholder', placeholder );
|
||||
} );
|
||||
|
||||
// This fixes the Chosen box being 0px wide when the thickbox is opened
|
||||
$( '#post' ).on( 'click', '.edd-thickbox', function() {
|
||||
$( '.edd-select-chosen', '#choose-download' ).css( 'width', '100%' );
|
||||
} );
|
||||
|
||||
// Variables for setting up the typing timer
|
||||
// Time in ms, Slow - 521ms, Moderate - 342ms, Fast - 300ms
|
||||
let userInteractionInterval = 342,
|
||||
typingTimerElements = '.edd-select-chosen .chosen-search input, .edd-select-chosen .search-field input',
|
||||
typingTimer;
|
||||
|
||||
// Replace options with search results
|
||||
$( document.body ).on( 'keyup', typingTimerElements, _.debounce( function( e ) {
|
||||
let element = $( this ),
|
||||
val = element.val(),
|
||||
container = element.closest( '.edd-select-chosen' ),
|
||||
|
||||
select = container.prev(),
|
||||
select_type = select.data( 'search-type' ),
|
||||
no_bundles = container.hasClass( 'no-bundles' ),
|
||||
variations = container.hasClass( 'variations' ),
|
||||
variations_only = container.hasClass( 'variations-only' ),
|
||||
|
||||
lastKey = e.which,
|
||||
search_type = 'edd_download_search';
|
||||
|
||||
// String replace the chosen container IDs
|
||||
container.attr( 'id' ).replace( '_chosen', '' );
|
||||
|
||||
// Detect if we have a defined search type, otherwise default to downloads
|
||||
if ( typeof select_type !== 'undefined' ) {
|
||||
// Don't trigger AJAX if this select has all options loaded
|
||||
if ( 'no_ajax' === select_type ) {
|
||||
return;
|
||||
}
|
||||
|
||||
search_type = 'edd_' + select_type + '_search';
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't fire if short or is a modifier key (shift, ctrl, apple command key, or arrow keys)
|
||||
if (
|
||||
( val.length <= 3 && 'edd_download_search' === search_type ) ||
|
||||
(
|
||||
lastKey === 16 ||
|
||||
lastKey === 13 ||
|
||||
lastKey === 91 ||
|
||||
lastKey === 17 ||
|
||||
lastKey === 37 ||
|
||||
lastKey === 38 ||
|
||||
lastKey === 39 ||
|
||||
lastKey === 40
|
||||
)
|
||||
) {
|
||||
container.children( '.spinner' ).remove();
|
||||
return;
|
||||
}
|
||||
|
||||
// Maybe append a spinner
|
||||
if ( ! container.children( '.spinner' ).length ) {
|
||||
container.append( '<span class="spinner is-active"></span>' );
|
||||
}
|
||||
|
||||
$.ajax( {
|
||||
type: 'GET',
|
||||
dataType: 'json',
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
s: val,
|
||||
action: search_type,
|
||||
no_bundles: no_bundles,
|
||||
variations: variations,
|
||||
variations_only: variations_only,
|
||||
},
|
||||
|
||||
beforeSend: function() {
|
||||
select.closest( 'ul.chosen-results' ).empty();
|
||||
},
|
||||
|
||||
success: function( data ) {
|
||||
// Remove all options but those that are selected
|
||||
$( 'option:not(:selected)', select ).remove();
|
||||
|
||||
// Add any option that doesn't already exist
|
||||
$.each( data, function( key, item ) {
|
||||
if ( ! $( 'option[value="' + item.id + '"]', select ).length ) {
|
||||
select.prepend( '<option value="' + item.id + '">' + item.name + '</option>' );
|
||||
}
|
||||
} );
|
||||
|
||||
// Get the text immediately before triggering an update.
|
||||
// Any sooner will cause the text to jump around.
|
||||
const val = element.val();
|
||||
|
||||
// Update the options
|
||||
select.trigger( 'chosen:updated' );
|
||||
|
||||
element.val( val );
|
||||
},
|
||||
} ).fail( function( response ) {
|
||||
if ( window.console && window.console.log ) {
|
||||
console.log( response );
|
||||
}
|
||||
} ).done( function( response ) {
|
||||
container.children( '.spinner' ).remove();
|
||||
} );
|
||||
}, userInteractionInterval ) );
|
||||
} );
|
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Date picker
|
||||
*
|
||||
* This juggles a few CSS classes to avoid styling collisions with other
|
||||
* third-party plugins.
|
||||
*/
|
||||
jQuery( document ).ready( function( $ ) {
|
||||
const edd_datepicker = $( 'input.edd_datepicker' );
|
||||
|
||||
if ( edd_datepicker.length > 0 ) {
|
||||
edd_datepicker
|
||||
|
||||
// Disable autocomplete to avoid it covering the calendar
|
||||
.attr( 'autocomplete', 'off' )
|
||||
|
||||
// Invoke the datepickers
|
||||
.datepicker( {
|
||||
dateFormat: edd_vars.date_picker_format,
|
||||
beforeShow: function() {
|
||||
$( '#ui-datepicker-div' )
|
||||
.removeClass( 'ui-datepicker' )
|
||||
.addClass( 'edd-datepicker' );
|
||||
},
|
||||
} );
|
||||
}
|
||||
} );
|
@ -0,0 +1,23 @@
|
||||
jQuery( document ).ready( function ( $ ) {
|
||||
$( '.edd_countries_filter' ).on( 'change', function () {
|
||||
const select = $( this ),
|
||||
data = {
|
||||
action: 'edd_get_shop_states',
|
||||
country: select.val(),
|
||||
nonce: select.data( 'nonce' ),
|
||||
field_name: 'edd_regions_filter',
|
||||
};
|
||||
|
||||
$.post( ajaxurl, data, function ( response ) {
|
||||
$( 'select.edd_regions_filter' ).find( 'option:gt(0)' ).remove();
|
||||
|
||||
if ( 'nostates' !== response ) {
|
||||
$( response ).find( 'option:gt(0)' ).appendTo( 'select.edd_regions_filter' );
|
||||
}
|
||||
|
||||
$( 'select.edd_regions_filter' ).trigger( 'chosen:updated' );
|
||||
} );
|
||||
|
||||
return false;
|
||||
} );
|
||||
} );
|
@ -0,0 +1,125 @@
|
||||
/* global edd_vars */
|
||||
|
||||
document.addEventListener( 'alpine:init', () => {
|
||||
Alpine.store( 'eddNotifications', {
|
||||
isPanelOpen: false,
|
||||
notificationsLoaded: false,
|
||||
numberActiveNotifications: 0,
|
||||
activeNotifications: [],
|
||||
inactiveNotifications: [],
|
||||
|
||||
init: function() {
|
||||
const eddNotifications = this;
|
||||
|
||||
/*
|
||||
* The bubble starts out hidden until AlpineJS is initialized. Once it is, we remove
|
||||
* the hidden class. This prevents a flash of the bubble's visibility in the event that there
|
||||
* are no notifications.
|
||||
*/
|
||||
const notificationCountBubble = document.querySelector( '#edd-notification-button .edd-number' );
|
||||
if ( notificationCountBubble ) {
|
||||
notificationCountBubble.classList.remove( 'edd-hidden' );
|
||||
}
|
||||
|
||||
document.addEventListener( 'keydown', function( e ) {
|
||||
if ( e.key === 'Escape' ) {
|
||||
eddNotifications.closePanel();
|
||||
}
|
||||
} );
|
||||
|
||||
const params = new URLSearchParams( window.location.search );
|
||||
|
||||
const triggerNotifications = params.has( 'notifications' );
|
||||
if ( triggerNotifications && 'true' === params.get( 'notifications' ) ) {
|
||||
eddNotifications.openPanel();
|
||||
}
|
||||
},
|
||||
|
||||
openPanel: function() {
|
||||
const panelHeader = document.getElementById( 'edd-notifications-header' );
|
||||
|
||||
if ( this.notificationsLoaded ) {
|
||||
this.isPanelOpen = true;
|
||||
if ( panelHeader ) {
|
||||
setTimeout( function() {
|
||||
panelHeader.focus();
|
||||
} );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.isPanelOpen = true;
|
||||
|
||||
this.apiRequest( '/notifications', 'GET' )
|
||||
.then( data => {
|
||||
this.activeNotifications = data.active;
|
||||
this.inactiveNotifications = data.dismissed;
|
||||
this.notificationsLoaded = true;
|
||||
|
||||
if ( panelHeader ) {
|
||||
panelHeader.focus();
|
||||
}
|
||||
} )
|
||||
.catch( error => {
|
||||
console.log( 'Notification error', error );
|
||||
} );
|
||||
},
|
||||
|
||||
closePanel: function() {
|
||||
if ( ! this.isPanelOpen ) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.isPanelOpen = false;
|
||||
|
||||
const notificationButton = document.getElementById( 'edd-notification-button' );
|
||||
if ( notificationButton ) {
|
||||
notificationButton.focus();
|
||||
}
|
||||
},
|
||||
|
||||
apiRequest: function( endpoint, method ) {
|
||||
return fetch( edd_vars.restBase + endpoint, {
|
||||
method: method,
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-WP-Nonce': edd_vars.restNonce
|
||||
}
|
||||
} ).then( response => {
|
||||
if ( ! response.ok ) {
|
||||
return Promise.reject( response );
|
||||
}
|
||||
|
||||
/*
|
||||
* Returning response.text() instead of response.json() because dismissing
|
||||
* a notification doesn't return a JSON response, so response.json() will break.
|
||||
*/
|
||||
return response.text();
|
||||
//return response.json();
|
||||
} ).then( data => {
|
||||
return data ? JSON.parse( data ) : null;
|
||||
} );
|
||||
} ,
|
||||
|
||||
dismiss: function( event, index ) {
|
||||
if ( 'undefined' === typeof this.activeNotifications[ index ] ) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.target.disabled = true;
|
||||
|
||||
const notification = this.activeNotifications[ index ];
|
||||
|
||||
this.apiRequest( '/notifications/' + notification.id, 'DELETE' )
|
||||
.then( response => {
|
||||
this.activeNotifications.splice( index, 1 );
|
||||
this.numberActiveNotifications = this.activeNotifications.length;
|
||||
} )
|
||||
.catch( error => {
|
||||
console.log( 'Dismiss error', error );
|
||||
} );
|
||||
}
|
||||
} );
|
||||
} );
|
@ -0,0 +1,42 @@
|
||||
/* global ajaxurl */
|
||||
|
||||
jQuery( document ).ready( function( $ ) {
|
||||
/**
|
||||
* Display notices
|
||||
*/
|
||||
const topOfPageNotice = $( '.edd-admin-notice-top-of-page' );
|
||||
if ( topOfPageNotice ) {
|
||||
const topOfPageNoticeEl = topOfPageNotice.detach();
|
||||
|
||||
$( '#wpbody-content' ).prepend( topOfPageNoticeEl );
|
||||
topOfPageNotice.delay( 1000 ).slideDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Dismiss notices
|
||||
*/
|
||||
$( '.edd-promo-notice' ).each( function() {
|
||||
const notice = $( this );
|
||||
|
||||
notice.on( 'click', '.edd-promo-notice-dismiss', function( e ) {
|
||||
// Only prevent default behavior for buttons, not links.
|
||||
if ( ! $( this ).attr( 'href' ) ) {
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
$.ajax( {
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'edd_dismiss_promo_notice',
|
||||
notice_id: notice.data( 'id' ),
|
||||
nonce: notice.data( 'nonce' ),
|
||||
lifespan: notice.data( 'lifespan' )
|
||||
},
|
||||
url: ajaxurl,
|
||||
success: function( response ) {
|
||||
notice.slideUp();
|
||||
}
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
} );
|
@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Sortables
|
||||
*
|
||||
* This makes certain settings sortable, and attempts to stash the results
|
||||
* in the nearest .edd-order input value.
|
||||
*/
|
||||
jQuery( document ).ready( function( $ ) {
|
||||
const edd_sortables = $( 'ul.edd-sortable-list' );
|
||||
|
||||
if ( edd_sortables.length > 0 ) {
|
||||
edd_sortables.sortable( {
|
||||
axis: 'y',
|
||||
items: 'li',
|
||||
cursor: 'move',
|
||||
tolerance: 'pointer',
|
||||
containment: 'parent',
|
||||
distance: 2,
|
||||
opacity: 0.7,
|
||||
scroll: true,
|
||||
|
||||
/**
|
||||
* When sorting stops, assign the value to the previous input.
|
||||
* This input should be a hidden text field
|
||||
*/
|
||||
stop: function() {
|
||||
const keys = $.map( $( this ).children( 'li' ), function( el ) {
|
||||
return $( el ).data( 'key' );
|
||||
} );
|
||||
|
||||
$( this ).prev( 'input.edd-order' ).val( keys );
|
||||
},
|
||||
} );
|
||||
}
|
||||
} );
|
@ -0,0 +1,7 @@
|
||||
/* global jQuery */
|
||||
|
||||
jQuery( document ).ready( function ( $ ) {
|
||||
if ( $( 'body' ).hasClass( 'taxonomy-download_category' ) || $( 'body' ).hasClass( 'taxonomy-download_tag' ) ) {
|
||||
$( '.nav-tab-wrapper, .nav-tab-wrapper + br' ).detach().insertAfter( '.wp-header-end' );
|
||||
}
|
||||
} );
|
@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Attach tooltips
|
||||
*
|
||||
* @param {string} selector
|
||||
*/
|
||||
export const edd_attach_tooltips = function( selector ) {
|
||||
selector.tooltip( {
|
||||
content: function() {
|
||||
return $( this ).prop( 'title' );
|
||||
},
|
||||
tooltipClass: 'edd-ui-tooltip',
|
||||
position: {
|
||||
my: 'center top',
|
||||
at: 'center bottom+10',
|
||||
collision: 'flipfit',
|
||||
},
|
||||
hide: {
|
||||
duration: 200,
|
||||
},
|
||||
show: {
|
||||
duration: 200,
|
||||
},
|
||||
} );
|
||||
};
|
||||
|
||||
jQuery( document ).ready( function( $ ) {
|
||||
edd_attach_tooltips( $( '.edd-help-tip' ) );
|
||||
} );
|
@ -0,0 +1,74 @@
|
||||
jQuery( document ).ready( function( $ ) {
|
||||
// AJAX user search
|
||||
$( '.edd-ajax-user-search' )
|
||||
|
||||
// Search
|
||||
.keyup( function() {
|
||||
let user_search = $( this ).val(),
|
||||
exclude = '';
|
||||
|
||||
if ( $( this ).data( 'exclude' ) ) {
|
||||
exclude = $( this ).data( 'exclude' );
|
||||
}
|
||||
|
||||
$( '.edd_user_search_wrap' ).addClass( 'loading' );
|
||||
|
||||
const data = {
|
||||
action: 'edd_search_users',
|
||||
user_name: user_search,
|
||||
exclude: exclude,
|
||||
};
|
||||
|
||||
$.ajax( {
|
||||
type: 'POST',
|
||||
data: data,
|
||||
dataType: 'json',
|
||||
url: ajaxurl,
|
||||
|
||||
success: function( search_response ) {
|
||||
$( '.edd_user_search_wrap' ).removeClass( 'loading' );
|
||||
$( '.edd_user_search_results' ).removeClass( 'hidden' );
|
||||
$( '.edd_user_search_results span' ).html( '' );
|
||||
if ( search_response.results ) {
|
||||
$( search_response.results ).appendTo( '.edd_user_search_results span' );
|
||||
}
|
||||
},
|
||||
} );
|
||||
} )
|
||||
|
||||
// Hide
|
||||
.blur( function() {
|
||||
if ( edd_user_search_mouse_down ) {
|
||||
edd_user_search_mouse_down = false;
|
||||
} else {
|
||||
$( this ).removeClass( 'loading' );
|
||||
$( '.edd_user_search_results' ).addClass( 'hidden' );
|
||||
}
|
||||
} )
|
||||
|
||||
// Show
|
||||
.focus( function() {
|
||||
$( this ).keyup();
|
||||
} );
|
||||
|
||||
$( document.body ).on( 'click.eddSelectUser', '.edd_user_search_results span a', function( e ) {
|
||||
e.preventDefault();
|
||||
const login = $( this ).data( 'login' );
|
||||
$( '.edd-ajax-user-search' ).val( login );
|
||||
$( '.edd_user_search_results' ).addClass( 'hidden' );
|
||||
$( '.edd_user_search_results span' ).html( '' );
|
||||
} );
|
||||
|
||||
$( document.body ).on( 'click.eddCancelUserSearch', '.edd_user_search_results a.edd-ajax-user-cancel', function( e ) {
|
||||
e.preventDefault();
|
||||
$( '.edd-ajax-user-search' ).val( '' );
|
||||
$( '.edd_user_search_results' ).addClass( 'hidden' );
|
||||
$( '.edd_user_search_results span' ).html( '' );
|
||||
} );
|
||||
|
||||
// Cancel user-search.blur when picking a user
|
||||
var edd_user_search_mouse_down = false;
|
||||
$( '.edd_user_search_results' ).mousedown( function() {
|
||||
edd_user_search_mouse_down = true;
|
||||
} );
|
||||
} );
|
@ -0,0 +1,61 @@
|
||||
jQuery( document ).ready( function( $ ) {
|
||||
|
||||
const sectionSelector = '.edd-vertical-sections.use-js';
|
||||
// If the current screen doesn't have JS sections, return.
|
||||
if ( 0 === $( sectionSelector ).length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Hides the section content.
|
||||
$( `${ sectionSelector } .section-content` ).hide();
|
||||
|
||||
const hash = window.location.hash;
|
||||
if ( hash && hash.includes( 'edd_' ) ) {
|
||||
// Show the section content related to the URL.
|
||||
$( sectionSelector ).find( hash ).show();
|
||||
|
||||
// Set the aria-selected for section titles to be false
|
||||
$( `${ sectionSelector } .section-title` ).attr( 'aria-selected', 'false' ).removeClass( 'section-title--is-active' );
|
||||
|
||||
// Set aria-selected true on the related link.
|
||||
$( sectionSelector ).find( '.section-title a[href="' + hash + '"]' ).parents( '.section-title' ).attr( 'aria-selected', 'true' ).addClass( 'section-title--is-active' );
|
||||
|
||||
} else {
|
||||
// Shows the first section's content.
|
||||
$( `${ sectionSelector } .section-content:first-child` ).show();
|
||||
|
||||
// Makes the 'aria-selected' attribute true for the first section nav item.
|
||||
$( `${ sectionSelector } .section-nav li:first-child` ).attr( 'aria-selected', 'true' ).addClass( 'section-title--is-active' );
|
||||
}
|
||||
|
||||
// When a section nav item is clicked.
|
||||
$( `${ sectionSelector } .section-nav li a` ).on( 'click',
|
||||
function( j ) {
|
||||
// Prevent the default browser action when a link is clicked.
|
||||
j.preventDefault();
|
||||
|
||||
// Get the `href` attribute of the item.
|
||||
const them = $( this ),
|
||||
href = them.attr( 'href' ),
|
||||
rents = them.parents( '.edd-vertical-sections' );
|
||||
|
||||
// Hide all section content.
|
||||
rents.find( '.section-content' ).hide();
|
||||
|
||||
// Find the section content that matches the section nav item and show it.
|
||||
rents.find( href ).show();
|
||||
|
||||
// Set the `aria-selected` attribute to false for all section nav items.
|
||||
rents.find( '.section-title' ).attr( 'aria-selected', 'false' ).removeClass( 'section-title--is-active' );
|
||||
|
||||
// Set the `aria-selected` attribute to true for this section nav item.
|
||||
them.parent().attr( 'aria-selected', 'true' ).addClass( 'section-title--is-active' );
|
||||
|
||||
// Maybe re-Chosen
|
||||
rents.find( 'div.chosen-container' ).css( 'width', '100%' );
|
||||
|
||||
// Add the current "link" to the page URL
|
||||
window.history.pushState( 'object or string', '', href );
|
||||
}
|
||||
); // click()
|
||||
} );
|
Reference in New Issue
Block a user