Jdlrobson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/167972
Change subject: WIP: Make watchlist load page images beyond top 50
......................................................................
WIP: Make watchlist load page images beyond top 50
Change-Id: Iea3ad59d2a498c621c624aa74b2bb02b70fecc98
---
M javascripts/modules/PageList.js
M javascripts/specials/watchlist.js
2 files changed, 64 insertions(+), 4 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend
refs/changes/72/167972/1
diff --git a/javascripts/modules/PageList.js b/javascripts/modules/PageList.js
index d863a0a..466cbf4 100644
--- a/javascripts/modules/PageList.js
+++ b/javascripts/modules/PageList.js
@@ -12,6 +12,30 @@
pages: [],
enhance: false
},
+ loadPageImages: function( offset, limit ) {
+ var self = this,
+ pages = this.options.pages,
+ ids = $.map( pages.slice( offset, offset +
limit ), function( page ) {
+ return page.id;
+ } );
+
+ // load page images
+ api.get( { prop: 'pageimages', piprop: 'thumbnail',
+ pilimit: limit, pageids: ids
+ } ).done( function( resp ) {
+ // update the pages with the new ones in the
response.
+ $.each( pages, function( i, page ) {
+ var id = page.id;
+ if ( resp.query.pages[id] ) {
+ page.thumbnail =
resp.query.pages[id].thumbnail;
+ }
+ } );
+ console.log( pages );
+ self.options.pages = pages;
+ // re-render the page images
+ self.renderPageImages();
+ } );
+ },
/**
* Render page images for the existing page list. Assumes no
page images have been loaded.
* Only load when wgImagesDisabled has not been activated via
Special:MobileOptions.
diff --git a/javascripts/specials/watchlist.js
b/javascripts/specials/watchlist.js
index f5df5be..20d9866 100644
--- a/javascripts/specials/watchlist.js
+++ b/javascripts/specials/watchlist.js
@@ -1,20 +1,56 @@
( function( M, $ ) {
- var PageList = M.require( 'modules/PageList' ),
+ var pageListView,
+ PageList = M.require( 'modules/PageList' ),
schema = M.require( 'loggingSchemas/MobileWebClickTracking' ),
pageName = mw.config.get( 'wgCanonicalSpecialPageName' ) ===
'Watchlist' ? 'watchlist' : 'diff',
+ offset = 50,
+ limit = 50,
+ pages = [],
+ api = M.require( 'api' ),
subPageName = M.query.watchlistview || 'a-z';
+ function loadPageImages() {
+ var scrollBottom, ids,
+ $triggerAt = pageListView.$el.find( 'li' ).eq( offset -
10 );
+
+ if ( $triggerAt.length ) {
+ scrollBottom = $( window ).scrollTop() + $( window
).height();
+
+ if ( scrollBottom > $triggerAt.offset().top ) {
+ offset += limit;
+ pageListView.loadPageImages( offset, limit );
+ }
+ }
+ }
+
function init() {
- var $watchlist = $( 'ul.page-list' ),
- actionNamePrefix = pageName + '-' + subPageName + '-';
+ var actionNamePrefix = pageName + '-' + subPageName + '-',
+ $watchlist = $( '.page-list' );
+
+ pages = $watchlist.find( 'li' ).map( function () {
+ return {
+ id: $( this ).data( 'id' ),
+ title: $( this ).attr( 'title' )
+ };
+ } );
// FIXME: find more elegant way to not show watchlist stars on
recent changes
if ( $( '.mw-mf-watchlist-selector' ).length === 0 ) {
- new PageList( { el: $watchlist, enhance: true,
isWatchList: true } );
+ pageListView = new PageList( { pages: pages,
+ el: $watchlist, enhance: true, isWatchList:
true } );
$watchlist.find( 'a.title' ).on( 'mousedown',
function() {
// name funnel for watchlists to catch
subsequent uploads
$.cookie( 'mwUploadsFunnel', 'watchlist', {
expires: new Date( new Date().getTime() + 60000 ) } );
} );
+
+ if ( $watchlist.find( 'li' ).eq( offset ).length ) {
+ // FIXME: Consider using setInterval instead or
some sort of dethrottling/debouncing to
+ // avoid performance degradation.
+ // FIXME: Code duplication with Special:Uploads
+ // See code in Special:Watchlist
+ // e.g.
http://benalman.com/projects/jquery-throttle-debounce-plugin/
+ $( window ).on( 'scroll', loadPageImages );
+ }
}
// Register EventLogging events
--
To view, visit https://gerrit.wikimedia.org/r/167972
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iea3ad59d2a498c621c624aa74b2bb02b70fecc98
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits