1 $(document).ready(function() {
2 var focused_field = false;
3 $('.show_pagination').each(function() {
4 $(this).bind('click', function() {
9 $('#pagination_id_1').bind('focus', function() {
10 focused_field = $(this).attr('id');
12 $('#pagination_id_2').bind('focus', function() {
13 focused_field = $(this).attr('id');
16 $('#pagination_id_1').bind('change', function() {
17 propagate_val($(this).val());
19 $('#pagination_id_2').bind('change', function() {
20 focused_field = $(this).attr('id');
21 propagate_val($(this).val());
24 // check if we have a customized items_per_page
25 var url = location.search;
26 var cust_val = $.query.get('custom_pagination_field');
28 // do we have an option with this value?
29 value_exists(cust_val); // added if not
32 $('.pagination_form').bind('submit', function() {
33 preserve_get_params($('#' + focused_field).attr('value'));
38 function set_items_per_page()
41 $('.pagination_form').trigger('submit');
44 function preserve_get_params(custom_val, sel_id)
46 if (custom_val != false && typeof custom_val != 'undefined' && custom_val != 'sel') {
47 propagate_val(custom_val);
49 if (custom_val == 'sel') {
50 propagate_val($('#' + sel_id).val());
54 // make sure we don't loose GET variables from current query string
56 for (var key in $.query.keys) {
57 if (key != 'items_per_page' && key!= 'custom_pagination_field' && key!='result') {
58 if("object" == typeof $.query.keys[key] && !($.query.keys[key] instanceof Array)) {
59 // only iterate true objects' properties by; 1) check type, and; 2) exclude arrays
60 // (which in javascript also are typeof === object... sigh)
61 $.each($.query.keys[key], function(index) {
62 var val = $.query.keys[key][index];
65 $('.pagination_form').append('<input type="hidden" name="' + key + '['+index+']" value="' + val + '">');
68 var val = $.query.keys[key];
71 $('.pagination_form').append('<input type="hidden" name="' + key + '" value="' + val + '">');
78 function propagate_val(val)
80 val = parseInt(val, '10');
82 var cust_val = $.query.get('custom_pagination_field');
83 cust_val = cust_val ? cust_val : 100;
84 propagate_val(cust_val);
87 $('.custom_pagination_field').each(function() {
93 function value_exists(val)
95 $('.items_per_page').each(function() {
96 if (! $(this).containsOption(val) ) {
97 pagination_add_option(val);
99 $(this).selectOptions(val);
103 function pagination_add_option(val)
105 val = parseInt(val, '10');
112 var entries_str = $('.pagination_entries_str').html();
113 $('.items_per_page').each(function() {
114 $(this).addOption(val, val + ' ' + entries_str);
115 //$(this).sortOptions(); // this is not working as of now since sorting is string based :(