general: clean up ajax cell loading to fix autorefresh (#13816)

This commit is contained in:
Frédéric Péters 2016-11-01 17:56:09 +01:00
parent 56f7e8e76f
commit 7886f636f6
1 changed files with 11 additions and 11 deletions

View File

@ -1,4 +1,6 @@
function combo_load_cell(elem, url) {
function combo_load_cell(elem) {
var $elem = $(elem);
var url = $elem.data('ajax-cell-url');
$.support.cors = true; /* IE9 */
$.ajax({url: url + window.location.search,
xhrFields: { withCredentials: true },
@ -6,18 +8,17 @@ function combo_load_cell(elem, url) {
dataType: 'html',
crossDomain: true,
success: function(data) {
var parent = $(elem).parent();
$(elem).parent().parent().addClass('ajax-loaded');
$(elem).parent().nextAll().remove();
$elem.addClass('ajax-loaded');
$elem.find('> div').nextAll().remove();
if (data == '') {
$(elem).remove();
$elem.find('> div').remove();
} else {
$(elem).replaceWith(data);
$elem.find('> div').html(data);
}
$(document).trigger('combo:cell-loaded', parent);
},
error: function(error) {
$(elem).addClass('error-loading');
$elem.addClass('error-loading');
window.console && console.log(':(', error);
}
});
@ -58,13 +59,12 @@ $(function() {
$('[data-ajax-cell-refresh]').each(function(idx, elem) {
var $elem = $(elem);
function refresh() {
combo_load_cell($elem.find('> div'), $elem.data('ajax-cell-url'));
combo_load_cell($elem);
}
$elem.timeout_id = setInterval(refresh, $elem.data('ajax-cell-refresh')*1000);
});
$('[data-ajax-cell-must-load]').each(function(idx, elem) {
var $elem = $(elem);
combo_load_cell($elem, $elem.parents('div.cell').data('ajax-cell-url'));
combo_load_cell($(elem).parents('div.cell'));
});
/* utility functions and events, for themes */
@ -77,7 +77,7 @@ $(function() {
var $elem = $(elem);
var msg = $(elem).data('ajax-cell-loading-message');
$elem.prepend('<div><div class="loading"><span class="loading-message">' + msg + '</span></div></div>');
combo_load_cell($elem.find('div.loading'), $elem.data('ajax-cell-url'));
combo_load_cell($elem);
});
}
if (window.history.pushState && $('.parameterscell').length > 0) {