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

1 line
6.1 KiB
JavaScript

!function(k,p,r){k(function(){function c(e,s){var t=document.createElement("a");return t.classList.add("suggestion-dismiss"),t.setAttribute("title",p.i18n_marketplace_suggestions_dismiss_tooltip),t.setAttribute("href","#"),t.onclick=function(t){t.preventDefault(),function i(t,e){if(k("[data-suggestion-slug="+e+"]").fadeOut(function(){k(this).remove(),o()}),jQuery.post(r,{action:"woocommerce_add_dismissed_marketplace_suggestion",_wpnonce:p.dismiss_suggestion_nonce,slug:e}),_.contains(["products-list-inline"],t)){var s="woocommerce_snooze_suggestions__"+t;Cookies.set(s,"true",{expires:2});var n="woocommerce_dismissed_suggestions__"+t,a=parseInt(Cookies.get(n))||0;Cookies.set(n,a+1,{expires:31})}window.wcTracks.recordEvent("marketplace_suggestion_dismissed",{suggestionSlug:e})}(e,s)},t}function d(t,e,s,n,a){var i=document.createElement("a"),o=function c(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,s);if(i.setAttribute("href",o),i.setAttribute("target","blank"),i.textContent=n,i.onclick=function(){window.wcTracks.recordEvent("marketplace_suggestion_clicked",{suggestionSlug:e})},a)i.classList.add("button");else{i.classList.add("linkout");var r=document.createElement("span");r.classList.add("dashicons","dashicons-external"),i.appendChild(r)}return i}function g(t){if(!t)return null;var e=document.createElement("img");return e.src=t,e.classList.add("marketplace-suggestion-icon"),e}function m(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 f(t,e,s,n,a,i){var o=document.createElement("div");if(n||(n=p.i18n_marketplace_suggestions_default_cta),o.classList.add("marketplace-suggestion-container-cta"),s&&n){var r=d(t,e,s,n,a);o.appendChild(r)}return i&&o.appendChild(c(t,e)),o}function h(){return k("table.wp-list-table.posts thead th:not(.hidden)").length+1}function u(t,e,s,n,a,i,o,r,c){var d=document.createElement("div");d.classList.add("marketplace-suggestion-container"),d.dataset.suggestionSlug=e;var u=g(s);return u&&d.appendChild(u),d.appendChild(m(n,a)),d.appendChild(f(t,e,i,o,r,c)),d}function l(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(p.dismissed_suggestions,t.slug)}),s=_.filter(s,function(t){return!_.contains(p.active_plugins,t["hide-if-active"])}),s=_.filter(s,function(t){return!t["show-if-active"]||0<_.intersection(p.active_plugins,t["show-if-active"]).length})}function o(){k('.marketplace-suggestions-container[data-marketplace-suggestions-context="product-edit-meta-tab-body"]').children().length<=0&&(k('.marketplace-suggestions-container[data-marketplace-suggestions-context="product-edit-meta-tab-header"]').slideUp(),k('.marketplace-suggestions-container[data-marketplace-suggestions-context="product-edit-meta-tab-body"]').fadeOut())}void 0!==p&&(window.wcTracks=window.wcTracks||{},window.wcTracks.recordEvent=window.wcTracks.recordEvent||function(){},p.suggestions_data&&function t(c){var d=[];k(".marketplace-suggestions-container").each(function(){var t=this.dataset.marketplaceSuggestionsContext,e=l(c,t),s=_.sample(e,5);for(var n in s){var a=s[n]["link-text"],i=!0;s[n]["link-text"]&&(a=s[n]["link-text"],i=!1);var o=!0;!1===s[n]["allow-dismiss"]&&(o=!1);var r=u(t,s[n].slug,s[n].icon,s[n].title,s[n].copy,s[n].url,a,i,o);k(this).append(r),k(this).addClass("showing-suggestion"),d.push(t),window.wcTracks.recordEvent("marketplace_suggestion_displayed",{suggestionSlug:s[n].slug})}}),0===d.length&&k(".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<parseInt(Cookies.get("contextDismissalCountCookie")))){var e=l(c,t);if(e&&e.length){var s=_.sample(e),n=!0;!1===s["allow-dismiss"]&&(n=!1);var a=function p(t,e,s,n,a,i,o,r){if(n&&i){var c=document.createElement("tr");c.classList.add("marketplace-table-banner"),c.classList.add("marketplace-suggestions-container"),c.classList.add("showing-suggestion"),c.dataset.marketplaceSuggestionsContext="products-list-inline",c.dataset.suggestionSlug=e;var d=document.createElement("td");d.classList.add("marketplace-table-banner-td"),d.setAttribute("colspan",h());var u=document.createElement("div");u.classList.add("marketplace-suggestion-container"),u.dataset.suggestionSlug=e;var l=g(s);return l&&u.appendChild(l),u.appendChild(m(n,a)),u.appendChild(f(t,e,i,o,!0,r)),d.appendChild(u),c.appendChild(d),c}}(t,s.slug,s.icon,s.title,s.copy,s.url,s["button-text"],n);if(a){var i=k(this).children();k(a).hide(),i.length<=3?k(this).append(a):k(i[2]).after(a),k(a).fadeIn(),d.push(t),function o(t){k("#show-settings-link").on("focus.scroll-into-view",function(){k(".marketplace-table-banner-td").attr("colspan",h())})}(),window.wcTracks.recordEvent("marketplace_suggestion_displayed",{suggestionSlug:s.slug})}}}}),function s(t){var e=0<_.intersection(t,["products-list-empty-body","orders-list-empty-body"]).length;e&&(k("#screen-meta-links").hide(),k("#wpfooter").hide()),e||(k('.marketplace-suggestions-container[data-marketplace-suggestions-context="products-list-empty-header"]').hide(),k('.marketplace-suggestions-container[data-marketplace-suggestions-context="products-list-empty-footer"]').hide(),k('.marketplace-suggestions-container[data-marketplace-suggestions-context="orders-list-empty-header"]').hide(),k('.marketplace-suggestions-container[data-marketplace-suggestions-context="orders-list-empty-footer"]').hide())}(d),o()}(p.suggestions_data))})}(jQuery,marketplace_suggestions,ajaxurl);