User talk:Dantman/Tricks

Some built-in functions
I found your tricks page and was wondering if you knew about these built-in functions in MediaWiki?

These are what I use to import/append CSS or Javascript to pages.

Background
A handy collection of javascript functions called wikibits.js is included in everypage on Wikipedia. On Wikia these functions are found in allinone_non_loggedin.js (this file is loaded on every page) which is compressed (not readable), to see the readable code it says you must add query string ?allinone=0 at the end. I haven't gotten that part to work, but the functions are there. How I found these is because I am web developer and I study webpages very carefully. ;)

Functions
Using Wikipedia's wikibits.js, I'll list some of the useful functions:
 * function addOnloadHook(hookFunct)
 * function importScript(page)
 * function importStylesheet(page)
 * function importStylesheetURI(url)
 * function appendCSS(text)
 * function escapeQuotes(text)
 * function escapeQuotesHTML(text)
 * function addHandler( element, attach, handler )
 * function addClickHandler( element, handler )
 * function removeHandler( element, remove, handler )

Examples
These would go in Common.js:

Code #1
function loadFunc {   //your code here }

addOnloadHook(loadFunc);

Result #1
Your function will run after the page as loaded. Equivalent to having window.onload=yourFunc; in the header.

Code #2
This is a snippet from my wiki that uses the Yahoo! User Interface library of scripts. var container = 'http://yui.yahooapis.com/2.6.0/build/container/container-min.js'; var container_css = 'http://yui.yahooapis.com/2.6.0/build/container/assets/skins/sam/container.css'; importScriptURI(container); importStylesheetURI(container_css);

Result #2
This will import an external javascript or style sheet.

Code #3
appendCSS(".notes {font-size:10px;}");

Result #3
This will find the tag of the webpage and dynamically create a tag and insert your CSS.

Other wikis

 * Memory Alpha's Common.js uses the hookEvent
 * Everyquest's Common.js uses addOnloadHook
 * WOWWiki's Common.js also use addOnloadHook

Hope this may be useful!

I think will I have to start my own tricks page now if no one knows about this stuff :)

&mdash; JeiaraTalk 18:47, 24 March 2009 (UTC)