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 | |
---|
33 | var event = jQuery.Event( "RVTS_add" ); |
---|
34 | $(window).trigger(event, [htm, false]); |
---|
35 | |
---|
36 | if (!event.isDefaultPrevented()) |
---|
37 | RVTS.$thumbs.prepend(htm); |
---|
38 | |
---|
39 | if (RVTS.start<=0) |
---|
40 | $("#rvtsUp").remove(); |
---|
41 | }, |
---|
42 | complete: function() { |
---|
43 | RVTS.loadingUp = 0; |
---|
44 | RVTS.loading || $('#ajaxLoader').hide(); |
---|
45 | $(window).trigger('RVTS_loaded', 0); |
---|
46 | if (typeof pwg_ajax_thumbnails_loader != 'undefined') |
---|
47 | pwg_ajax_thumbnails_loader(); |
---|
48 | } |
---|
49 | }); |
---|
50 | }, |
---|
51 | |
---|
52 | doAutoScroll: function() { |
---|
53 | if (RVTS.loading || RVTS.next >= RVTS.total) return; |
---|
54 | var url = RVTS.ajaxUrlModel.replace('%start%', RVTS.next).replace('%per%', RVTS.perPage); |
---|
55 | if (RVTS.adjust) { |
---|
56 | url += '&adj=' + RVTS.adjust; |
---|
57 | RVTS.adjust=0; |
---|
58 | } |
---|
59 | $('#ajaxLoader').show(); |
---|
60 | RVTS.loading = 1; |
---|
61 | $.ajax({ |
---|
62 | type:'GET', dataType:'html', 'url': url, |
---|
63 | success: function(htm) { |
---|
64 | RVTS.next+=RVTS.perPage; |
---|
65 | var event = jQuery.Event( "RVTS_add" ); |
---|
66 | $(window).trigger(event, [htm, true]); |
---|
67 | |
---|
68 | if (!event.isDefaultPrevented()) |
---|
69 | RVTS.$thumbs.append(htm); |
---|
70 | if (RVTS.next-RVTS.start>500 && RVTS.total-RVTS.next>50) { |
---|
71 | RVTS.$thumbs.after( |
---|
72 | '<div style="text-align:center;font-size:180%;margin:0 0 20px"><a href="' |
---|
73 | +RVTS.urlModel.replace('%start%', RVTS.next)+'">' |
---|
74 | +RVTS.moreMsg.replace('%d', RVTS.total-RVTS.next) |
---|
75 | +'</a></div>'); |
---|
76 | RVTS.total = 0; |
---|
77 | } |
---|
78 | }, |
---|
79 | complete: function() { |
---|
80 | RVTS.loading = 0; |
---|
81 | RVTS.loadingUp || $('#ajaxLoader').hide(); |
---|
82 | $(window).trigger('RVTS_loaded', 1); |
---|
83 | if (typeof pwg_ajax_thumbnails_loader != 'undefined') |
---|
84 | pwg_ajax_thumbnails_loader(); |
---|
85 | } |
---|
86 | }); |
---|
87 | }, |
---|
88 | |
---|
89 | checkAutoScroll: function(evt) { |
---|
90 | var tBot=RVTS.$thumbs.position().top+RVTS.$thumbs.outerHeight() |
---|
91 | ,wBot=$(window).scrollTop()+$(window).height(); |
---|
92 | tBot -= !evt ? 0:100; //begin 100 pixels before end |
---|
93 | return tBot <= wBot ? (RVTS.doAutoScroll(),1) : 0; |
---|
94 | }, |
---|
95 | |
---|
96 | engage: function() { |
---|
97 | var $w = $(window); |
---|
98 | RVTS.$thumbs = $('#thumbnails'); |
---|
99 | 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>'); |
---|
100 | |
---|
101 | if ("#top" == window.location.hash) |
---|
102 | window.scrollTo(0,0); |
---|
103 | |
---|
104 | if ( RVTS.$thumbs.outerHeight() < $w.height() ) |
---|
105 | RVTS.adjust = 1; |
---|
106 | else if ( RVTS.$thumbs.height() > 2*$w.height() ) |
---|
107 | RVTS.adjust = -1; |
---|
108 | $w.on('scroll resize', RVTS.checkAutoScroll); |
---|
109 | if (RVTS.checkAutoScroll()) |
---|
110 | window.setTimeout(RVTS.checkAutoScroll,1500); |
---|
111 | } |
---|
112 | } );//end extend |
---|
113 | |
---|
114 | $(document).ready( function() { |
---|
115 | if ("#top" == window.location.hash) |
---|
116 | window.scrollTo(0,0); |
---|
117 | window.setTimeout(RVTS.engage,150); |
---|
118 | }); |
---|
119 | |
---|
120 | if (window.history.replaceState) { |
---|
121 | var iniStart = RVTS.start; |
---|
122 | $(window).one("RVTS_loaded", function() { |
---|
123 | $(window).on("unload", function() { |
---|
124 | var threshold = Math.max(0, $(window).scrollTop() - 60), |
---|
125 | elts = RVTS.$thumbs.children("li"); |
---|
126 | for (var i=0; i<elts.length; i++) { |
---|
127 | var offset = $(elts[i]).offset(); |
---|
128 | if (offset.top >= threshold) { |
---|
129 | var start = RVTS.start+i, |
---|
130 | delta = start-iniStart; |
---|
131 | if (delta<0 || delta>=RVTS.perPage) { |
---|
132 | var url = start ? RVTS.urlModel.replace("%start%", start) : RVTS.urlModel.replace("/start-%start%", ""); |
---|
133 | window.history.replaceState(null, "", url+ "#top"); |
---|
134 | } |
---|
135 | break; |
---|
136 | } |
---|
137 | } |
---|
138 | }); |
---|
139 | }); |
---|
140 | } |
---|
141 | })(jQuery); |
---|