Index: trunk/extensions/Storyboard/jquery/jquery.ajaxscroll.js |
— | — | @@ -1,17 +1,18 @@ |
2 | 2 | /** |
3 | 3 | * AjaxScroll (jQuery Plugin) |
4 | | - * Modified for MediaWiki storyboard extension. |
| 4 | + * http://project.yctin.com/ajaxscroll |
| 5 | + * Modified for MediaWiki Storyboard extension. |
5 | 6 | * |
6 | | - * @author Timmy Tin - http://project.yctin.com/ajaxscroll |
7 | | - * @author Jeroen De Dauw |
8 | 7 | * @license GPL |
9 | 8 | * @version 0.2 |
| 9 | + * |
| 10 | + * @author Timmy Tin |
| 11 | + * @author Jeroen De Dauw |
10 | 12 | */ |
11 | 13 | (function($) { |
12 | 14 | $.fn.ajaxScroll = function( opt ) { |
13 | 15 | opt = jQuery.extend( |
14 | 16 | { |
15 | | - batchNum: 5, |
16 | 17 | batchSize: 30, |
17 | 18 | batchTemplate: null, |
18 | 19 | boxTemplate: null, |
— | — | @@ -22,11 +23,11 @@ |
23 | 24 | lBound: "auto", |
24 | 25 | uBound: "auto", |
25 | 26 | eBound: "auto", |
26 | | - maxOffset: 1000, |
27 | 27 | scrollDelay: 600, // The interval for checking if the user scrolled, in ms. |
28 | 28 | endDelay: 100, |
29 | 29 | updateBatch: null, |
30 | | - updateEnd: null |
| 30 | + updateEnd: null, |
| 31 | + loaded: false |
31 | 32 | }, |
32 | 33 | opt |
33 | 34 | ); |
— | — | @@ -35,7 +36,6 @@ |
36 | 37 | var ele = this; |
37 | 38 | var $me = jQuery( this ); |
38 | 39 | var $sp; |
39 | | - var offset = 0; |
40 | 40 | var previousScrollPos = -1; |
41 | 41 | |
42 | 42 | $me.css( { |
— | — | @@ -48,24 +48,31 @@ |
49 | 49 | |
50 | 50 | $sp = jQuery( "<div></div>" ).addClass( opt.scrollPaneClass ); |
51 | 51 | $me.append( $sp ); |
52 | | - offset = batch( $sp, offset, opt ); |
| 52 | + batch( $sp, opt ); |
| 53 | + batch( $sp, opt ); |
53 | 54 | $me.scrollTop(0).scrollLeft(0); |
54 | 55 | |
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; |
57 | 58 | |
58 | | - if ( "auto" == opt.uBound ) { |
| 59 | + if ( opt.uBound == "auto" ) { |
59 | 60 | opt.uBound = b; |
60 | 61 | } |
61 | 62 | |
62 | | - if ( "auto" == opt.lBound ) { |
| 63 | + if ( opt.lBound == "auto" ) { |
63 | 64 | opt.lBound = -b; |
64 | 65 | } |
65 | 66 | |
66 | | - if ( "auto" == opt.eBound ) { |
| 67 | + if ( opt.eBound == "auto" ) { |
67 | 68 | opt.eBound = b * 2; |
68 | 69 | } |
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 | + */ |
70 | 77 | setTimeout( monEnd, opt.endDelay ); |
71 | 78 | |
72 | 79 | // Initiate the scroll handling. |
— | — | @@ -73,29 +80,23 @@ |
74 | 81 | setTimeout( handleScrolling, opt.scrollDelay ); |
75 | 82 | } |
76 | 83 | |
77 | | - function batch( $s, offset, opt ) { |
| 84 | + function batch( $s, opt ) { |
78 | 85 | var $b; |
79 | 86 | var i; |
80 | | - var rp = opt.batchNum; |
81 | 87 | |
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 ); |
97 | 98 | } |
98 | 99 | |
99 | | - return offset; |
| 100 | + $s.append( $b ); |
100 | 101 | }; |
101 | 102 | |
102 | 103 | /** |
— | — | @@ -106,19 +107,22 @@ |
107 | 108 | function handleScrolling() { |
108 | 109 | var scrollPos = $me.scrollTop(); |
109 | 110 | |
110 | | - if( !window.storyboardBusy && previousScrollPos != scrollPos ) { |
| 111 | + // TODO: add check to make sure the board is not currently busy |
| 112 | + if( previousScrollPos != scrollPos ) { |
111 | 113 | previousScrollPos = scrollPos; |
112 | 114 | var co = $me.offset().top; |
113 | 115 | |
114 | 116 | $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 | + |
115 | 120 | var $batchDiv = jQuery( obj ); |
116 | 121 | var p = $batchDiv.position().top - co; |
117 | 122 | |
118 | 123 | if ( opt.lBound > p || p > opt.uBound ) { |
119 | 124 | return; |
120 | | - } |
| 125 | + } |
121 | 126 | |
122 | | - window.storyboardBusy = true; |
123 | 127 | opt.updateBatch( $batchDiv.removeClass( opt.emptyBatchClass ) ); |
124 | 128 | }); |
125 | 129 | } |
— | — | @@ -127,14 +131,12 @@ |
128 | 132 | }; |
129 | 133 | |
130 | 134 | function monEnd() { |
131 | | - if ( offset < opt.maxOffset ) { |
132 | | - setTimeout( monEnd, vEnd() ); |
133 | | - } |
| 135 | + setTimeout( monEnd, vEnd() ); |
134 | 136 | } |
135 | 137 | |
136 | 138 | function vEnd() { |
137 | 139 | if ( ele.scrollTop > 0 && ele.scrollHeight - ele.scrollTop < opt.eBound ) { |
138 | | - offset = batch( $sp, offset, opt ); |
| 140 | + batch( $sp, opt ); |
139 | 141 | return 1; |
140 | 142 | } |
141 | 143 | |
Index: trunk/extensions/Storyboard/tags/Storyboard/storyboard.js |
— | — | @@ -10,8 +10,7 @@ |
11 | 11 | $( '.storyboard' ).ajaxScroll( { |
12 | 12 | updateBatch: updateStoryboard, |
13 | 13 | 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, |
16 | 15 | batchClass: "batch", |
17 | 16 | boxClass: "storyboard-box", |
18 | 17 | emptyBatchClass: "storyboard-empty", |
— | — | @@ -24,7 +23,7 @@ |
25 | 24 | 'action': 'query', |
26 | 25 | 'list': 'stories', |
27 | 26 | 'format': 'json', |
28 | | - 'stlimit': 2, |
| 27 | + 'stlimit': 4, |
29 | 28 | 'stlanguage': window.storyboardLanguage |
30 | 29 | }; |
31 | 30 | |
— | — | @@ -122,8 +121,6 @@ |
123 | 122 | } |
124 | 123 | |
125 | 124 | window.storyContinueParam = data["query-continue"] ? data["query-continue"] : false; |
126 | | - |
127 | | - window.storyboardBusy = false; |
128 | 125 | } |
129 | 126 | |
130 | 127 | })(jQuery); |
\ No newline at end of file |