mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-26 02:57:45 +01:00
7a785704c0
- avoids a focus loss when clicking the "Copy site info" button - uses `setTimeout()` and `clearTimeout()` to properly handle the "Copied!" text - minor JavaScript coding standards Props audrasjb, Clorith, afercia. See #48463, #50335. Fixes #50322. Built from https://develop.svn.wordpress.org/trunk@48233 git-svn-id: http://core.svn.wordpress.org/trunk@48002 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2 lines
5.1 KiB
JavaScript
2 lines
5.1 KiB
JavaScript
/*! This file is auto-generated */
|
|
jQuery(document).ready(function(l){var e,a,t,s,i,r=wp.i18n.__,n=wp.i18n._n,c=wp.i18n.sprintf,h=new ClipboardJS(".site-health-copy-buttons .copy-button"),u=l(".health-check-body.health-check-debug-tab").length,o=l("#health-check-accordion-block-wp-paths-sizes");function d(e){var t,s,a=wp.template("health-check-issue"),i=l("#health-check-issues-"+e.status);SiteHealth.site_status.issues[e.status]++,s=SiteHealth.site_status.issues[e.status],"critical"===e.status?t=c(n("%s critical issue","%s critical issues",s),'<span class="issue-count">'+s+"</span>"):"recommended"===e.status?t=c(n("%s recommended improvement","%s recommended improvements",s),'<span class="issue-count">'+s+"</span>"):"good"===e.status&&(t=c(n("%s item with no issues detected","%s items with no issues detected",s),'<span class="issue-count">'+s+"</span>")),t&&l(".site-health-issue-count-title",i).html(t),l(".issues","#health-check-issues-"+e.status).append(a(e))}function p(){var e,t,s=l(".site-health-progress"),a=s.closest(".site-health-progress-wrapper"),i=l(".site-health-progress-label",a),n=l(".site-health-progress svg #bar"),c=parseInt(SiteHealth.site_status.issues.good,0)+parseInt(SiteHealth.site_status.issues.recommended,0)+1.5*parseInt(SiteHealth.site_status.issues.critical,0),h=.5*parseInt(SiteHealth.site_status.issues.recommended,0)+1.5*parseInt(SiteHealth.site_status.issues.critical,0),o=100-Math.ceil(h/c*100);0!==c?(a.removeClass("loading"),e=n.attr("r"),o<0&&(o=0),100<o&&(o=100),t=(100-o)/100*(Math.PI*(2*e)),n.css({strokeDashoffset:t}),parseInt(SiteHealth.site_status.issues.critical,0)<1&&l("#health-check-issues-critical").addClass("hidden"),parseInt(SiteHealth.site_status.issues.recommended,0)<1&&l("#health-check-issues-recommended").addClass("hidden"),80<=o&&0===parseInt(SiteHealth.site_status.issues.critical,0)?(a.addClass("green").removeClass("orange"),i.text(r("Good")),wp.a11y.speak(r("All site health tests have finished running. Your site is looking good, and the results are now available on the page."))):(a.addClass("orange").removeClass("green"),i.text(r("Should be improved")),wp.a11y.speak(r("All site health tests have finished running. There are items that should be addressed, and the results are now available on the page."))),u||(l.post(ajaxurl,{action:"health-check-site-status-result",_wpnonce:SiteHealth.nonce.site_status_result,counts:SiteHealth.site_status.issues}),100===o&&(l(".site-status-all-clear").removeClass("hide"),l(".site-status-has-issues").addClass("hide")))):s.addClass("hidden")}h.on("success",function(e){var t=l(e.trigger),s=l(".success",t.closest("div"));e.clearSelection(),t.focus(),clearTimeout(a),s.removeClass("hidden"),a=setTimeout(function(){s.addClass("hidden"),h.clipboardAction.fakeElem&&h.clipboardAction.removeFake&&h.clipboardAction.removeFake()},3e3),wp.a11y.speak(r("Site information has been copied to your clipboard."))}),l(".health-check-accordion").on("click",".health-check-accordion-trigger",function(){"true"===l(this).attr("aria-expanded")?(l(this).attr("aria-expanded","false"),l("#"+l(this).attr("aria-controls")).attr("hidden",!0)):(l(this).attr("aria-expanded","true"),l("#"+l(this).attr("aria-controls")).attr("hidden",!1))}),l(".site-health-view-passed").on("click",function(){var e=l("#health-check-issues-good");e.toggleClass("hidden"),l(this).attr("aria-expanded",!e.hasClass("hidden"))}),"undefined"==typeof SiteHealth||u||(0===SiteHealth.site_status.direct.length&&0===SiteHealth.site_status.async.length?p():SiteHealth.site_status.issues={good:0,recommended:0,critical:0},0<SiteHealth.site_status.direct.length&&l.each(SiteHealth.site_status.direct,function(){d(this)}),0<SiteHealth.site_status.async.length?(e={action:"health-check-"+SiteHealth.site_status.async[0].test.replace("_","-"),_wpnonce:SiteHealth.nonce.site_status},SiteHealth.site_status.async[0].completed=!0,l.post(ajaxurl,e,function(e){d(e.data),function t(){var s=!0;1<=SiteHealth.site_status.async.length&&l.each(SiteHealth.site_status.async,function(){var e={action:"health-check-"+this.test.replace("_","-"),_wpnonce:SiteHealth.nonce.site_status};return!!this.completed||(s=!1,this.completed=!0,l.post(ajaxurl,e,function(e){d(wp.hooks.applyFilters("site_status_test_result",e.data)),t()}),!1)}),s&&p()}()})):p()),u&&(o.length?(t={action:"health-check-get-sizes",_wpnonce:SiteHealth.nonce.site_status_result},s=(new Date).getTime(),i=window.setTimeout(function(){wp.a11y.speak(r("Please wait..."))},3e3),l.post({type:"POST",url:ajaxurl,data:t,dataType:"json"}).done(function(e){!function(i){var e=l("button.button.copy-button"),a=e.attr("data-clipboard-text");l.each(i,function(e,t){var s=t.debug||t.size;void 0!==s&&(a=a.replace(e+": loading...",e+": "+s))}),e.attr("data-clipboard-text",a),o.find("td[class]").each(function(e,t){var s=l(t),a=s.attr("class");i.hasOwnProperty(a)&&i[a].size&&s.text(i[a].size)})}(e.data||{})}).always(function(){var e=(new Date).getTime()-s;l(".health-check-wp-paths-sizes.spinner").css("visibility","hidden"),p(),3e3<e?(e=6e3<e?0:6500-e,window.setTimeout(function(){wp.a11y.speak(r("All site health tests have finished running."))},e)):window.clearTimeout(i),l(document).trigger("site-health-info-dirsizes-done")})):p())}); |