JavaScript & AJAX API


For Runtime control and integration with non PHP Languages

  • Fully featured JavaScript API and
  • Detailed event model.
  • AJAX spell-checker API allowing - allowing you to build custom form validation and UI elements in minutes.

Installation outside of PHP Applications

The JavaScript API allows developers the choice to use all of PHPSpellCheck's functionality using JavaScript as the integration language. This also allows PHPSpellCheck to be implemented within non-php applications.

  1. Ensure that phpspellcheck is installed in the website root (and test this installation using the examples).
  2. Use JavaScript to implement PHPSpellCheck. Example code in javascript can be generated using the API explorer on our homepage

e.g.

SourceCode:
<script src="/phpspellcheck/include.js' type='text/javascript'></script>
<script type='text/javascript'>
var mySpell = new LiveSpellInstance();
mySpell.Fields = "ALL"
mySpell.DrawSpellImageButton()
mySpell.ActivateAsYouType()
</script>

Scripting & PHPSpellCheck

You can access your existing PHPSpellCheck AsYouType and SpellButton objects in JavaScript using their ID attribute as their JavaScript object name. Both the AsYouType and SpellButton PHP objects create an instance of the JavaScript LiveSpellObject class documented below.

SourceCode:
<?php
	require "/phpspellcheck/include.php";	
	$mySpell = new SpellCheckButton();
	$mySpell->InstallationPath = "/phpspellcheck/";	 
	echo $mySpell->SpellImageButton();
?>	
	
<script type='text/javascript'>
	var mySpellObject = <?php echo ($mySpell->ID)?>;

	mySpellObject.onDialogOpen = function(){
		alert("onDialogOpen event fired")		
	}

</script>

Class LiveSpellInstance

Core Properties

CaseSensitive

  • Consider case mistakes when spellchecking.
    • (bool) [Default Value: true]

CheckGrammar

  • Check for structural grammar errors such as repeated words, and sentence casing.
    • (bool) [Default Value: true]

CSSTheme

  • Theme for the spell-checker UI context menu and spelling dialog window.
  • Maps to a folder name within /phpspellcheck/themes/
  • See the Skinning tutorial
    • (string) [Default Value: ""]

Fields

  • Set the html elements to be spell-checked by this instance.
  • Multiple fields may be set using:
    • a "comma,separated,list" or
    • array("an","array","of","ids").
  • Each field must have an InnerHTML or Value property.
    • (string) [Default Value: "ALL"] (all text-areas and text inputs on the page)

FormToSubmit

  • A form id to submit upon successful spellchecking using the dialog.
    • (string) [Default Value: ""]

IgnoreAllCaps

  • Ignore ALL CAPITALIZED words.
    • (bool) [Default Value: true]

IgnoreNumeric

  • Ignore strings with numbers in them which are often product codes or serial numbers.
  • E.g. HSH-S872-282P
    • (bool) [Default Value: true]

Language

  • [Dictionary] language to be used for spellchecking.
  • This maps to a ".dic" dictionary in your /phpspellcheck/dictionaries directory
  • Exclude the ".dic" file extension in the value
  • Multiple languages can be set simultaneously using a comma separated list
    • E.g. "English (International), Svenska"
    • (string)[Default Value: "English (International)"]

SettingsFile

  • Low level Settings File used to set up the spellchecker UI.
  • Maps to a file in /phpspellcheck/settings
    • (string)[Default Value: "default-settings" ]

UserInterfaceLanguage

  • Language of the user interface dialog and context menu.
  • See the User Interface Language guide for all values and details on customization.
    • (string)[Default Value: "en" ]

Setup Properties

CustomOpener

  • Set a custom function which can be set to override the regular spell-checker window opening method.
  • Also see function url()
    • (function)[Default Value: null]

CustomOpenerClose

  • Set a custom function called when spellchecking in a CustomOpener scenario is completed.
    • (function)[Default Value: null]

