MediaWiki:WiktionaryLookup-external.js

From Wikinews, the free news source you can write!
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 down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac); IE: hold Ctrl while clicking Refresh, or press Ctrl-F5; Konqueror: simply click the Reload button, or press F5; Opera users may need to completely clear their cache in Tools→Preferences. — More skins

/***********

NOTE: If this script is loaded after the page loads, use http://en.wikinews.org/wiki/MediaWiki:WiktionaryLookup-external-bookmarklet.js instead.

This script is for external sites (blogs) to add the wiktionary look up gadget.

Add 
  <script src='http://en.wikinews.org/w/index.php?title=MediaWiki%3AWiktionaryLookup-external.js&amp;action=raw&amp;ctype=text/javascript' type='text/javascript'></script>

To the head (FIXME: that url should probably have a s-maxage param)...

-----
This script implements the following functions/variables normally provided by the mediawiki environment:
wgUserLanguage, wgContentLanguage, hookEvent.

This script than loads the main script.

**********/

if (!window.wgContentLanguage) {
  var wgContentLanguage;
  if (document.documentElement && document.documentElement.lang) {
    wgContentLanguage = document.documentElement.lang;
  }
  /** body not loaded yet
  else if (document.body && document.body.lang) {
    wgContentLanguage = document.body.lang;
  }
**/
  else { //default to english. 
    wgContentLanguage = "en";
  }
}
if (!window.wgUserLanguage) {
  var wgUserLanguage = wgContentLanguage;
}

/**********
The following are adapted from mediawiki's wikibits.js . See http://mediawiki.org .
As such they are under the GPL
***********/
function hookEvent(attach, handler) {
  if (window.addEventListener) {
    document.addEventListener(attach, handler, false);
  } else if (window.attachEvent) {
    document.attachEvent("on" + attach, handler); 
  }
}

//This is assumed to be called well the document is loading.
//this is temp url for testing.
document.write("<script src='http://en.wikinews.org/w/index.php?title=MediaWiki:Gadget-dictionaryLookupHover.js&action=raw&ctype=text/javascript&scrver=1' type='text/javascript'></script>");