Making WordPress.org

Changeset 12784


Ignore:
Timestamp:
08/01/2023 10:41:25 PM (3 years ago)
Author:
coffee2code
Message:

Photo Directory, Admin JS: Prevent some JS warnings/errors when run in other contexts.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/photo-directory/assets/js/admin.js

    r12781 r12784  
    1919    // Hide 'Orientations' metabox when a value is assigned.
    2020    //  Orientation shouldn't need direct assignment or changing, so don't show it (as long as a value was set).
    21     const orientation_value = document.querySelector('input[name="tax_input[photo_orientation][]"]:checked' );
    22     if ( orientation_value ) {
    23         document.getElementById('photo_orientationdiv').hidden = true;
     21    const orientationValue = document.querySelector('input[name="tax_input[photo_orientation][]"]:checked' );
     22    const orientationDiv = document.getElementById('photo_orientationdiv');
     23    if ( orientationValue && orientationDiv ) {
     24        orientationDiv.hidden = true;
    2425    }
    2526
     
    6061
    6162        // The tag list is handled differently. Re-determine as tags are added/removed.
    62         if (element[3]) {
     63        const tagList = element[3] ? document.querySelector(element[3]) : null;
     64        if (tagList) {
    6365            const observer = new MutationObserver(function(mutations_list) {
    6466                mutations_list.forEach(function(mutation) {
     
    6971            });
    7072
    71             observer.observe(document.querySelector(element[3]), { subtree: false, childList: true });
     73            observer.observe(tagList, { subtree: false, childList: true });
    7274        }
    7375    });
     
    9698        // If tagListClass is present, see if it has any values if one not already found.
    9799        if (!value && tagListClass) {
    98             value = document.querySelector(tagListClass).hasChildNodes();
     100            value = document.querySelector(tagListClass)?.hasChildNodes();
    99101        }
    100102
Note: See TracChangeset for help on using the changeset viewer.