woocommerce/assets/js/admin/marketplace-suggestions.min.js

1 line
6.2 KiB
JavaScript

!function(f,h,w){f(function(){var c,d,t,u;function m(r,c,d,u,l){var t=document.createElement("a");return t.classList.add("suggestion-dismiss"),t.setAttribute("title",h.i18n_marketplace_suggestions_dismiss_tooltip),t.setAttribute("href","#"),t.onclick=function(t){var e,s,a,n,o,i;t.preventDefault(),e=r,s=c,a=d,n=u,f("[data-suggestion-slug="+(o=l)+"]").fadeOut(function(){f(this).remove(),p()}),jQuery.post(w,{action:"woocommerce_add_dismissed_marketplace_suggestion",_wpnonce:h.dismiss_suggestion_nonce,slug:o}),_.contains(["products-list-inline"],e)&&(i="woocommerce_snooze_suggestions__"+e,Cookies.set(i,"true",{expires:2}),t="woocommerce_dismissed_suggestions__"+e,i=parseInt(Cookies.get(t),10)||0,Cookies.set(t,i+1,{expires:31})),window.wcTracks.recordEvent("marketplace_suggestion_dismissed",{suggestion_slug:o,context:e,product:s||"",promoted:a||"",target:n||""})},t}function k(t,e,s,a,n,o,i){var r=document.createElement("a"),c=function(e,t){var s=h.in_app_purchase_params;s.utm_source="unknown",s.utm_campaign="marketplacesuggestions",s.utm_medium="product";var a=_.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 a&&(s.utm_source=a),t+"?"+jQuery.param(s)}(t,n);r.setAttribute("href",c);return _.includes(["product-edit-meta-tab-header","product-edit-meta-tab-footer","product-edit-meta-tab-body","products-list-empty-footer"],t)&&r.setAttribute("target","blank"),r.textContent=o,r.onclick=function(){window.wcTracks.recordEvent("marketplace_suggestion_clicked",{suggestion_slug:a,context:t,product:e||"",promoted:s||"",target:n||""})},i?r.classList.add("button"):(r.classList.add("linkout"),(i=document.createElement("span")).classList.add("dashicons","dashicons-external"),r.appendChild(i)),r}function l(t,e,s,a,n,o,i,r,c,d,u){var l=document.createElement("div");l.classList.add("marketplace-suggestion-container"),l.dataset.suggestionSlug=a;var p,g=function(t){if(!t)return null;var e=document.createElement("img");return e.src=t,e.classList.add("marketplace-suggestion-icon"),e}(n);return g&&l.appendChild(g),l.appendChild((n=a,g=o,o=i,(i=document.createElement("div")).classList.add("marketplace-suggestion-container-content"),g&&((p=document.createElement("h4")).textContent=g,i.appendChild(p)),o&&((p=document.createElement("p")).textContent=o,i.appendChild(p)),-1!==["product-edit-empty-footer-browse-all","product-edit-meta-tab-footer-browse-all"].indexOf(n)&&(i.classList.add("has-manage-link"),(n=document.createElement("a")).classList.add("marketplace-suggestion-manage-link","linkout"),n.setAttribute("href",h.manage_suggestions_url),n.textContent=h.i18n_marketplace_suggestions_manage_suggestions,i.appendChild(n)),i)),l.appendChild((i=t,t=e,e=s,s=a,a=r,r=c,c=d,d=u,u=document.createElement("div"),r=r||h.i18n_marketplace_suggestions_default_cta,u.classList.add("marketplace-suggestion-container-cta"),a&&r&&(c=k(i,t,e,s,a,r,c),u.appendChild(c)),d&&u.appendChild(m(i,t,e,a,s)),u)),l}function p(){f('.marketplace-suggestions-container[data-marketplace-suggestions-context="product-edit-meta-tab-body"]').children().length<=0&&f('.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(){f(".marketplace-suggestions-metabox-nosuggestions-placeholder").fadeIn()}})}function g(t){return _.includes(["product-edit-meta-tab-header","product-edit-meta-tab-body","product-edit-meta-tab-footer"],t)}void 0!==h&&(window.wcTracks=window.wcTracks||{},window.wcTracks.recordEvent=window.wcTracks.recordEvent||function(){},c=!1,h.suggestions_data&&(d=h.suggestions_data,u=[],f(".marketplace-suggestions-container").each(function(){var t,e,s,a=this.dataset.marketplaceSuggestionsContext,t=(t=d,e=a,t=_.filter(t,function(t){return _.isArray(t.context)?_.contains(t.context,e):e===t.context}),t=_.filter(t,function(t){return!_.contains(h.dismissed_suggestions,t.slug)}),t=_.filter(t,function(t){return!_.contains(h.active_plugins,t.product)}),t=_.filter(t,function(t){return!t["show-if-active"]||0<_.intersection(h.active_plugins,t["show-if-active"]).length})),n=_.sample(t,5);for(s in n){var o=n[s]["link-text"],i=!0;n[s]["link-text"]&&(o=n[s]["link-text"],i=!1);var r=!0;!1===n[s]["allow-dismiss"]&&(r=!1);r=l(a,n[s].product,n[s].promoted,n[s].slug,n[s].icon,n[s].title,n[s].copy,n[s].url,o,i,r);f(this).append(r),f(this).addClass("showing-suggestion"),u.push(a),g(a)||window.wcTracks.recordEvent("marketplace_suggestion_displayed",{suggestion_slug:n[s].slug,context:a,product:n[s].product||"",promoted:n[s].promoted||"",target:n[s].url||""})}f("ul.product_data_tabs li.marketplace-suggestions_options a").on("click",function(t){if(t.preventDefault(),"#marketplace_suggestions"!==c&&g(a))for(var e in n)window.wcTracks.recordEvent("marketplace_suggestion_displayed",{suggestion_slug:n[e].slug,context:a,product:n[e].product||"",promoted:n[e].promoted||"",target:n[e].url||""})})}),t=u,(t=0<_.intersection(t,["products-list-empty-body","orders-list-empty-body"]).length)&&(f("#screen-meta-links").hide(),f("#wpfooter").hide()),t||(f('.marketplace-suggestions-container[data-marketplace-suggestions-context="products-list-empty-header"]').hide(),f('.marketplace-suggestions-container[data-marketplace-suggestions-context="products-list-empty-footer"]').hide(),f('.marketplace-suggestions-container[data-marketplace-suggestions-context="orders-list-empty-header"]').hide(),f('.marketplace-suggestions-container[data-marketplace-suggestions-context="orders-list-empty-footer"]').hide()),p(),f("ul.product_data_tabs").on("click","li a",function(t){t.preventDefault(),c=f(this).attr("href")})),f("a.marketplace-suggestion-manage-link").on("click",function(){window.wcTracks.recordEvent("marketplace_suggestions_manage_clicked")}))})}(jQuery,marketplace_suggestions,ajaxurl);