From bc2da0e87ab021787ab7d94e7383205fbff6ac2e Mon Sep 17 00:00:00 2001 From: Geoffrey Crofte <452767+geoffreycrofte@users.noreply.github.com> Date: Mon, 26 Dec 2022 12:10:46 +0100 Subject: [PATCH] Put back the focus after modal closes --- assets/js/juiz-social-post-sharer.js | 7 +++++-- assets/js/juiz-social-post-sharer.min.js | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/assets/js/juiz-social-post-sharer.js b/assets/js/juiz-social-post-sharer.js index 2f746e8..b84c5de 100755 --- a/assets/js/juiz-social-post-sharer.js +++ b/assets/js/juiz-social-post-sharer.js @@ -1,8 +1,8 @@ -/** +/**! * Plugin Name: Nobs • Share Buttons * Plugin URI: https://sharebuttons.social * Author: Geoffrey Crofte - * Updated: 2.0.0 - No jQuery needed anymore. + * Updated: 2.3.2 - No jQuery needed anymore. */ ; document.addEventListener("DOMContentLoaded", function(event) { @@ -305,6 +305,7 @@ document.addEventListener("DOMContentLoaded", function(event) { return; } let animation = 400; + let focusedEl = document.activeElement; let post_id = event.target.closest('.juiz_sps_links').getAttribute('data-post-id'); let modalContent = '
'+jsps.modalEmailTitle+'
'+e.data+"
'+n.statusText+"("+n.status+")
",o=document.createElement("div");o.classList.add("juiz-sps-error"),o.classList.add("juiz-sps-message"),o.innerHTML=a,r.querySelector("form").append(o),l.classList.remove("is-active")}},n.open("GET",jsps.ajax_url+t(o)),n.send(),!1}),document.querySelector(".juiz-sps-close").addEventListener("click",function(){return l.setAttribute("aria-hidden","true"),l.classList.remove("jsps-modal-show"),temp=setInterval(function(){l.remove()},400),!1}),window.addEventListener("keyup",function(e){"Escape"===e.code&&document.querySelector('.juiz-sps-modal[aria-hidden="false"]')&&document.querySelector(".juiz-sps-close").click()}),document.querySelector(".juiz-sps-close").addEventListener("blur",function(){return this.closest(".juiz-sps-modal").querySelector("form > p:first-child input").focus(),!1}),!1}),!window.print&&document.querySelector(".juiz_sps_link_print")&&document.querySelectorAll(".juiz_sps_link_print").forEach(function(e){e.remove()}),"addToHomescreen"in window&&window.addToHomescreen.isCompatible||window.sidebar&&window.sidebar.addPanel||window.external&&"AddFavorite"in window.external||"undefined"==typeof chrome||"undefined"!=typeof chrome?l=function(e){e.preventDefault();let t=window.location.href,s=document.title;return"addToHomescreen"in window&&window.addToHomescreen.isCompatible?addToHomescreen({autostart:!1,startDelay:0}).show(!0):window.sidebar&&window.sidebar.addPanel?window.sidebar.addPanel(s,t,""):window.external&&"AddFavorite"in window.external?window.external.AddFavorite(t,s):(command=(/Mac/i.test(navigator.userAgent)?"Cmd":"Ctrl")+"+D",alert(message=(message=e.target.getAttribute("data-alert")||e.target.closest("a, button").getAttribute("data-alert")).replace(/%s/,command))),!1}:document.querySelector(".juiz_sps_link_bookmark")&&document.querySelectorAll(".juiz_sps_link_bookmark").forEach(function(e){e.remove()})});
\ No newline at end of file
+document.addEventListener("DOMContentLoaded",function(e){let t=function(e){return"?"+Object.keys(e).map(function(t){return t+"="+encodeURIComponent(e[t])}).join("&")},s=function(e){var t=[];return Array.prototype.slice.call(e.elements).forEach(function(e){if(!(!e.name||e.disabled||["file","reset","submit","button"].indexOf(e.type)>-1)){if("select-multiple"===e.type){Array.prototype.slice.call(e.options).forEach(function(s){s.selected&&t.push({name:e.name,value:s.value})});return}(!(["checkbox","radio"].indexOf(e.type)>-1)||e.checked)&&t.push({name:e.name,value:e.value})}}),t},i=function(e){return"NaN"==typeof parseInt(e)?0:e>=1e9?parseInt(e/1e9)+"b":e>=1e6?parseInt(e/1e6)+"m":e>=1e3?parseInt(e/1e3)+"k":e},r=function(){return document.querySelector(".juiz_sps_counters.counters_both")?"both":document.querySelector(".juiz_sps_counters.counters_subtotal")?"subtotal":document.querySelector(".juiz_sps_counters.counters_total")?"total":"nope"},a,l;if(document.querySelector(".juiz_sps_counters")){let o=document.querySelectorAll(".juiz_sps_counters");document.querySelector(".juiz_sps_info_plugin_url").value,document.querySelector(".juiz_sps_info_permalink").value,document.querySelector(".juiz_sps_info_post_id").value,o.forEach(function(e){let s=e.querySelectorAll(".juiz_sps_item"),r=document.querySelector(".juiz_sps_links").getAttribute("data-post-id"),a="",l=0;if(e.classList.contains("counters_total")&&(a="juiz_hidden_counter"),null===s)return;let o={action:"jsps-get-counters","jsps-get-counters-nonce":jsps.getCountersNonce,id:r},n=new XMLHttpRequest;n.onload=function(){if(n.status>=200&&n.status<300){let t=JSON.parse(n.response);if(t="object"==typeof t.data?t.data[1]:{},s.forEach(function(e){if(e.classList.contains("juiz_sps_totalcount_item"))return;let s=e.querySelector("button, a").getAttribute("data-nobs-key");if(!t[s])return;let r=document.createElement("span");r.classList.add("juiz_sps_counter"),""!==a&&r.classList.add(a),r.setAttribute("data-nobs-raw-count",t[s]),r.textContent=i(parseInt(t[s])),e.prepend(r),l+=parseInt(t[s])}),!e.classList.contains("counters_subtotal")){let r=document.createElement("span"),o=document.createElement("span"),u=e.querySelector(".juiz_sps_totalcount"),_=u.getAttribute("title");r.classList.add("juiz_sps_total_text"),r.classList.add("juiz_sps_maybe_hidden_text"),r.textContent=_,o.classList.add("juiz_sps_total_number"),o.setAttribute("data-nobs-raw-count",l),o.textContent=i(l),u.append(r,o),u.setAttribute("title",_+" "+l)}0===parseInt(l)&&document.querySelectorAll(".juiz_sps_totalcount_item")&&document.querySelectorAll(".juiz_sps_totalcount_item").forEach(function(e){e.classList.add("juiz_sps_maybe_hidden_text")})}else console.warn("The request failed!")},n.open("GET",jsps.ajax_url+t(o)),n.send()})}document.querySelector(".juiz_sps_item")&&document.querySelectorAll(".juiz_sps_item button, .juiz_sps_item a").forEach(function(e){e.addEventListener("click",function(e){let s=e;if(0===e.clientX)return;e.preventDefault();let o=this,n=o.getAttribute("data-nobs-key"),u=document.querySelector(".juiz_sps_links").getAttribute("data-post-id"),_={action:"jsps-click-count","jsps-click-count-nonce":jsps.clickCountNonce,id:u,network:n},$=new XMLHttpRequest;return $.onload=function(){if($.status>=200&&$.status<300){let e=JSON.parse($.response),t=document.querySelectorAll(".juiz_sps_link_"+n);if(!0===e.success&&document.querySelector(".juiz_sps_counters")){let u=document.querySelector(".juiz_sps_link_"+n+" .juiz_sps_counter"),_=document.querySelector(".juiz_sps_totalcount"),c=parseInt(e.data[2]);if(u)t.forEach(function(e){null!==e.querySelector(".juiz_sps_counter")&&(e.querySelector(".juiz_sps_counter").innerHTML=i(c))});else if("both"===r()||"subtotal"===r()){let d=document.createElement("span");d.classList.add("juiz_sps_counter"),d.textContent=i(c),t.forEach(function(e){e.prepend(d)})}_?document.querySelectorAll(".juiz_sps_totalcount").forEach(function(e){let t=e.querySelector(".juiz_sps_total_number"),s=t.getAttribute("data-nobs-raw-count");t.textContent=i(parseInt(s)+1),t.setAttribute("data-nobs-raw-count",parseInt(s)+1)}):"both"===r()||r()}}else console.warn($,$.status);if(o.href&&""!==o.href&&"#"!==o.href&&"mail"!==n&&"bookmark"!==n){if("_blank"===o.target){let p=document.createElement("a");p.href=o.href,p.target="_blank",p.id="nobs-temp",document.querySelector("body").prepend(p),document.getElementById("nobs-temp").click(),document.getElementById("nobs-temp").remove()}else document.location.href=o.href}else switch(n){case"bookmark":l(s);break;case"mail":a(s);break;case"print":window.print&&window.print();break;case"shareapi":break;default:console.log("Ooops")}},$.open("GET",jsps.ajax_url+t(_)),$.send(),!1})}),document.querySelector(".juiz_sps_link_mail")&&(document.querySelectorAll(".juiz_sps_link_mail"),a=function(e){if(e.preventDefault(),document.querySelector(".juiz-sps-modal"))return;let i=document.activeElement,r=e.target.closest(".juiz_sps_links").getAttribute("data-post-id"),a=''+jsps.modalEmailTitle+'
'+e.data+"
'+n.statusText+"("+n.status+")
",o=document.createElement("div");o.classList.add("juiz-sps-error"),o.classList.add("juiz-sps-message"),o.innerHTML=a,r.querySelector("form").append(o),l.classList.remove("is-active")}},n.open("GET",jsps.ajax_url+t(o)),n.send(),!1}),document.querySelector(".juiz-sps-close").addEventListener("click",function(){return o.setAttribute("aria-hidden","true"),o.classList.remove("jsps-modal-show"),i.focus(),temp=setInterval(function(){o.remove()},400),!1}),window.addEventListener("keyup",function(e){"Escape"===e.code&&document.querySelector('.juiz-sps-modal[aria-hidden="false"]')&&document.querySelector(".juiz-sps-close").click()}),document.querySelector(".juiz-sps-close").addEventListener("blur",function(){return this.closest(".juiz-sps-modal").querySelector("form > p:first-child input").focus(),!1}),!1}),!window.print&&document.querySelector(".juiz_sps_link_print")&&document.querySelectorAll(".juiz_sps_link_print").forEach(function(e){e.remove()}),"addToHomescreen"in window&&window.addToHomescreen.isCompatible||window.sidebar&&window.sidebar.addPanel||window.external&&"AddFavorite"in window.external||"undefined"==typeof chrome||"undefined"!=typeof chrome?l=function(e){e.preventDefault();let t=window.location.href,s=document.title;return"addToHomescreen"in window&&window.addToHomescreen.isCompatible?addToHomescreen({autostart:!1,startDelay:0}).show(!0):window.sidebar&&window.sidebar.addPanel?window.sidebar.addPanel(s,t,""):window.external&&"AddFavorite"in window.external?window.external.AddFavorite(t,s):(command=(/Mac/i.test(navigator.userAgent)?"Cmd":"Ctrl")+"+D",alert(message=(message=e.target.getAttribute("data-alert")||e.target.closest("a, button").getAttribute("data-alert")).replace(/%s/,command))),!1}:document.querySelector(".juiz_sps_link_bookmark")&&document.querySelectorAll(".juiz_sps_link_bookmark").forEach(function(e){e.remove()})});
\ No newline at end of file