Whitespace and comment cleanup for dm annotation classes

* Added comments to classes and methods
* Quieted a jshint warning
* Broke some long lines
* Replaced instances of "var\t" with "var "

Change-Id: I1d617ed9e5180f1a3dff42078fb5debb5d718407
This commit is contained in:
Trevor Parscal 2012-10-15 11:45:50 -07:00
parent 1c5ac9d502
commit 5cd4222d9c
7 changed files with 211 additions and 18 deletions

View file

@ -146,7 +146,7 @@ ve.ce.Surface.prototype.handleInsertion = function () {
* @param {Object} next.range New selection
*/
ve.ce.Surface.prototype.onContentChange = function ( node, previous, next ) {
var nodeOffset = node.model.getOffset(), // TODO: call getModel() or add getOffset() to view
var nodeOffset = node.model.getOffset(), // TODO: call getModel() or add getOffset() to view
offsetDiff = ( previous.range.isCollapsed() && next.range.isCollapsed() )
? next.range.start - previous.range.start : null,
lengthDiff = next.text.length - previous.text.length,
@ -575,7 +575,7 @@ ve.ce.Surface.prototype.onCut = function ( e ) {
this.onCopy( e );
setTimeout( function () {
var selection,
var selection,
tx;
// We don't like how browsers cut, so let's undo it and do it ourselves.

View file

@ -6,21 +6,49 @@
*/
/**
* Generic link annotation. Represents <a> tags that don't have a specific type.
* Generic link annotation.
*
* Represents <a> tags that don't have a specific type.
*
* @class
* @constructor
* @extends {ve.dm.Annotation}
* @param {HTMLElement} element
*/
ve.dm.LinkAnnotation = function VeDmLinkAnnotation( element ) {
// Parent constructor
ve.dm.Annotation.call( this, element );
};
/* Inheritance */
ve.inheritClass( ve.dm.LinkAnnotation, ve.dm.Annotation );
/* Static Members */
ve.dm.LinkAnnotation.static.name = 'link';
ve.dm.LinkAnnotation.static.matchTagNames = ['a'];
/* Methods */
/**
* Get annotation data, especially the href of the link.
*
* @method
* @param {HTMLElement} element
* @returns {Object} Annotation data, containing href property
*/
ve.dm.LinkAnnotation.prototype.getAnnotationData = function( element ) {
return { 'href': element.getAttribute( 'href' ) };
};
/**
* Convert to an object with HTML element information.
*
* @method
* @returns {Object} HTML element information, including tag and attributes properties
*/
ve.dm.LinkAnnotation.prototype.toHTML = function () {
var parentResult = ve.dm.Annotation.prototype.toHTML.call( this );
parentResult.tag = 'a';
@ -28,4 +56,6 @@ ve.dm.LinkAnnotation.prototype.toHTML = function () {
return parentResult;
};
/* Registration */
ve.dm.annotationFactory.register( 'link', ve.dm.LinkAnnotation );

View file

@ -6,23 +6,49 @@
*/
/**
* Annotation representing an external link in MediaWiki, i.e. <a rel="mw:ExtLink">,
* <a rel="mw:ExtLink/Numbered"> and <a rel="mw:ExtLink/URL">. Those three are semantically
* slightly different, but they don't need to be treated differently by us, at least for now.
* MediaWiki external link annotation.
*
* Example HTML sources:
* <a rel="mw:ExtLink">
* <a rel="mw:ExtLink/Numbered">
* <a rel="mw:ExtLink/URL">
*
* Each example is semantically slightly different, but don't need special treatment (yet).
*
* @class
* @constructor
* @extends {ve.dm.LinkAnnotation}
* @param {HTMLElement} element
*/
ve.dm.MWExternalLinkAnnotation = function VeDmMWExternalLinkAnnotation( element ) {
// Parent constructor
ve.dm.LinkAnnotation.call( this, element );
};
/* Inheritance */
ve.inheritClass( ve.dm.MWExternalLinkAnnotation, ve.dm.LinkAnnotation );
ve.dm.MWExternalLinkAnnotation.static.name = 'link/MWexternal';
ve.dm.MWExternalLinkAnnotation.static.matchRdfaTypes = ['mw:ExtLink', 'mw:ExtLink/Numbered', 'mw:ExtLink/URL'];
/* Static Members */
ve.dm.MWExternalLinkAnnotation.static.name = 'link/MWexternal';
ve.dm.MWExternalLinkAnnotation.static.matchRdfaTypes = [
'mw:ExtLink', 'mw:ExtLink/Numbered', 'mw:ExtLink/URL'
];
/**
* Convert to an object with HTML element information.
*
* @method
* @returns {Object} HTML element information, including tag and attributes properties
*/
ve.dm.MWExternalLinkAnnotation.prototype.toHTML = function () {
var parentResult = ve.dm.LinkAnnotation.prototype.toHTML.call( this );
parentResult.attributes.rel = parentResult.attributes.rel || 'mw:ExtLink';
return parentResult;
};
/* Registration */
ve.dm.annotationFactory.register( 'link/MWexternal', ve.dm.MWExternalLinkAnnotation );

View file

@ -6,22 +6,45 @@
*/
/**
* Annotation representing an internal link in MediaWiki, i.e. <a rel="mw:WikiLink">
* MediaWiki internal link annotation.
*
* Example HTML sources:
* <a rel="mw:WikiLink">
*
* @class
* @constructor
* @extends {ve.dm.LinkAnnotation}
* @param {HTMLElement} element
*/
ve.dm.MWInternalLinkAnnotation = function VeDmMWInternalLinkAnnotation( element ) {
// Parent constructor
ve.dm.LinkAnnotation.call( this, element );
};
/* Inheritance */
ve.inheritClass( ve.dm.MWInternalLinkAnnotation, ve.dm.LinkAnnotation );
/* Static Members */
ve.dm.MWInternalLinkAnnotation.static.name = 'link/MWinternal';
ve.dm.MWInternalLinkAnnotation.static.matchRdfaTypes = ['mw:WikiLink'];
/* Methods */
/**
* Get annotation data, especially the href of the link.
*
* @method
* @param {HTMLElement} element
* @returns {Object} Annotation data, containing 'hrefPrefix' and 'title' properties
*/
ve.dm.MWInternalLinkAnnotation.prototype.getAnnotationData = function( element ) {
// Get title from href
// The href is simply the title, unless we're dealing with a page that
// has slashes in its name in which case it's preceded by one or more
// instances of "./" or "../", so strip those.
// The href is simply the title, unless we're dealing with a page that has slashes in its name
// in which case it's preceded by one or more instances of "./" or "../", so strip those
/*jshint regexp:false */
var matches = element.getAttribute( 'href' ).match( /^((?:\.\.?\/)*)(.*)$/ );
return {
// Store the ./ and ../ prefixes so we can restore them on the way out
@ -30,6 +53,12 @@ ve.dm.MWInternalLinkAnnotation.prototype.getAnnotationData = function( element )
};
};
/**
* Convert to an object with HTML element information.
*
* @method
* @returns {Object} HTML element information, including tag and attributes properties
*/
ve.dm.MWInternalLinkAnnotation.prototype.toHTML = function () {
var href,
parentResult = ve.dm.LinkAnnotation.prototype.toHTML.call( this );
@ -43,4 +72,6 @@ ve.dm.MWInternalLinkAnnotation.prototype.toHTML = function () {
return parentResult;
};
/* Registration */
ve.dm.annotationFactory.register( 'link/MWinternal', ve.dm.MWInternalLinkAnnotation );

View file

@ -6,28 +6,54 @@
*/
/**
* Abstract annotation for text styles. Should not be instantiated directly, only use this for
* subclassing.
* TextStyle annotation.
*
* Should not be instantiated directly, only use this for subclassing.
*
* @class
* @constructor
* @extends {ve.dm.Annotation}
* @param {HTMLElement} element
*/
ve.dm.TextStyleAnnotation = function VeDmTextStyleAnnotation( element ) {
ve.dm.Annotation.call( this, element );
};
/* Inheritance */
ve.inheritClass( ve.dm.TextStyleAnnotation, ve.dm.Annotation );
/* Static Members */
ve.dm.TextStyleAnnotation.static.name = 'textStyle';
ve.dm.TextStyleAnnotation.static.matchTagNames = [];
/**
* Convert to an object with HTML element information.
*
* @method
* @returns {Object} HTML element information, including tag and attributes properties
*/
ve.dm.TextStyleAnnotation.prototype.toHTML = function () {
var parentResult = ve.dm.Annotation.prototype.toHTML.call( this );
parentResult.tag = parentResult.tag || this.constructor.static.matchTagNames[0];
return parentResult;
};
/* Registration */
ve.dm.annotationFactory.register( 'textStyle', ve.dm.TextStyleAnnotation );
// Concrete subclasses
/* Concrete Subclasses */
/**
* Bold annotation.
*
* @class
* @constructor
* @extends {ve.dm.TextStyleAnnotation}
* @param {HTMLElement} element
*/
ve.dm.TextStyleBoldAnnotation = function VeDmTextStyleBoldAnnotation( element ) {
ve.dm.TextStyleAnnotation.call( this, element );
};
@ -36,6 +62,14 @@ ve.dm.TextStyleBoldAnnotation.static.name = 'textStyle/bold';
ve.dm.TextStyleBoldAnnotation.static.matchTagNames = ['b'];
ve.dm.annotationFactory.register( 'textStyle/bold', ve.dm.TextStyleBoldAnnotation );
/**
* Italic annotation.
*
* @class
* @constructor
* @extends {ve.dm.TextStyleAnnotation}
* @param {HTMLElement} element
*/
ve.dm.TextStyleItalicAnnotation = function VeDmTextStyleItalicAnnotation( element ) {
ve.dm.TextStyleAnnotation.call( this, element );
};
@ -44,6 +78,14 @@ ve.dm.TextStyleItalicAnnotation.static.name = 'textStyle/italic';
ve.dm.TextStyleItalicAnnotation.static.matchTagNames = ['i'];
ve.dm.annotationFactory.register( 'textStyle/italic', ve.dm.TextStyleItalicAnnotation );
/**
* Underline annotation.
*
* @class
* @constructor
* @extends {ve.dm.TextStyleAnnotation}
* @param {HTMLElement} element
*/
ve.dm.TextStyleUnderlineAnnotation = function VeDmTextStyleUnderlineAnnotation( element ) {
ve.dm.TextStyleAnnotation.call( this, element );
};
@ -52,6 +94,14 @@ ve.dm.TextStyleUnderlineAnnotation.static.name = 'textStyle/underline';
ve.dm.TextStyleUnderlineAnnotation.static.matchTagNames = ['u'];
ve.dm.annotationFactory.register( 'textStyle/underline', ve.dm.TextStyleUnderlineAnnotation );
/**
* Strike annotation.
*
* @class
* @constructor
* @extends {ve.dm.TextStyleAnnotation}
* @param {HTMLElement} element
*/
ve.dm.TextStyleStrikeAnnotation = function VeDmTextStyleStrikeAnnotation( element ) {
ve.dm.TextStyleAnnotation.call( this, element );
};
@ -60,6 +110,14 @@ ve.dm.TextStyleStrikeAnnotation.static.name = 'textStyle/strike';
ve.dm.TextStyleStrikeAnnotation.static.matchTagNames = ['s'];
ve.dm.annotationFactory.register( 'textStyle/strike', ve.dm.TextStyleStrikeAnnotation );
/**
* Small annotation.
*
* @class
* @constructor
* @extends {ve.dm.TextStyleAnnotation}
* @param {HTMLElement} element
*/
ve.dm.TextStyleSmallAnnotation = function VeDmTextStyleSmallAnnotation( element ) {
ve.dm.TextStyleAnnotation.call( this, element );
};
@ -68,6 +126,14 @@ ve.dm.TextStyleSmallAnnotation.static.name = 'textStyle/small';
ve.dm.TextStyleSmallAnnotation.static.matchTagNames = ['small'];
ve.dm.annotationFactory.register( 'textStyle/small', ve.dm.TextStyleSmallAnnotation );
/**
* Big annotation.
*
* @class
* @constructor
* @extends {ve.dm.TextStyleAnnotation}
* @param {HTMLElement} element
*/
ve.dm.TextStyleBigAnnotation = function VeDmTextStyleBigAnnotation( element ) {
ve.dm.TextStyleAnnotation.call( this, element );
};
@ -76,6 +142,14 @@ ve.dm.TextStyleBigAnnotation.static.name = 'textStyle/big';
ve.dm.TextStyleBigAnnotation.static.matchTagNames = ['big'];
ve.dm.annotationFactory.register( 'textStyle/big', ve.dm.TextStyleBigAnnotation );
/**
* Span annotation.
*
* @class
* @constructor
* @extends {ve.dm.TextStyleAnnotation}
* @param {HTMLElement} element
*/
ve.dm.TextStyleSpanAnnotation = function VeDmTextStyleSpanAnnotation( element ) {
ve.dm.TextStyleAnnotation.call( this, element );
};
@ -84,6 +158,14 @@ ve.dm.TextStyleSpanAnnotation.static.name = 'textStyle/span';
ve.dm.TextStyleSpanAnnotation.static.matchTagNames = ['span'];
ve.dm.annotationFactory.register( 'textStyle/span', ve.dm.TextStyleSpanAnnotation );
/**
* Strong annotation.
*
* @class
* @constructor
* @extends {ve.dm.TextStyleAnnotation}
* @param {HTMLElement} element
*/
ve.dm.TextStyleStrongAnnotation = function VeDmTextStyleStrongAnnotation( element ) {
ve.dm.TextStyleAnnotation.call( this, element );
};
@ -92,6 +174,14 @@ ve.dm.TextStyleStrongAnnotation.static.name = 'textStyle/strong';
ve.dm.TextStyleStrongAnnotation.static.matchTagNames = ['strong'];
ve.dm.annotationFactory.register( 'textStyle/strong', ve.dm.TextStyleStrongAnnotation );
/**
* Emphasis annotation.
*
* @class
* @constructor
* @extends {ve.dm.TextStyleAnnotation}
* @param {HTMLElement} element
*/
ve.dm.TextStyleEmphasizeAnnotation = function VeDmTextStyleEmphasizeAnnotation( element ) {
ve.dm.TextStyleAnnotation.call( this, element );
};
@ -100,6 +190,14 @@ ve.dm.TextStyleEmphasizeAnnotation.static.name = 'textStyle/emphasize';
ve.dm.TextStyleEmphasizeAnnotation.static.matchTagNames = ['em'];
ve.dm.annotationFactory.register( 'textStyle/emphasize', ve.dm.TextStyleEmphasizeAnnotation );
/**
* SuperScript annotation.
*
* @class
* @constructor
* @extends {ve.dm.TextStyleAnnotation}
* @param {HTMLElement} element
*/
ve.dm.TextStyleSuperScriptAnnotation = function VeDmTextStyleSuperScriptAnnotation( element ) {
ve.dm.TextStyleAnnotation.call( this, element );
};
@ -108,6 +206,14 @@ ve.dm.TextStyleSuperScriptAnnotation.static.name = 'textStyle/superScript';
ve.dm.TextStyleSuperScriptAnnotation.static.matchTagNames = ['sup'];
ve.dm.annotationFactory.register( 'textStyle/superScript', ve.dm.TextStyleSuperScriptAnnotation );
/**
* SubScript annotation.
*
* @class
* @constructor
* @extends {ve.dm.TextStyleAnnotation}
* @param {HTMLElement} element
*/
ve.dm.TextStyleSubScriptAnnotation = function VeDmTextStyleSubScriptAnnotation( element ) {
ve.dm.TextStyleAnnotation.call( this, element );
};

View file

@ -663,7 +663,7 @@ ve.dm.Document.prototype.getAnnotationsFromRange = function ( range, all ) {
*/
ve.dm.Document.prototype.trimOuterSpaceFromRange = function ( range ) {
range.normalize();
var start = range.start,
var start = range.start,
end = range.end;
while ( this.data[start] === ' ' ) {
start++;

View file

@ -113,7 +113,7 @@ ve.ui.LinkInspector.prototype.getFirstLinkAnnotation = function ( annotations )
* OR unwrap outer whitespace from selection.
*/
ve.ui.LinkInspector.prototype.prepareOpen = function () {
var surfaceView = this.context.getSurfaceView(),
var surfaceView = this.context.getSurfaceView(),
surfaceModel = surfaceView.getModel(),
doc = surfaceModel.getDocument(),
annotations = this.getAllLinkAnnotationsFromSelection(),
@ -143,7 +143,7 @@ ve.ui.LinkInspector.prototype.prepareOpen = function () {
};
ve.ui.LinkInspector.prototype.onOpen = function () {
var annotation = this.getFirstLinkAnnotation( this.getAllLinkAnnotationsFromSelection() ),
var annotation = this.getFirstLinkAnnotation( this.getAllLinkAnnotationsFromSelection() ),
surfaceModel = this.context.getSurfaceView().getModel(),
documentModel = surfaceModel.getDocument(),
selection = surfaceModel.getSelection().truncate( 255 ),