I have 2 .js
files, the first is plugins.js
and, the second, ui.js
, and both are visible on the 'debug' of the inspector, so both are being included.
I have a jquery function in plugins.js
that I need to call on in ui.js
, so I enqueue plugins.js
first, and immediately beneath that I enqueue ui.js
.
However, the console in the web-browser tells me that the function isn't defined, and it doesn't work.
It works if I cut and paste the function from plugins.js
into ui.js
. It worked when I tried it in JSfiddle too.
functions.php
function add_scripts() {
wp_enqueue_script( 'plugins', get_template_directory_uri() . '/javascript/plugins.js', array( 'jquery', 'jquery-ui-core' ) , '1.0.0', true );
wp_enqueue_script( 'ui' , get_template_directory_uri() . '/javascript/ui.js' , array(), '1.0.0', true );
}
add_action('wp_enqueue_scripts', 'add_scripts');
plugins.js
:
jQuery(document).ready(function($) {
function PNGPreloader(e,t,i,r,n,a){...}
});
ui.js
:
jQuery(document).ready(function($) {
$(...).each(function(){
mobileIcons[ID] = new PNGPreloader($object,frames,size[0],size[1],20,false);
});
It works if I put the function from plugins.js
in ui.js
, :
jQuery(document).ready(function($) {
function PNGPreloader(e,t,i,r,n,a){...}
$(...).each(function(){
... = new PNGPreloader(...);
});