Merge branch 'master' into 'live'
General js-setup framework & revert to fetch-based modals See merge request !104
This commit is contained in:
commit
8d012005d3
@ -17,4 +17,10 @@ $newline never
|
|||||||
<script>
|
<script>
|
||||||
document.body.classList.remove('no-js');
|
document.body.classList.remove('no-js');
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
console.log('Setup body');
|
||||||
|
|
||||||
|
document.dispatchEvent(new CustomEvent('setup', { detail: { scope: document.body }, bubbles: true, cancelable: true }));
|
||||||
|
});
|
||||||
|
|
||||||
^{pageBody pc}
|
^{pageBody pc}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
document.addEventListener('DOMContentLoaded', function () {
|
document.addEventListener('setup', function (e) {
|
||||||
|
|
||||||
var themeSelector = document.querySelector('#theme-select');
|
var themeSelector = e.detail.scope.querySelector('#theme-select');
|
||||||
themeSelector.addEventListener('change', function() {
|
themeSelector.addEventListener('change', function() {
|
||||||
// get rid of old themes on body
|
// get rid of old themes on body
|
||||||
var options = Array.from(themeSelector.options)
|
var options = Array.from(themeSelector.options)
|
||||||
|
|||||||
@ -76,8 +76,10 @@
|
|||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('setup', function(e) {
|
||||||
|
|
||||||
// setup alerts
|
// setup alerts
|
||||||
window.utils.alerts(document.querySelector('.alerts'));
|
var alertsEl = e.detail.scope.querySelector('.alerts');
|
||||||
|
if (alertsEl)
|
||||||
|
window.utils.alerts(alertsEl);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('setup', function(e) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var config = {
|
var config = {
|
||||||
@ -24,13 +24,13 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Array.from(document.querySelectorAll('input[type="date"]')).forEach(function(el) {
|
Array.from(e.detail.scope.querySelectorAll('input[type="date"]')).forEach(function(el) {
|
||||||
flatpickr(el, config.d);
|
flatpickr(el, config.d);
|
||||||
});
|
});
|
||||||
Array.from(document.querySelectorAll('input[type="time"]')).forEach(function(el) {
|
Array.from(e.detail.scope.querySelectorAll('input[type="time"]')).forEach(function(el) {
|
||||||
flatpickr(el, config.t);
|
flatpickr(el, config.t);
|
||||||
});
|
});
|
||||||
Array.from(document.querySelectorAll('input[type="datetime-local"]')).forEach(function(el) {
|
Array.from(e.detail.scope.querySelectorAll('input[type="datetime-local"]')).forEach(function(el) {
|
||||||
flatpickr(el, config.dtLocal);
|
flatpickr(el, config.dtLocal);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -113,25 +113,25 @@
|
|||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('setup', function(e) {
|
||||||
|
|
||||||
// initialize checkboxes
|
// initialize checkboxes
|
||||||
Array.from(document.querySelectorAll('input[type="checkbox"]')).forEach(function(inp) {
|
Array.from(e.detail.scope.querySelectorAll('input[type="checkbox"]')).forEach(function(inp) {
|
||||||
window.utils.initializeCheckboxRadio(inp, 'checkbox');
|
window.utils.initializeCheckboxRadio(inp, 'checkbox');
|
||||||
});
|
});
|
||||||
|
|
||||||
// initialize radios
|
// initialize radios
|
||||||
Array.from(document.querySelectorAll('input[type="radio"]')).forEach(function(inp) {
|
Array.from(e.detail.scope.querySelectorAll('input[type="radio"]')).forEach(function(inp) {
|
||||||
window.utils.initializeCheckboxRadio(inp, 'radio');
|
window.utils.initializeCheckboxRadio(inp, 'radio');
|
||||||
});
|
});
|
||||||
|
|
||||||
// initialize file-upload-fields
|
// initialize file-upload-fields
|
||||||
Array.from(document.querySelectorAll('input[type="file"]')).forEach(function(inp) {
|
Array.from(e.detail.scope.querySelectorAll('input[type="file"]')).forEach(function(inp) {
|
||||||
window.utils.initializeFileUpload(inp);
|
window.utils.initializeFileUpload(inp);
|
||||||
});
|
});
|
||||||
|
|
||||||
// initialize file-checkbox-fields
|
// initialize file-checkbox-fields
|
||||||
Array.from(document.querySelectorAll('.js-file-checkbox')).forEach(function(inp) {
|
Array.from(e.detail.scope.querySelectorAll('.js-file-checkbox')).forEach(function(inp) {
|
||||||
window.utils.reactiveFileCheckbox(inp);
|
window.utils.reactiveFileCheckbox(inp);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
document.body.insertBefore(overlay, modal);
|
document.body.insertBefore(overlay, modal);
|
||||||
overlay.classList.add('modal__overlay--open');
|
overlay.classList.add('modal__overlay--open');
|
||||||
|
|
||||||
if (modal.dataset.closeable === 'true') {
|
if ('closeable' in modal.dataset) {
|
||||||
closer.classList.add('modal__closer');
|
closer.classList.add('modal__closer');
|
||||||
modal.insertBefore(closer, null);
|
modal.insertBefore(closer, null);
|
||||||
closer.addEventListener('click', close, false);
|
closer.addEventListener('click', close, false);
|
||||||
@ -56,63 +56,106 @@
|
|||||||
trigger.addEventListener('click', open, false);
|
trigger.addEventListener('click', open, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (modal.dataset.dynamic === 'True') {
|
if ('dynamic' in modal.dataset) {
|
||||||
// var dynamicContentURL = trigger.getAttribute('href');
|
|
||||||
// console.log(dynamicContentURL);
|
|
||||||
// if (dynamicContentURL.length > 0) {
|
|
||||||
// fetch(dynamicContentURL, {
|
|
||||||
// credentials: 'same-origin',
|
|
||||||
// }).then(function(response) {
|
|
||||||
// return response.text();
|
|
||||||
// }).then(function(body) {
|
|
||||||
// var modalContent = document.createElement('div');
|
|
||||||
// modalContent.innerHTML = body;
|
|
||||||
// var main = modalContent.querySelector('.main__content-body');
|
|
||||||
// if (main) {
|
|
||||||
// modal.appendChild(main);
|
|
||||||
// } else {
|
|
||||||
// replaceMe.innerHTML = body;
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
var dynamicContentURL = trigger.getAttribute('href');
|
var dynamicContentURL = trigger.getAttribute('href');
|
||||||
console.log(dynamicContentURL);
|
|
||||||
var frame = document.createElement('iframe');
|
|
||||||
frame.setAttribute('id', "frame-" + modal.getAttribute('id'));
|
|
||||||
modal.insertBefore(frame, null);
|
|
||||||
|
|
||||||
var resizeFrame = function() {
|
|
||||||
frame.style.visibility = 'hidden';
|
|
||||||
frame.style.height = '0';
|
|
||||||
|
|
||||||
var doc = frame.contentDocument ? frame.contentDocument : frame.contentWindow.document;
|
|
||||||
var body = doc.body, html = doc.documentElement;
|
|
||||||
var height = Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight );
|
|
||||||
|
|
||||||
frame.style.height = height.toPrecision() + "px";
|
|
||||||
frame.style.visibility = 'visible';
|
|
||||||
frame.setAttribute("scrolling", "no");
|
|
||||||
|
|
||||||
doc.querySelectorAll("form").forEach(function(form) {
|
|
||||||
form.setAttribute("target", "_top");
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
frame.onload = function() {
|
|
||||||
frame.contentWindow.onresize = resizeFrame;
|
|
||||||
resizeFrame();
|
|
||||||
}
|
|
||||||
|
|
||||||
var url = "";
|
|
||||||
var i = dynamicContentURL.indexOf('?');
|
var i = dynamicContentURL.indexOf('?');
|
||||||
if (i === -1) {
|
if (i === -1) {
|
||||||
url = dynamicContentURL + "?" + #{String modalParameter};
|
dynamicContentURL = dynamicContentURL + "?" + #{String modalParameter};
|
||||||
} else {
|
} else {
|
||||||
url = dynamicContentURL.slice(0,i) + "?" + #{String modalParameter} + "&" + dynamicContentURL.slice(i + 1);
|
dynamicContentURL = dynamicContentURL.slice(0,i) + "?" + #{String modalParameter} + "&" + dynamicContentURL.slice(i + 1);
|
||||||
}
|
}
|
||||||
|
console.log(dynamicContentURL);
|
||||||
|
|
||||||
frame.setAttribute('src', url);
|
if (dynamicContentURL.length > 0) {
|
||||||
|
fetch(dynamicContentURL, {
|
||||||
|
credentials: 'same-origin',
|
||||||
|
}).then(function(response) {
|
||||||
|
return response.text();
|
||||||
|
}).then(function(body) {
|
||||||
|
var modalContent = document.createElement('div');
|
||||||
|
modalContent.classList.add('modal__content');
|
||||||
|
modalContent.innerHTML = body;
|
||||||
|
|
||||||
|
var contentBody = modalContent.querySelector('.main__content-body');
|
||||||
|
var scriptTags = [];
|
||||||
|
if (contentBody) {
|
||||||
|
modalContent.querySelectorAll('script').forEach(function(scriptTag) {
|
||||||
|
if (Array.from(document.body.querySelectorAll('script')).some(function(haystack) {
|
||||||
|
if (haystack.text === scriptTag.text && haystack.getAttribute('src') === scriptTag.getAttribute('src')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
})) { return }
|
||||||
|
|
||||||
|
console.log(scriptTag);
|
||||||
|
var scriptClone = document.createElement('script');
|
||||||
|
if (scriptTag.text)
|
||||||
|
scriptClone.text = striptTag.text;
|
||||||
|
if (scriptTag.hasAttributes()) {
|
||||||
|
var attrs = scriptTag.attributes;
|
||||||
|
for (var i = attrs.length - 1; i >= 0; i--) {
|
||||||
|
scriptClone.setAttribute(attrs[i].name, attrs[i].value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.body.insertBefore(scriptClone, null);
|
||||||
|
scriptTags.push(scriptClone);
|
||||||
|
});
|
||||||
|
|
||||||
|
modalContent.querySelectorAll('style').forEach(function(styleTag) {
|
||||||
|
if (Array.from(document.head.querySelectorAll('style')).some(function(haystack) {
|
||||||
|
return haystack.innerText === styleTag.innerText;
|
||||||
|
})) { return }
|
||||||
|
|
||||||
|
document.head.insertBefore(styleTag, null);
|
||||||
|
});
|
||||||
|
|
||||||
|
modalContent.querySelectorAll('link').forEach(function(linkTag) {
|
||||||
|
if (linkTag.getAttribute('rel') !== 'stylesheet')
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (Array.from(document.head.querySelectorAll('link')).some(function(haystack) {
|
||||||
|
return haystack.getAttribute('href') === linkTag.getAttribute('href');
|
||||||
|
})) { return }
|
||||||
|
|
||||||
|
|
||||||
|
document.head.insertBefore(linkTag, null);
|
||||||
|
});
|
||||||
|
|
||||||
|
modalContent = contentBody;
|
||||||
|
}
|
||||||
|
|
||||||
|
var nudgeAttr = function(attr, x) {
|
||||||
|
var oldVal = x.getAttribute(attr);
|
||||||
|
var newVal = modal.getAttribute('id') + '__' + oldVal;
|
||||||
|
|
||||||
|
// console.log(oldVal, newVal);
|
||||||
|
x.setAttribute(attr, newVal);
|
||||||
|
};
|
||||||
|
|
||||||
|
var idAttrs = ['id', 'for', 'data-conditional-id'];
|
||||||
|
idAttrs.map(function(attr) {
|
||||||
|
modalContent.querySelectorAll('[' + attr + ']').forEach(function(x) { nudgeAttr(attr, x); });
|
||||||
|
});
|
||||||
|
|
||||||
|
modal.appendChild(modalContent);
|
||||||
|
|
||||||
|
var triggerContentLoad = function() {
|
||||||
|
document.dispatchEvent(new CustomEvent('setup', {
|
||||||
|
detail: { scope: modalContent },
|
||||||
|
bubbles: true,
|
||||||
|
cancelable: true
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scriptTags.length !== 0) {
|
||||||
|
scriptTags.forEach(function(t) { t.onload = triggerContentLoad; });
|
||||||
|
}
|
||||||
|
|
||||||
|
triggerContentLoad();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// tell further modals, that this one already got initialized
|
// tell further modals, that this one already got initialized
|
||||||
modal.classList.add('js-modal-initialized');
|
modal.classList.add('js-modal-initialized');
|
||||||
@ -121,10 +164,11 @@
|
|||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('setup', function(e) {
|
||||||
|
|
||||||
Array.from(document.querySelectorAll('.js-modal:not(.js-modal-initialized)')).map(function(modal) {
|
Array.from(e.detail.scope.querySelectorAll('.js-modal:not(.js-modal-initialized)')).map(function(modal) {
|
||||||
new utils.modal(modal);
|
new utils.modal(modal);
|
||||||
});
|
});
|
||||||
|
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@ div.modal {
|
|||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
z-index: -1;
|
z-index: -1;
|
||||||
color: var(--color-font);
|
color: var(--color-font);
|
||||||
/* padding: 20px; */
|
padding: 20px;
|
||||||
padding-right: 65px;
|
padding-right: 65px;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
transition: all .15s ease;
|
transition: all .15s ease;
|
||||||
@ -24,17 +24,6 @@ div.modal {
|
|||||||
z-index: 200;
|
z-index: 200;
|
||||||
transform: translate(-50%, -50%) scale(1, 1);
|
transform: translate(-50%, -50%) scale(1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
iframe {
|
|
||||||
height: calc(60vh);
|
|
||||||
width: 100%;
|
|
||||||
border-style: none;
|
|
||||||
overflow: auto;
|
|
||||||
|
|
||||||
[scrolling='no'] {
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 1024px) {
|
@media (max-width: 1024px) {
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
* content here
|
* content here
|
||||||
*/
|
*/
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('setup', function(e) {
|
||||||
|
|
||||||
var LSNAME = 'SHOW_HIDE';
|
var LSNAME = 'SHOW_HIDE';
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Array
|
Array
|
||||||
.from(document.querySelectorAll('.js-show-hide__toggle'))
|
.from(e.detail.scope.querySelectorAll('.js-show-hide__toggle'))
|
||||||
.forEach(function(el) {
|
.forEach(function(el) {
|
||||||
var index = el.dataset.shIndex || null;
|
var index = el.dataset.shIndex || null;
|
||||||
el.parentElement.classList.toggle(
|
el.parentElement.classList.toggle(
|
||||||
|
|||||||
@ -52,17 +52,17 @@
|
|||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('setup', function(e) {
|
||||||
|
|
||||||
// JS-TOOLTIPS NOT USED CURRENTLY.
|
// JS-TOOLTIPS NOT USED CURRENTLY.
|
||||||
|
|
||||||
// initialize tooltips set via `data-tooltip`
|
// initialize tooltips set via `data-tooltip`
|
||||||
// Array.from(document.querySelectorAll('[data-tooltip]')).forEach(function(el) {
|
// Array.from(e.detail.scope.querySelectorAll('[data-tooltip]')).forEach(function(el) {
|
||||||
// window.utils.tooltipFromAttribute(el)
|
// window.utils.tooltipFromAttribute(el)
|
||||||
// });
|
// });
|
||||||
|
|
||||||
// initialize tooltips
|
// initialize tooltips
|
||||||
// Array.from(document.querySelectorAll('.js-tooltip')).forEach(function(tt) {
|
// Array.from(e.detail.scope.querySelectorAll('.js-tooltip')).forEach(function(tt) {
|
||||||
// window.utils.tooltip(tt);
|
// window.utils.tooltip(tt);
|
||||||
// });
|
// });
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
(function collonadeClosure() {
|
(function collonadeClosure() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function DOMContentLoaded() {
|
document.addEventListener('setup', function DOMContentLoaded(e) {
|
||||||
|
|
||||||
function setupAsync(wrapper) {
|
function setupAsync(wrapper) {
|
||||||
|
|
||||||
@ -71,7 +71,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var selector = '#' + #{String $ dbtIdent} + '-table-wrapper';
|
var wrapperEl = e.detail.scope.querySelector('#' + #{String $ dbtIdent} + '-table-wrapper');
|
||||||
setupAsync(document.querySelector(selector));
|
if (wrapperEl)
|
||||||
|
setupAsync(wrapperEl);
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|||||||
@ -17,9 +17,9 @@
|
|||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('setup', function(e) {
|
||||||
|
|
||||||
var asidenavEl = document.querySelector('.main__aside');
|
var asidenavEl = e.detail.scope.querySelector('.main__aside');
|
||||||
|
|
||||||
window.utils.aside(asidenavEl);
|
window.utils.aside(asidenavEl);
|
||||||
|
|
||||||
|
|||||||
@ -55,6 +55,8 @@
|
|||||||
|
|
||||||
function addEventListeners() {
|
function addEventListeners() {
|
||||||
fields.forEach(function(field) {
|
fields.forEach(function(field) {
|
||||||
|
console.log('interactiveFieldset', 'addEventListeners', field);
|
||||||
|
|
||||||
field.condEl.addEventListener('input', updateFields)
|
field.condEl.addEventListener('input', updateFields)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -66,9 +68,11 @@
|
|||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('setup', function(e) {
|
||||||
|
|
||||||
var forms = document.querySelectorAll('form');
|
console.log('form setup', e.detail.scope);
|
||||||
|
|
||||||
|
var forms = e.detail.scope.querySelectorAll('form');
|
||||||
Array.from(forms).forEach(function(form) {
|
Array.from(forms).forEach(function(form) {
|
||||||
// auto reactiveButton submit-buttons with required fields
|
// auto reactiveButton submit-buttons with required fields
|
||||||
var submitBtns = Array.from(form.querySelectorAll('[type=submit]'));
|
var submitBtns = Array.from(form.querySelectorAll('[type=submit]'));
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
<div .modal.js-modal #modal-#{modalId} data-trigger=#{triggerId} data-closeable=true data-dynamic=#{modalDynamic}>
|
<div .modal.js-modal #modal-#{modalId} data-trigger=#{triggerId} data-closeable :modalDynamic:data-dynamic>
|
||||||
$case modalContent
|
$case modalContent
|
||||||
$of Right content
|
$of Right content
|
||||||
^{content}
|
^{content}
|
||||||
|
|||||||
@ -26,6 +26,6 @@
|
|||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function () {
|
document.addEventListener('setup', function (e) {
|
||||||
// utils.stickynav(document.querySelector('.js-sticky-navbar'));
|
// utils.stickynav(e.detail.scope.querySelector('.js-sticky-navbar'));
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user