PageSourceSearch

https://www.kisr.edu.kw/static/el-pagination/js/el-pagination.js

js kisr.edu.kw collected 2026-09-24 19:52:04 UTC 5,081 bytes, 122 lines download raw bytes

1'use strict';
2
3(function ($) {
4
5    // Fix JS String.trim() function is unavailable in IE<9 #45
6    if (typeof(String.prototype.trim) === "undefined") {
7         String.prototype.trim = function() {
8             return String(this).replace(/^\s+|\s+$/g, '');
9         };
10    }
11
12    $.fn.endlessPaginate = function(options) {
13        var defaults = {
14            // Twitter-style pagination container selector.
15            containerSelector: '.endless_container',
16            // Twitter-style pagination loading selector.
17            loadingSelector: '.endless_loading',
18            // Twitter-style pagination link selector.
19            moreSelector: 'a.endless_more',
20            // Digg-style pagination page template selector.
21            pageSelector: '.endless_page_template',
22            // Digg-style pagination link selector.
23            pagesSelector: 'a.endless_page_link',
24            // Callback called when the user clicks to get another page.
25            onClick: function() {},
26            // Callback called when the new page is correctly displayed.
27            onCompleted: function() {},
28            // Set this to true to use the paginate-on-scroll feature.
29            paginateOnScroll: false,
30            // If paginate-on-scroll is on, this margin will be used.
31            paginateOnScrollMargin : 1,
32            // If paginate-on-scroll is on, it is possible to define chunks.
33            paginateOnScrollChunkSize: 0
34        },
35            settings = $.extend(defaults, options);
36
37        var getContext = function(link) {
38            return {
39                key: link.data("el-querystring-key").split(' ')[0],
40                url: link.attr('href')
41            };
42        };
43
44        return this.each(function() {
45            var element = $(this),
46                loadedPages = 1;
47
48            // Twitter-style pagination.
49            element.on('click', settings.moreSelector, function() {
50                var link = $(this),
51                    html_link = link.get(0),
52                    container = link.closest(settings.containerSelector),
53                    loading = container.find(settings.loadingSelector);
54                // Avoid multiple Ajax calls.
55                if (loading.is(':visible')) {
56                    return false;
57                }
58                link.hide();
59                loading.show();
60                var context = getContext(link);
61                // Fire onClick callback.
62                if (settings.onClick.apply(html_link, [context]) !== false) {
63                    var data = 'querystring_key=' + context.key;
64                    // Send the Ajax request.
65                    $.get(context.url, data, function(fragment) {
66                        container.before(fragment);
67                        container.remove();
68                        // Increase the number of loaded pages.
69                        loadedPages += 1;
70                        // Fire onCompleted callback.
71                        settings.onCompleted.apply(
72                            html_link, [context, fragment.trim()]);
73                    });
74                }
75                return false;
76            });
77
78            // On scroll pagination.
79            if (settings.paginateOnScroll) {
80                var win = $(window),
81                    doc = $(document);
82                doc.scroll(function(){
83                    if (doc.height() - win.height() -
84                        win.scrollTop() <= settings.paginateOnScrollMargin) {
85                        // Do not paginate on scroll if chunks are used and
86                        // the current chunk is complete.
87                        var chunckSize = settings.paginateOnScrollChunkSize;
88                        if (!chunckSize || loadedPages % chunckSize) {
89                            element.find(settings.moreSelector).click();
90                        } else {
91                            element.find(settings.moreSelector).addClass('endless_chunk_complete');
92                        }
93                    }
94                });
95            }
96
97            // Digg-style pagination.
98            element.on('click', settings.pagesSelector, function() {
99                var link = $(this),
100                    html_link = link.get(0),
101                    context = getContext(link);
102                // Fire onClick callback.
103                if (settings.onClick.apply(html_link, [context]) !== false) {
104                    var page_template = link.closest(settings.pageSelector),
105                        data = 'querystring_key=' + context.key;
106                    // Send the Ajax request.
107                    page_template.load(context.url, data, function(fragment) {
108                        // Fire onCompleted callback.
109                        settings.onCompleted.apply(
110                            html_link, [context, fragment.trim()]);
111                    });
112                }
113                return false;
114            });
115        });
116    };
117
118    $.endlessPaginate = function(options) {
119        return $('body').endlessPaginate(options);
120    };
121
122})(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.