Jdlrobson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/288550

Change subject: Rewrite createPopup with template for better readability
......................................................................

Rewrite createPopup with template for better readability

Change-Id: If646623ba4ebf5dfac2a94c73b6f053131739767
---
M Popups.hooks.php
M resources/ext.popups.renderer.article.js
A resources/popup.mustache
3 files changed, 38 insertions(+), 37 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Popups 
refs/changes/50/288550/1

diff --git a/Popups.hooks.php b/Popups.hooks.php
index 8663a90..8af73da 100644
--- a/Popups.hooks.php
+++ b/Popups.hooks.php
@@ -76,6 +76,9 @@
                                'resources/ext.popups.disablenavpop.js',
                                'resources/ext.popups.settings.js',
                        ),
+                       'templates' => array(
+                               'popup.mustache' => 'resources/popup.mustache',
+                       ),
                        'styles' => array(
                                'resources/ext.popups.animation.less',
                                'resources/ext.popups.settings.less',
diff --git a/resources/ext.popups.renderer.article.js 
b/resources/ext.popups.renderer.article.js
index d0aa1c4..67e52e2 100644
--- a/resources/ext.popups.renderer.article.js
+++ b/resources/ext.popups.renderer.article.js
@@ -115,51 +115,37 @@
         * @return {jQuery}
         */
        article.createPopup = function ( page, href ) {
-               var $div,
-                       $contentbox = $( '<a>' )
-                               .attr( {
-                                       href: href,
-                                       lang: page.pagelanguagehtmlcode,
-                                       dir: page.pagelanguagedir
-                               } )
-                               .addClass( 'mwe-popups-extract' )
-                               .append(
-                                       article.getProcessedElements( 
page.extract, page.title )
-                               ),
+               var $div, hasThumbnail,
                        thumbnail = page.thumbnail,
                        tall = thumbnail && thumbnail.height > thumbnail.width,
                        $thumbnail = article.createThumbnail( thumbnail, tall ),
                        timestamp = new Date( page.revisions[ 0 ].timestamp ),
                        timediff = new Date() - timestamp,
-                       oneDay = 1000 * 60 * 60 * 24,
-                       timestampclass = ( timediff < oneDay ) ?
-                               'mwe-popups-timestamp-recent' :
-                               'mwe-popups-timestamp-older',
-                       $settingsImage = $( '<a>' ).addClass( 'mwe-popups-icon 
mwe-popups-settings-icon' ),
-                       $footer = $( '<footer>' )
-                               .append(
-                                       $( '<span>' )
-                                               .text( mw.message( 
'popups-last-edited',
-                                                       moment( timestamp 
).fromNow() ).text() )
-                                               .addClass( timestampclass ),
-                                       $settingsImage
-                               );
-
-               if ( article.surveyLink ) {
-                       $footer.append( article.createSurveyLink( 
article.surveyLink ) );
-               }
+                       oneDay = 1000 * 60 * 60 * 24;
 
                // createThumbnail returns an empty <span> if there is no 
thumbnail
-               if ( $thumbnail.prop( 'tagName' ) !== 'SPAN' ) {
-                       $thumbnail = $( '<a>' )
-                               .addClass( 'mwe-popups-discreet' )
-                               .attr( 'href', href )
-                               .append( $thumbnail );
-               } else {
-                       tall = thumbnail = undefined;
-               }
+               hasThumbnail = $thumbnail.prop( 'tagName' ) !== 'SPAN';
 
-               $div = $( '<div>' ).append( $thumbnail, $contentbox, $footer );
+               $div = mw.template.get( 'ext.popups.desktop', 'popup.mustache' 
).render( {
+                       langcode: page.pagelanguagehtmlcode,
+                       langdir: page.pagelanguagedir,
+                       href: href,
+                       isRecent: timediff < oneDay,
+                       lastModified: mw.message( 'popups-last-edited', moment( 
timestamp ).fromNow() ).text(),
+                       hasThumbnail: hasThumbnail
+               } );
+
+               // FIXME: Ideally these things should be added in template. 
These will be refactored in future patches.
+               if ( !hasThumbnail ) {
+                       tall = thumbnail = undefined;
+               } else {
+                       $div.find( '.mwe-popups-discreet' ).append( $thumbnail 
);
+               }
+               $div.find( '.mwe-popups-extract' )
+                       .append( article.getProcessedElements( page.extract, 
page.title ) );
+               if ( article.surveyLink ) {
+                       $div.find( 'footer' ).append( article.createSurveyLink( 
article.surveyLink ) );
+               }
 
                mw.popups.render.cache[ href ].settings = {
                        title: page.title,
diff --git a/resources/popup.mustache b/resources/popup.mustache
new file mode 100644
index 0000000..163de28
--- /dev/null
+++ b/resources/popup.mustache
@@ -0,0 +1,12 @@
+<div>
+       {{#hasThumbnail}}
+       <a href="{{href}}" class="mwe-popups-discreet"><!-- thumbnail injected 
post render --></a>
+       {{/hasThumbnail}}
+       <a dir="{{langcode}}" lang="{{langdir}}" class="mwe-popups-extract" 
href="{{href}}"><!-- extract will be appended here --></a>
+       <footer>
+                       <span
+                               
class="{{#isRecent}}mwe-popups-timestamp-recent{{/isRecent}}{{^isRecent}}mwe-popups-timestamp-older{{/isRecent}}">{{lastModified}}</span>
+                       <a class="mwe-popups-icon mwe-popups-settings-icon"></a>
+                       <!-- survey link injected here if found -->
+       </footer>
+</div>
\ No newline at end of file

-- 
To view, visit https://gerrit.wikimedia.org/r/288550
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If646623ba4ebf5dfac2a94c73b6f053131739767
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Popups
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to