ServerModel

  • Server hypertext processing language.
    • (string)[Default Value: "php"]

Delay

  • Delay in milliseconds between the user finishing typing and As-You-Type fields having their spelling re-validated.
    • (int)[Default Value: 888]

WindowMode

Sets the behavior of the spellchecker dialog to either:

  • "modal" - a floating toolbar linked to the opening page
  • "popup" - a popup browser window
    • (string)[Default Value: "modal"]

Strict

ShowSummaryScreen

  • Shows a summary of statistics after a spell checker dialog has successfully finished.
    • (bool)[Default Value: true]

ShowMeanings

  • Shows the meaning of words and thesaurus using the "Lookup meaning..." link in the spell checker dialog.
  • Also see MeaningProvider
    • (bool)[Default Value: true]

MeaningProvider

UndoLimit

  • Maximum remembered levels of user undo.
    • (int)[Default Value: 20]

HiddenButtons

  • A "comma,separated,list" of buttons to be removed from the spell-checker dialog and context menu - identified by their id
    • (string)[Default Value: ""]

Methods

checkInWindow()

  • Spell checks your Fields in a pop-up dialog window.
    • Arguments: none
    • Returns: null

checkInSitu()

  • Spell checks your text-area fields in place using red-wiggly-underlining and a context menu.
    • Arguments: none
    • Returns: null

activateAsYouType()

  • All textarea fields named in the Fields property will now automatically validate spelling in context when their value changes due to user interaction.
    • Arguments: none
    • Returns: null

pauseAsYouType()

  • Pauses the behavior started by the activateAsYouType function
    • Arguments: none
    • Returns: null

Rendering Methods

url()

  • Returns the URL used to open the spell-checker dialog window.
    • Arguments: none
    • Returns: (string)

DrawSpellButton ([inPlace] [,text] [,Class] [,style] )

  • document.writes a SpellButton
    • Arguments: see SpellButton function
    • Returns: null - writes an element to the HTML DOM

DrawSpellImageButton ([inPlace] [,image] [,rollover] [,text] [,Class] [,style])

  • document.writes a SpellImageButton
    • Arguments: see SpellImageButton function
    • Returns: null - writes an element to the HTML DOM

DrawSpellLink ([inPlace] [,text] [,Class] [,style])

  • document.writes a SpellLink
    • Arguments: see SpellLink function
    • Returns: null - writes an element to the HTML DOM


SpellButton ([inPlace][,text][,Class][,style])

  • Returns an HTML string for a form button that will open a spellchecker.
  • Also see DrawSpellButton.
  • Arguments:
    • inPlace (boolean) [Default Value:false]. Spell-check will take place in the context of the text area (true) - or in a popup window (false)
    • text (string) [Default Value:"Spell Check"] - the value attribute of the button
    • Class (string) [Default Value:""] CSS class to be applied to the button
    • style (string) [Default Value:""] The CSS style attribute to be applied to the button
    • Returns: (string) of the button's full html

SpellLink ([inPlace][,text][,Class][,style])

  • Returns an HTML string for a hyperlink that will open a spell-checker.
  • Also see DrawSpellLink.
  • Arguments:
    • inPlace (boolean) [Default Value:false]. Spell-check will take place in the context of the text area (true) - or in a popup window (false)
    • text (string) [Default Value:"Spell Check"] - the value attribute of the button
    • Class (string) [Default Value:""] CSS class to be applied to the button
    • style (string) [Default Value:""] The CSS style attribute to be applied to the button
    • Returns: (string) of the link's full html

SpellImageButton ([inPlace][,image,][,rolloverImage][,Class][,style])

  • Returns an HTML string for an image with rollover effect that will open a spellchecker. Also see *DrawSpellImageButton.
  • Arguments:
    • inPlace (boolean) [Default Value:false]. Spell-check will take place in the context of the text area (true) - or in a popup window (false)
    • text (string) [Default Value:"Spell Check"] - the value attribute of the button
    • image (string) [Default Value:""] - image of the button. If unset uses a standard image.
    • rolloverImage (string) [Default Value:""] - rollover image of the button.
    • Class (string) [Default Value:""] CSS class to be applied to the button
    • style (string) [Default Value:""] The CSS style attribute to be applied to the button
    • Returns: (string) of the Image Button's full html

