r65773 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65772‎ | r65773 | r65774 >
Date:00:13, 2 May 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Refactoring ajaxscroll JS
Modified paths:
  • /trunk/extensions/Storyboard/jquery/jquery.ajaxscroll.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Storyboard/jquery/jquery.ajaxscroll.js
@@ -36,11 +36,13 @@
3737 var ele = this;
3838 var $me = jQuery( this );
3939 var $sp;
40 - var fnEnd;
4140 var offset = 0;
4241 var lsp = -1;
4342
44 - _css();
 43+ $me.css( {
 44+ "overflow-x": "hidden",
 45+ "overflow-y": "auto"
 46+ } );
4547
4648 opt.boxTemplate = ( opt.boxTemplate || "<span class='" + opt.boxClass + "'>&nbsp</span>" );
4749 opt.batchTemplate = ( opt.batchTemplate || "<span></span>" );
@@ -50,40 +52,27 @@
5153 offset = batch( $sp, offset, opt );
5254 $me.scrollTop(0).scrollLeft(0);
5355
54 - _ab();
 56+ var os = $me.find( '.batch:first' ).next().offset().top;
 57+ var b = ( $me.height() / os + 1 ) * os;
5558
56 - fnEnd = vEnd;
 59+ if ( "auto" == opt.uBound ) {
 60+ opt.uBound = b;
 61+ }
5762
 63+ if ( "auto" == opt.lBound ) {
 64+ opt.lBound = -b;
 65+ }
 66+
 67+ if ( "auto" == opt.eBound ) {
 68+ opt.eBound = b * 2;
 69+ }
 70+
5871 setTimeout( monEnd, opt.endDelay );
5972
6073 if( typeof opt.updateBatch == 'function' ){
6174 setTimeout( handleScrolling, opt.scrollDelay );
6275 }
6376
64 - function _css(){
65 - $me.css( {
66 - "overflow-x": "hidden",
67 - "overflow-y": "auto"
68 - } );
69 - }
70 -
71 - function _ab(){
72 - var os = $me.find( '.batch:first' ).next().offset().top;
73 - var b = ( $me.height() / os + 1 ) * os;
74 -
75 - if ( "auto" == opt.uBound ) {
76 - opt.uBound = b;
77 - }
78 -
79 - if ( "auto" == opt.lBound ) {
80 - opt.lBound = -b;
81 - }
82 -
83 - if ( "auto" == opt.eBound ) {
84 - opt.eBound = b * 2;
85 - }
86 - }
87 -
8877 function batch( $s, offset, opt ) {
8978 var $b;
9079 var i;
@@ -111,12 +100,12 @@
112101 return offset;
113102 };
114103
115 - function vScroll() {
116 - // If a batcnh is currently being loaded, we can't start another one yet.
117 - if ( opt.busy ) {
118 - return;
119 - }
120 -
 104+ /**
 105+ * This function emulates a scroll event handler by firing itself every so many ms.
 106+ * It checks if the user has scrolled down far enough, and calls the update batch
 107+ * function if this is the case.
 108+ */
 109+ function handleScrolling() {
121110 var so = $me.scrollTop();
122111
123112 if( lsp != so) {
@@ -129,13 +118,20 @@
130119
131120 if ( opt.lBound > p || p > opt.uBound ) {
132121 return;
133 - }
 122+ }
134123
135 - opt.busy = true;
136124 opt.updateBatch( $b.removeClass( opt.emptyBatchClass ), opt );
137125 });
138126 }
 127+
 128+ setTimeout( handleScrolling, opt.scrollDelay );
139129 };
 130+
 131+ function monEnd() {
 132+ if ( offset < opt.maxOffset ) {
 133+ setTimeout( monEnd, vEnd() );
 134+ }
 135+ }
140136
141137 function vEnd() {
142138 if ( ele.scrollTop > 0 && ele.scrollHeight - ele.scrollTop < opt.eBound ) {
@@ -146,21 +142,6 @@
147143 return opt.endDelay;
148144 };
149145
150 - /**
151 - * This function emulates a scroll event handler by firing itself every so many ms, and
152 - * then calling a function checking if the user has scrolled, and if any batches should be loaded.
153 - */
154 - function handleScrolling() {
155 - vScroll();
156 - setTimeout( handleScrolling, opt.scrollDelay );
157 - };
158 -
159 - function monEnd() {
160 - if ( offset < opt.maxOffset ) {
161 - setTimeout( monEnd, fnEnd() );
162 - }
163 - }
164 -
165146 });
166147 };
167148 })(jQuery);

Status & tagging log