Check renderers' matcher method to find the appropriate renderers for a link

Right now the main renderer always picks the article renderer, no matter
if any other renderers is registered. It will now run the 'matcher'
method in the rendered, and if it returns true, we use that renderer.

Not sure how we'll avoid matchers stepping on each other.

Bug: T69434
Bug: T102921
Change-Id: Ib06812836cdbd3a5bfd54d4bc6147012fb891694
This commit is contained in:
Prateek Saxena 2015-08-18 11:17:18 +05:30 committed by Marius Hoch
parent 486e34fb38
commit 93ef48221e

View file

@ -108,9 +108,22 @@
// Wait for timer before making API queries and showing hovercard
mw.popups.render.openTimer = mw.popups.render.wait( mw.popups.render.API_DELAY )
.done( function () {
// TODO: check for link type and call correct renderer
// There is only one popup type right now so it isn't necessary
var cachePopup = mw.popups.render.renderers.article.init( link );
var cachePopup, key,
renderers = mw.popups.render.renderers;
// Check run the matcher method of all renderers to find the right one
for ( key in renderers ) {
if ( renderers.hasOwnProperty( key ) && key !== 'article' ) {
if ( !!renderers[ key ].matcher( link.attr( 'href' ) ) ) {
cachePopup = renderers[ key ].init( link );
}
}
}
// Use the article renderer if nothing else matches
if ( cachePopup === undefined ) {
cachePopup = mw.popups.render.renderers.article.init( link );
}
mw.popups.render.openTimer = mw.popups.render.wait( mw.popups.render.POPUP_DELAY - mw.popups.render.API_DELAY );