Javascript Events

onDialogOpen()

  • Spellchecker dialog is opened.

onDialogComplete()

  • Spellchecker dialog completes spellchecking all words.

onDialogCancel()

  • Spellchecker dialog is cancelled before spellchecking all words.

onDialogClose()

  • Spellchecker dialog closes for any reason.

onChangeLanguage(Language)

  • User changes the selected dictionary language in either a dialog window or context menu.

onIgnore (Word)

  • A word is ignored by the user.
    • Arguments: (string) Word

onIgnoreAll (Word)

  • The users tells the spellchecker to "Ignore All"
    • Arguments: (string) Word

onChangeWord (From, To)

  • The user corrects a word's spelling.
    • Arguments: (string) From, (string) To

onChangeAll (From, To)

  • The user corrects a words spelling and applies that change globally across all current fields.
    • Arguments: (string) From, (string) To

onLearnWord (Word)

  • A words is added to the user's own personal dictionary.
    • Arguments: (string) Word

onLearnAutoCorrect(From,To)

  • A words is added to the user's own personal auto-correct.
    • Arguments: (string) From, (string) To

onUpdateFields(arrayOfFieldIds)

  • A form field is updated due to spellchecking. The fields affected are listed in the arrayofFieldIds array.
    • Arguments: (array) arrayofFieldIds. An array of strings of the fields which have been updated.

AJAX Methods

AjaxSpellCheck(word, makeSuggestions)

  • Makes an AJAX request to spell-check the word.
  • Results are returned asynchronously to the onSpellCheck callback event.
  • Spelling suggestions are only returned to onSpellCheck if makeSuggestions is true.
    • Arguments: (string) word, (bool) makeSuggestions
    • Returns null - results are sent to the onSpellCheck event

AjaxSpellCheckArray(arrayOfWords, makeSuggestions)

  • ajaxSpellCheckArray functions much as ajaxSpellCheck excapt an array of words is spellchecked.
    • Arguments: (array) arrayOfWords, (bool) makeSuggestions
    • Returns null - results are sent to the onSpellCheck event

AjaxDidYouMean(inputString)

  • Requests the most likely "Did You Mean..." search query string for inputString.
  • Results are returned asynchronously to the onDidYouMean event.
    • Arguments: (string) inputString
    • Returns null - results are sent to the onDidYouMean event

AJAX Events & Callbacks

onSpellCheck (word, spelling, reason, suggestions)

  • Callback function for the ajaxSpellCheck method (also ajaxSpellCheckArray, see below)
  • Arguments:
    • (string) word. The word which was spell checked.
    • (bool) Spelling - a boolean spellchecking result.
    • (char) reason is the reason for spelling failure:
      • "E" - Enforced Correction
      • "B" - Word is on your banned words list
      • "C" - A CaSe Mistake
      • "X" - (infrequent) Unlicensed software
      • "S" - Spelling mistake. Not found in any dictionary and none of the above cases apply.
      • "" - Spelling was correct
    • (array) suggestions - returns a sorted array of spelling suggestion is probability order. Will be empty if makeSuggestions was set false in the calling function.
  • This even also calls back for the AjaxSpellCheckArray function.
    • All the event arguments will be (arrays) of the above types.

onDidYouMean(suggestion, original)

  • Callback function for the AjaxDidYouMean function.
  • Arguments:
    • (string) suggestion:
      • If spelling of the original is not valid - a suggestion string will be returned.
      • If spelling is valid - the suggestion will be an empty string.
    • (string) original - the original AjaxDidYouMean inputString