document all js methods

This commit is contained in:
haszari 2019-02-21 15:51:41 +13:00
parent 950b873583
commit b4a36dc620
1 changed files with 18 additions and 1 deletions

View File

@ -17,6 +17,7 @@
// All are prefixed by {WC_Tracks::PREFIX}. // All are prefixed by {WC_Tracks::PREFIX}.
// All have one property for `suggestionSlug`, to identify the specific suggestion message. // All have one property for `suggestionSlug`, to identify the specific suggestion message.
// Dismiss the specified suggestion from the UI, and save the dismissal in settings.
function dismissSuggestion( suggestionSlug ) { function dismissSuggestion( suggestionSlug ) {
// hide the suggestion in the UI // hide the suggestion in the UI
var selector = '[data-suggestion-slug=' + suggestionSlug + ']'; var selector = '[data-suggestion-slug=' + suggestionSlug + ']';
@ -39,6 +40,7 @@
} ); } );
} }
// Render DOM element for suggestion dismiss button.
function renderDismissButton( suggestionSlug ) { function renderDismissButton( suggestionSlug ) {
var dismissButton = document.createElement( 'a' ); var dismissButton = document.createElement( 'a' );
@ -52,6 +54,7 @@
return dismissButton; return dismissButton;
} }
// Render DOM element for suggestion linkout, optionally with button style.
function renderLinkout( slug, url, text, isButton ) { function renderLinkout( slug, url, text, isButton ) {
var linkoutButton = document.createElement( 'a' ); var linkoutButton = document.createElement( 'a' );
@ -78,6 +81,7 @@
return linkoutButton; return linkoutButton;
} }
// Render DOM element for suggestion icon image.
function renderSuggestionIcon( slug, iconUrl ) { function renderSuggestionIcon( slug, iconUrl ) {
if ( !iconUrl ) { if ( !iconUrl ) {
return null; return null;
@ -90,6 +94,7 @@
return image; return image;
} }
// Render DOM elements for suggestion content.
function renderSuggestionContent( slug, title, copy ) { function renderSuggestionContent( slug, title, copy ) {
var left = document.createElement( 'div' ); var left = document.createElement( 'div' );
@ -110,6 +115,7 @@
return left; return left;
} }
// Render DOM elements for suggestion call-to-action button or link with dismiss 'x'.
function renderSuggestionCTA( slug, url, linkText, linkIsButton, allowDismiss ) { function renderSuggestionCTA( slug, url, linkText, linkIsButton, allowDismiss ) {
var right = document.createElement( 'div' ); var right = document.createElement( 'div' );
@ -126,6 +132,8 @@
return right; return right;
} }
// Render a "table banner" style suggestion.
// These are used in admin lists, e.g. products list.
function renderTableBanner( slug, iconUrl, title, copy, url, buttonText, allowDismiss ) { function renderTableBanner( slug, iconUrl, title, copy, url, buttonText, allowDismiss ) {
if ( ! title || ! url ) { if ( ! title || ! url ) {
return; return;
@ -166,6 +174,8 @@
return row; return row;
} }
// Render a "list item" style suggestion.
// These are used in onboarding style contexts, e.g. products list empty state.
function renderListItem( slug, iconUrl, title, copy, url, linkText, linkIsButton, allowDismiss ) { function renderListItem( slug, iconUrl, title, copy, url, linkText, linkIsButton, allowDismiss ) {
var container = document.createElement( 'div' ); var container = document.createElement( 'div' );
container.classList.add( 'marketplace-suggestion-container' ); container.classList.add( 'marketplace-suggestion-container' );
@ -185,6 +195,7 @@
return container; return container;
} }
// Filter suggestion data to remove less-relevant suggestions.
function getRelevantPromotions( marketplaceSuggestionsApiData, displayContext ) { function getRelevantPromotions( marketplaceSuggestionsApiData, displayContext ) {
// select based on display context // select based on display context
var promos = _.filter( marketplaceSuggestionsApiData, function( promo ) { var promos = _.filter( marketplaceSuggestionsApiData, function( promo ) {
@ -215,19 +226,24 @@
return promos; return promos;
} }
// Show and hide page elements dependent on suggestion state.
function hidePageElementsForEmptyState( visibleSuggestions ) { function hidePageElementsForEmptyState( visibleSuggestions ) {
var showingProductsEmptyStateSuggestions = _.contains( visibleSuggestions, 'products-list-empty-body' ); var showingProductsEmptyStateSuggestions = _.contains( visibleSuggestions, 'products-list-empty-body' );
// Streamline onboarding UI if we're in 'empty state' welcome mode.
if ( showingProductsEmptyStateSuggestions ) { if ( showingProductsEmptyStateSuggestions ) {
$( '#screen-meta-links' ).hide(); $( '#screen-meta-links' ).hide();
$( '#wpfooter' ).hide(); $( '#wpfooter' ).hide();
} }
// Hide the header & footer, they don't make sense without specific promotion content
if ( ! showingProductsEmptyStateSuggestions ) { if ( ! showingProductsEmptyStateSuggestions ) {
// hide the header & footer, they don't make sense without specific promotion content
$( '.marketplace-suggestions-container[data-marketplace-suggestions-context="products-list-empty-header"]' ).hide(); $( '.marketplace-suggestions-container[data-marketplace-suggestions-context="products-list-empty-header"]' ).hide();
$( '.marketplace-suggestions-container[data-marketplace-suggestions-context="products-list-empty-footer"]' ).hide(); $( '.marketplace-suggestions-container[data-marketplace-suggestions-context="products-list-empty-footer"]' ).hide();
} }
} }
// Render suggestion data in appropriate places in UI.
function displaySuggestions( jsonResponse ) { function displaySuggestions( jsonResponse ) {
var marketplaceSuggestionsApiData = jsonResponse.data || []; var marketplaceSuggestionsApiData = jsonResponse.data || [];
var visibleSuggestions = []; var visibleSuggestions = [];
@ -329,6 +345,7 @@
hidePageElementsForEmptyState( visibleSuggestions ); hidePageElementsForEmptyState( visibleSuggestions );
} }
// Top-level AJAX request to get suggestion data then render suggestions.
var data = var data =
jQuery.getJSON( jQuery.getJSON(
ajaxurl, ajaxurl,