Plugin Directory

Changeset 2698925


Ignore:
Timestamp:
03/24/2022 12:31:57 PM (4 years ago)
Author:
pressmate
Message:

Fixed media library lodash conflict

File:
1 edited

Legend:

Unmodified
Added
Removed
  • makestories-helper/trunk/templates/editor.php

    r2481763 r2698925  
    2525    };
    2626    window.msWPConfig = msWPConfig;
     27    const isLodash = () => {
     28        let isLodash = false;
     29
     30        // If _ is defined and the function _.forEach exists then we know underscore OR lodash are in place
     31        if ( 'undefined' != typeof( _ ) && 'function' == typeof( _.forEach ) ) {
     32
     33            // A small sample of some of the functions that exist in lodash but not underscore
     34            const funcs = [ 'get', 'set', 'at', 'cloneDeep' ];
     35
     36            // Simplest if assume exists to start
     37            isLodash  = true;
     38
     39            funcs.forEach( function ( func ) {
     40                // If just one of the functions do not exist, then not lodash
     41                isLodash = ( 'function' != typeof( _[ func ] ) ) ? false : isLodash;
     42            } );
     43        }
     44
     45        if ( isLodash ) {
     46            // We know that lodash is loaded in the _ variable
     47            return true;
     48        } else {
     49            // We know that lodash is NOT loaded
     50            return false;
     51        }
     52    };
     53   
     54    $(document).ready(function(){
     55        if ( isLodash() ) {
     56            _.noConflict();
     57        }       
     58    });
    2759</script>
Note: See TracChangeset for help on using the changeset viewer.