From 93ef48221eff443602a1873f411b3bd7ddc2f00c Mon Sep 17 00:00:00 2001 From: Prateek Saxena Date: Tue, 18 Aug 2015 11:17:18 +0530 Subject: [PATCH] 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 --- resources/ext.popups.renderer.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/resources/ext.popups.renderer.js b/resources/ext.popups.renderer.js index cdfa24a74..f477c2d53 100644 --- a/resources/ext.popups.renderer.js +++ b/resources/ext.popups.renderer.js @@ -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 );