Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dispatchers/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,10 @@ public function enqueue_assets() {
// Only load if the wp-admin bar is visible.
if ( is_admin_bar_showing() ) {
wp_enqueue_script(
'web-vitals',
'qm-web-vitals',
$this->qm->plugin_url( 'assets/web-vitals.js' ),
array(),
QM_VERSION,
'3.3.2',
true
);
}
Expand Down
16 changes: 15 additions & 1 deletion output/html/web_vitals.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ public function name() {
* @return void
*/
public function output() {
if ( ! wp_script_is( 'qm-web-vitals', 'enqueued' ) && ! wp_script_is( 'qm-web-vitals', 'done' ) ) {
$this->before_non_tabular_output();
/* translators: %s: Script handle. */
$notice = sprintf( __( 'Script %s is not available.', 'query-monitor' ), 'qm-web-vitals' );
echo $this->build_notice( $notice );
$this->after_non_tabular_output();
return;
}

$this->before_tabular_output();
echo '<thead>';

Expand All @@ -47,19 +56,24 @@ public function output() {
echo '</thead>';

echo '<tbody id="qm-web-vitals-inner">';
echo '<tr class="waiting">';
echo '<td colspan="4">';
echo '<div class="qm-none"><p>Waiting for data...</p></div>';
echo '</td>';
echo '</tr>';
echo '</tbody>';

$this->after_tabular_output();
echo '<script>
// Insert the web vital into the qm-web-vitals div.
function insertWebVital( webVital ) {
console.log( { webVital } );
var webVitalsDiv = document.getElementById( "qm-web-vitals-inner" );
var divToAdd = document.createElement("tr");
divToAdd.innerHTML = "<td>" + webVital.name + "</td>" +
"<td>" + webVital.value + "</td>" +
"<td>" + webVital.rating + "</td>" +
"<td><pre class=\"qm-pre-wrap\"><code>" + JSON.stringify( webVital ) + "</code></pre></td>";
webVitalsDiv.querySelector( ".waiting" )?.remove();
webVitalsDiv.appendChild( divToAdd );
}

Expand Down