1 | /* |
---|
2 | Don't use directly. Compile on http://closure-compiler.appspot.com/home |
---|
3 | */ |
---|
4 | if (window.jQuery && window.RVTS) |
---|
5 | (function($){ |
---|
6 | if (RVTS.start>0) { |
---|
7 | var $f = $('.navigationBar A[rel=first]'); |
---|
8 | $('#thumbnails').before( '<div id=rvtsUp style="text-align:center;font-size:120%;margin:10px"><a href="'+$f.attr("href")+'">'+$f.html()+'</a> | <a href="javascript:RVTS.loadUp()">'+RVTS.prevMsg+"</a></div>" ); |
---|
9 | } |
---|
10 | |
---|
11 | RVTS = $.fn.extend( RVTS, { |
---|
12 | loading: 0, |
---|
13 | loadingUp: 0, |
---|
14 | adjust: 0, |
---|
15 | |
---|
16 | loadUp: function() { |
---|
17 | if (RVTS.loadingUp || RVTS.start <= 0) return; |
---|
18 | var newStart = RVTS.start-RVTS.perPage, |
---|
19 | reqCount = RVTS.perPage; |
---|
20 | if (newStart<0) |
---|
21 | { |
---|
22 | reqCount += newStart; |
---|
23 | newStart = 0; |
---|
24 | } |
---|
25 | var url = RVTS.ajaxUrlModel.replace('%start%', newStart).replace('%per%', reqCount); |
---|
26 | $('#ajaxLoader').show(); |
---|
27 | RVTS.loadingUp = 1; |
---|
28 | $.ajax({ |
---|
29 | type:'GET', dataType:'html', 'url': url, |
---|
30 | success: function(htm) { |
---|
31 | RVTS.start = newStart; |
---|
32 | RVTS.$thumbs.prepend(htm); |
---|
33 | if (RVTS.start<=0) |
---|
34 | $("#rvtsUp").remove(); |
---|
35 | }, |
---|
36 | complete: function() { |
---|
37 | RVTS.loadingUp = 0; |
---|
38 | RVTS.loading || $('#ajaxLoader').hide(); |
---|
39 | $(window).trigger('RVTS_loaded', 0); |
---|
40 | if (typeof pwg_ajax_thumbnails_loader != 'undefined') |
---|
41 | pwg_ajax_thumbnails_loader(); |
---|
42 | } |
---|
43 | }); |
---|
44 | }, |
---|
45 | |
---|
46 | doAutoScroll: function() { |
---|
47 | if (RVTS.loading || RVTS.next >= RVTS.total) return; |
---|
48 | var url = RVTS.ajaxUrlModel.replace('%start%', RVTS.next).replace('%per%', RVTS.perPage); |
---|
49 | if (RVTS.adjust) { |
---|
50 | url += '&adj=' + RVTS.adjust; |
---|
51 | RVTS.adjust=0; |
---|
52 | } |
---|
53 | $('#ajaxLoader').show(); |
---|
54 | RVTS.loading = 1; |
---|
55 | $.ajax({ |
---|
56 | type:'GET', dataType:'html', 'url': url, |
---|
57 | success: function(htm) { |
---|
58 | RVTS.next+=RVTS.perPage; |
---|
59 | RVTS.$thumbs.append(htm); |
---|
60 | if (RVTS.next-RVTS.start>500 && RVTS.total-RVTS.next>50) { |
---|
61 | RVTS.$thumbs.after( |
---|
62 | '<div style="text-align:center;font-size:180%;margin:0 0 20px"><a href="' |
---|
63 | +RVTS.urlModel.replace('%start%', RVTS.next)+'">' |
---|
64 | +RVTS.moreMsg.replace('%d', RVTS.total-RVTS.next) |
---|
65 | +'</a></div>'); |
---|
66 | RVTS.total = 0; |
---|
67 | } |
---|
68 | }, |
---|
69 | complete: function() { |
---|
70 | RVTS.loading = 0; |
---|
71 | RVTS.loadingUp || $('#ajaxLoader').hide(); |
---|
72 | $(window).trigger('RVTS_loaded', 1); |
---|
73 | if (typeof pwg_ajax_thumbnails_loader != 'undefined') |
---|
74 | pwg_ajax_thumbnails_loader(); |
---|
75 | } |
---|
76 | }); |
---|
77 | }, |
---|
78 | |
---|
79 | checkAutoScroll: function(evt) { |
---|
80 | var tBot=RVTS.$thumbs.position().top+RVTS.$thumbs.outerHeight() |
---|
81 | ,wBot=$(window).scrollTop()+$(window).height(); |
---|
82 | tBot -= !evt ? 0:100; //begin 100 pixels before end |
---|
83 | return tBot <= wBot ? (RVTS.doAutoScroll(),1) : 0; |
---|
84 | }, |
---|
85 | |
---|
86 | engage: function() { |
---|
87 | var $w = $(window); |
---|
88 | RVTS.$thumbs = $('#thumbnails'); |
---|
89 | 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>'); |
---|
90 | |
---|
91 | if ("#top" == window.location.hash) |
---|
92 | window.scrollTo(0,0); |
---|
93 | |
---|
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.on('scroll resize', RVTS.checkAutoScroll); |
---|
99 | if (RVTS.checkAutoScroll()) |
---|
100 | window.setTimeout(RVTS.checkAutoScroll,1500); |
---|
101 | } |
---|
102 | } );//end extend |
---|
103 | |
---|
104 | $(document).ready( function() { |
---|
105 | if ("#top" == window.location.hash) |
---|
106 | window.scrollTo(0,0); |
---|
107 | window.setTimeout(RVTS.engage,150); |
---|
108 | }); |
---|
109 | |
---|
110 | if (window.history.replaceState) { |
---|
111 | var iniStart = RVTS.start; |
---|
112 | $(window).one("RVTS_loaded", function() { |
---|
113 | $(window).on("unload", function() { |
---|
114 | var threshold = Math.max(0, $(window).scrollTop() - 60), |
---|
115 | elts = RVTS.$thumbs.children("li"); |
---|
116 | for (var i=0; i<elts.length; i++) { |
---|
117 | var offset = $(elts[i]).offset(); |
---|
118 | if (offset.top >= threshold) { |
---|
119 | var start = RVTS.start+i, |
---|
120 | delta = start-iniStart; |
---|
121 | if (delta<0 || delta>=RVTS.perPage) { |
---|
122 | var url = start ? RVTS.urlModel.replace("%start%", start) : RVTS.urlModel.replace("/start-%start%", ""); |
---|
123 | window.history.replaceState(null, "", url+ "#top"); |
---|
124 | } |
---|
125 | break; |
---|
126 | } |
---|
127 | } |
---|
128 | }); |
---|
129 | }); |
---|
130 | } |
---|
131 | })(jQuery); |
---|