The new Waze Wiki, aka Wazeopedia, is now live at! While this legacy wiki will remain accessible for the time being, it is no longer updated by the community. For the most up-to-date guidance, please visit your local Wazeopedia.

Please do not make any more updates to these legacy wiki pages, all future updates should be made in your country's local Wazeopedia.

Clock over a larger globe

Scripts/WME JavaScript development

From waze
< Scripts
Revision as of 02:59, 6 February 2014 by Dbraughlr (Talk | contribs)

Jump to: navigation, search

Best practices for development of JavaScript extensions

All normal best practice guidelines apply; some references are:

Run your code through some useful analyzers to head off potential problems, like:


WME (Waze Map Editor) is built on jQuery. This makes it easy to access and manipulate properties and directly reference the built-in Waze objects underlying WME. Using jQuery enables tighter integration into WME, reduces code, and builds on what is already there. WME runs jQuery 1.7 vanilla (which does not include any optional modules like jQuery UI).

Prefix for variables and functions

To ensure that your code is safe from collision with other scripts and extensions, please prefix all variables and functions with a prefix of your choosing (this includes local variables and global variables, since your entire script is made public when it is loaded in WME). An example would be instead of naming a variable "version", name it "coolscript_version" instead, if your script is named "Cool Script".

Code encapsulation

While not technically code encapsulation in the object oriented sense, please encapsulate all code in a function, except requisite bootstrap code and initializer calls.

UserScript Bootstraping

When creating user scripts for Greasemonkey, Chrome, or TamperMonkey, use the following bootstrap at the start of your script. timbones did extensive research on this to make sure it is completely cross-browser compatible. Not only does it work in GreaseMonkey, Chrome, and TamperMonkey, but can also be dropped into a Safari Extension without any recoding.

function coolscript_bootstrap()
	var bGreasemonkeyServiceDefined     = false;

		if ("object" === typeof Components.interfaces.gmIGreasemonkeyService)
			bGreasemonkeyServiceDefined = true;
	catch (err)
	if ( "undefined" === typeof unsafeWindow  ||  ! bGreasemonkeyServiceDefined)
		unsafeWindow    = ( function ()
			var dummyElem   = document.createElement('p');
			dummyElem.setAttribute ('onclick', 'return window;');
			return dummyElem.onclick ();
		} ) ();
	/* begin running the code! */

function coolscript_init()
	//run your code here

// [...]
// then at the end of your script, call the bootstrap to get things started