mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-25 06:46:26 +00:00
34cbc729db
Based on https://github.com/ccampbell/mousetrap. Cleaned up to fit our coding standards, pass JSHint, and assume jQuery's fixes where possible (e.g. no need for an addEvent utility, no need for filling e.target, e.which, etc. cross-browser which jQuery.Event already does). Initially all were local functions in the constructor, but to allow some customisations in subclasses moved various methods to the prototype instead and marked with @private. Really, only .register() must be called from the outside. The rest assumes normalisation etc. or might break things if called incorrectly. Change-Id: Ic69a3c70759052094aefbeab623d885f8b118e14
1.4 KiB
1.4 KiB
VisualEditor Code Guidelines
We inherit the code structure (about whitespace, naming and comments) conventions from MediaWiki:
- Manual:Coding conventions/JavaScript#Code structure on mediawiki.org.
Documentation comments
- End sentences in a full stop.
- Continue sentences belonging to an annotation on the next line, indented with an additional space.
- Types in documentation comments should be separated by a pipe character. Use types
that are listed in the Types section of this document, otherwise use the identifier
(full path from the global scope) of the constructor function (e.g.
{ve.dm.BranchNode}
).
Annotations
We use the following annotations. They should be used in the order as they are described here for consistency.
- @class
- @mixin
- @abstract
- @constructor
- @extends {Type}
- @private
- @static
- @method
- @until Text: Optional details.
- @source
- @context {Type} The type of the
this
value. - @param {Type} varName Optional description.
- @returns {Type} Optional description.
Types
Special values:
- undefined
- null
- Infinity
- NaN
Native language types:
- Boolean
- String
- Number
- Object
Native constructors:
- Array
- Date
Browser constructors:
- DOMElement (alias for HTMLElement)
jQuery constructors:
- jQuery
- jQuery.Event