take id nudging in async table into account
This commit is contained in:
parent
cc90faf732
commit
c8f4a6f528
@ -58,7 +58,9 @@
|
|||||||
asyncTableHeader = element.dataset.asyncTableDbHeader;
|
asyncTableHeader = element.dataset.asyncTableDbHeader;
|
||||||
}
|
}
|
||||||
|
|
||||||
asyncTableId = element.querySelector('table').id;
|
var rawTableId = element.querySelector('table').id;
|
||||||
|
cssIdPrefix = findCssIdPrefix(rawTableId);
|
||||||
|
asyncTableId = rawTableId.replace(cssIdPrefix, '');
|
||||||
|
|
||||||
// find scrolltable wrapper
|
// find scrolltable wrapper
|
||||||
scrollTable = element.querySelector(ASYNC_TABLE_SCROLLTABLE_SELECTOR);
|
scrollTable = element.querySelector(ASYNC_TABLE_SCROLLTABLE_SELECTOR);
|
||||||
@ -209,10 +211,11 @@
|
|||||||
var selectionStart = focusedInput.selectionStart;
|
var selectionStart = focusedInput.selectionStart;
|
||||||
// remove the following part of the id to get rid of the random
|
// remove the following part of the id to get rid of the random
|
||||||
// (yet somewhat structured) prefix we got from nudging.
|
// (yet somewhat structured) prefix we got from nudging.
|
||||||
var matcher = /r\d*?__/;
|
var prefix = findCssIdPrefix(focusedInput.id);
|
||||||
var focusId = focusedInput.id.replace(matcher, '');
|
var focusId = focusedInput.id.replace(prefix, '');
|
||||||
callback = function(wrapper) {
|
callback = function(wrapper) {
|
||||||
var toBeFocused = wrapper.querySelector('#' + cssIdPrefix + focusId);
|
var idPrefix = getLocalStorageParameter('cssIdPrefix');
|
||||||
|
var toBeFocused = wrapper.querySelector('#' + idPrefix + focusId);
|
||||||
if (toBeFocused) {
|
if (toBeFocused) {
|
||||||
toBeFocused.focus();
|
toBeFocused.focus();
|
||||||
toBeFocused.selectionStart = selectionStart;
|
toBeFocused.selectionStart = selectionStart;
|
||||||
@ -341,14 +344,18 @@
|
|||||||
// update table with new
|
// update table with new
|
||||||
updateWrapperContents(response);
|
updateWrapperContents(response);
|
||||||
|
|
||||||
if (callback && typeof callback === 'function') {
|
if (UtilRegistry) {
|
||||||
callback(element);
|
UtilRegistry.setupAll(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
element.classList.add(ASYNC_TABLE_INITIALIZED_CLASS);
|
if (callback && typeof callback === 'function') {
|
||||||
element.classList.remove(ASYNC_TABLE_LOADING_CLASS);
|
setLocalStorageParameter('cssIdPrefix', response.idPrefix);
|
||||||
|
callback(element);
|
||||||
|
setLocalStorageParameter('cssIdPrefix', '');
|
||||||
|
}
|
||||||
}).catch(function(err) {
|
}).catch(function(err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
}).finally(function() {
|
||||||
element.classList.remove(ASYNC_TABLE_LOADING_CLASS);
|
element.classList.remove(ASYNC_TABLE_LOADING_CLASS);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -356,18 +363,23 @@
|
|||||||
function updateWrapperContents(response) {
|
function updateWrapperContents(response) {
|
||||||
var newPage = document.createElement('div');
|
var newPage = document.createElement('div');
|
||||||
newPage.appendChild(response.element);
|
newPage.appendChild(response.element);
|
||||||
cssIdPrefix = response.idPrefix;
|
var newWrapperContents = newPage.querySelector('#' + response.idPrefix + element.id);
|
||||||
var newWrapperContents = newPage.querySelector('#' + cssIdPrefix + element.id);
|
|
||||||
element.innerHTML = newWrapperContents.innerHTML;
|
element.innerHTML = newWrapperContents.innerHTML;
|
||||||
|
|
||||||
if (UtilRegistry) {
|
|
||||||
UtilRegistry.setupAll(element);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return init();
|
return init();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// returns any random nudged prefix found in the given id
|
||||||
|
function findCssIdPrefix(id) {
|
||||||
|
var matcher = /r\d*?__/;
|
||||||
|
var maybePrefix = id.match(matcher);
|
||||||
|
if (maybePrefix && maybePrefix[0]) {
|
||||||
|
return maybePrefix[0]
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
function setLocalStorageParameter(key, value) {
|
function setLocalStorageParameter(key, value) {
|
||||||
var currentLSState = JSON.parse(window.localStorage.getItem(ASYNC_TABLE_LOCAL_STORAGE_KEY)) || {};
|
var currentLSState = JSON.parse(window.localStorage.getItem(ASYNC_TABLE_LOCAL_STORAGE_KEY)) || {};
|
||||||
if (value !== null) {
|
if (value !== null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user