mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-24 22:35:41 +00:00
Merge "Add a node type for numbered external links"
This commit is contained in:
commit
8a13ed0d14
|
@ -333,6 +333,7 @@ $wgResourceModules += array(
|
|||
've-mw/dm/nodes/ve.dm.MWInlineImageNode.js',
|
||||
've-mw/dm/nodes/ve.dm.MWBlockImageNode.js',
|
||||
've-mw/dm/nodes/ve.dm.MWImageCaptionNode.js',
|
||||
've-mw/dm/nodes/ve.dm.MWNumberedExternalLinkNode.js',
|
||||
've-mw/dm/nodes/ve.dm.MWTransclusionNode.js',
|
||||
've-mw/dm/nodes/ve.dm.MWReferenceListNode.js',
|
||||
've-mw/dm/nodes/ve.dm.MWReferenceNode.js',
|
||||
|
@ -409,6 +410,7 @@ $wgResourceModules += array(
|
|||
've-mw/ce/nodes/ve.ce.MWInlineImageNode.js',
|
||||
've-mw/ce/nodes/ve.ce.MWBlockImageNode.js',
|
||||
've-mw/ce/nodes/ve.ce.MWImageCaptionNode.js',
|
||||
've-mw/ce/nodes/ve.ce.MWNumberedExternalLinkNode.js',
|
||||
've-mw/ce/nodes/ve.ce.MWTransclusionNode.js',
|
||||
've-mw/ce/nodes/ve.ce.MWReferenceListNode.js',
|
||||
've-mw/ce/nodes/ve.ce.MWReferenceNode.js',
|
||||
|
|
69
modules/ve-mw/ce/nodes/ve.ce.MWNumberedExternalLinkNode.js
Normal file
69
modules/ve-mw/ce/nodes/ve.ce.MWNumberedExternalLinkNode.js
Normal file
|
@ -0,0 +1,69 @@
|
|||
/*!
|
||||
* VisualEditor ContentEditable MWNumberedExternalLinkNode class.
|
||||
*
|
||||
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
||||
* @license The MIT License (MIT); see LICENSE.txt
|
||||
*/
|
||||
|
||||
/**
|
||||
* ContentEditable MediaWiki numbered external link node.
|
||||
*
|
||||
* @class
|
||||
* @extends ve.ce.LeafNode
|
||||
* @constructor
|
||||
* @param {ve.dm.MWNumberedExternalLinkNode} model Model to observe
|
||||
* @param {Object} [config] Configuration options
|
||||
*/
|
||||
ve.ce.MWNumberedExternalLinkNode = function VeCeMWNumberedExternalLinkNode( model, config ) {
|
||||
// Parent constructor
|
||||
ve.ce.LeafNode.call( this, model, config );
|
||||
|
||||
// Mixin constructors
|
||||
ve.ce.ProtectedNode.call( this );
|
||||
ve.ce.FocusableNode.call( this );
|
||||
|
||||
// DOM changes
|
||||
this.$.addClass( 've-ce-mwNumberedExternalLinkNode' );
|
||||
// Need CE=false to prevent selection issues
|
||||
this.$.prop( 'contentEditable', 'false' );
|
||||
|
||||
// Add link
|
||||
this.$link = this.$$( '<a>' ).appendTo( this.$ );
|
||||
|
||||
// Events
|
||||
this.model.connect( this, { 'update': 'onUpdate' } );
|
||||
|
||||
// Initialization
|
||||
this.onUpdate();
|
||||
};
|
||||
|
||||
/* Inheritance */
|
||||
|
||||
OO.inheritClass( ve.ce.MWNumberedExternalLinkNode, ve.ce.LeafNode );
|
||||
|
||||
OO.mixinClass( ve.ce.MWNumberedExternalLinkNode, ve.ce.ProtectedNode );
|
||||
|
||||
OO.mixinClass( ve.ce.MWNumberedExternalLinkNode, ve.ce.FocusableNode );
|
||||
|
||||
/* Static Properties */
|
||||
|
||||
ve.ce.MWNumberedExternalLinkNode.static.name = 'link/mwNumberedExternal';
|
||||
|
||||
ve.ce.MWNumberedExternalLinkNode.static.tagName = 'span';
|
||||
|
||||
/* Methods */
|
||||
|
||||
/**
|
||||
* Handle model update events.
|
||||
*
|
||||
* If the source changed since last update the image's src attribute will be updated accordingly.
|
||||
*
|
||||
* @method
|
||||
*/
|
||||
ve.ce.MWNumberedExternalLinkNode.prototype.onUpdate = function () {
|
||||
this.$link.attr( 'href', this.model.getAttribute( 'href' ) );
|
||||
};
|
||||
|
||||
/* Registration */
|
||||
|
||||
ve.ce.nodeFactory.register( ve.ce.MWNumberedExternalLinkNode );
|
|
@ -68,3 +68,14 @@
|
|||
.ve-ce-mwHieroNode {
|
||||
display: table;
|
||||
}
|
||||
|
||||
/* ve.ce.MWNumberedExternalLinkNode */
|
||||
|
||||
.ve-ce-surface {
|
||||
counter-reset: ve-ce-mwNumberedExternalLinkNode;
|
||||
}
|
||||
|
||||
.ve-ce-mwNumberedExternalLinkNode a:empty:after {
|
||||
content: "[" counter(ve-ce-mwNumberedExternalLinkNode) "]";
|
||||
counter-increment: ve-ce-mwNumberedExternalLinkNode;
|
||||
}
|
|
@ -33,10 +33,7 @@ OO.inheritClass( ve.dm.MWExternalLinkAnnotation, ve.dm.LinkAnnotation );
|
|||
|
||||
ve.dm.MWExternalLinkAnnotation.static.name = 'link/mwExternal';
|
||||
|
||||
ve.dm.MWExternalLinkAnnotation.static.matchRdfaTypes = [
|
||||
'mw:ExtLink',
|
||||
'mw:ExtLink/Numbered'
|
||||
];
|
||||
ve.dm.MWExternalLinkAnnotation.static.matchRdfaTypes = [ 'mw:ExtLink' ];
|
||||
|
||||
ve.dm.MWExternalLinkAnnotation.static.toDataElement = function ( domElements ) {
|
||||
var parentResult = ve.dm.LinkAnnotation.static.toDataElement.apply( this, arguments );
|
||||
|
|
59
modules/ve-mw/dm/nodes/ve.dm.MWNumberedExternalLinkNode.js
Normal file
59
modules/ve-mw/dm/nodes/ve.dm.MWNumberedExternalLinkNode.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*!
|
||||
* VisualEditor DataModel MWNumberedExternalLinkNode class.
|
||||
*
|
||||
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
||||
* @license The MIT License (MIT); see LICENSE.txt
|
||||
*/
|
||||
|
||||
/**
|
||||
* DataModel MediaWiki numbered external link node.
|
||||
*
|
||||
* @class
|
||||
* @extends ve.dm.LeafNode
|
||||
* @constructor
|
||||
* @param {number} [length] Length of content data in document
|
||||
* @param {Object} [element] Reference to element in linear model
|
||||
*/
|
||||
ve.dm.MWNumberedExternalLinkNode = function VeDmMWNumberedExternalLinkNode( length, element ) {
|
||||
// Parent constructor
|
||||
ve.dm.LeafNode.call( this, 0, element );
|
||||
};
|
||||
|
||||
/* Inheritance */
|
||||
|
||||
OO.inheritClass( ve.dm.MWNumberedExternalLinkNode, ve.dm.LeafNode );
|
||||
|
||||
/* Static Properties */
|
||||
|
||||
ve.dm.MWNumberedExternalLinkNode.static.name = 'link/mwNumberedExternal';
|
||||
|
||||
ve.dm.MWNumberedExternalLinkNode.static.isContent = true;
|
||||
|
||||
ve.dm.MWNumberedExternalLinkNode.static.matchTagNames = [ 'a' ];
|
||||
|
||||
ve.dm.MWNumberedExternalLinkNode.static.matchRdfaTypes = [ 'mw:ExtLink' ];
|
||||
|
||||
ve.dm.MWNumberedExternalLinkNode.static.matchFunction = function ( element ) {
|
||||
// Must be empty
|
||||
return element.childNodes.length === 0;
|
||||
};
|
||||
|
||||
ve.dm.MWNumberedExternalLinkNode.static.toDataElement = function ( domElements ) {
|
||||
return {
|
||||
'type': 'link/mwNumberedExternal',
|
||||
'attributes': {
|
||||
'href': domElements[0].getAttribute( 'href' )
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
ve.dm.MWNumberedExternalLinkNode.static.toDomElements = function ( dataElement, doc ) {
|
||||
var domElement = doc.createElement( 'a' );
|
||||
domElement.setAttribute( 'href', dataElement.attributes.href );
|
||||
domElement.setAttribute( 'rel', 'mw:ExtLink' );
|
||||
return [ domElement ];
|
||||
};
|
||||
|
||||
/* Registration */
|
||||
|
||||
ve.dm.modelRegistry.register( ve.dm.MWNumberedExternalLinkNode );
|
|
@ -1370,52 +1370,25 @@ ve.dm.mwExample.domToDataCases = {
|
|||
{ 'type': '/internalList' }
|
||||
]
|
||||
},
|
||||
'numbered external link': {
|
||||
'html': '<body><p><a rel="mw:ExtLink/Numbered" href="http://www.mediawiki.org/">[1]</a></p></body>',
|
||||
'numbered external link (empty mw:Extlink)': {
|
||||
'html': '<body><p>Foo<a rel="mw:ExtLink" href="http://www.example.com"></a>Bar</p></body>',
|
||||
'data': [
|
||||
{ 'type': 'paragraph' },
|
||||
[
|
||||
'[',
|
||||
[ {
|
||||
'type': 'link/mwExternal',
|
||||
'attributes': {
|
||||
'href': 'http://www.mediawiki.org/',
|
||||
'rel': 'mw:ExtLink/Numbered'
|
||||
},
|
||||
'htmlAttributes': [ { 'values': {
|
||||
'href': 'http://www.mediawiki.org/',
|
||||
'rel': 'mw:ExtLink/Numbered'
|
||||
} } ]
|
||||
'F', 'o', 'o',
|
||||
{
|
||||
'type': 'link/mwNumberedExternal',
|
||||
'attributes': {
|
||||
'href': 'http://www.example.com'
|
||||
},
|
||||
'htmlAttributes': [ {
|
||||
'values': {
|
||||
'href': 'http://www.example.com',
|
||||
'rel': 'mw:ExtLink'
|
||||
}
|
||||
} ]
|
||||
],
|
||||
[
|
||||
'1',
|
||||
[ {
|
||||
'type': 'link/mwExternal',
|
||||
'attributes': {
|
||||
'href': 'http://www.mediawiki.org/',
|
||||
'rel': 'mw:ExtLink/Numbered'
|
||||
},
|
||||
'htmlAttributes': [ { 'values': {
|
||||
'href': 'http://www.mediawiki.org/',
|
||||
'rel': 'mw:ExtLink/Numbered'
|
||||
} } ]
|
||||
} ]
|
||||
],
|
||||
[
|
||||
']',
|
||||
[ {
|
||||
'type': 'link/mwExternal',
|
||||
'attributes': {
|
||||
'href': 'http://www.mediawiki.org/',
|
||||
'rel': 'mw:ExtLink/Numbered'
|
||||
},
|
||||
'htmlAttributes': [ { 'values': {
|
||||
'href': 'http://www.mediawiki.org/',
|
||||
'rel': 'mw:ExtLink/Numbered'
|
||||
} } ]
|
||||
} ]
|
||||
],
|
||||
},
|
||||
{ 'type': '/link/mwNumberedExternal' },
|
||||
'B', 'a', 'r',
|
||||
{ 'type': '/paragraph' },
|
||||
{ 'type': 'internalList' },
|
||||
{ 'type': '/internalList' }
|
||||
|
|
Loading…
Reference in a new issue