PageSourceSearch

https://urbancube.rs/wp-content/plugins/jnews-auto-load-post/assets/js/jquery.autoload.js

js urbancube.rs collected 2026-10-02 23:32:29 UTC 6,744 bytes, 237 lines download raw bytes

1(function($){
2    "use strict";
3
4    var Autoload = function(element, options)
5    {
6        this.content_container   = '.post-wrapper';
7        this.content_class       = '.post-autoload';
8        this.current_url         = window.location.href;
9        this.post_cache          = [];
10        this.is_sidefeed         = $("#jeg_sidecontent").length ? true : false;
11        this.sidefeed            = $(".jeg_sidefeed");
12        this.change_url_locked   = false;
13
14        $(document).bind('jnews-sidefeed-ajax', $.proxy(this.clear_post_cache, this));
15        $(document).bind('jnews-sidefeed-ajax-begin', $.proxy(this.lock_change_url, this));
16        this.init();
17    };
18
19    Autoload.DEFAULTS = {};
20
21    Autoload.prototype.lock_change_url = function()
22    {
23        this.change_url_locked = true;
24    };
25
26    Autoload.prototype.init = function()
27    {
28        var base = this;
29
30        base.initialise_waypoint();
31    };
32
33    Autoload.prototype.clear_post_cache = function()
34    {
35        var base = this;
36        base.change_url_locked = false;
37        base.post_cache = [];
38        base.initialise_waypoint();
39
40    };
41
42    Autoload.prototype.find_prev_post = function(element)
43    {
44        var base = this;
45        element = $(element).next();
46
47        if(element.length)
48        {
49            if(element.hasClass('jeg_post')) {
50                return element;
51            } else {
52                return base.find_prev_post(element);
53            }
54        } else {
55            return null;
56        }
57    };
58
59    Autoload.prototype.get_previous_url = function(element, post_id)
60    {
61        var base = this;
62
63        if(base.is_sidefeed)
64        {
65            var post = base.sidefeed.find('[data-id="' + post_id + '"]');
66            var prev_post = base.find_prev_post(post);
67
68            if(prev_post) {
69                return $(prev_post).find('a.ajax').attr('href');
70            } else {
71                return null;
72            }
73        } else {
74            return $(element).data('prev');
75        }
76    };
77
78    Autoload.prototype.initialise_waypoint = function()
79    {
80        var base = this;
81
82        $( base.content_class ).each(function()
83        {
84            if(!$(this).hasClass('loaded'))
85            {
86                $(this).addClass('loaded').waypoint(function(direction)
87                {
88                    if( ! base.change_url_locked )
89                    {
90                        var waypoint = this;
91                        var func = $.proxy(base.change_url, base, waypoint.element, direction);
92                        func.call();
93                    }
94                }, {
95                    offset: '0%',
96                    context: window
97                });
98
99                $(this).find('.jnews-autoload-splitter').waypoint(function(direction)
100                {
101                    if( ! base.change_url_locked )
102                    {
103                        var waypoint = $(this.element).parents('.post-wrap');
104                        var func = $.proxy(base.change_url, base, waypoint, direction);
105                        func.call();
106                    }
107                },{
108                    offset: '0%',
109                    context: window
110                });
111            }
112        });
113    };
114
115    Autoload.prototype.strip_html = function(html){
116        var tmp = document.createElement("DIV");
117        tmp.innerHTML = html;
118        return tmp.textContent || tmp.innerText || "";
119    };
120
121    Autoload.prototype.change_url = function(element, direction)
122    {
123        var base        = this;
124        var el          = $(element);
125        var url         = el.data('url');
126        var title       = el.data('title');
127        var post_id     = el.data('id');
128        var prev_url    = base.get_previous_url(el, post_id);
129
130        // If exiting or entering from top, change URL
131        if (base.current_url != url)
132        {
133            base.current_url = url;
134
135            if(history && history.pushState)
136            {
137                history.pushState(null, title, url);
138                document.title = base.strip_html(title);
139            }
140
141            // update analytic
142            if(window.jnews && window.jnews.ajax_analytic)
143            {
144                jnews.ajax_analytic.update(url, post_id);
145            }
146
147            $(document).trigger('jnews-autoload-change-id', [post_id]);
148        }
149
150        // autoload limit
151        if ( jnewsoption.autoload_limit && ( $(base.content_class).length > parseInt(jnewsoption.autoload_limit) ) ) {
152            return false;
153        }
154
155        // Look for the next post to load if any.
156        if (prev_url && direction === 'down')
157        {
158            base.auto_load_prev_post(prev_url, post_id);
159        }
160    };
161
162    Autoload.prototype.check_loaded = function(post_id)
163    {
164        var base = this;
165        return base.post_cache.indexOf(post_id) > -1;
166    };
167
168    Autoload.prototype.push_post_id = function(post_id)
169    {
170        var base = this;
171        base.post_cache.push(post_id);
172    };
173
174    Autoload.prototype.auto_load_prev_post = function(post_url, post_id)
175    {
176        var base = this,
177            np_url = null;
178
179        if ( !post_url || base.check_loaded(post_id) )
180        {
181            return;
182        } else {
183            base.push_post_id(post_id);
184        }
185
186        // Check to see if pretty permalinks, if not then add partial=1
187        if ( post_url.indexOf( '?p=' ) > -1 )
188        {
189            np_url = post_url + '&autoload=1'
190        } else {
191            var partial_endpoint = 'autoload/';
192
193            if ( post_url.charAt(post_url.length - 1) != '/' )
194                partial_endpoint = '/' + partial_endpoint;
195
196            np_url = post_url + partial_endpoint;
197        }
198
199        $.get( np_url , function( data )
200        {
201            $(base.content_container).append(data);
202
203            // need to set up ScrollSpy on new content
204            base.initialise_waypoint();
205
206            // trigger load
207            $(document).trigger('jnews-ajax-load', [ $(base.content_container).find(base.content_class).last() ]);
208        });
209    };
210
211    function Plugin(option)
212    {
213        return $(this).each(function()
214        {
215            var $this = $(this);
216            var options = $.extend({}, Autoload.DEFAULTS, $this.data(), typeof option == 'object' && option);
217            var data = $this.data('jeg.autoload');
218
219            if (!data) $this.data('jeg.autoload', (data = new Autoload(options)));
220        });
221    }
222
223    var old = $.fn.jautoload;
224
225    $.fn.jautoload = Plugin;
226    $.fn.jautoload.Constructor = Autoload;
227
228    $.fn.jautoload.noConflict = function () {
229        $.fn.jautoload = old;
230        return this
231    };
232
233    $(document).ready(function(){
234        $('body').jautoload();
235    });
236
237})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.