PageSourceSearch

https://www.kanuhawaii.org/wp-content/plugins/paginator-shortcode/…/src/jquery.paginate.js?ver=1.0.0

js kanuhawaii.org collected 2026-10-02 10:33:07 UTC 7,609 bytes, 211 lines download raw bytes

1/*
2    jquery.paginate
3    ^^^^^^^^^^^^^^^
4
5    Description: Add a pagination to everything.
6    Version: Version 0.3.0
7    Author: Kevin Eichhorn (https://github.com/neighbordog)
8*/
9
10(function( $ ) {
11
12    $.paginate = function(element, options) {
13
14        /*
15            #Defaults
16        */
17        var defaults = {
18            perPage:                3,              //how many items per page
19            autoScroll:             true,           //boolean: scroll to top of the container if a user clicks on a pagination link
20            scope:                  '',             //which elements to target
21            paginatePosition:       ['bottom'],     //defines where the pagination will be displayed
22            containerTag:           'nav',
23            paginationTag:          'ul',
24            itemTag:                'li',
25            linkTag:                'a',
26            useHashLocation:        true,           //Determines whether or not the plugin makes use of hash locations
27            onPageClick:            function() {}   //Triggered when a pagination link is clicked
28
29        };
30
31        var plugin = this;
32        var plugin_index = $('.paginate').length;
33
34        plugin.settings = {};
35
36        var $element = $(element);
37
38        var curPage, items, offset, maxPage;
39
40        /*
41            #Initliazes plugin
42        */
43        plugin.init = function() {
44            plugin.settings = $.extend({}, defaults, options);
45
46            curPage = 1;
47            items =  $element.children(plugin.settings.scope);
48            maxPage = Math.ceil( items.length / plugin.settings.perPage ); //determines how many pages exist
49
50            var paginationHTML = generatePagination(); //generate HTML for pageination
51
52            if($.inArray('top', plugin.settings.paginatePosition) > -1) {
53                $element.before(paginationHTML);
54            }
55
56            if($.inArray('bottom', plugin.settings.paginatePosition) > -1) {
57                $element.after(paginationHTML);
58            }
59
60            $element.addClass("paginate");
61            $element.addClass("paginate-" + plugin_index);
62
63            var hash = location.hash.match(/\#paginate\-(\d)/i);
64
65            //Check if URL has matching location hash
66            if(hash && plugin.settings.useHashLocation) {
67                plugin.switchPage(hash[1]);
68            } else {
69                plugin.switchPage(1); //go to initial page
70            }
71
72        };
73
74        /*
75            #Switch to Page > 'page'
76        */
77        plugin.switchPage = function(page) {
78
79            if(page == "next") {
80                page = curPage + 1;
81            }
82
83            if(page == "prev") {
84                page = curPage - 1;
85            }
86
87            //If page is out of range return false
88            if(page < 1 || page > maxPage) {
89                return false;
90            }
91
92            if(page > maxPage) {
93                $('.paginate-pagination-' + plugin_index).find('.page-next').addClass("deactive");
94                return false;
95            } else {
96                $('.paginate-pagination-' + plugin_index).find('.page-next').removeClass("deactive");
97            }
98
99            $('.paginate-pagination-' + plugin_index).find('.active').removeClass('active');
100            $('.paginate-pagination-' + plugin_index).find('.page-' + page).addClass('active');
101
102            offset = (page - 1) * plugin.settings.perPage;
103
104            $( items ).hide();
105
106            //Display items of page
107            for(i = 0; i < plugin.settings.perPage; i++) {
108                if($( items[i + offset] ).length)
109                    $( items[i + offset] ).fadeTo(100, 1);
110            }
111
112            //Deactive prev button
113            if(page == 1) {
114                $('.paginate-pagination-' + plugin_index).find('.page-prev').addClass("deactive");
115            } else {
116                $('.paginate-pagination-' + plugin_index).find('.page-prev').removeClass("deactive");
117            }
118
119            //Deactive next button
120            if(page == maxPage) {
121                $('.paginate-pagination-' + plugin_index).find('.page-next').addClass("deactive");
122            } else {
123                $('.paginate-pagination-' + plugin_index).find('.page-next').removeClass("deactive");
124            }
125
126            curPage = page;
127
128            return curPage;
129
130        };
131
132        /*
133        #Kills plugin
134        */
135        plugin.kill = function() {
136
137            $( items ).show();
138            $('.paginate-pagination-' + plugin_index).remove();
139            $element.removeClass('paginate');
140            $element.removeData('paginate');
141
142        };
143
144        /*
145        #Generates HTML for pagination (nav)
146        */
147        var generatePagination = function() {
148
149            var paginationEl = '<' + plugin.settings.containerTag + ' class="paginate-pagination paginate-pagination-' + plugin_index + '" data-parent="' + plugin_index + '">';
150            paginationEl += '<' + plugin.settings.paginationTag + '>';
151
152            paginationEl += '<' + plugin.settings.itemTag + '>';
153            paginationEl += '<' + plugin.settings.linkTag + ' href="#" data-page="prev" class="page page-prev">&laquo;</' + plugin.settings.linkTag + '>';
154            paginationEl += '</' + plugin.settings.itemTag + '>';
155
156            for(i = 1; i <= maxPage; i++) {
157                paginationEl += '<' + plugin.settings.itemTag + '>';
158                paginationEl += '<' + plugin.settings.linkTag + ' href="#paginate-' + i + '" data-page="' + i + '" class="page page-' + i + '">' + i + '</' + plugin.settings.linkTag + '>';
159                paginationEl += '</' + plugin.settings.itemTag + '>';
160            }
161
162            paginationEl += '<' + plugin.settings.itemTag + '>';
163            paginationEl += '<' + plugin.settings.linkTag + ' href="#" data-page="next" class="page page-next">&raquo;</' + plugin.settings.linkTag + '>';
164            paginationEl += '</' + plugin.settings.itemTag + '>';
165
166            paginationEl += '</' + plugin.settings.paginationTag + '>';
167            paginationEl += '</' + plugin.settings.containerTag + '>';
168
169            //Adds event listener for the buttons
170            $(document).on('click', '.paginate-pagination-' + plugin_index + ' .page', function(e) {
171                e.preventDefault();
172
173                var page = $(this).data('page');
174                var paginateParent = $(this).parents('.paginate-pagination').data('parent');
175
176                //Call onPageClick callback function
177                $('.paginate-' + paginateParent).data('paginate').settings.onPageClick();
178
179                page = $('.paginate-' + paginateParent).data('paginate').switchPage(page);
180
181                if(page) {
182                    if(plugin.settings.useHashLocation)
183                        location.hash = '#paginate-' + page; //set location hash
184
185                    if(plugin.settings.autoScroll)
186                        $('html, body').animate({scrollTop: $('.paginate-' + paginateParent).offset().top}, 'slow');
187
188                }
189
190            });
191
192            return paginationEl;
193
194        };
195
196        plugin.init();
197
198    };
199
200    $.fn.paginate = function(options) {
201
202        return this.each(function() {
203            if (undefined === $(this).data('paginate')) {
204                var plugin = new $.paginate(this, options);
205                    $(this).data('paginate', plugin);
206            }
207        });
208
209    };
210
211}( 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.