INCLUDEJS vs. script src

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Post Reply
RobiX
Registered User
Posts: 110
Joined: Thu Oct 05, 2017 9:59 am

INCLUDEJS vs. script src

Post by RobiX »

goal:
I wanna load javascript files within an extension and load the javasript before calling a function

variant 1 via includejs

Code: Select all

<!-- INCLUDEJS @mod_mod/myfileinclude.js?assets_version={T_ASSETS_VERSION} -->
variant 2 via script tag

Code: Select all

<script type="text/javascript" src="mylink/myfilescript.js"></script>
    <script>
     var input = document.getElementById('str');
     var colorHash = new functionA();
...
</script>
problems
variant 1:
+ file is within ext mod_mod
- file is (nearyly) included on the bottom of the outputfile. So it is after functionA and produces error message ReferenceError: functionA is not defined (i guess it is because the javascript isnt loaded before)

variant2
+ is included before the call of the function
+ It works
- i cant use @mod_mod

how can i use INCLUDEJS so that it is loaded before the call of the function?
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: INCLUDEJS vs. script src

Post by mrgoldy »

As far as I recall, you do not have to include the assets version with INCLUDEJS.

And you bind the functionA handle, to the event after the page/document has fully loaded.
For example:

Code: Select all

(function($) {

'use strict';

$(function() {

	$('#element1').on('click', functionA());
	
});

})(jQuery);
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
RobiX
Registered User
Posts: 110
Joined: Thu Oct 05, 2017 9:59 am

Re: INCLUDEJS vs. script src

Post by RobiX »

oh interesting solution will try it - tnx a lot
User avatar
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: INCLUDEJS vs. script src

Post by david63 »

Just a minor point.

Although technically it is the same but it is preferred that extensions use Jquery rather than javascript.
David
Remember: You only know what you know and - you don't know what you don't know!

I now no longer support any of my extensions but they will start to become available here
Post Reply

Return to “phpBB Custom Coding”