js utils now return function to destroy them
This commit is contained in:
parent
1b2d980971
commit
57f9e058f3
@ -87,5 +87,9 @@
|
|||||||
|
|
||||||
initToggler();
|
initToggler();
|
||||||
alertElements.forEach(initAlert);
|
alertElements.forEach(initAlert);
|
||||||
|
|
||||||
|
return {
|
||||||
|
destroy: function() {},
|
||||||
|
};
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|||||||
@ -55,5 +55,9 @@
|
|||||||
|
|
||||||
initFavoritesButton();
|
initFavoritesButton();
|
||||||
initAsidenavSubmenus();
|
initAsidenavSubmenus();
|
||||||
|
|
||||||
|
return {
|
||||||
|
destroy: function() {},
|
||||||
|
};
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|||||||
@ -56,5 +56,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
setup();
|
setup();
|
||||||
|
|
||||||
|
return {
|
||||||
|
destroy: function() {},
|
||||||
|
};
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|||||||
@ -21,6 +21,8 @@
|
|||||||
var pagesizeForm;
|
var pagesizeForm;
|
||||||
var scrollTable;
|
var scrollTable;
|
||||||
|
|
||||||
|
var utilInstances = [];
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
var table = wrapper.querySelector('#' + tableIdent);
|
var table = wrapper.querySelector('#' + tableIdent);
|
||||||
|
|
||||||
@ -47,13 +49,13 @@
|
|||||||
pagesizeForm = wrapper.querySelector('#' + tableIdent + '-pagesize-form');
|
pagesizeForm = wrapper.querySelector('#' + tableIdent + '-pagesize-form');
|
||||||
|
|
||||||
// check all
|
// check all
|
||||||
window.utils.setup('checkAll', wrapper);
|
utilInstances.push(window.utils.setup('checkAll', wrapper));
|
||||||
|
|
||||||
// filter
|
// filter
|
||||||
var filterForm = wrapper.querySelector('.' + TABLE_FILTER_FORM_CLASS);
|
var filterForm = wrapper.querySelector('.' + TABLE_FILTER_FORM_CLASS);
|
||||||
if (filterForm) {
|
if (filterForm) {
|
||||||
options.updateTableFrom = updateTableFrom;
|
options.updateTableFrom = updateTableFrom;
|
||||||
window.utils.setup('asyncTableFilter', filterForm, options);
|
utilInstances.push(window.utils.setup('asyncTableFilter', filterForm, options));
|
||||||
}
|
}
|
||||||
|
|
||||||
// take options into account
|
// take options into account
|
||||||
@ -177,9 +179,8 @@
|
|||||||
wrapper.classList.remove(JS_INITIALIZED_CLASS);
|
wrapper.classList.remove(JS_INITIALIZED_CLASS);
|
||||||
wrapper.classList.add(ASYNC_TABLE_CONTENT_CHANGED_CLASS);
|
wrapper.classList.add(ASYNC_TABLE_CONTENT_CHANGED_CLASS);
|
||||||
|
|
||||||
// setup the wrapper and its components to behave async again
|
destroyUtils();
|
||||||
window.utils.teardown('asyncTable');
|
|
||||||
window.utils.teardown('form');
|
|
||||||
// merge global options and table specific options
|
// merge global options and table specific options
|
||||||
var resetOptions = {};
|
var resetOptions = {};
|
||||||
Object.keys(options)
|
Object.keys(options)
|
||||||
@ -205,13 +206,23 @@
|
|||||||
window.utils.setup('asyncTable', wrapper, combinedOptions);
|
window.utils.setup('asyncTable', wrapper, combinedOptions);
|
||||||
|
|
||||||
Array.from(wrapper.querySelectorAll('form')).forEach(function(form) {
|
Array.from(wrapper.querySelectorAll('form')).forEach(function(form) {
|
||||||
window.utils.setup('form', form);
|
utilInstances.push(window.utils.setup('form', form));
|
||||||
});
|
});
|
||||||
Array.from(wrapper.querySelectorAll('.modal')).forEach(function(modal) {
|
Array.from(wrapper.querySelectorAll('.modal')).forEach(function(modal) {
|
||||||
window.utils.setup('modal', modal);
|
utilInstances.push(window.utils.setup('modal', modal));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function destroyUtils() {
|
||||||
|
utilInstances.forEach(function(utilInstance) {
|
||||||
|
utilInstance.destroy();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
||||||
|
return {
|
||||||
|
destroy: destroyUtils,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|||||||
@ -157,5 +157,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
setup();
|
setup();
|
||||||
|
|
||||||
|
return {
|
||||||
|
destroy: function() {},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|||||||
@ -22,6 +22,8 @@
|
|||||||
var checkboxColumn = [];
|
var checkboxColumn = [];
|
||||||
var checkAllCheckbox = null;
|
var checkAllCheckbox = null;
|
||||||
|
|
||||||
|
var utilInstances = [];
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
|
|
||||||
columns = gatherColumns(wrapper);
|
columns = gatherColumns(wrapper);
|
||||||
@ -80,7 +82,7 @@
|
|||||||
checkAllCheckbox.setAttribute('id', getCheckboxId());
|
checkAllCheckbox.setAttribute('id', getCheckboxId());
|
||||||
th.innerHTML = '';
|
th.innerHTML = '';
|
||||||
th.insertBefore(checkAllCheckbox, null);
|
th.insertBefore(checkAllCheckbox, null);
|
||||||
window.utils.setup('checkboxRadio', checkAllCheckbox);
|
utilInstances.push(window.utils.setup('checkboxRadio', checkAllCheckbox));
|
||||||
|
|
||||||
checkAllCheckbox.addEventListener('input', onCheckAllCheckboxInput);
|
checkAllCheckbox.addEventListener('input', onCheckAllCheckboxInput);
|
||||||
setupCheckboxListeners();
|
setupCheckboxListeners();
|
||||||
@ -113,6 +115,16 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function destroy() {
|
||||||
|
utilInstances.forEach(function(util) {
|
||||||
|
util.destroy();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
||||||
|
return {
|
||||||
|
destroy: destroy,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|||||||
@ -25,25 +25,37 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var utilInstances = [];
|
||||||
|
|
||||||
// reactive buttons
|
// reactive buttons
|
||||||
window.utils.setup('reactiveButton', form);
|
utilInstances.push(window.utils.setup('reactiveButton', form));
|
||||||
|
|
||||||
// conditonal fieldsets
|
// conditonal fieldsets
|
||||||
var fieldSets = Array.from(form.querySelectorAll('fieldset[data-conditional-id][data-conditional-value]'));
|
var fieldSets = Array.from(form.querySelectorAll('fieldset[data-conditional-id][data-conditional-value]'));
|
||||||
window.utils.setup('interactiveFieldset', form, { fieldSets });
|
utilInstances.push(window.utils.setup('interactiveFieldset', form, { fieldSets }));
|
||||||
|
|
||||||
// hide autoSubmit submit button
|
// hide autoSubmit submit button
|
||||||
window.utils.setup('autoSubmit', form, options);
|
utilInstances.push(window.utils.setup('autoSubmit', form, options));
|
||||||
|
|
||||||
// async form
|
// async form
|
||||||
if (AJAX_SUBMIT_FLAG in form.dataset) {
|
if (AJAX_SUBMIT_FLAG in form.dataset) {
|
||||||
window.utils.setup('asyncForm', form, options);
|
utilInstances.push(window.utils.setup('asyncForm', form, options));
|
||||||
}
|
}
|
||||||
|
|
||||||
// inputs
|
// inputs
|
||||||
window.utils.setup('inputs', form, options);
|
utilInstances.push(window.utils.setup('inputs', form, options));
|
||||||
|
|
||||||
form.classList.add(JS_INITIALIZED);
|
form.classList.add(JS_INITIALIZED);
|
||||||
|
|
||||||
|
function destroyUtils() {
|
||||||
|
utilInstances.forEach(function(utilInstance) {
|
||||||
|
utilInstance.destroy();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
destroy: destroyUtils,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// registers input-listener for each element in <inputs> (array) and
|
// registers input-listener for each element in <inputs> (array) and
|
||||||
@ -83,6 +95,10 @@
|
|||||||
button.setAttribute('disabled', 'true');
|
button.setAttribute('disabled', 'true');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
destroy: function() {},
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
window.utils.interactiveFieldset = function(form, options) {
|
window.utils.interactiveFieldset = function(form, options) {
|
||||||
@ -120,6 +136,10 @@
|
|||||||
addEventListeners();
|
addEventListeners();
|
||||||
updateFields();
|
updateFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
destroy: function() {},
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
window.utils.autoSubmit = function(form, options) {
|
window.utils.autoSubmit = function(form, options) {
|
||||||
@ -127,5 +147,9 @@
|
|||||||
if (button) {
|
if (button) {
|
||||||
button.classList.add('hidden');
|
button.classList.add('hidden');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
destroy: function() {},
|
||||||
|
};
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|||||||
@ -10,22 +10,36 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
window.utils.inputs = function(wrapper, options) {
|
window.utils.inputs = function(wrapper, options) {
|
||||||
|
|
||||||
|
var utilInstances = [];
|
||||||
|
|
||||||
// checkboxes / radios
|
// checkboxes / radios
|
||||||
var checkboxes = Array.from(wrapper.querySelectorAll('input[type="checkbox"], input[type="radio"]'));
|
var checkboxes = Array.from(wrapper.querySelectorAll('input[type="checkbox"], input[type="radio"]'));
|
||||||
checkboxes.filter(isNotInitialized).forEach(window.utils.checkboxRadio);
|
checkboxes.filter(isNotInitialized).forEach(function(checkbox) {
|
||||||
|
utilInstances.push(window.utils.setup('checkboxRadio', checkbox));
|
||||||
|
});
|
||||||
|
|
||||||
// file-uploads
|
// file-uploads
|
||||||
var fileUploads = Array.from(wrapper.querySelectorAll('input[type="file"]'));
|
var fileUploads = Array.from(wrapper.querySelectorAll('input[type="file"]'));
|
||||||
fileUploads.filter(isNotInitialized).forEach(function(input) {
|
fileUploads.filter(isNotInitialized).forEach(function(input) {
|
||||||
window.utils.fileUpload(input, options);
|
utilInstances.push(window.utils.setup('fileUpload', input, options));
|
||||||
});
|
});
|
||||||
|
|
||||||
// file-checkboxes
|
// file-checkboxes
|
||||||
var fileCheckboxes = Array.from(wrapper.querySelectorAll('.file-checkbox'));
|
var fileCheckboxes = Array.from(wrapper.querySelectorAll('.file-checkbox'));
|
||||||
fileCheckboxes.filter(isNotInitialized).forEach(function(inp) {
|
fileCheckboxes.filter(isNotInitialized).forEach(function(input) {
|
||||||
window.utils.fileCheckbox(inp);
|
utilInstances.push(window.utils.setup('fileCheckbox', input, options));
|
||||||
inp.classList.add(JS_INITIALIZED_CLASS);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function destroyUtils() {
|
||||||
|
utilInstances.forEach(function(utilInstance) {
|
||||||
|
utilInstance.destroy();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
destroy: destroyUtils,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// (multiple) dynamic file uploads
|
// (multiple) dynamic file uploads
|
||||||
@ -113,6 +127,10 @@
|
|||||||
|
|
||||||
updateLabel(input.files);
|
updateLabel(input.files);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
destroy: function() {},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// to remove previously uploaded files
|
// to remove previously uploaded files
|
||||||
@ -141,7 +159,12 @@
|
|||||||
input.classList.add(JS_INITIALIZED_CLASS);
|
input.classList.add(JS_INITIALIZED_CLASS);
|
||||||
cont.classList.add(JS_INITIALIZED_CLASS);
|
cont.classList.add(JS_INITIALIZED_CLASS);
|
||||||
}
|
}
|
||||||
|
|
||||||
setup();
|
setup();
|
||||||
|
|
||||||
|
return {
|
||||||
|
destroy: function() {},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// turns native checkboxes and radio buttons into custom ones
|
// turns native checkboxes and radio buttons into custom ones
|
||||||
@ -166,6 +189,10 @@
|
|||||||
parentEl.appendChild(wrapperEl);
|
parentEl.appendChild(wrapperEl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
destroy: function() {},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|||||||
@ -23,6 +23,8 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var utilInstances = [];
|
||||||
|
|
||||||
var overlayElement = document.createElement('div');
|
var overlayElement = document.createElement('div');
|
||||||
var closerElement = document.createElement('div');
|
var closerElement = document.createElement('div');
|
||||||
var triggerElement = document.querySelector('#' + modalElement.dataset.trigger);
|
var triggerElement = document.querySelector('#' + modalElement.dataset.trigger);
|
||||||
@ -73,7 +75,7 @@
|
|||||||
function setupForm() {
|
function setupForm() {
|
||||||
var form = modalElement.querySelector('form');
|
var form = modalElement.querySelector('form');
|
||||||
if (form) {
|
if (form) {
|
||||||
window.utils.setup('form', form, { headers: MODAL_HEADERS });
|
utilInstances.push(window.utils.setup('form', form, { headers: MODAL_HEADERS }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,5 +138,15 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
setup();
|
setup();
|
||||||
|
|
||||||
|
function destroyUtils() {
|
||||||
|
utilInstances.forEach(function(utilInstance) {
|
||||||
|
utilInstance.destroy();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
destroy: destroyUtils,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|||||||
@ -51,5 +51,9 @@
|
|||||||
});
|
});
|
||||||
addEventHandler(el);
|
addEventHandler(el);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
destroy: function() {},
|
||||||
|
};
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|||||||
@ -86,5 +86,9 @@
|
|||||||
$(t).tabgroup();
|
$(t).tabgroup();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
destroy: function() {},
|
||||||
|
};
|
||||||
});
|
});
|
||||||
})($);
|
})($);
|
||||||
|
|||||||
Reference in New Issue
Block a user