( function ( $, mw ) { /** * @class mw.popups.render.article * @singleton */ var article = {}; /** * Size constants for popup images * @property SIZES */ article.SIZES = { portraitImage: { h: 250, // Exact height w: 203 // Max width }, landscapeImage: { h: 200, // Max height w: 300 // Exact Width }, landscapePopupWidth: 450, // Exact width of a landscape popup portraitPopupWidth: 300 // Exact width of a portrait popup }; /** * Send an API request and cache the jQuery element * * @param {jQuery} link * @return {jQuery.Promise} */ article.init = function ( link ) { var href = link.attr( 'href' ), title = link.data( 'title' ), deferred = $.Deferred(); mw.popups.render.currentRequest = mw.popups.api.get( { action: 'query', prop: 'extracts|pageimages|revisions|info', redirects: 'true', exintro: 'true', exsentences: 2, // there is an added geometric limit on .mwe-popups-extract // so that text does not overflow from the card explaintext: 'true', piprop: 'thumbnail', pithumbsize: 300, rvprop: 'timestamp', inprop: 'watched', indexpageids: true, titles: title } ); mw.popups.render.currentRequest.done( function ( re ) { mw.popups.render.currentRequest = undefined; if ( !re.query.pages[ re.query.pageids[ 0 ] ].extract || re.query.pages[ re.query.pageids[ 0 ] ].extract === '' ) { return false; } mw.popups.render.cache[ href ] = {}; mw.popups.render.cache[ href ].popup = article.createPopup( re, href ); mw.popups.render.cache[ href ].getOffset = article.getOffset; mw.popups.render.cache[ href ].getClasses = article.getClasses; mw.popups.render.cache[ href ].process = article.processPopup; deferred.resolve(); } ); return deferred.promise(); }; /** * Returns a thumbnail object based on the ratio of the image * Uses an SVG image where available to add the triangle/pokey * mask on the image. Crops and resizes the SVG image so that * is fits inside a rectangle of a particular size. * * @method createPopup * @param {Object} re * @param {String} href * @return {jQuery} */ article.createPopup = function ( re, href ) { var $a, page = re.query.pages[ re.query.pageids[ 0 ] ], $contentbox = $( '