Code help -newbie adding button to template -Spell Check / phpSpell

Started by Dove, April 27, 2004, 12:32:53 PM

Previous topic - Next topic

Dove

Hello,

     I am trying to use a different Spell Checker, since Pspell is
not an option for me.  I have everything set with the database
and the dictionary is loaded.  I just need to add 2 things to
the template.

This is what I need, and I'm not sure which template & where in
the template to edit.
----

You will need to modify the HTML in which ever program you use and add the following javascript & button:


   <script language='javascript' src='spelling/spellmessage.js'></script>
   <input type="button" class="" value="Spell Check" onclick="openspell();">

Any help is appreciated.

[Unknown]

Please try replacing the single quotes (') with doubles quotes (") or escaped quotes (\').

You'll want to add it to the Post template.  Search for <input type="submit".

-[Unknown]

Dove

#2
Thank you for leading me in the right direction! 

This is what worked (the double quotes like you said):
<script language="Javascript" src="spelling/spellmessage.js"></script>

and this for the button:
<input type="button" class="button" name="spellcheck" value="SpellCheck" accesskey="p" tabindex="4" onclick="openspell();"/>';

I now have a working spellcheck, I am soooo happy!!

If anyone would like the link to the software (it's free),
and uses a table in your mysql database for the dictionary,
I could post the link.  Right now they only offer English, &
Russian.  It's an alternative to the great spell check offered
here.
 
In fact I would like to send this to the company so they
could support it, since they already support 4 other boards,
why not this one?  Would that be ok?

Thanks Again!



[Unknown]

It would be great if you could write a package to install the spell checker ;).

I can help you do that ;).

-[Unknown]

Springer


Dove

LOL ... there is newbie in the topic up there ^

There is an installer already - sort of.  What they do is
give you instructions for a specific board, and since there wasn't
one for "SMF," I had to use the general MySQL based board
(Native MySQL) instructions.

Here is the link to the software, so you could see what I mean:

http://www.master-technology.com/demos/spell/download.php [nofollow]

What I was going to do was send them what I changed so they
could make an instruction sheet for a SMF board, and hopefully
they would use it.   Maybe you want to look at what I changed, &
check it before I send it, if you have time.  If you want to make
an installer of some kind, I will definitely send it to them.

Where I added the javascript and button:
Open post.template.php in themes/default
Find around line 350:

<td align="center" colspan="2">', !empty($settings['additional_options_collapsable']) ? '
<script language="JavaScript" type="text/javascript"><!--

Change to:

<td align="center" colspan="2">', !empty($settings['additional_options_collapsable']) ? '
<script language="Javascript" src="spelling/spellmessage.js"></script>
<script language="JavaScript" type="text/javascript"><!--


Find around line 356:

<input type="submit" name="preview" value="' . $txt[507] . '" onclick="return submitThisOnce(this);" accesskey="p" tabindex="4" />';

Change to:

<input type="submit" name="preview" value="' . $txt[507] . '" onclick="return submitThisOnce(this);" accesskey="p" tabindex="4" />
<input type="button" class="button" name="spellcheck" value="SpellCheck" accesskey="p" tabindex="4" onclick="openspell();"/>';


Open spellmessage.js (they give you this file):
Find:

