1 line
6.5 KiB
JavaScript
1 line
6.5 KiB
JavaScript
!function(h,g,r){h(function(){function c(e,s){var t=document.createElement("a");return t.classList.add("suggestion-dismiss"),t.setAttribute("title",g.i18n_marketplace_suggestions_dismiss_tooltip),t.setAttribute("href","#"),t.onclick=function(t){t.preventDefault(),function i(t,e){if(h("[data-suggestion-slug="+e+"]").fadeOut(function(){h(this).remove(),o()}),jQuery.post(r,{action:"woocommerce_add_dismissed_marketplace_suggestion",_wpnonce:g.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),10)||0;Cookies.set(n,a+1,{expires:31})}window.wcTracks.recordEvent("marketplace_suggestion_dismissed",{suggestion_slug: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",{suggestion_slug: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 p(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=g.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 k(){return h("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=p(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(g.dismissed_suggestions,t.slug)}),s=_.filter(s,function(t){return!_.contains(g.active_plugins,t["hide-if-active"])}),s=_.filter(s,function(t){return!t["show-if-active"]||0<_.intersection(g.active_plugins,t["show-if-active"]).length})}function o(){if(h('.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"]',h('.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(){h(".marketplace-suggestions-metabox-nosuggestions-placeholder").fadeIn()}})}}void 0!==g&&(window.wcTracks=window.wcTracks||{},window.wcTracks.recordEvent=window.wcTracks.recordEvent||function(){},g.suggestions_data&&function t(c){var d=[];h(".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);h(this).append(r),h(this).addClass("showing-suggestion"),d.push(t),window.wcTracks.recordEvent("marketplace_suggestion_displayed",{suggestion_slug:s[n].slug})}}),0===d.length&&h(".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"),10))){var e=l(c,t);if(e&&e.length){var s=_.sample(e),n=!0;!1===s["allow-dismiss"]&&(n=!1);var a=function g(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",k());var u=document.createElement("div");u.classList.add("marketplace-suggestion-container"),u.dataset.suggestionSlug=e;var l=p(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=h(this).children();h(a).hide(),i.length<=3?h(this).append(a):h(i[2]).after(a),h(a).fadeIn(),d.push(t),function o(){h("#show-settings-link").on("focus.scroll-into-view",function(){h(".marketplace-table-banner-td").attr("colspan",k())})}(),window.wcTracks.recordEvent("marketplace_suggestion_displayed",{suggestion_slug:s.slug})}}}}),function s(t){var e=0<_.intersection(t,["products-list-empty-body","orders-list-empty-body"]).length;e&&(h("#screen-meta-links").hide(),h("#wpfooter").hide()),e||(h('.marketplace-suggestions-container[data-marketplace-suggestions-context="products-list-empty-header"]').hide(),h('.marketplace-suggestions-container[data-marketplace-suggestions-context="products-list-empty-footer"]').hide(),h('.marketplace-suggestions-container[data-marketplace-suggestions-context="orders-list-empty-header"]').hide(),h('.marketplace-suggestions-container[data-marketplace-suggestions-context="orders-list-empty-footer"]').hide())}(d),o()}(g.suggestions_data))})}(jQuery,marketplace_suggestions,ajaxurl); |