PageSourceSearch

https://qalamnass.com/wp-content/plugins/dnews/assets/js/rt-loadmore.js?ver=201513434

js qalamnass.com collected 2026-10-03 18:10:08 UTC 14,918 bytes, 329 lines download raw bytes

1(function ($) {
2    "use strict";
3    
4    // Load More Post Script
5    if ($('.rt-load-more-inner').length || $('.rt_infinite_posts').length) {
6        $(document).ready(function ($) {
7            let posts_per_page = $('.rt-post').attr('data-perload');
8            let pageNumber = $('.rt-post').attr('data-paged');
9            let isLoading = false; // To prevent multiple AJAX calls
10
11            function back__load_more_posts(back_this, pageNumber, category, layout, portfolio_column, enable_cate, back_thumbnail, length_title, read_text, posts_sort_orderby, posts_sort) {
12                let page_count = 0;
13                let str =
14                    "&pageNumber=" +
15                    pageNumber +
16                    "&posts_per_page=" +
17                    posts_per_page +
18                    "&action=back_load_more_post_ajax" +
19                    "&category=" +
20                    category +
21                    "&layout=" +
22                    layout +
23                    "&read_text=" +
24                    read_text +
25                    "&enable_cate=" +
26                    enable_cate +
27                    "&length_title=" +
28                    length_title +
29                    "&portfolio_column=" +
30                    portfolio_column +
31                    "&back_thumbnail=" +
32                    back_thumbnail +
33                    "&posts_sort_orderby=" +
34                    posts_sort_orderby +
35                    "&posts_sort=" +
36                    posts_sort;
37
38                if (!back_this.hasClass("back-disabled") && !isLoading) {
39                    isLoading = true; // Prevent multiple AJAX calls
40
41                    jQuery.ajax({
42                        type: "POST",
43                        dataType: "html",
44                        url: ajax_posts.ajaxurl,
45                        data: str,
46                        beforeSend: function () {
47                            $('.rt-loading-message').show(); // Show loading message
48                        },
49                        success: function (response) {
50                            $('.rt-loading-message').hide();
51                            if (response) {
52                                back_this.removeClass("back-active");
53                                var json_html = JSON.parse(response);
54                                if (json_html.html.length) {
55                                    page_count = parseInt(pageNumber) + 1;
56                                    back_this.attr("data-page", page_count);
57                                    back_this.attr("data-cate", category);
58                                    back_this
59                                        .parents(".rt-post-wrap")
60                                        .find(".back-posts")
61                                        .append(json_html.html);
62                                } else {
63                                    back_this.addClass("back-disabled");
64                                    $('.rt-loading-message').remove();
65                                    $('.rt-no-more-posts').show();
66                                }
67                            }
68                            isLoading = false; // Reset loading state
69                        },
70                    });
71                }
72                return false;
73            }
74
75            // Load more button click event        
76            if ($('.rt-load-more-inner').length) {
77                $(document).on("click", ".rt-load-more", function () {
78                    let back_this = $(this);
79                    let pageNumber = back_this.attr("data-page");
80                    let category = back_this.attr("data-cate");
81                    let layout = back_this.attr('data-layout');
82                    let back_thumbnail = back_this.attr('data-thumbnail');
83                    let length_title = back_this.attr('data-length');
84                    let read_text = back_this.attr('data-read');
85                    let enable_cate = back_this.attr('data-enable-cate');
86                    let portfolio_column = back_this.attr('data-column');
87                    let posts_sort_orderby = back_this.attr('data-orderby');
88                    let posts_sort = back_this.attr('data-sort');
89
90                    $('.rt-loading-message').show();
91                    back_this.addClass("back-active");
92                    back__load_more_posts(back_this, pageNumber, 
92category, layout, portfolio_column, enable_cate, back_thumbnail, length_title, read_text, posts_sort_orderby, posts_sort);
93                    back_this.insertAfter(".back-posts");
94                });
95            }
96
97            // Infinite scroll event
98            if ($('.rt_infinite_posts').length) {
99                $(window).on('scroll', function () {
100                    if ($(window).scrollTop() + $(window).height() >= $(document).height() - 200) { 
101                        if (!isLoading) {
102                            let back_this = $('.rt-load-more');
103                            let pageNumber = back_this.attr("data-page");
104                            let category = back_this.attr("data-cate");
105                            let layout = back_this.attr('data-layout');
106                            let back_thumbnail = back_this.attr('data-thumbnail');
107                            let length_title = back_this.attr('data-length');
108                            let read_text = back_this.attr('data-read');
109                            let enable_cate = back_this.attr('data-enable-cate');
110                            let portfolio_column = back_this.attr('data-column');
111                            let posts_sort_orderby = back_this.attr('data-orderby');
112                            let posts_sort = back_this.attr('data-sort');
113
114                            back__load_more_posts(back_this, pageNumber, category, layout, portfolio_column, enable_cate, back_thumbnail, length_title, read_text, posts_sort_orderby, posts_sort);
115                        }
116                    }
117                });
118            }
119        });
120    }
121
122    
123    if ($('.rt-post-content-wrap').length) {
124        let isLoading = false;
125        let currentPostId = $('.reactheme-blog-details').data('post-id'); 
126        let previousPostUrl = $('.next a').attr('href');
127        let visitedPosts = [currentPostId];
128        function loadPreviousPost() {
129            if (isLoading || !previousPostUrl) return;
130            isLoading = true;
131            $('#rt-loading-post').show();
132            $.ajax({
133                url: previousPostUrl,
134                type: 'GET',
135                dataType: 'html',
136                success: function (response) {
137                    $('#rt-loading-post').hide();
138                    const newContent = $(response).find('.reactheme-blog-details');
139                    const newPostId = newContent.data('post-id');
140                    const newPreviousPostUrl = $(response).find('.next a').attr('href');
141                    if (visitedPosts.includes(newPostId)) {
142                        visitedPosts = [currentPostId];
143                        previousPostUrl = $('.next a').attr('href');
144                        isLoading = false;
145                        return;
146                    }
147                    visitedPosts.push(newPostId);
148                    previousPostUrl = newPreviousPostUrl;
149                    if (newContent.length) {
150                        $('.rt-post-content-wrap').append('<div class="reactheme-blog-details" data-post-id="' + newPostId + '">' + newContent.html() + '</div>');
151                    }
152
153                    isLoading = false;
154                },
155                error: function () {
156                    $('#rt-loading-post').hide();
157                    isLoading = false;
158                }
159            });
160        }
161
162        if ($('.rt-post-infinite-wrap').length) {
163            $(window).on('scroll', function () {
164                const scrollPosition = $(window).scrollTop() + $(window).height();
165                const threshold = $(document).height() - 10;
166
167                if (scrollPosition >= threshold) {
168                    loadPreviousPost();
169                }
170            });
171        }
172
173        if ($('#load-more-btn').length) {
174            $('#load-more-btn').on('click', function () {
175                loadPreviousPost();
176            });
177        }
178    }
179    
180    
181    if ($('.rt-post-progress-wrap').length) {
182        if (!$('#rt-loading-progress-container').length) {
183            $('body').append(`
184                <div id="rt-loading-progress-container" style="position: fixed; top: 0; left: 0; width: 100%; z-index: 9999;">
185                    <div id="rt-loading-progress" style="height: 4px; width: 0%; transition: width 0.1s;"></div>
186                </div>
187            `);
188        }
189
190        function updateProgressBar(currentPost) {
191            const postTop = $(currentPost).offset().top;
192            const postHeight = $(currentPost).outerHeight();
193            const scrollTop = $(window).scrollTop();
194            const windowHeight = $(window).height();
195            let scrollPercent = ((scrollTop - postTop) / (postHeight - windowHeight)) * 100;
196            scrollPercent = Math.max(0, Math.min(scrollPercent, 100));
197            $('#rt-loading-progress').css('width', scrollPercent + '%');
198        }
199
200        $(window).on('scroll', function () {
201            const currentPost = $('.reactheme-blog-details').last();
202            updateProgressBar(currentPost);
203        });
204        updateProgressBar($('.reactheme-blog-details').last());
205    }
206
207
208    if ($('.reactheme-blog').length) {
209        let isLoading = false;
210        let nextPageUrl = $('.pagination-area .next').attr('href');
211        function loadNextPosts() {
212            if (isLoading || !nextPageUrl) return;
213            isLoading = true;
214            $('#rt-loading-post').show();
215
216            $.ajax({
217                url: nextPageUrl,
218                type: 'GET',
219                dataType: 'html',
220                success: function (response) {
221                    $('#rt-loading-post').hide();
222                    const newPosts = $(response).find('.rt-contents-sticky .rt-row-load .post-item');
223                    const newPaginationUrl = $(response).find('.pagination-area .next').attr('href');
224                    if (newPosts.length) {
225                        $('.rt-contents-sticky .rt-row-load').append(newPosts);
226                    }
227                    if (newPaginationUrl) {
228                        nextPageUrl = newPaginationUrl;
229                    } else {
230                        nextPageUrl = null;
231                        $('#load-more-btn').remove();
232                        $('.no-more-posts-message').fadeIn();
233                    }
234                    isLoading = false;
235                },
236                error: function () {
237                    $('#rt-loading-post').hide();
238                    isLoading = false;
239                }
240            });
241        }
242
243        if ($('.rt-blog-infinite-wrap').length) {
244            $(window).on('scroll', function () {
245                const scrollPosition = $(window).scrollTop() + $(window).height();
246                const triggerPosition = $('.rt-contents-sticky').offset().top + $('.rt-contents-sticky').outerHeight();
247                if (scrollPosition >= triggerPosition - 100) {
248                    loadNextPosts();
249                }
250            });
251        }
252
253        if ($('#load-more-btn').length) {
254            $('#load-more-btn').off('click').on('click', function () {
255                loadNextPosts();
256            });
257        }
258    }
259
260
261    if ($('.rt-cart-count').length) {
262        jQuery(document).ready(function ($) {
263            function updateCartCount() {
264                $.ajax({
265                    url: ajax_posts.ajaxurl,
266                    type: 'POST',
267                    data: {
268                        action: 'get_cart_count',
269                    },
270                    success: function (response) {
271                        if (response.success) {
272                            if (response.data.cart_count > 0) {
273                                $('.rt-woo-cart .cart-count').show().text(response.data.cart_count);
274                            } else {
275                            }
276                        } else {
277                            console.error('Failed to update cart count:', response);
278                        }
279                    },
280                    error: function (xhr, status, error) {
281                        console.error('AJAX Error:', error);
282                    },
283                });
284            }
285            $(document.body).on('wc_fragments_refreshed wc_fragments_loaded', updateCartCount);
286            updateCartCount();
287        });
288    }
289
290    
291    if ($('.rt-auto-search').length) {
292        document.addEventListener("DOMContentLoaded", function () {
293            const searchInput = document.querySelector(".search-input");
294            const resultsContainer = document.createElement("div");
295            resultsContainer.classList.add("search-suggestions");
296            searchInput.parentNode.appendChild(resultsContainer);
297            searchInput.addEventListener("input", function () {
298                const query = searchInput.value.trim();
299                if (!query) {
300                    resultsContainer.innerHTML = "";
301                    resultsContainer.style.display = "none";
302                    return;
303                }
304                fetch(`${ajax_posts.ajaxurl}?action=dnews_search_suggestions&term=${encodeURIComponent(query)}`)
305                    .then((response) => response.json())
306                    .then((data) => {
307                        resultsContainer.innerHTML = "";
308                        resultsContainer.style.display = "block";
309
310                        if (data.success) {
311                            data.data.forEach((item) => {
312                                const suggestion = document.createElement("div");
313                                suggestion.classList.add("suggestion-item");
314                                suggestion.innerHTML = `<a href="${item.link}">${item.title}</a>`;
315                                resultsContainer.appendChild(suggestion);
316                            });
317                        } else {
318                            resultsContainer.innerHTML = `<div class="no-results">${data.data.message}</div>`;
319                        }
320                    })
321                    .catch((error) => {
322                        console.error("Error fetching suggestions:", error);
323                    });
324            });
325        });
326    }
327
328
329})(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.