function openspell()
        {
          height = 391;
          width = 555;
          if (ie4) LinkToField = self.post.message;
          if (gecko) {
            LinkToField = parent.document.post.message;
            height = height + 6;
          }


Change to:

function openspell()
        {
          height = 391;
          width = 555;
          if (ie4) LinkToField = self.postmodify.message;
          if (gecko) {
            LinkToField = parent.document.postmodify.message;
            height = height + 6;
          }


It works great.  Thanks again for your help.



oscar2001

Sorry for dragging up a old post but I became interested in this option since Pspell isnt a option for me either.

I applied this mod to a newly installed test forum (the newest RC2) and it works ok (even though the coding for the post.template.php is different to when dove first posted this) but after applying it in the same way to my working forum it wont function. The java script wont pop up and I get a error in internet explorer staing there there is a error on that page.

Here is the way I did it
Here is where I added the <script language="Javascript" src="spelling/spellmessage.js"></script>
<td align="center" colspan="2">';
if (!empty($settings['additional_options_collapsable']) && empty($context['attached']))
echo '
                                    <script language="Javascript" src="spelling/spellmessage.js"></script>
<script language="JavaScript" type="text/javascript"><!--
swapOptions();
// --></script>';


Heres where I added the <input type="button" class="button" name="spellcheck" value="SpellCheck" accesskey="p" tabindex="4" onclick="openspell();"/>';

<input type="submit" name="preview" value="', $txt[507], '" onclick="return (!document.postmodify.attachmentPreview.value || confirm(\'' . $txt['attach_lose'] . '\')) &amp;&amp; submitThisOnce(this);" accesskey="p" tabindex="4" />
                                    <input type="button" class="button" name="spellcheck" value="SpellCheck" accesskey="p" tabindex="4" onclick="openspell();"/>';


I thought possibly a "solve topic" mod by grudge might be affecting it so I uninstalled it but I still get the same.

I have dummy testing account on both forums if anyone wants to take a look and try the spell check.
username tester
pass   tester

This is the testing forum it works on
http://www.worldcichlids.com/smf2 (freshly installed forum)

this is the main working forum which I get the error

http://www.worldcichlids.com/yabbse (forum that has been from the old various versions of yabbse to various versions to the newest verion of smf)

Any help would be greatly appreciated :)


Oldiesmann

#7
You forgot to put this in Post.template.php:

<script type="text/javascript" langauge="JavaScript" src="spellmessage.js"></script>

Add that somewhere inside one of the echo statements (doesn't really matter where as long as it's before that input line) and it should work fine. That "error on page" thing is IE's way of telling you there is (are) javascript error(s) on that page (in this case, the openSpell() function is undefined).
Michael Eshom
Christian Metal Fans

oscar2001

isnt that basicly the same as <script language="Javascript" src="spelling/spellmessage.js"></script> which I  already added here


<td align="center" colspan="2">';
if (!empty($settings['additional_options_collapsable']) && empty($context['attached']))
echo '
                                    [font=Verdana]script language="Javascript" src="spelling/spellmessage.js"></script>[/font]
<script language="JavaScript" type="text/javascript"><!--
swapOptions();
// --></script


You got me thinking though with the idea of placing it elswhere, so I added it here and it now works
echo '
                                    <script language="Javascript" src="spelling/spellmessage.js"></script>   
<span class="smalltext"><br />', $txt['smf16'], '</span><br />
<input type="submit" name="post" value="', $context['submit_label'], '" onclick="return submitThisOnce(this);" accesskey="s" tabindex="3" />
<input type="submit" name="preview" value="', $txt[507], '" onclick="return (!document.postmodify.attachmentPreview.value || confirm(\'' . $txt['attach_lose'] . '\')) &amp;&amp; submitThisOnce(this);" accesskey="p" tabindex="4" />
                                    <input type="button" class="button" name="spellcheck" value="SpellCheck" accesskey="p" tabindex="4" onclick="openspell();"/>';



Thanks :)

[Unknown]

Hmm, interesting.  How well does this spell checking work, anyway?

