PluginProbe ʕ •ᴥ•ʔ
Post Views Counter / trunk
Post Views Counter vtrunk
1.7.13 1.7.12 1.7.11 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.2 1.3.2.1 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.7.0 1.7.1 1.7.10 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9
post-views-counter / js / integration-gutenberg.js
post-views-counter / js Last commit date
admin-columns.js 5 months ago admin-dashboard.js 3 weeks ago admin-post.js 5 months ago admin-quick-edit.js 3 weeks ago admin-settings.js 3 weeks ago admin-theme.js 5 months ago admin-widgets.js 5 months ago block-editor.js 5 months ago counter.js 5 months ago frontend.js 3 weeks ago integration-gutenberg.js 5 months ago
integration-gutenberg.js
5 lines
1 (function(){
2 !function(e,t){var o=t.hooks.addFilter,n=t.compose.createHigherOrderComponent,r=t.element,s=r.Fragment,i=r.useEffect,c=t.blockEditor.InspectorControls,l=t.components,u=l.PanelBody,a=l.ToggleControl,d=t.i18n.__,v=e.pvcGutenbergIntegration||{enabled:!0,defaultIncludeZeroViews:!0};if(v.enabled){var p=new Map,f=!1;o("blocks.registerBlockType","pvc/latest-posts-add-post-views-orderby",function(e,t){return"core/latest-posts"!==t||(e.attributes||(e.attributes={}),e.attributes.pvcIncludeZeroViews={type:"boolean",default:v.defaultIncludeZeroViews}),e});var m=function(e,t,o){if(e){var n=Array.from(e.options).some(function(e){return e.value===t});if(!n){var r=document.createElement("option");r.value=t,r.text=o,e.appendChild(r)}}},w=function(){return document.querySelector(".block-editor-block-inspector")||document.querySelector(".interface-interface-skeleton__sidebar")||document.body},y=function(){var t=w().querySelectorAll("select");e.pvcDebug&&(console.log("[PVC] findLatestPostsOrderBySelect - Found selects:",t.length),t.forEach(function(e,t){var o=Array.from(e.options).map(function(e){return e.value});console.log("[PVC] Select",t,"options:",o)}));for(var o=0;o<t.length;o++){var n=t[o],r=n.querySelector('option[value="date/desc"]'),s=n.querySelector('option[value="date/asc"]'),i=n.querySelector('option[value="title/asc"]'),c=n.querySelector('option[value="title/desc"]'),l=n.querySelector('option[value="menu_order/asc"]')||n.querySelector('option[value="menu_order/desc"]');if(r&&s&&i&&c&&!l)return e.pvcDebug&&console.log("[PVC] Found Latest Posts orderBy select (QueryControls format) at index",o),n}return e.pvcDebug&&console.log("[PVC] Latest Posts orderBy select NOT found"),null},b=function(e){if(e){var t=w(),o=t.querySelector(".pvc-post-views-settings--latest-posts");if(o){var n=e.closest(".components-tools-panel");if(n){for(var r=n;r.parentNode&&r.parentNode!==t;){var s=r.parentNode;if(s.querySelector(":scope > .components-panel__body"))break;r=s}var i=r.parentNode;if(i){for(var c=o;c.parentNode&&c.parentNode!==i&&c.parentNode!==t;)c=c.parentNode;c.previousElementSibling!==r&&(c.parentNode===i?i.insertBefore(c,r.nextSibling):i.insertBefore(o,r.nextSibling))}}}}},g=n(function(e){return function(o){var n=o.name,r=o.attributes,l=o.setAttributes;if("core/query"!==n)return t.element.createElement(e,o);i(function(){if(o.isSelected){var e=function(){var e=function(){for(var e=w().querySelectorAll("select"),t=0;t<e.length;t++){var o=e[t],n=o.querySelector('option[value="date/desc"]'),r=o.querySelector('option[value="date/asc"]'),s=o.querySelector('option[value="title/asc"]');if(n&&r&&s)return o}return null}();e&&(m(e,"post_views/desc",d("Most viewed","post-views-counter")),m(e,"post_views/asc",d("Least viewed","post-views-counter")))},t=w(),n=new MutationObserver(e);return e(),n.observe(t,{childList:!0,subtree:!0}),function(){n.disconnect()}}},[o.clientId,o.isSelected]);var p=r.query&&"post_views"===r.query.orderBy,f=r.query&&void 0!==r.query.pvcIncludeZeroViews?r.query.pvcIncludeZeroViews:v.defaultIncludeZeroViews;return t.element.createElement(s,null,t.element.createElement(e,o),p&&t.element.createElement(c,null,t.element.createElement(u,{title:d("Post Views Settings","post-views-counter"),initialOpen:!0,className:"pvc-post-views-settings pvc-post-views-settings--query"},t.element.createElement(a,{label:d("Include posts with zero views","post-views-counter"),checked:f,onChange:function(e){var t=Object.assign({},r.query||{});t.pvcIncludeZeroViews=e,l({query:t})},help:d("When enabled, posts with no views will be included in the results.","post-views-counter")}))))}},"withQueryLoopControls"),S=n(function(e){return function(o){var n=o.name,r=o.attributes,l=o.setAttributes;if("core/latest-posts"!==n)return t.element.createElement(e,o);var g=o.clientId;i(function(){var e;"post_views"===r.orderBy&&(e="post_views",p.set(g,e))},[r.orderBy,g]),i(function(){if("post_views"===p.get(g)&&"date"===r.orderBy&&!f){var e=requestAnimationFrame(function(){l({orderBy:"post_views"})});return function(){cancelAnimationFrame(e)}}},[r.orderBy,g,l]),i(function(){f&&"post_views"!==r.orderBy&&p.delete(g)},[r.orderBy,g]),i(function(){return function(){var e=setTimeout(function(){p.get(g)&&null===document.querySelector('[data-block="'+g+'"]')&&p.delete(g)},5e3);return function(){clearTimeout(e)}}},[g]),i(function(){if(o.isSelected){var e=function(){var e=y();if(e){if(m(e,"post_views/desc",d("Most viewed","post-views-counter")),m(e,"post_views/asc",d("Least viewed","post-views-counter")),e.dataset.pvcListenerAdded||(e.dataset.pvcListenerAdded="true",e.addEventListener("change",function(){f=!0,setTimeout(function(){f=!1},100)})),"post_views"===r.orderBy){var t="post_views/"+(r.order||"desc");e.value!==t&&(e.value=t)}b(e)}},t=w(),n=new MutationObserver(e);e();var s=setTimeout(e,100),i=setTimeout(e,300);return n.observe(t,{childList:!0,subtree:!0}),function(){n.disconnect(),clearTimeout(s),clearTimeout(i)}}},[o.clientId,o.isSelected,r.orderBy,r.order]);var S="post_views"===r.orderBy;i(function(){if(S&&o.isSelected){var e=function(){var e=y();e&&b(e)},t=setTimeout(e,50),n=setTimeout(e,150),r=setTimeout(e,300),s=setTimeout(e,500),i=setTimeout(e,1e3),c=w(),l=new MutationObserver(function(){c.querySelector(".pvc-post-views-settings--latest-posts")&&e()});return l.observe(c,{childList:!0,subtree:!0}),function(){clearTimeout(t),clearTimeout(n),clearTimeout(r),clearTimeout(s),clearTimeout(i),l.disconnect()}}},[S,o.isSelected]);var q=void 0!==r.pvcIncludeZeroViews?r.pvcIncludeZeroViews:v.defaultIncludeZeroViews;return t.element.createElement(s,null,t.element.createElement(e,o),S&&t.element.createElement(c,null,t.element.createElement(u,{title:d("Post Views Settings","post-views-counter"),initialOpen:!0,className:"pvc-post-views-settings pvc-post-views-settings--latest-posts"},t.element.createElement(a,{label:d("Include posts with zero views","post-views-counter"),checked:q,onChange:function(e){l({pvcIncludeZeroViews:e})},help:d("When enabled, posts with no views will be included in the results.","post-views-counter")}))))}},"withLatestPostsControls");o("editor.BlockEdit","pvc/query-loop-controls",g),o("editor.BlockEdit","pvc/latest-posts-controls",S)}}(window,window.wp);
3
4 })();
5