Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2005-11-14 02:56:32

1beb
Plugin Author
From: Canada, Ontario, Toronto
Registered: 2004-11-22
Posts: 169
Website

Including js only if a function is called.

For example,

Let’s say I want javascript to be called into the head iff a specific plugin has been called to action. Is there a method for replacing what is in the head of the document?

And if so, how could I do this within the plugin code itself?

One idea that I had to accomplish this was to find n’ replace within the variable that pumps out the html of a specific page using the plugin. Is it possible? What variable would it be!

Offline

#2 2005-11-14 03:25:31

akokskis
Plugin Author
From: Baltimore-ish, USofA
Registered: 2004-11-28
Posts: 230
Website

Re: Including js only if a function is called.

Well, I’m not entirely sure how one would go about this, but one idea that strikes my mind would be to find and replace “/ head” (silly forum strips < & >) with the js and then close the head tag.

As far as implementing this though, I’m not really sure how you would do it. You might want to check out some of the admin plugins, which use DOM scripting.

I’m pretty sure it has something to do with the <code>register_callback()</code> function, but this is one that has eluded me thus far (although I haven’t really had any need for it, so…)

Last edited by akokskis (2005-11-14 03:26:50)


My Photoblog, and my personal site. Got nav? ako_nav.
Thanks for taking the time to look…

— vc3 —

Offline

#3 2005-11-14 04:01:33

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: Including js only if a function is called.

Output buffering.

if (txpinterface == 'public')
{
	ob_start('ext_yourplugin_load_js');
}

function ext_yourplugin_load_js($buffer)
{
	$find = '</head>';
	$replace = n.'<script type="text/javascript" src="script-url.js"></script>'.n.$find;

	return str_replace($find, $replace, $buffer);
}

Offline

#4 2005-11-14 05:58:16

1beb
Plugin Author
From: Canada, Ontario, Toronto
Registered: 2004-11-22
Posts: 169
Website

Re: Including js only if a function is called.

Ma ma ma Mary… I need some loving… ( album scratches ).

Thanks Mary!

/me runs to go try it now.

Offline

Board footer

Powered by FluxBB