Perhaps someone wants (I'm saying this again..) to create a full-fledged package to make this available to even PHP illiterate people?

-[Unknown]

oscar2001

#10
Seems to work pretty well, while I still have my test forum up anyone can try it using the tester account, http://www.worldcichlids.com/smf2

EDIT: Fixed link - Oldiesmann

Oldiesmann

Does seem to work pretty well. Nice little interface there too.
Michael Eshom
Christian Metal Fans

Jack.R.Abbit™

Javascript error using Opera 7.54:
QuoteEvent thread: onclick
Error:
name: TypeError
message: Statement on line 40: Expression evaluated to null or undefined and is not convertible to Object: LinkToField
Backtrace:
  Line 40 of linked script http://www.worldcichlids.com/smf2/spelling/spellmessage.js
    if (LinkToField.value.length == 0)
  In unknown script
    openspell();
  At unknown location
    {event handler trampoline}

Oldiesmann

Looks like they weren't paying attention...

This is the line to determine whether or not you're using opera 7:

        var op7=(navigator.userAgent.indexOf('Opera/7') > -1) ? 1 : (navigator.userAgent.indexOf('Opera 7') > -1) ? 1:0;

I wouldn't think that could mess things up, but it might...
Michael Eshom
Christian Metal Fans

[Unknown]

Why not just use document.postmodify instead of this document.forms[0] crap?  That works in Opera too...

I just messed with it, but it seems like this would be a lot more cross browser:
// --------------------------------------------------------------------
// phpSpell Javascript (For the SMF Message Document)
//
// This is (c)Copyright 2003, Team phpSpell.
// --------------------------------------------------------------------
        var LinkToField;

        function openspell()
        {
          height = 391;
          width = 555;

          if (navigator.userAgent.indexOf('Gecko') > -1 || navigator.userAgent.indexOf('Safari') > -1)
            height = height + 6;

          if (navigator.userAgent.indexOf('Opera/6') > -1)
          {
            height = height + 10;
            width = width + 10;
          }

          if (typeof(parent.document.postmodify.message) == "undefined")
            alert("Sorry, phpSpell only supports the following browsers:\nOpera 6+, Netscape 6+, Mozilla 1+, Internet Explorer 4+, Safari");
          else
          {
            LinkToField = parent.document.postmodify.message;
            if (LinkToField.value.length == 0) return;

            directory = penspell.arguments.length == 1 ? "" : "spelling/";
            win1=window.open(directory+"phpSpell.html","spellcheckwin",'resizable=no,width='+width+',height='+height);
            if (win1.opener == null) win1.opener = self;
          }

          return false;
        }

        function Opera_Get_Link()
        {
          return LinkToField;
        }


-[Unknown]

Dove

This worked :) except for an itsy bitsy typo where it says:

penspell

should be

openspell

;)

Dove

Quote from: [Unknown] on November 01, 2004, 02:16:27 AM
Hmm, interesting.  How well does this spell checking work, anyway?

Perhaps someone wants (I'm saying this again..) to create a full-fledged package to make this available to even PHP illiterate people?

-[Unknown]

I wouldn't mind doing this, except I am not sure how to go about it.
I am concerned about copyrights (the re-distributing their files part-
if there is any...).
Should I just offer the "smf" edited code files for download, or attach
them here or something with an install for SMF specific instructions?

- DoVe




Dove

I am going to reply to my own post, since I have heard from the
owner of Pspell.  He is going to add SMF to his official distribution
of this as soon as I send him the edited files (or the code on how
to edit them).

Presently this script supports:

  PHPBB v2.0x
  HiveMail 1.2
  Invision 1.1x
  phpNuke 6.5
  pSpell (php module)
  phpMail 1.x
  VBulletian
  Native MySQL interface

..... and hopefully soon SMF will be on there. :)

icegator

Has anyone successfully intergrated this spell checker into the Personal Message template, and if so how?  :-\

Dove

Hello,
Open (Version 1.03) Themes/default/InstantMessage.template.php
^^ or each theme -InstantMessage.template.php

[ FIND around line 372 ]-----------------------------------------
  <input type="submit" name="preview" value="', $txt[507], '" onclick="return submitThisOnce(this);" accesskey="p" />';
if ($context['show_spellchecking'])
echo '
<input type="button" value="', $txt['spell_check'], '" onclick="spellCheck( \'postmodify\', \'message\');">';


[ Change to : so it looks like this]-------------------
<input type="submit" name="preview" value="', $txt[507], '" onclick="return submitThisOnce(this);" accesskey="p" />';
echo '
<script language="Javascript" src="spelling/spellmessage.js"></script>
<input type="button" value="', $txt['spell_check'], '" onclick="openspell();"/>';


:)



Advertisement: