jQuery(document).ready(function($) { window.listTable = { init: function() { this.loading = false; $('form').each(function() { this.reset(); }); if ( '' == $.query.GET('paged') ) $.query.SET('paged', 1); this.set_total_pages(); this.$tbody = $('#the-list, #the-comment-list'); this.$overlay = $('
'); }, show_overlay: function() { this.loading = true; $('.error.ajax').remove(); this.$overlay .css({ width: this.$tbody.width() + 'px', height: this.$tbody.height() - 20 + 'px' }) .css(this.$tbody.offset()) .show(); }, hide_overlay: function() { this.loading = false; this.$overlay.hide(); } } listTable.init(); // Ajaxify various UI elements // pagination $('.tablenav-pages a').click(function() { var paged = $.query.GET('paged'); switch ( $(this).attr('class') ) { case 'first-page': paged = 1; break; case 'prev-page': paged -= 1; break; case 'next-page': paged += 1; break; case 'last-page': paged = listTable.get_total_pages(); break; } listTable.change_page(paged); return false; }); $('.current-page').keypress(function(e) { if ( 13 != e.keyCode ) return; listTable.change_page(parseInt($(this).val())); return false; }); // sortable columns $('th a').click(function() { var orderby = $.query.GET('orderby'), order = $.query.GET('order'), $th = $(this).parent('th'); if ( $th.hasClass('sortable') ) { orderby = $.query.load($(this).attr('href')).get('orderby'); order = 'asc'; $('th.sorted-desc, th.sorted-asc') .removeClass('sorted-asc') .removeClass('sorted-desc') .addClass('sortable'); $th.removeClass('sortable').addClass('sorted-asc'); } else if ( $th.hasClass('sorted-asc') ) { order = 'desc'; $th.removeClass('sorted-asc').addClass('sorted-desc'); } else if ( $th.hasClass('sorted-desc') ) { order = 'asc'; $th.removeClass('sorted-desc').addClass('sorted-asc'); } listTable.update_rows({'orderby': orderby, 'order': order}, true); return false; }); // searchbox function change_search(ev) { if ( 'keypress' == ev.type && 13 != ev.keyCode ) return; ev.preventDefault(); ev.stopImmediatePropagation(); var data = $(this).parent('.search-box').find(':input').serializeObject(); listTable.update_rows(data, true, function() { $('h2 .subtitle').remove(); if ( data.s ) $('h2').append($('').html( listTableL10n.search.replace('%s', this.htmlencode(data.s)) )); }); } $('.search-box :submit').click(change_search); $('.search-box :text').keypress(change_search); // tablenav dropdowns $('#post-query-submit').click(function() { var args = {}; $(this).parents('.actions').find('select[name!="action"]').each(function() { var $el = $(this); args[$el.attr('name')] = $el.val(); }); listTable.update_rows(args, true); return false; }); // view switch $('.view-switch a').click(function() { var $this = $(this); listTable.update_rows({'mode': $.query.load($this.attr('href')).get('mode')}, false, function() { $('.view-switch .current').removeClass('current'); $this.addClass('current'); }); return false; }); });