News:

Wondering if this will always be free?  See why free is better.

Main Menu

Dragmath in SMF 2.0? Help needed

Started by hefesto, August 29, 2008, 03:19:08 PM

Previous topic - Next topic

hefesto

I've followed step by step this instructions for inserting Dragmath support into my SMF 2.0 beta3.1public forum, but it doesn't seem to work.

The instructions are for SMF 1.1.x, and I had to change a few things. Instead of into post.templete.php, I inserted the code needed into GenericControls.template.php:

after this code (around line 33)

// I guess it's a divider...
elseif ($found_button)
{
echo '<img src="', $settings['images_url'], '/bbc/divider.gif" alt="|" style="margin: 0 3px 0 3px;" />';
$found_button = false;
}
}


I inserted this one

// now display a dragmath button
echo '
<a href="javascript:dragmath();">';
// Okay... we have the link. Now for the image and the closing </a>!
echo '<img onmouseover="bbc_highlight(this, true);" onmouseout="if (window.bbc_highlight) bbc_highlight(this, false);" src="', $settings['images_url'], '/bbc/dragmath.gif" align="bottom" width="23" height="22" alt="DragMath" title="DragMath" style="background-image: url(', $settings['images_url'], '/bbc/bbc_bg.gif); margin: 1px 2px 1px 1px;" /></a>';

// and then insert a bit of javascript to display the dragmath editor
echo '
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[

var dragmathWindow;
var messageControl;

function dragmath()
{
if(dragmathWindow)
dragmathWindow.close();

messageControl = document.forms.', $context['post_form'], '.', $context['post_box_name'],';

dragmathWindow = window.open("http://MyDomain/forum/dragmath.html", "create_maths", "toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,width=560,height=350,resizable=yes");
}

// ]]></script>';


The button appears, but whenever I press it I get two errors:

-bbc_highlight is not defined (additional information from firebug below)

onmouseover(mouseover clientX=478, clientY=341)index.ph...zJg%3D%3D (línea 2)
[Break on this error] bbc_highlight(this, true);


-XML descendants internal method called on incompatible HTMLCollection

dragmath()
javascript:dragmath();()()
messageControl = document.forms..message;


I have no idea about Javascript, but I think this can't be difficult to solve, as it probably will be a version issue. If I manage to get it to work I'll be pleased to try to make a mod from it...

spearfish

1) It's trying to use the function "bbc_highlight", but your JavaScript hasn't defined the function yet.  Was there any more code you inserted, or were supposed to insert?  Your instructions link is broken, so I can't check it out for myself.... were there multiple edits to Post.template.php, and you only skipped the last one?  Perhaps the function was defined in one of the earlier edits.
2) No idea.  I'm not too into JavaScript.

hefesto

#2
Oops! Sorry about the link. I have repaired it.

You're right. It might be a SMF 1.1 function. I searched a bit in the forums and added this immediately before the line that calls bbc_highlight:


echo '<script language="JavaScript" type="text/javascript">
                  function bbc_highlight(something, mode)
                  {
                     something.style.backgroundImage = "url(" + smf_images_url + (mode ? "/bbc/bbc_hoverbg.gif)" : "/bbc/bbc_bg.gif)");
                  }
               </script>';


The first error disappears  ;), but the second persists. If you look carefully, the browser returns this:


messageControl = document.forms..message;


for this line:


messageControl = document.forms.', $context['post_form'], '.', $context['post_box_name'],';


so most probably these two variables aren't correctly handled by the script. Any ideas?

EDIT:

All you have to do when everything has been edited is to upload Dragmath into your root smf folder, as well as this html file (called dragmath.html):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>"DragMath Equation Editor</title>
<link rel="stylesheet" href="dialog.css" type="text/css" />
<script type="text/javascript" src="popup.js"></script>
<script type="text/javascript">

function Init() {
}

function insert(text) {
  window.opener.replaceText(text, window.opener.messageControl);
  window.opener.focus();
  close();
  return false;
}

function cancel() {
  close();
  return false;
}

function getLatexAndInsert(){
    var mathExpression = document.dragmath.getMathExpression();
//
// TBD any massaging needed here?
//
var text = mathExpression;
//
// Escape the expression
//
var text = '[tex]' + text + '[/tex]';
insert(text);
}

</script>
</head>
<body onload="Init()">

<applet
name="dragmath"
codebase="http://YOURDOMAIN/forum/DragMath/applet/classes"
code="Display.MainApplet.class"
archive="Project.jar,AbsoluteLayout.jar,swing-layout-1.0.jar,jdom.jar,jep.jar"
width=540 height=300
>
<param name=language value="en">
<param name=outputFormat value="Latex">
<param name=showOutputToolBar value="false">
To use this page you need a Java-enabled browser.
Download the latest Java plug-in from
<a> href="http://www.java.com">Java.com</a>
</applet >
<form name="form">
<div>
<button type="button" onclick="return getLatexAndInsert();">Insert</button>
<button type="button" onclick="return cancel();">Cancel</button>
</div>
</form>

</body>
</html>


As you see, dragmath function is defined here, so I'd bet that the problem is what I suggested above...

hefesto

I've done it! Once I took a look at $context, I managed that, as I suspected, in SMF2.0 $context[post_form] doesn't exist. So I justy had to replace

messageControl = document.forms.', $context['post_form'], '.', $context['post_box_name'],';

by

messageControl = document.forms.postmodify.', $context['post_box_name'],';

It works like a charm  8). I'll try to package it in a few days as a mod  ;).

spearfish

Cool!  Glad you could get it working.

bjraines

do you still have a copy of these instructions i cannot find them.

smartmouse

Quote from: hefesto on August 29, 2008, 09:16:51 PM
I'll try to package it in a few days as a mod  ;)
Hello, can you help me with installing DragMath on SMF 2.0.2?
Thank you.

Advertisement: