Not logged in. · Lost password · Register
Forum: Customising UNB Modifications and plug-ins RSS
[Solved] Include a Javascript file within a plugin without a templatee
Pompei2 #1
Member since Mar 2010 · 17 posts
Group memberships: Members
Show profile · Link to this post
Subject: [Solved] Include a Javascript file within a plugin without a templatee
Hi,

I'm writing a plugin that creates a new ABBC tag. This tag needs javascript - a lot (jQuery & co). Currently, I was not able to include a javascript file from within my plugin. I tried with UnbRequireJs but it does not seem to do anything. Rather, when used in global-scope, it said that this function does not exist, but when used inside a function, it did not produce an error but did not include the js file either.

How to go about this? I don't want to hack around other files than my plugin's files but I need to have a javascript file included in any shown page.

Edit: I may insert the js code directly into my tag's php output, but that is harakiri as the js code includes jQuery, which contains a lot of ' and " things.....
Pompei2 #2
Member since Mar 2010 · 17 posts
Group memberships: Members
Show profile · Link to this post
Sorry to answer myself, seems you deactivated post editing after x minutes.

I just found
{$headCustom}{-- this comes from plug-ins}
and the similar lines, I think I'll find the solution myself very soon, I will of course post it here as soon as I got it. Still, if you read this and I didn't come to a solution yet, I'd appreciate your help.
Pompei2 #3
Member since Mar 2010 · 17 posts
Group memberships: Members
Show profile · Link to this post
I've got it sorted. Here is my solution for reference:
  1. function UnbHookUploadGalleryAddheader(&$data)
  2. {
  3.     $data = '
  4. <script type="text/javascript" src="unb_lib/plugins/uploadgallery.jquery.min.js"></script>
  5. <script type="text/javascript" src="unb_lib/plugins/uploadgallery.piroBox.1_2_min.en.js"></script>
  6. <script type="text/javascript" src="unb_lib/plugins/uploadgallery.piroBoxSetup.js"></script>
  7. ';
  8.  
  9.     return true;
  10. }
  11.  
  12. UnbRegisterHook('page.htmlhead', 'UnbHookUploadGalleryAddheader');
Two last questions:
  • what is supposed to be the best place for a plugin's javascript that is design-independent? Probably not designs/*/js ? Would I just put them into the plugins folder?
  • Can I add or you a "Solved" to my first post's subject?
This post was edited on 2010-03-06, 12:10 by Pompei2.
Avatar
Yves (Administrator) #4
User title: UNB developer & webmaster
Member since Jan 2004 · 3814 posts · Location: Erlangen, Germany
Group memberships: Administrators, Members
Show profile · Link to this post
UnbRequireJs returns the piece of HTML code to include that JavaScript file. When called from a template, it results in the insertion of the <script> code into the template output. There is no collect&insert thing like for UnbRequireCss. So you cannot use UnbRequireJs from anywhere else than templates, except that you use its return value in a way you did then.

I haven't thought about such a default directory for plug-in JavaScript files yet. Maybe the plug-in directory would be a reasonable place, if it's not too many resource files and there's no .htaccess restriction on that directory. For multiple files, you could create a separate directory under unb_lib/plugins/ to store all of your additional plug-in files (except the plug-in code file).
♪ ...nanananah, all in all we’re just brilliant thieves, nanananah... ♪♬
Pompei2 #5
Member since Mar 2010 · 17 posts
Group memberships: Members
Show profile · Link to this post
Ohh I see, that makes sense.

Good idea for the subdirectory in the plugins directory.
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
This board is powered by the Unclassified NewsBoard software, 20110527-dev, © 2003-2011 by Yves Goergen
Page created in 200.5 ms (99.8 ms) · 62 database queries in 132.9 ms
Current time: 2012-02-07, 20:21:48 (UTC +01:00)