mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 18:39:52 +00:00
Add ve.resolveUrl for URL resolution
Use it to replace fullUrl in the tests Change-Id: I06425e2c90a08a6f622e083f9297444f6f4672e8
This commit is contained in:
parent
ec008a6464
commit
17192da3a2
|
@ -163,13 +163,9 @@ ve.dm.example.createDomElement = function ( type, attributes ) {
|
||||||
|
|
||||||
ve.dm.example.testDir = window.VE_TESTDIR || '.';
|
ve.dm.example.testDir = window.VE_TESTDIR || '.';
|
||||||
|
|
||||||
ve.dm.example.fullUrl = function ( href ) {
|
|
||||||
return $( '<a>' ).attr( 'href', href )[0].href;
|
|
||||||
};
|
|
||||||
|
|
||||||
ve.dm.example.imgSrc = ve.dm.example.testDir + '/example.png';
|
ve.dm.example.imgSrc = ve.dm.example.testDir + '/example.png';
|
||||||
|
|
||||||
ve.dm.example.fullImgSrc = ve.dm.example.fullUrl( ve.dm.example.imgSrc );
|
ve.dm.example.fullImgSrc = ve.resolveUrl( ve.dm.example.imgSrc, document );
|
||||||
|
|
||||||
ve.dm.example.image = {
|
ve.dm.example.image = {
|
||||||
html: '<img src="' + ve.dm.example.imgSrc + '" alt="Example" width="100" height="50">',
|
html: '<img src="' + ve.dm.example.imgSrc + '" alt="Example" width="100" height="50">',
|
||||||
|
|
|
@ -750,6 +750,32 @@
|
||||||
return newDocument;
|
return newDocument;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve a URL according to a given base.
|
||||||
|
*
|
||||||
|
* Passing a string for the base parameter causes a throwaway document to be created, which is
|
||||||
|
* slow.
|
||||||
|
*
|
||||||
|
* @param {string} url URL to resolve
|
||||||
|
* @param {HTMLDocument|string} base Document whose base URL to use, or base URL as a string
|
||||||
|
* @returns {string} Resolved URL
|
||||||
|
*/
|
||||||
|
ve.resolveUrl = function ( url, base ) {
|
||||||
|
var doc, node;
|
||||||
|
if ( typeof base === 'string' ) {
|
||||||
|
doc = ve.createDocumentFromHtml( '' );
|
||||||
|
node = doc.createElement( 'base' );
|
||||||
|
node.setAttribute( 'href', base );
|
||||||
|
doc.head.appendChild( node );
|
||||||
|
} else {
|
||||||
|
doc = base;
|
||||||
|
}
|
||||||
|
|
||||||
|
node = doc.createElement( 'a' );
|
||||||
|
node.setAttribute( 'href', url );
|
||||||
|
return node.href;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the actual inner HTML of a DOM node.
|
* Get the actual inner HTML of a DOM node.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue