- md5
- 865d43a54f1b4548a6049880a388d1b4
- sha1
- 86dcd9bfa2ad17fc11c88fbf2f143ad5cc1b2045
- sha256
- 923584293128cd05a5bb954f7d41b95a60d8d289d66be55f6384ce879050bc34
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
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 = $('<div id="loading-items>')
.html(listTableL10n.loading)
.hide()
.prependTo($('body'));
},
// paging
set_total_pages: function(num) {
var last_page_url = $('.last-page').attr('href');
if ( last_page_url )
this.total_pages = num || $.query.load( last_page_url ).get('paged');
},
get_total_pages: function() {
return this.total_pages;
},
change_page: function(paged) {
if ( paged < 1 || paged > this.total_pages )
return false;
this.update_rows({'paged': paged});
},
htmlencode: function(value) {
return $('<div/>').text(value).html();
},
update_rows: function(args, reset_paging, callback) {
if ( this.loading )
return false;
var different = false, data = {};
$.each(args, function(key, val) {
if ( val != $.query.GET(key) ) {
$.query.SET(key, val);
different = true;
}
});
if ( !different )
return false;
this.show_overlay();
if ( reset_paging )
$.query.SET('paged', 1);
$.each( $.query.get(), function(key, value) {
if ( true === value )
data[key] = '';
else
data[key] = value;
});
this._callback = callback;
this.fetch_list(
data,
$.proxy(this, 'handle_success'),
$.proxy(this, 'handle_error')
);
return true;
},
fetch_list: function(data, success_callback, error_callback) {
data = $.extend(data, {
'action': 'fetch-list',
'list_args': list_args
});
$.ajax({
url: ajaxurl,
global: false,
dataType: 'json',
data: data,
success: success_callback,
error: error_callback
});
},
handle_success: function(response) {
if ( 'object' != typeof response ) {
this.handle_error();
} else {
this.hide_overlay();
this.$tbody.html(response.rows);
$('.displaying-num').html(response.total_items_i18n);
$('.total-pages').html(response.total_pages_i18n);
this.set_total_pages(response.total_pages);
$('.current-page').val($.query.GET('paged'));
$('th.column-cb :input').attr('checked', false);
if ( this._callback )
this._callback();
}
},
handle_error: function() {
this.hide_overlay();
$('h2').after('<div class="error ajax below-h2"><p>' + listTableL10n.error + '</p></div>');
},
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() {
if ( $('h2.nav-tab-wrapper').length )
return;
$('h2 .subtitle').remove();
if ( data.s )
$('h2').append($('<span class="subtitle">').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;
});
});
No other release has this exact content. See every version of this file.