1/** 2 * Cookie plugin 3 * 4 * Copyright (c) 2006 Klaus Hartl (stilbuero.de) 5 * Dual licensed under the MIT and GPL licenses: 6 * http://www.opensource.org/licenses/mit-license.php 7 * http://www.gnu.org/licenses/gpl.html 8 * 9 */ 10 11/** 12 * Create a cookie with the given name and value and other optional parameters. 13 * 14 * @example $.cookie('the_cookie', 'the_value'); 15 * @desc Set the value of a cookie. 16 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true }); 17 * @desc Create a cookie with all available options. 18 * @example $.cookie('the_cookie', 'the_value'); 19 * @desc Create a session cookie. 20 * @example $.cookie('the_cookie', null); 21 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain 22 * used when the cookie was set. 23 * 24 * @param String name The name of the cookie. 25 * @param String value The value of the cookie. 26 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes. 27 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object. 28 * If a negative value is specified (e.g. a date in the past), the cookie will be deleted. 29 * If set to null or omitted, the cookie will be a session cookie and will not be retained 30 * when the the browser exits. 31 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie). 32 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie). 33 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will 34 * require a secure protocol (like HTTPS). 35 * @type undefined 36 * 37 * @name $.cookie 38 * @cat Plugins/Cookie 39 * @author Klaus Hartl/[email protected] 40 */ 41 42/** 43 * Get the value of a cookie with the given name. 44 * 45 * @example $.cookie('the_cookie'); 46 * @desc Get the value of a cookie. 47 * 48 * @param String name The name of the cookie. 49 * @return The value of the cookie. 50 * @type String 51 * 52 * @name $.cookie 53 * @cat Plugins/Cookie 54 * @author Klaus Hartl/[email protected] 55 */ 56jQuery.cookie = function(name, value, options) { 57 if (typeof value != 'undefined') { // name and value given, set cookie 58 options = options || {}; 59 if (value === null) { 60 value = ''; 61 options = $.extend({}, options); // clone object since it's unexpected behavior if the expired property were changed 62 options.expires = -1; 63 } 64 var expires = ''; 65 if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { 66 var date; 67 if (typeof options.expires == 'number') { 68 date = new Date(); 69 date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); 70 } else { 71 date = options.expires; 72 } 73 expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE 74 } 75 // NOTE Needed to parenthesize options.path and options.domain 76 // in the following expressions, otherwise they evaluate to undefined 77 // in the packed version for some reason... 78 var path = options.path ? '; path=' + (options.path) : ''; 79 var domain = options.domain ? '; domain=' + (options.domain) : ''; 80 var secure = options.secure ? '; secure' : ''; 81 document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); 82 } else { // only name given, get cookie 83 var cookieValue = null; 84 if (document.cookie && document.cookie != '') { 85 var cookies = document.cookie.split(';'); 86 for (var i = 0; i < cookies.length; i++) { 87 var cookie = jQuery.trim(cookies[i]); 88 // Does this cookie string begin with the name we want? 89 if (cookie.substring(0, name.length + 1) == (name + '=')) { 90 cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); 91 break; 92 } 93 } 94 } 95 return cookieValue; 96 } 97}; 98 99/** 100 * This jQuery plugin displays pagination links inside the selected elements. 101 * 102 * @author Gabriel Birke (birke *at* d-scribe *dot* de) 103 * @version 1.2 104 * @param {int} maxentries Number of entries to paginate 105 * @param {Object} opts Several options (see README for documentation) 106 * @return {Object} jQuery Object 107 */ 108jQuery.fn.pagination = function(maxentries, opts) { 109 opts = jQuery.extend({ 110 items_per_page: 10, 111 num_display_entries: 10, 112 current_page: 0,
113 num_edge_entries: 0, 114 link_to: "#", 115 prev_text: "Prev", 116 next_text: "Next", 117 ellipse_text: "...", 118 prev_show_always: true, 119 next_show_always: true, 120 callback: function() { 121 return false; 122 } 123 }, opts || {}); 124 125 return this.each(function() { 126 /** 127 * Calculate the maximum number of pages 128 */ 129 function numPages() { 130 return Math.ceil(maxentries / opts.items_per_page); 131 } 132 133 /** 134 * Calculate start and end point of pagination links depending on 135 * current_page and num_display_entries. 136 * @return {Array} 137 */ 138 function getInterval() { 139 var ne_half = Math.ceil(opts.num_display_entries / 2); 140 var np = numPages(); 141 var upper_limit = np - opts.num_display_entries; 142 var start = current_page > ne_half ? Math.max(Math.min(current_page - ne_half, upper_limit), 0) : 0; 143 var end = current_page > ne_half ? Math.min(current_page + ne_half, np) : Math.min(opts.num_display_entries, np); 144 return [start, end]; 145 } 146 147 /** 148 * This is the event handling function for the pagination links. 149 * @param {int} page_id The new page number 150 */ 151 function pageSelected(page_id, evt) { 152 current_page = page_id; 153 drawLinks(); 154 var continuePropagation = opts.callback(page_id, panel); 155 if (!continuePropagation) { 156 if (evt.stopPropagation) { 157 evt.stopPropagation(); 158 } 159 else { 160 evt.cancelBubble = true; 161 } 162 } 163 return continuePropagation; 164 } 165 166 /** 167 * This function inserts the pagination links into the container element 168 */ 169 function drawLinks() { 170 panel.empty(); 171 var interval = getInterval(); 172 var np = numPages(); 173 // This helper function returns a handler function that calls pageSelected with the right page_id 174 var getClickHandler = function(page_id) { 175 return function(evt) { 176 return pageSelected(page_id, evt); 177 } 178 } 179 // Helper function for generating a single link (or a span tag if it's the current page) 180 var appendItem = function(page_id, appendopts) { 181 page_id = page_id < 0 ? 0 : (page_id < np ? page_id : np - 1); // Normalize page id to sane value 182 appendopts = jQuery.extend({text: page_id + 1, classes: ""}, appendopts || {}); 183 if (page_id == current_page) { 184 var lnk = jQuery("<span class='current'>" + (appendopts.text) + "</span>"); 185 } 186 else 187 { 188 var lnk = jQuery("<a>" + (appendopts.text) + "</a>") 189 .bind("click", getClickHandler(page_id)) 190 .attr('href', opts.link_to.replace(/__id__/, page_id)); 191 192 193 } 194 if (appendopts.classes) { 195 lnk.addClass(appendopts.classes); 196 } 197 panel.append(lnk); 198 } 199 // Generate "Previous"-Link 200 if (opts.prev_text && (current_page > 0 || opts.prev_show_always)) { 201 appendItem(current_page - 1, {text: opts.prev_text, classes: "prev"}); 202 } 203 // Generate starting points 204 if (interval[0] > 0 && opts.num_edge_entries > 0) 205 { 206 var end = Math.min(opts.num_edge_entries, interval[0]); 207 for (var i = 0; i < end; i++) { 208 appendItem(i); 209 } 210 if (opts.num_edge_entries < interval[0] && opts.ellipse_text) 211 { 212 jQuery("<span>" + opts.ellipse_text + "</span>").appendTo(panel); 213 } 214 } 215 // Generate interval links 216 for (var i = interval[0]; i < interval[1]; i++) { 217 appendItem(i); 218 } 219 // Generate ending points
220 if (interval[1] < np && opts.num_edge_entries > 0) 221 { 222 if (np - opts.num_edge_entries > interval[1] && opts.ellipse_text) 223 { 224 jQuery("<span>" + opts.ellipse_text + "</span>").appendTo(panel); 225 } 226 var begin = Math.max(np - opts.num_edge_entries, interval[1]); 227 for (var i = begin; i < np; i++) { 228 appendItem(i); 229 } 230 231 } 232 // Generate "Next"-Link 233 if (opts.next_text && (current_page < np - 1 || opts.next_show_always)) { 234 appendItem(current_page + 1, {text: opts.next_text, classes: "next"}); 235 } 236 } 237 238 // Extract current_page from options 239 var current_page = opts.current_page; 240 // Create a sane value for maxentries and items_per_page 241 maxentries = (!maxentries || maxentries < 0) ? 1 : maxentries; 242 opts.items_per_page = (!opts.items_per_page || opts.items_per_page < 0) ? 1 : opts.items_per_page; 243 // Store DOM element for easy access from all inner functions 244 var panel = jQuery(this); 245 // Attach control functions to the DOM element 246 this.selectPage = function(page_id) { 247 pageSelected(page_id); 248 } 249 this.prevPage = function() { 250 if (current_page > 0) { 251 pageSelected(current_page - 1); 252 return true; 253 } 254 else { 255 return false; 256 } 257 } 258 this.nextPage = function() { 259 if (current_page < numPages() - 1) { 260 pageSelected(current_page + 1); 261 return true; 262 } 263 else { 264 return false; 265 } 266 } 267 // When all initialisation is done, draw the links 268 drawLinks(); 269 // call callback function 270 opts.callback(current_page, this); 271 }); 272}
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.