1
marijun
javascript in admin head tags
  • 2005/3/9 11:20

  • marijun

  • Just popping in

  • Posts: 53

  • Since: 2004/6/4 1


potentially yet another dumb question ;)

i've got a couple javascripts i need to include in the head tags of an admin page (for a module). how the heck can i get em to load there? including them in the body is no good, they need to load in the head tags.

2
wtravel
Re: javascript in admin head tags

You can do a search for the function:

xoops_cp_header()

In that function you should be able to add the javascript to the header.

Regards,

Martijn

3
marijun
Re: javascript in admin head tags
  • 2005/3/11 23:16

  • marijun

  • Just popping in

  • Posts: 53

  • Since: 2004/6/4 1


Quote:

wtravel wrote:
You can do a search for the function:

xoops_cp_header()

In that function you should be able to add the javascript to the header.

Regards,

Martijn


excellent, thanks!

4
spiff
Re: javascript in admin head tags
  • 2005/3/22 17:01

  • spiff

  • Just popping in

  • Posts: 47

  • Since: 2003/4/16


I'm just now facing an issue related to this.

When you're developing a module for everyone's use and wish to include JavaScript in the HEAD, you don't want to make a change to the admin file itself.

I'm having a very long process to handle and wish to display a progress bar without page refresh, and hence am using JavaScript to do so.

In 2.0.9.2, xoops_cp_header() essentially hard-codes the HEAD data. I think the ability to add a JavaScript file in the HEAD would be useful, that would permit calls such as:

xoops_cp_header(); // For default
xoops_cp_header('/modulename/file.js'); // Adds a file
xoops_cp_header(array('/modulename/file1.js','/modulename/file2.js')); // Includes two, etc. files

This would make it possible to make modules more portable when they have to rely on some JavaScript operation.

Comments?
Eric

5
marijun
Re: javascript in admin head tags
  • 2005/3/22 17:10

  • marijun

  • Just popping in

  • Posts: 53

  • Since: 2004/6/4 1


absolutely!

to get everything working the way i needed it to, i had to copy both the cp_header.php and cp_functions.php files into my module admin area. not a good way to do things, by far. it was either that or make people edit the cp_functions file to use the module.

6
spiff
Re: javascript in admin head tags
  • 2005/3/26 1:35

  • spiff

  • Just popping in

  • Posts: 47

  • Since: 2003/4/16


I've just been hit by the obvious...

All that's needed is to set an output buffer, and then insert the script where appropriate!

So, for the subject dealt with here, first set up a function to insert the script (that's a barebone version, you can make it more fancy):
function insert_javascript($buffer) {
  
$jstags '.XOOPS_URL.'/modules/mycoolmodule/admin/file.js" type="text/javascript" language="javascript1.2">

'
;
  return 
str_replace('',"$jstags",$buffer);
}

Then wrap up the header and footer, like so:
ob_start('insert_javascript');
xoops_cp_header();
// html output goes here
xoops_cp_footer();
ob_end_flush();

7
marijun
Re: javascript in admin head tags
  • 2005/3/26 14:56

  • marijun

  • Just popping in

  • Posts: 53

  • Since: 2004/6/4 1


whoa! i'm definitely going to try that. if it really works, you should post that as a code snippet in the dev forge.

8
spiff
Re: javascript in admin head tags
  • 2005/3/26 15:51

  • spiff

  • Just popping in

  • Posts: 47

  • Since: 2003/4/16


Whaddya mean "if it really works"? I don't post code that ain't tested .

I got it to work on a XOOPS site on my laptop before submitting it here. Let us know how it goes, but there's no reason it shouldn't do the trick (unless you have conflicting tags).

9
marijun
Re: javascript in admin head tags
  • 2005/3/26 16:40

  • marijun

  • Just popping in

  • Posts: 53

  • Since: 2004/6/4 1


ah, i wasn't sure if you'd tested it or not ;)

good work, it works perfectly! included 2 javascripts and a stylesheet with no probs.

10
spiff
Re: javascript in admin head tags
  • 2005/3/26 20:27

  • spiff

  • Just popping in

  • Posts: 47

  • Since: 2003/4/16


Quote:
it works perfectly! included 2 javascripts and a stylesheet with no probs.

Yea!

Login

Who's Online

167 user(s) are online (143 user(s) are browsing Support Forums)


Members: 0


Guests: 167


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Dec 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits