r65924 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65923‎ | r65924 | r65925 >
Date:00:38, 5 May 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Fixed ajaxscroll load issue
Modified paths:
  • /trunk/extensions/Storyboard/jquery/jquery.ajaxscroll.js (modified) (history)
  • /trunk/extensions/Storyboard/tags/Storyboard/storyboard.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Storyboard/jquery/jquery.ajaxscroll.js
@@ -1,17 +1,18 @@
22 /**
33 * AjaxScroll (jQuery Plugin)
4 - * Modified for MediaWiki storyboard extension.
 4+ * http://project.yctin.com/ajaxscroll
 5+ * Modified for MediaWiki Storyboard extension.
56 *
6 - * @author Timmy Tin - http://project.yctin.com/ajaxscroll
7 - * @author Jeroen De Dauw
87 * @license GPL
98 * @version 0.2
 9+ *
 10+ * @author Timmy Tin
 11+ * @author Jeroen De Dauw
1012 */
1113 (function($) {
1214 $.fn.ajaxScroll = function( opt ) {
1315 opt = jQuery.extend(
1416 {
15 - batchNum: 5,
1617 batchSize: 30,
1718 batchTemplate: null,
1819 boxTemplate: null,
@@ -22,11 +23,11 @@
2324 lBound: "auto",
2425 uBound: "auto",
2526 eBound: "auto",
26 - maxOffset: 1000,
2727 scrollDelay: 600, // The interval for checking if the user scrolled, in ms.
2828 endDelay: 100,
2929 updateBatch: null,
30 - updateEnd: null
 30+ updateEnd: null,
 31+ loaded: false
3132 },
3233 opt
3334 );
@@ -35,7 +36,6 @@
3637 var ele = this;
3738 var $me = jQuery( this );
3839 var $sp;
39 - var offset = 0;
4040 var previousScrollPos = -1;
4141
4242 $me.css( {
@@ -48,24 +48,31 @@
4949
5050 $sp = jQuery( "<div></div>" ).addClass( opt.scrollPaneClass );
5151 $me.append( $sp );
52 - offset = batch( $sp, offset, opt );
 52+ batch( $sp, opt );
 53+ batch( $sp, opt );
5354 $me.scrollTop(0).scrollLeft(0);
5455
55 - var os = $me.find( '.batch:first' ).next().offset().top;
56 - var b = ( $me.height() / os + 1 ) * os;
 56+ var topOffset = $me.find( '.batch:first' ).next().offset().top;
 57+ var b = ( $me.height() / topOffset + 1 ) * topOffset;
5758
58 - if ( "auto" == opt.uBound ) {
 59+ if ( opt.uBound == "auto" ) {
5960 opt.uBound = b;
6061 }
6162
62 - if ( "auto" == opt.lBound ) {
 63+ if ( opt.lBound == "auto" ) {
6364 opt.lBound = -b;
6465 }
6566
66 - if ( "auto" == opt.eBound ) {
 67+ if ( opt.eBound == "auto" ) {
6768 opt.eBound = b * 2;
6869 }
69 -
 70+ /*
 71+ $sp.find( '> .' + opt.emptyBatchClass ).each( function( i, obj ) {
 72+ if ( i > 0 ) {
 73+ var $batchDiv = jQuery( obj ).removeClass( opt.emptyBatchClass );
 74+ }
 75+ });
 76+ */
7077 setTimeout( monEnd, opt.endDelay );
7178
7279 // Initiate the scroll handling.
@@ -73,29 +80,23 @@
7481 setTimeout( handleScrolling, opt.scrollDelay );
7582 }
7683
77 - function batch( $s, offset, opt ) {
 84+ function batch( $s, opt ) {
7885 var $b;
7986 var i;
80 - var rp = opt.batchNum;
8187
82 - while( rp-- ) {
83 - $b = jQuery( opt.batchTemplate )
84 - .attr({
85 - offset: offset,
86 - len: opt.batchSize
87 - })
88 - .addClass( opt.batchClass + " " + opt.emptyBatchClass );
89 -
90 - i = opt.batchSize;
91 -
92 - while( i-- && opt.maxOffset > offset++ ){
93 - $b.append( opt.boxTemplate );
94 - }
95 -
96 - $s.append( $b );
 88+ $b = jQuery( opt.batchTemplate )
 89+ .attr({
 90+ len: opt.batchSize
 91+ })
 92+ .addClass( opt.batchClass + " " + opt.emptyBatchClass );
 93+
 94+ i = opt.batchSize;
 95+
 96+ while( i-- ){
 97+ $b.append( opt.boxTemplate );
9798 }
9899
99 - return offset;
 100+ $s.append( $b );
100101 };
101102
102103 /**
@@ -106,19 +107,22 @@
107108 function handleScrolling() {
108109 var scrollPos = $me.scrollTop();
109110
110 - if( !window.storyboardBusy && previousScrollPos != scrollPos ) {
 111+ // TODO: add check to make sure the board is not currently busy
 112+ if( previousScrollPos != scrollPos ) {
111113 previousScrollPos = scrollPos;
112114 var co = $me.offset().top;
113115
114116 $sp.find( '> .' + opt.emptyBatchClass ).each( function( i, obj ) {
 117+ // Only do one batch. This is needed to retain empty space at load, while not loading 2 identical batches.
 118+ if ( i > 0 ) return;
 119+
115120 var $batchDiv = jQuery( obj );
116121 var p = $batchDiv.position().top - co;
117122
118123 if ( opt.lBound > p || p > opt.uBound ) {
119124 return;
120 - }
 125+ }
121126
122 - window.storyboardBusy = true;
123127 opt.updateBatch( $batchDiv.removeClass( opt.emptyBatchClass ) );
124128 });
125129 }
@@ -127,14 +131,12 @@
128132 };
129133
130134 function monEnd() {
131 - if ( offset < opt.maxOffset ) {
132 - setTimeout( monEnd, vEnd() );
133 - }
 135+ setTimeout( monEnd, vEnd() );
134136 }
135137
136138 function vEnd() {
137139 if ( ele.scrollTop > 0 && ele.scrollHeight - ele.scrollTop < opt.eBound ) {
138 - offset = batch( $sp, offset, opt );
 140+ batch( $sp, opt );
139141 return 1;
140142 }
141143
Index: trunk/extensions/Storyboard/tags/Storyboard/storyboard.js
@@ -10,8 +10,7 @@
1111 $( '.storyboard' ).ajaxScroll( {
1212 updateBatch: updateStoryboard,
1313 maxOffset: 500,
14 - batchSize: 2,
15 - batchNum: 2, // TODO: change to 1. Some issue in the ajaxscroll plugin makesit break when this is the case though.
 14+ batchSize: 4,
1615 batchClass: "batch",
1716 boxClass: "storyboard-box",
1817 emptyBatchClass: "storyboard-empty",
@@ -24,7 +23,7 @@
2524 'action': 'query',
2625 'list': 'stories',
2726 'format': 'json',
28 - 'stlimit': 2,
 27+ 'stlimit': 4,
2928 'stlanguage': window.storyboardLanguage
3029 };
3130
@@ -122,8 +121,6 @@
123122 }
124123
125124 window.storyContinueParam = data["query-continue"] ? data["query-continue"] : false;
126 -
127 - window.storyboardBusy = false;
128125 }
129126
130127 })(jQuery);
\ No newline at end of file

Follow-up revisions

RevisionCommit summaryAuthorDate
r65925Follow up t0 r65924jeroendedauw00:45, 5 May 2010

Status & tagging log