source: extensions/rv_tscroller/rv_tscroller.js @ 27153

Last change on this file since 27153 was 18904, checked in by rvelices, 11 years ago

rv_tscroller hide navigation bar earlier (instead of async script loading) to avoid visible reflows on slow browsers

  • Property svn:eol-style set to LF
File size: 3.1 KB
Line 
1/*
2Don't use directly. Compile on http://closure-compiler.appspot.com/home
3*/
4if (window.jQuery && window.RVTS)
5(function($){
6if (RVTS.start>0) {
7        var $f = $('.navigationBar A[rel=first]');
8        var f = '<a href="'+$f.attr("href")+'">'+$f.html()+'</a> | ';
9        $('#thumbnails').before( '<div id=rvtsUp style="text-align:center;font-size:120%;margin:10px">'+f+'<a href="javascript:RVTS.loadUp()">'+RVTS.prevMsg+"</a></div>" );
10}
11
12RVTS = $.fn.extend( RVTS, {
13loading: 0,
14loadingUp: 0,
15adjust: 0,
16
17loadUp: function() {
18        if (RVTS.loadingUp || RVTS.start <= 0) return;
19        var newStart = RVTS.start-RVTS.perPage,
20                reqCount = RVTS.perPage;
21        if (newStart<0)
22        {
23                reqCount += newStart;
24                newStart = 0;
25        }
26        var url = RVTS.ajaxUrlModel.replace('%start%', newStart).replace('%per%', reqCount);
27        $('#ajaxLoader').show();
28        RVTS.loadingUp = 1;
29        $.ajax({
30                type:'GET', dataType:'html', 'url': url,
31                success: function(htm) {
32                        RVTS.start = newStart;
33                        RVTS.$thumbs.prepend(htm);
34                        if (RVTS.start<=0)
35                                $("#rvtsUp").remove();
36                },
37                complete: function() {
38                        RVTS.loadingUp = 0;
39                        RVTS.loading || $('#ajaxLoader').hide();
40                        $(window).trigger('RVTS_loaded', 0);
41                        if (typeof pwg_ajax_thumbnails_loader != 'undefined')
42                                pwg_ajax_thumbnails_loader();
43                        }
44                });
45},
46
47doAutoScroll: function() {
48        if (RVTS.loading || RVTS.next >= RVTS.total) return;
49        var url = RVTS.ajaxUrlModel.replace('%start%', RVTS.next).replace('%per%', RVTS.perPage);
50        if (RVTS.adjust) {
51                url += '&adj=' + RVTS.adjust;
52                RVTS.adjust=0;
53        }
54        $('#ajaxLoader').show();
55        RVTS.loading = 1;
56        $.ajax({
57                type:'GET', dataType:'html', 'url': url,
58                success: function(htm) {
59                        RVTS.next+=RVTS.perPage;
60                        RVTS.$thumbs.append(htm);
61                        if (RVTS.next-RVTS.start>500 && RVTS.total-RVTS.next>50) {
62                                RVTS.$thumbs.after(
63                                        '<div style="text-align:center;font-size:180%;margin:0 0 20px"><a href="'
64                                        +RVTS.moreUrlModel.replace('%start%', RVTS.next)+'">'
65                                        +RVTS.moreMsg.replace('%d', RVTS.total-RVTS.next)
66                                        +'</a></div>');
67                                RVTS.total = 0;
68                        }
69                },
70                complete: function() {
71                        RVTS.loading = 0;
72                        RVTS.loadingUp || $('#ajaxLoader').hide();
73                        $(window).trigger('RVTS_loaded', 1);
74                        if (typeof pwg_ajax_thumbnails_loader != 'undefined')
75                                pwg_ajax_thumbnails_loader();
76                        }
77                });
78},
79
80checkAutoScroll: function(evt) {
81        var tBot=RVTS.$thumbs.position().top+RVTS.$thumbs.outerHeight()
82                ,wBot=$(window).scrollTop()+$(window).height();
83        tBot -= !evt ? 0:100; //begin 100 pixels before end
84        return tBot <= wBot ? (RVTS.doAutoScroll(),1) : 0;
85},
86
87engage: function() {
88        var $w = $(window);
89        RVTS.$thumbs = $('#thumbnails');
90        RVTS.$thumbs.after('<div id="ajaxLoader" style="display:none;position:fixed;bottom:32px;right:1%;z-index:999"><img src="'+ RVTS.ajaxLoaderImage + '" width="128" height="15" alt="~"></div>');
91
92        $w.scrollTop(0);
93        if ( RVTS.$thumbs.outerHeight() < $w.height() )
94                RVTS.adjust = 1;
95        else if ( RVTS.$thumbs.height() > 2*$w.height() )
96                RVTS.adjust = -1;
97        $w.bind('scroll resize', RVTS.checkAutoScroll);
98        if (RVTS.checkAutoScroll())
99                window.setTimeout(RVTS.checkAutoScroll,1500);
100}
101} );//end extend
102
103$(document).ready( function() {
104        window.setTimeout(RVTS.engage,250);
105});
106
107
108
109})(jQuery);
Note: See TracBrowser for help on using the repository browser.