Jdlrobson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/247536
Change subject: Add infinite scrolling on collection
......................................................................
Add infinite scrolling on collection
Bug: T104736
Change-Id: Iebd18fc5ab4afeb7f5fbe828a73211e2743b8cca
---
M resources/ext.gather.collections.models/Collection.js
M resources/ext.gather.special.usercollections/init.js
2 files changed, 69 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Gather
refs/changes/36/247536/1
diff --git a/resources/ext.gather.collections.models/Collection.js
b/resources/ext.gather.collections.models/Collection.js
index c0207e6..f24064d 100644
--- a/resources/ext.gather.collections.models/Collection.js
+++ b/resources/ext.gather.collections.models/Collection.js
@@ -1,6 +1,10 @@
-( function ( M ) {
+( function ( M, $ ) {
var Collection,
+ CollectionItemCard = M.require(
'ext.gather.collections.models/CollectionItemCard' ),
+ InfiniteScroll = M.require( 'InfiniteScroll' ),
+ api = new mw.Api(),
+ Page = M.require( 'Page' ),
View = M.require( 'View' );
/**
@@ -23,9 +27,70 @@
add: function ( collectionItemCard ) {
this.options.items.push( collectionItemCard );
this.$( '.collection-cards' ).append(
collectionItemCard.$el );
+ },
+ /**
+ * Set the query required to retrieve more items in the
collection
+ * @private
+ * @param {String} query
+ */
+ _setQuery: function ( query ) {
+ var data = {};
+ query.split( '&' ).map( function ( nameVal ) {
+ nameVal = nameVal.split( '=' );
+ data[nameVal[0]] = decodeURIComponent(
nameVal[1] );
+ } );
+ data.formatversion = 2;
+ // Server side rendering of image differs from client
+ // (client cannot calculate thumbnail url from page
image title)
+ data.pithumbsize = 480;
+ this.continueArgs = data;
+ },
+ /**
+ * Load new items into the collection from the associated api
if available
+ * @private
+ */
+ _loadItems: function () {
+ var self = this;
+ if ( this.continueArgs ) {
+ api.get( this.continueArgs ).done( function (
resp ) {
+ // Record that there is nothing left to
show.
+ if ( !resp.continue ) {
+ self.continueArgs = false;
+ } else {
+ $.extend( self.continueArgs,
resp.continue );
+ }
+ $( resp.query.pages ).each( function ()
{
+ var itemOptions = {
+ page: new Page( this )
+ };
+ itemOptions.extract =
this.extract;
+ // todo: pageimage
+ itemOptions.hasExtract =
Boolean( this.extract );
+ itemOptions.hasImage = Boolean(
this.thumbnail );
+ self.add(
+ new CollectionItemCard(
itemOptions )
+ );
+ } );
+ } ).always( function () {
+ self.infiniteScroll.enable();
+ } );
+ }
+ },
+ /** @inheritdoc */
+ initialize: function ( options ) {
+ var $btn;
+ View.prototype.initialize.call( this, options );
+ $btn = this.$( '.collections-pagination a' );
+ if ( $btn.length ) {
+ this.infiniteScroll = new InfiniteScroll();
+ this.infiniteScroll.setElement( this.$el );
+ this._query = this._setQuery( $btn.data(
'pagination-query' ) );
+ this.infiniteScroll.on( 'load', $.proxy( this,
'_loadItems' ) );
+ $btn.remove();
+ }
}
} );
M.define( 'ext.gather.collections.models/Collection', Collection );
-} )( mw.mobileFrontend );
+} )( mw.mobileFrontend, jQuery );
diff --git a/resources/ext.gather.special.usercollections/init.js
b/resources/ext.gather.special.usercollections/init.js
index 4ee2605..d8ca9ff 100644
--- a/resources/ext.gather.special.usercollections/init.js
+++ b/resources/ext.gather.special.usercollections/init.js
@@ -16,7 +16,8 @@
} );
new Collection( {
el: $collection,
- enhance: true
+ enhance: true,
+ items: []
} );
} );
--
To view, visit https://gerrit.wikimedia.org/r/247536
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iebd18fc5ab4afeb7f5fbe828a73211e2743b8cca
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Gather
Gerrit-Branch: dev
Gerrit-Owner: Jdlrobson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits