GRAYBYTE WORDPRESS FILE MANAGER6844

Server IP : 198.54.121.189 / Your IP : 216.73.216.140
System : Linux premium69.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
PHP Version : 7.4.33
Disable Function : NONE
cURL : ON | WGET : ON | Sudo : OFF | Pkexec : OFF
Directory : /home/giriqfky/trustyourlawyer.com/wp-content/plugins/essential-blocks/src/helpers/
Upload Files :
Current_dir [ Writeable ] Document_root [ Writeable ]

Command :


Current File : /home/giriqfky/trustyourlawyer.com/wp-content/plugins/essential-blocks/src/helpers//LoadAssets.js
/**
 * WordPress dependencies
 */
import apiFetch from '@wordpress/api-fetch';

/**
 * Load an asset for a block.
 *
 * This function returns a Promise that will resolve once the asset is loaded,
 * or in the case of Stylesheets and Inline JavaScript, will resolve immediately.
 *
 * @param {HTMLElement} el A HTML Element asset to inject.
 *
 * @return {Promise} Promise which will resolve when the asset is loaded.
 */
export const LoadAsset = (el) => {
    return new Promise((resolve, reject) => {
        /*
         * Reconstruct the passed element, this is required as inserting the Node directly
         * won't always fire the required onload events, even if the asset wasn't already loaded.
         */
        const newNode = document.createElement(el.nodeName);

        ['id', 'rel', 'src', 'href', 'type'].forEach((attr) => {
            if (el[attr]) {
                newNode[attr] = el[attr];
            }
        });

        // Append inline <script> contents.
        if (el.innerHTML) {
            newNode.appendChild(document.createTextNode(el.innerHTML));
        }

        newNode.onload = () => resolve(true);
        newNode.onerror = () => reject(new Error('Error loading asset.'));

        document.body.appendChild(newNode);

        // Resolve Stylesheets and Inline JavaScript immediately.
        if (
            'link' === newNode.nodeName.toLowerCase() ||
            ('script' === newNode.nodeName.toLowerCase() && !newNode.src)
        ) {
            resolve();
        }
    });
};

/**
 * Load the asset files for a block
 */
export async function LoadAssets() {
    /*
     * Fetch the current URL (post-new.php, or post.php?post=1&action=edit) and compare the
     * JavaScript and CSS assets loaded between the pages. This imports the required assets
     * for the block into the current page while not requiring that we know them up-front.
     * In the future this can be improved by reliance upon block.json and/or a script-loader
     * dependency API.
     */
    const response = await apiFetch({
        url: document.location.href,
        parse: false,
    });

    const data = await response.text();

    const doc = new window.DOMParser().parseFromString(data, 'text/html');
    const oldAssets = [
        // load block categories
        'wp-blocks-js-after',
        // woocommerce blocks
        'essential-blocks-blocks-localize-js-extra',
        'elementor-editor-js-before',
    ];

    const newAssets = Array.from(
        doc.querySelectorAll('link[rel="stylesheet"],script')
    ).filter((asset) => asset.id && (oldAssets.includes(asset.id) || !document.getElementById(asset.id)));

    /*
     * Load each asset in order, as they may depend upon an earlier loaded script.
     * Stylesheets and Inline Scripts will resolve immediately upon insertion.
     */
    for (const newAsset of newAssets) {
        await LoadAsset(newAsset);
    }
}

[ Back ]
Name
Size
Last Modified
Owner / Group
Permissions
Options
..
--
July 10 2025 04:32:24
giriqfky / giriqfky
0755
.htaccess
0.41 KB
July 10 2025 04:32:25
giriqfky / giriqfky
0644
LoadAssets.js
2.848 KB
August 27 2024 16:37:06
giriqfky / giriqfky
0644
fetch.js
3.166 KB
February 26 2025 16:22:10
giriqfky / giriqfky
0644
helpers.js
6.286 KB
September 03 2024 16:13:22
giriqfky / giriqfky
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2025
CONTACT ME
Static GIF