Advertisement:

Author Topic: Dragmath in SMF 2.0? Help needed  (Read 3249 times)

Offline hefesto

  • Senior Translator
  • Jr. Member
  • *
  • Posts: 172
  • Beati Hispani quibus bibere vivere est
    • Isidrao on Facebook
    • isidrobaq on LinkedIn
    • @isidrobaq on Twitter
    • Joomgouts
Dragmath in SMF 2.0? Help needed
« on: August 29, 2008, 03:19:08 PM »
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)
Code: [Select]
// 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
Code: [Select]
// 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)
Code: [Select]
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
Code: [Select]
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...
« Last Edit: August 29, 2008, 04:41:31 PM by hefesto »

spearfish

  • Guest
Re: Dragmath in SMF 2.0? Help needed
« Reply #1 on: August 29, 2008, 04:27:56 PM »
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.

Offline hefesto

  • Senior Translator
  • Jr. Member
  • *
  • Posts: 172
  • Beati Hispani quibus bibere vivere est
    • Isidrao on Facebook
    • isidrobaq on LinkedIn
    • @isidrobaq on Twitter
    • Joomgouts
Re: Dragmath in SMF 2.0? Help needed
« Reply #2 on: August 29, 2008, 05:02:42 PM »
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:

Code: [Select]
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:

Code: [Select]
messageControl = document.forms..message;

for this line:

Code: [Select]
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):
Code: [Select]
<!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...
« Last Edit: August 29, 2008, 05:21:49 PM by hefesto »

Offline hefesto

  • Senior Translator
  • Jr. Member
  • *
  • Posts: 172
  • Beati Hispani quibus bibere vivere est
    • Isidrao on Facebook
    • isidrobaq on LinkedIn
    • @isidrobaq on Twitter
    • Joomgouts
Re: Dragmath in SMF 2.0? Help needed
« Reply #3 on: August 29, 2008, 09:16:51 PM »
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

Code: [Select]
messageControl = document.forms.', $context['post_form'], '.', $context['post_box_name'],';
by

Code: [Select]
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

  • Guest
Re: Dragmath in SMF 2.0? Help needed
« Reply #4 on: August 29, 2008, 10:38:24 PM »
Cool!  Glad you could get it working.

Offline bjraines

  • Full Member
  • ***
  • Posts: 549
Re: Dragmath in SMF 2.0? Help needed
« Reply #5 on: August 13, 2009, 04:28:30 PM »
do you still have a copy of these instructions i cannot find them.

Offline smartmouse

  • Full Member
  • ***
  • Posts: 549
Re: Dragmath in SMF 2.0? Help needed
« Reply #6 on: February 02, 2012, 07:01:00 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.