1/* 2* jQuery easyShare plugin 3* Update on 04 april 2017 4* Version 1.2 5* 6* Licensed under GPL <http://en.wikipedia.org/wiki/GNU_General_Public_License> 7* Copyright (c) 2008, St?hane Litou <[email protected]> 8* All rights reserved. 9* 10 This program is free software: you can redistribute it and/or modify 11 it under the terms of the GNU General Public License as published by 12 the Free Software Foundation, either version 3 of the License, or 13 (at your option) any later version. 14 15 This program is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU General Public License for more details. 19 20 You should have received a copy of the GNU General Public License 21 along with this program. If not, see <http://www.gnu.org/licenses/>. 22*/ 23 24(function($){ 25$.fn.easyPaginate = function (options) { 26 var defaults = { 27 paginateElement: 'li', 28 hashPage: 'page', 29 elementsPerPage: 10, 30 effect: 'default', 31 slideOffset: 200, 32 firstButton: true, 33 firstButtonText: '<<', 34 lastButton: true, 35 lastButtonText: '>>', 36 prevButton: true, 37 prevButtonText: '<', 38 nextButton: true, 39 nextButtonText: '>' 40 } 41 42 return this.each (function (instance) { 43 44 var plugin = {}; 45 plugin.el = $(this); 46 plugin.el.addClass('easyPaginateList'); 47 48 plugin.settings = { 49 pages: 0, 50 objElements: Object, 51 currentPage: 1 52 } 53 54 var getNbOfPages = function() { 55 return Math.ceil(plugin.settings.objElements.length / plugin.settings.elementsPerPage); 56 }; 57 58 var displayNav = function() { 59 htmlNav = '<div class="easyPaginateNav pagination-wrapper"><div class="nav-links">'; 60 61 if(plugin.settings.firstButton) { 62 htmlNav += '<a href="#'+plugin.settings.hashPage+':1" title="First page" rel="1" class="first page-numbers">'+plugin.settings.firstButtonText+'</a>'; 63 } 64 65 if(plugin.settings.prevButton) { 66 htmlNav += '<a href="" title="Previous" rel="" class="prev page-numbers">'+plugin.settings.prevButtonText+'</a>'; 67 } 68 69 for(i = 1;i <= plugin.settings.pages;i++) { 70 htmlNav += '<a href="#'+plugin.settings.hashPage+':'+i+'" title="Page '+i+'" rel="'+i+'" class="page page-numbers">'+i+'</a>'; 71 }; 72 73 if(plugin.settings.nextButton) { 74 htmlNav += '<a href="" title="Next" rel="" class="next page-numbers">'+plugin.settings.nextButtonText+'</a>'; 75 } 76 77 if(plugin.settings.lastButton) { 78 htmlNav += '<a href="#'+plugin.settings.hashPage+':'+plugin.settings.pages+'" title="Last page" rel="'+plugin.settings.pages+'" class="last page-numbers">'+plugin.settings.lastButtonText+'</a>'; 79 } 80 81 htmlNav += '</div></div>'; 82 plugin.nav = $(htmlNav); 83 plugin.nav.css({ 84 'width': plugin.el.width() 85 }); 86 plugin.el.after(plugin.nav); 87 88 var elSelector = '#' + plugin.el.get(0).id + ' + '; 89 90 $(elSelector + ' .easyPaginateNav a.page,' 91 + elSelector + ' .easyPaginateNav a.first,' 92 + elSelector + ' .easyPaginateNav a.last').on('click', function(e) { 93 e.preventDefault(); 94 displayPage($(this).attr('rel')); 95 }); 96 97 $(elSelector + ' .easyPaginateNav a.prev').on('click', function(e) { 98 e.preventDefault(); 99 page = plugin.settings.currentPage > 1?parseInt(plugin.settings.currentPage) - 1:1; 100 displayPage(page); 101 }); 102 103 $(elSelector + ' .easyPaginateNav a.next').on('click', function(e) { 104 e.preventDefault(); 105 page = plugin.settings.currentPage < plugin.settings.pages?parseInt(plugin.settings.currentPage) + 1:plugin.settings.pages; 106 displayPage(page); 107 }); 108 }; 109 110 var displayPage = function(page, forceEffect) { 111 if(plugin.settings.currentPage != page) { 112 plugin.settings.currentPage = parseInt(page); 113 114 console.log (plugin.nav); 115 116 offsetStart = (page - 1) * plugin.settings.elementsPerPage; 117 offsetEnd = page * plugin.settings.elementsPerPage; 118 if(typeof(forceEffect) != 'undefined') { 119 eval("transition_"+forceEffect+"("+offsetStart+", "+offsetEnd+")"); 120 }else { 121 eval("transition_"+plugin.settings.effect+"("+offsetStart+", "+offsetEnd+")"); 122 } 123 124 plugin.nav.find('.current').removeClass('current'); 125 plugin.nav.find('a.page:eq('+(page - 1)+')').addClass('current'); 126 127 history.pushState(null, null, `#page:${page}`); 128 129 switch(plugin.settings.currentPage) { 130 case 1: 131 $('a', plugin.nav).removeClass('inactive'); 132 $('a.first, a.prev', plugin.nav).addClass('inactive'); 133 break; 134 case plugin.settings.pages: 135 $('a', plugin.nav).removeClass('inactive'); 136 $('a.last, a.next', plugin.nav).addClass('inactive'); 137 break; 138 default: 139 $('a', plugin.nav).removeClass('inactive'); 140 break; 141 } 142 } 143 }; 144 145 var transition_default = function(offsetStart, offsetEnd) { 146 plugin.currentElements.hide(); 147 plugin.currentElements = plugin.settings.objElements.slice(offsetStart, offsetEnd).clone(); 148 plugin.el.html(plugin.currentElements); 149 plugin.currentElements.show(); 150 }; 151 152 var transition_fade = function(offsetStart, offsetEnd) { 153 plugin.currentElements.fadeOut(); 154 plugin.currentElements = plugin.settings.objElements.slice(offsetStart, offsetEnd).clone(); 155 plugin.el.html(plugin.currentElements); 156 plugin.currentElements.fadeIn(); 157 }; 158 159 var transition_slide = function(offsetStart, offsetEnd) { 160 plugin.currentElements.animate({ 161 'margin-left': plugin.settings.slideOffset * -1, 162 'opacity': 0 163 }, function() { 164 $(this).remove(); 165 }); 166 167 plugin.currentElements = plugin.settings.objElements.slice(offsetStart, offsetEnd).clone(); 168 plugin.currentElements.css({ 169 'margin-left': plugin.settings.slideOffset, 170 'display': 'block', 171 'opacity': 0, 172 'min-width': plugin.el.width() / 2 173 }); 174 plugin.el.html(plugin.currentElements); 175 plugin.currentElements.animate({ 176 'margin-left': 0, 177 'opacity': 1 178 }); 179 }; 180 181 var transition_climb = function(offsetStart, offsetEnd) { 182 plugin.currentElements.each(function(i) { 183 var $objThis = $(this); 184 setTimeout(function() { 185 $objThis.animate({ 186 'margin-left': plugin.settings.slideOffset * -1, 187 'opacity': 0 188 }, function() { 189 $(this).remove(); 190 }); 191 }, i * 200); 192 }); 193 194 plugin.currentElements = plugin.settings.objElements.slice(offsetStart, offsetEnd).clone(); 195 plugin.currentElements.css({ 196 'margin-left': plugin.settings.slideOffset, 197 'display': 'block', 198 'opacity': 0, 199 'min-width': plugin.el.width() / 2 200 }); 201 plugin.el.html(plugin.currentElements); 202 plugin.currentElements.each(function(i) { 203 var $objThis = $(this); 204 setTimeout(function() { 205 $objThis.animate({ 206 'margin-left': 0, 207 'opacity': 1 208 }); 209 }, i * 200); 210 }); 211 }; 212 213 plugin.settings = $.extend({}, defaults, options); 214 215 plugin.currentElements = $([]); 216 plugin.settings.objElements = plugin.el.find(plugin.settings.paginateElement); 217 plugin.settings.pages = getNbOfPages(); 218 if(plugin.settings.pages > 1) { 219 plugin.el.html(); 220 221 // Here we go 222 displayNav(); 223 224 page = 1; 225 if(document.location.hash.indexOf('#'+plugin.settings.hashPage+':') != -1) { 226 page = parseInt(document.location.hash.replace('#'+plugin.settings.hashPage+':', '')); 227 if(page.length <= 0 || page < 1 || page > plugin.settings.pages) { 228 page = 1; 229 } 230 } 231 232 displayPage(page, 'default'); 233 } 234 }); 235}; 236})(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.