How do I enable javascript in SMF on all pages and actions?

Started by amlucent, May 24, 2009, 12:26:20 AM

Previous topic - Next topic

amlucent

I have a bug in my mod GWBBCODE.

Heres the bug, I figure it cant hurt to include it maybe I will get lucky and someone might read it that knows.  The mod only displays correctly when the first news line item is displayed on a page.  I mean that if a theme is used with no news line item then the mod does not display correctly, if there are multiple news line items it will only display correctly on the first.   The mod displays correctly on polls.. regardless of smf news being present.

I believe that javascript is not loaded in SMF except for on polls and the first news line.  I need to get javascript enabled everywhere.. not just polls and when the first news item is displayed.

here is what I believe to be the code that calls javascript in polls:



// Takes care of voting - don't worry, this is done automatically.
function ssi_pollVote()
{
global $context, $db_prefix, $user_info, $sc, $smcFunc, $sourcedir, $modSettings;

if (!isset($_POST[$context['session_var']]) || $_POST[$context['session_var']] != $sc || empty($_POST['options']) || !isset($_POST['poll']))
{
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
history.go(-1);
// ]]></script>
</head>
<body>&laquo;</body>
</html>';
return;
}



couldnt I just insert this calling of javascript into the themes header?

amlucent


amlucent

bump x2.. maybe I am not phrasing things correctly.  If anyone needs more info pls let me know.

M-DVD


amlucent

Quote from: M-DVD on June 01, 2009, 11:30:29 PM
Can you give a sample URL where the MOD don't work?

Just keep refreshing the page until you have seen both news lines.

http://gwplayers.com/smf2/index.php?topic=4.0

as you can see the skill popups display when news line #1 is displayed but when news line #2 is displayed you get no pop up.  I believe that javascript is only loaded when the first news line is displayed.



But when gwbbcode is shown in a thread with a poll it will always display regardless of any news lines present.  I think this is because the poll causes javascript to be enabled on the page.  Here is an example thread with a poll:

http://gwplayers.com/smf2/index.php?topic=3.0

M-DVD

In the index.temaplte.php, in the header, put

echo '
<script type="text/javascript">
if (!GWBBCODE_HOOK) {
var GWBBCODE_HOOK = true;
var gwbb_dynamic_url = \'gwbbcode\';

/* Include the overDiv div */
var overdiv_div = document.createElement(\'div\');
overdiv_div.id = \'overDiv\';
document.body.insertBefore(overdiv_div, document.body.firstChild);

/* Include the send iframe for the pickup feature */
var send_frame = document.createElement(\'iframe\');
send_frame.id = \'send\';
send_frame.style.display = \'none\';
send_frame.src = \'about:blank\';
document.body.insertBefore(send_frame, document.body.firstChild);

/* Include the gwbbcode.css */
var headID = document.getElementsByTagName("head")[0];         
var cssNode = document.createElement(\'link\');
cssNode.type = \'text/css\';
cssNode.rel = \'stylesheet\';
cssNode.href = \'gwbbcode/gwbbcode.css\';
cssNode.media = \'screen\';
headID.appendChild(cssNode);

/* Include overlib.js */
var include_overlib = document.createElement(\'script\');
include_overlib.type = \'text/javascript\';
include_overlib.src = \'gwbbcode/overlib.js\';
document.body.insertBefore(include_overlib, document.body.firstChild);

/* Include gwbbcode.js */
var include_gwbbcode = document.createElement(\'script\');
include_gwbbcode.type = \'text/javascript\';
include_gwbbcode.src = \'gwbbcode/gwbbcode.js\';
document.body.insertBefore(include_gwbbcode, document.body.firstChild);
}
</script>';


And try.

Work fine? (It should work fine in all the cases. Where before work fine, now this code will be duplicated).
Then try, deleted (one by one) this changes of your package.

<file name="$sourcedir/Subs.php">
<operation>
<search position="before"><![CDATA[cache_put_data($cache_key, $message, 240);]]></search>
<add><![CDATA[

// Add gwbbcode mod

global $boarddir;
include($boarddir . '/gwbbcode/gwbbcode.php');]]></add>
</operation>
</file>

<file name="$themedir/index.template.php">
<operation>
<search position="before"><![CDATA[<body>';]]></search>
<add><![CDATA[

// Dont forget gwbbcode mod

global $boarddir;
echo include($boarddir . '/gwbbcode/body.php');]]></add>
</operation>
</file>

<file name="$themedir/index.template.php">
<operation>
<search position="before"><![CDATA[<link rel="index" href="', $scripturl, '?board=', $context['current_board'], '.0" />';]]></search>
<add><![CDATA[

// Make sure we add gwbbcode here

global $boarddir;
echo include($boarddir . '/gwbbcode/header.php');]]></add>
</operation>
</file>


amlucent

OMG!!!  You have fixed it!  Its amazing! MDVD..  I LOVE U.  In fact now I only need 2 file edits, the one you supplied me in the header and the one existing inside of Subs.php.  I can get rid of the others!

Thank you, thank you, thank you!

M-DVD

Your welcome.

Also, you can try put all this code:


if (!GWBBCODE_HOOK) {
var GWBBCODE_HOOK = true;
var gwbb_dynamic_url = 'gwbbcode';

/* Include the overDiv div */
var overdiv_div = document.createElement('div');
overdiv_div.id = 'overDiv';
document.body.insertBefore(overdiv_div, document.body.firstChild);
   
/* Include the send iframe for the pickup feature */
var send_frame = document.createElement('iframe');
send_frame.id = 'send';
send_frame.style.display = 'none';
send_frame.src = 'about:blank';
document.body.insertBefore(send_frame, document.body.firstChild);
   
/* Include the gwbbcode.css */
var headID = document.getElementsByTagName("head")[0];    
var cssNode = document.createElement('link');
cssNode.type = 'text/css';
cssNode.rel = 'stylesheet';
cssNode.href = 'gwbbcode/gwbbcode.css';
cssNode.media = 'screen';
headID.appendChild(cssNode);

/* Include overlib.js */
var include_overlib = document.createElement('script');
include_overlib.type = 'text/javascript';
include_overlib.src = 'gwbbcode/overlib.js';
document.body.insertBefore(include_overlib, document.body.firstChild);
   
/* Include gwbbcode.js */
var include_gwbbcode = document.createElement('script');
include_gwbbcode.type = 'text/javascript';
include_gwbbcode.src = 'gwbbcode/gwbbcode.js';
document.body.insertBefore(include_gwbbcode, document.body.firstChild);
}


In a file .js (for example bbc_gwbbcode_mod.js), and use in the index.template:

<script language="JavaScript" type="text/javascript" src="blablabla/bbc_gwbbcode_mod.js?blabla"></script>

Advertisement: