Plugin Directory

Changeset 3375732


Ignore:
Timestamp:
10/09/2025 01:03:25 PM (6 months ago)
Author:
systemik
Message:

Adjust glycerine annotation template change

Location:
glycerine/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • glycerine/trunk/assets/js/annotation-cutouts.js

    r3367216 r3375732  
    6161    img.addEventListener("mouseover", (event) => {
    6262        let tooltipContent = ``;
    63         for (let key in annotationData.fields) {
    64             const capitalizedKey = key
     63        annotationData.fields.forEach((field) => {
     64            let key = field.field.name;
     65            let capitalizedKey = key
    6566                .replace(/_/g, " ")
    6667                .replace(/\b\w/g, (l) => l.toUpperCase());
    67             const rawValue = annotationData.fields[key]?.en?.values[0];
    68             let value = "";
    69 
    70             if (typeof rawValue === "object" && rawValue !== null) {
    71                 value =
    72                     rawValue.term_label ||
    73                     rawValue.label ||
    74                     rawValue.value ||
    75                     rawValue.url ||
    76                     JSON.stringify(rawValue);
    77             } else {
    78                 value = rawValue || "N/A";
    79             }
     68            let value = field.values.en ? field.values.en[0] : "";
    8069
    8170            tooltipContent += `<strong>${capitalizedKey}:</strong> ${value}<br>`;
    82         }
     71        });
     72
    8373        tooltip.innerHTML = tooltipContent;
    8474        tooltip.style.display = "block";
  • glycerine/trunk/glycerine.php

    r3367216 r3375732  
    104104    }
    105105
    106      if ((is_singular() && has_block('glycerine/annotation-cutouts')) || $force_enqueue) {
     106    if ((is_singular() && has_block('glycerine/annotation-cutouts')) || $force_enqueue) {
    107107
    108108        wp_enqueue_script(
     
    114114        );
    115115    }
    116 
    117116}
    118117add_action('wp_enqueue_scripts', 'glycerine_enqueue_assets');
     
    366365    }
    367366
    368     $annotationTitle = isset($attributes['annotationTitle']) ? $attributes['annotationTitle'] : null;
    369     $annotationDescription = isset($attributes['annotationDescription']) ? $attributes['annotationDescription'] : null;
     367    $annotationTitle = null;
     368    $annotationDescription = null;
     369    $annotationDataFields = isset($annotationData['fields']) ? $annotationData['fields'] : [];
     370    foreach ($annotationDataFields as $field) {
     371        if ($field['field']['name'] == 'Title' && isset($field['values']['en'])) {
     372            $annotationTitle = $field['values']['en'][0];
     373        }
     374
     375        if ($field['field']['name'] == 'Description' && isset($field['values']['en'])) {
     376            $annotationDescription = $field['values']['en'][0];
     377        }
     378    }
    370379
    371380    // Prevent rendering inside the block editor
  • glycerine/trunk/includes/annotation-table.php

    r3367216 r3375732  
    8383                                    break;
    8484                                case 'Tags':
    85                                     if (!empty($annotation['fields']['tag']['en']['values']) && is_array($annotation['fields']['tag']['en']['values'])) {
    86                                         foreach ($annotation['fields']['tag']['en']['values'] as $tag) {
     85                                    if (!empty($annotation['tags']) && is_array($annotation['tags'])) {
     86                                        foreach ($annotation['tags'] as $tag) {
    8787                                            $value = $tag['term_label'] ?? '';
    8888                                            if (!empty($value)) {
     
    159159                                    break;
    160160                                case 'Title':
    161                                     echo esc_html($annotation['fields']['title']['en']['values'][0] ?? '');
     161                                    foreach ($annotation['fields'] as $field) {
     162                                        if ($field['field']['name'] == 'Title' && isset($field['values']['en'])) {
     163                                            echo esc_html($field['values']['en'][0] ?? '') ;
     164                                            break;
     165                                        }
     166                                    }
    162167                                    break;
    163168                                case 'Description':
    164                                     echo esc_html($annotation['fields']['description']['en']['values'][0] ?? '');
     169                                    foreach ($annotation['fields'] as $field) {
     170                                        if ($field['field']['name'] == 'Description' && isset($field['values']['en'])) {
     171                                            echo esc_html($field['values']['en'][0] ?? '') ;
     172                                            break;
     173                                        }
     174                                    }
    165175                                    break;
    166176                                case 'Notes':
    167                                     echo esc_html($annotation['fields']['note']['en']['values'][0] ?? '');
     177                                    foreach ($annotation['fields'] as $field) {
     178                                        if ($field['field']['name'] == 'Note' && isset($field['values']['en'])) {
     179                                            echo esc_html($field['values']['en'][0] ?? '') ;
     180                                            break;
     181                                        }
     182                                    }
    168183                                    break;
    169184                                case 'Tags':
    170                                     if (!empty($annotation['fields']['tag']['en']['values']) && is_array($annotation['fields']['tag']['en']['values'])) {
    171                                         foreach ($annotation['fields']['tag']['en']['values'] as $tag) {
     185                                    if (!empty($annotation['tags']) && is_array($annotation['tags'])) {
     186                                        foreach ($annotation['tags'] as $tag) {
    172187                                            $tag_label = $tag['term_label'] ?? '';
    173188                                            if (!empty($tag_label)) {
Note: See TracChangeset for help on using the changeset viewer.