diff --git a/assets/js/admin/marketplace-suggestions.js b/assets/js/admin/marketplace-suggestions.js index 1fdc0e2e80f..abd8c53b2c2 100644 --- a/assets/js/admin/marketplace-suggestions.js +++ b/assets/js/admin/marketplace-suggestions.js @@ -194,49 +194,6 @@ return container; } - function getTableBannerColspan() { - return $( 'table.wp-list-table.posts thead th:not(.hidden)' ).length + 1; - } - - // Render a "table banner" style suggestion. - // These are used in admin lists, e.g. products list. - function renderTableBanner( context, product, promoted, slug, iconUrl, title, copy, url, buttonText, allowDismiss ) { - if ( ! title || ! url ) { - return; - } - - var row = document.createElement( 'tr' ); - row.classList.add( 'marketplace-table-banner' ); - row.classList.add( 'marketplace-suggestions-container' ); - row.classList.add( 'showing-suggestion' ); - row.dataset.marketplaceSuggestionsContext = 'products-list-inline'; - row.dataset.suggestionSlug = slug; - - var cell = document.createElement( 'td' ); - cell.classList.add( 'marketplace-table-banner-td' ); - cell.setAttribute( 'colspan', getTableBannerColspan() ); - - var container = document.createElement( 'div' ); - container.classList.add( 'marketplace-suggestion-container' ); - container.dataset.suggestionSlug = slug; - - var icon = renderSuggestionIcon( iconUrl ); - if ( icon ) { - container.appendChild( icon ); - } - container.appendChild( - renderSuggestionContent( title, copy ) - ); - container.appendChild( - renderSuggestionCTA( context, product, promoted, slug, url, buttonText, true, allowDismiss ) - ); - - cell.appendChild( container ); - row.appendChild( cell ); - - return row; - } - // Render a "list item" style suggestion. // These are used in onboarding style contexts, e.g. products list empty state. function renderListItem( context, product, promoted, slug, iconUrl, title, copy, url, linkText, linkIsButton, allowDismiss ) { @@ -335,12 +292,6 @@ } } - function refreshBannerColspanForScreenOptions() { - $( '#show-settings-link' ).on( 'focus.scroll-into-view', function() { - $( '.marketplace-table-banner-td' ).attr( 'colspan', getTableBannerColspan() ); - }); - } - // Render suggestion data in appropriate places in UI. function displaySuggestions( marketplaceSuggestionsApiData ) { var usedSuggestionsContexts = []; @@ -399,87 +350,6 @@ } } ); - // render inline promos in products list - if ( 0 === usedSuggestionsContexts.length ) { - $( '.wp-admin.admin-bar.edit-php.post-type-product table.wp-list-table.posts tbody').first().each( function() { - var context = 'products-list-inline'; - - // product list banner suggestion is temporarily suppressed after a recent dismissal - var contextSnoozeCookie = 'woocommerce_snooze_suggestions__' + context; - if ( Cookies.get( contextSnoozeCookie ) ) { - return; - } - - // product list banner suggestion has been dismissed repeatedly – give user a break - // note that this is longer term but still temporary, based on the expiry of the cookie - var hideSuggestionsDismissalThreshold = 5; - if ( parseInt( Cookies.get( 'contextDismissalCountCookie' ), 10 ) > hideSuggestionsDismissalThreshold ) { - return; - } - - - // find promotions that target this context - var promos = getRelevantPromotions( marketplaceSuggestionsApiData, context ); - if ( ! promos || ! promos.length ) { - return; - } - - // shuffle/randomly select the suggestion to display - var suggestionToDisplay = _.sample( promos ); - - // dismiss is allowed by default - var allowDismiss = true; - if ( false === suggestionToDisplay['allow-dismiss'] ) { - allowDismiss = false; - } - - // render first promo - var content = renderTableBanner( - context, - suggestionToDisplay.product, - suggestionToDisplay.promoted, - suggestionToDisplay.slug, - suggestionToDisplay.icon, - suggestionToDisplay.title, - suggestionToDisplay.copy, - suggestionToDisplay.url, - suggestionToDisplay['button-text'], - allowDismiss - ); - - if ( content ) { - // where should we put it in the list? - var rows = $( this ).children(); - var minRow = 3; - - $( content ).hide(); - - if ( rows.length <= minRow ) { - // if small number of rows, append at end - $( this ).append( content ); - } - else { - // for more rows, insert - $( rows[ minRow - 1 ] ).after( content ); - } - - $( content ).fadeIn(); - - usedSuggestionsContexts.push( context ); - - refreshBannerColspanForScreenOptions( content ); - - window.wcTracks.recordEvent( 'marketplace_suggestion_displayed', { - suggestion_slug: suggestionToDisplay.slug, - context: context, - product: suggestionToDisplay.product || '', - promoted: suggestionToDisplay.promoted || '', - target: suggestionToDisplay.url || '' - } ); - } - } ); - } - hidePageElementsForSuggestionState( usedSuggestionsContexts ); tidyProductEditMetabox(); } diff --git a/assets/js/admin/marketplace-suggestions.min.js b/assets/js/admin/marketplace-suggestions.min.js index 22f061f8ebc..83822655bb6 100644 --- a/assets/js/admin/marketplace-suggestions.min.js +++ b/assets/js/admin/marketplace-suggestions.min.js @@ -1 +1 @@ -!function(w,b,d){w(function(){function u(e,s,n,a,o){var t=document.createElement("a");return t.classList.add("suggestion-dismiss"),t.setAttribute("title",b.i18n_marketplace_suggestions_dismiss_tooltip),t.setAttribute("href","#"),t.onclick=function(t){t.preventDefault(),function c(t,e,s,n,a){if(w("[data-suggestion-slug="+a+"]").fadeOut(function(){w(this).remove(),m()}),jQuery.post(d,{action:"woocommerce_add_dismissed_marketplace_suggestion",_wpnonce:b.dismiss_suggestion_nonce,slug:a}),_.contains(["products-list-inline"],t)){var o="woocommerce_snooze_suggestions__"+t;Cookies.set(o,"true",{expires:2});var i="woocommerce_dismissed_suggestions__"+t,r=parseInt(Cookies.get(i),10)||0;Cookies.set(i,r+1,{expires:31})}window.wcTracks.recordEvent("marketplace_suggestion_dismissed",{suggestion_slug:a,context:t,product:e||"",promoted:s||"",target:n||""})}(e,s,n,a,o)},t}function l(t,e,s,n,a,o,i){var r=document.createElement("a"),c=function u(e,t){var s={utm_source:"unknown",utm_campaign:"marketplacesuggestions",utm_medium:"product"},n=_.findKey({productstable:["products-list-inline"],productsempty:["products-list-empty-header","products-list-empty-footer","products-list-empty-body"],ordersempty:["orders-list-empty-header","orders-list-empty-footer","orders-list-empty-body"],editproduct:["product-edit-meta-tab-header","product-edit-meta-tab-footer","product-edit-meta-tab-body"]},function(t){return _.contains(t,e)});return n&&(s.utm_source=n),t+"?"+jQuery.param(s)}(t,a);if(r.setAttribute("href",c),r.setAttribute("target","blank"),r.textContent=o,r.onclick=function(){window.wcTracks.recordEvent("marketplace_suggestion_clicked",{suggestion_slug:n,context:t,product:e||"",promoted:s||"",target:a||""})},i)r.classList.add("button");else{r.classList.add("linkout");var d=document.createElement("span");d.classList.add("dashicons","dashicons-external"),r.appendChild(d)}return r}function f(t){if(!t)return null;var e=document.createElement("img");return e.src=t,e.classList.add("marketplace-suggestion-icon"),e}function k(t,e){var s=document.createElement("div");if(s.classList.add("marketplace-suggestion-container-content"),t){var n=document.createElement("h4");n.textContent=t,s.appendChild(n)}if(e){var a=document.createElement("p");a.textContent=e,s.appendChild(a)}return s}function h(t,e,s,n,a,o,i,r){var c=document.createElement("div");if(o||(o=b.i18n_marketplace_suggestions_default_cta),c.classList.add("marketplace-suggestion-container-cta"),a&&o){var d=l(t,e,s,n,a,o,i);c.appendChild(d)}return r&&c.appendChild(u(t,e,s,a,n)),c}function v(){return w("table.wp-list-table.posts thead th:not(.hidden)").length+1}function p(t,e,s,n,a,o,i,r,c,d,u){var l=document.createElement("div");l.classList.add("marketplace-suggestion-container"),l.dataset.suggestionSlug=n;var p=f(a);return p&&l.appendChild(p),l.appendChild(k(o,i)),l.appendChild(h(t,e,s,n,r,c,d,u)),l}function g(t,e){var s=_.filter(t,function(t){return _.isArray(t.context)?_.contains(t.context,e):e===t.context});return s=_.filter(s,function(t){return!_.contains(b.dismissed_suggestions,t.slug)}),s=_.filter(s,function(t){return!_.contains(b.active_plugins,t.product)}),s=_.filter(s,function(t){return!t["show-if-active"]||0<_.intersection(b.active_plugins,t["show-if-active"]).length})}function m(){if(w('.marketplace-suggestions-container[data-marketplace-suggestions-context="product-edit-meta-tab-body"]').children().length<=0){', .marketplace-suggestions-container[data-marketplace-suggestions-context="product-edit-meta-tab-header"]',', .marketplace-suggestions-container[data-marketplace-suggestions-context="product-edit-meta-tab-footer"]',w('.marketplace-suggestions-container[data-marketplace-suggestions-context="product-edit-meta-tab-body"], .marketplace-suggestions-container[data-marketplace-suggestions-context="product-edit-meta-tab-header"], .marketplace-suggestions-container[data-marketplace-suggestions-context="product-edit-meta-tab-footer"]').fadeOut({complete:function(){w(".marketplace-suggestions-metabox-nosuggestions-placeholder").fadeIn()}})}}void 0!==b&&(window.wcTracks=window.wcTracks||{},window.wcTracks.recordEvent=window.wcTracks.recordEvent||function(){},b.suggestions_data&&function t(c){var d=[];w(".marketplace-suggestions-container").each(function(){var t=this.dataset.marketplaceSuggestionsContext,e=g(c,t),s=_.sample(e,5);for(var n in s){var a=s[n]["link-text"],o=!0;s[n]["link-text"]&&(a=s[n]["link-text"],o=!1);var i=!0;!1===s[n]["allow-dismiss"]&&(i=!1);var r=p(t,s[n].product,s[n].promoted,s[n].slug,s[n].icon,s[n].title,s[n].copy,s[n].url,a,o,i);w(this).append(r),w(this).addClass("showing-suggestion"),d.push(t),window.wcTracks.recordEvent("marketplace_suggestion_displayed",{suggestion_slug:s[n].slug,context:t,product:s[n].product||"",promoted:s[n].promoted||"",target:s[n].url||""})}}),0===d.length&&w(".wp-admin.admin-bar.edit-php.post-type-product table.wp-list-table.posts tbody").first().each(function(){var t="products-list-inline";if(!(Cookies.get("woocommerce_snooze_suggestions__products-list-inline")||5