source: extensions/rv_tscroller/rv_tscroller.js @ 15555

Last change on this file since 15555 was 13453, checked in by patdenice, 12 years ago

Compatibility with ajax thumbnails loader

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