User:Conrad.Irwin/aspell.js

From Wiktionary, the free dictionary
Jump to navigation Jump to search

Note – after saving, you may have to bypass your browser’s cache to see the changes.

  • Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh);
  • Konqueror and Chrome: click Reload or press F5;
  • Opera: clear the cache in Tools → Preferences;
  • Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.

/**
  Try to do something useful after search, still provides guesses even on successful full-text search, just for testing ;)

  This is just to check the usefulness of aspell for the task - I want to try some language guesswork as aspell can't support multiple scripts simultaneously

  The spell checker is kindly hosted on [[User:Amgine]]'s server at http://devtionary.org/wiki/

  The aspell there only has English, though this can (and I have tested) be extended trivially to support most other common languages (see http://aspell.net/ ) 

  This will need installing as a PHP extension of some kind as this method is too inefficient - though it is possible that keeping the aspell on a seperate server from the PHP and doing inter server communication will be a good idea.

**/

function javascript_aspell(){

  var word = false;
  var ip = false;
  var el = false;

  if(el = document.getElementById('powerSearchText') ){
    word = el.value;
    ip = document.getElementById('search');
  }else if(el = document.getElementById('searchbox') ){
    ip = el;
    inps = el.getElementsByTagName('input');
    for(var i=0;i<inps.length;i++){
      if( inps[i].className == 'searchboxInput' ) word = inps[i].value
    }
  }

  if(!ip || !word) return false;

  var url = 'http://devtionary.info/cgi-bin/wikt/spell.py?format=wiki&wiki=en.wiktionary&langs=en,*&word='+encodeURIComponent(word);
  var iframe = document.createElement('iframe');
  iframe.setAttribute('src',url);
  iframe.style.cssText = 'border:none; width: 400px; height: 80px'
  
  ip.parentNode.insertBefore(iframe,ip.nextSibling);

}

$(javascript_aspell);