PHP Classes

File: public/assets/local/js/require.min.js

Recommend this page to a friend!
  Packages of Aby Dahana   Aksara   public/assets/local/js/require.min.js   Download  
File: public/assets/local/js/require.min.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Aksara
A CodeIgniter based API and CRUD generator
Author: By
Last change: Refine subscriber dashboard UI, update technical dashboard with videos, and change WhatsApp link to GitHub
Date: 22 days ago
Size: 2,202 bytes
 

Contents

Class file image Download
/** * A script library to import the javascript / css file on the fly * * @author Aby Dahana <abydahana@gmail.com> * @copyright (c) Aksara Laboratory <https://aksaracms.com> * @license MIT License * * This source file is subject to the MIT license that is bundled with this * source code in the LICENSE.txt file. */ "use strict"; // Track already-loaded sources to prevent duplicate loading let loaded_sources = []; let loading_sources = {}; // Track ongoing loads as Promises const require = (function() { return { js: async function(sources, callback) { if (typeof $ === 'undefined') { console.log('jQuery is required to use require.js()'); return; } if (!$.isArray(sources)) { sources = [sources]; } try { // Load each source sequentially for (const source of sources) { if (loading_sources[source]) { // Script is currently being loaded by another call ? wait for it await loading_sources[source]; } else if ($.inArray(source, loaded_sources) === -1) { // Script hasn't been loaded yet ? start loading it loading_sources[source] = $.getScript(source).then(function() { loaded_sources.push(source); delete loading_sources[source]; }); await loading_sources[source]; } // else: already loaded, just continue to next source } if (typeof callback === 'function') callback(); } catch (err) { console.error('[require.js] failed to load script:', err); } }, css: async function(sources, callback) { if (typeof $ === 'undefined') { console.log('jQuery is required to use require.css()'); return; } if (!$.isArray(sources)) { sources = [sources]; } sources.forEach(function(source) { if ($.inArray(source, loaded_sources) === -1) { loaded_sources.push(source); $(`<link rel="stylesheet" type="text/css" href="${source}" />`).appendTo('head'); } }); if (typeof callback === 'function') callback(); } }; })();