Commit 6df5c7a7 authored by Romain Courteaud's avatar Romain Courteaud

erp5_web_js_style: move main content into a noscript tag to prevent loading image

Nice idea, but it does not work with DOMParser :/
parent 9db63346
Pipeline #23733 failed with stage
in 0 seconds
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
<body tal:attributes="data-nostyle-gadget-url no_style_gadget_url; <body tal:attributes="data-nostyle-gadget-url no_style_gadget_url;
data-nostyle-css-url no_style_css_url"> data-nostyle-css-url no_style_css_url">
<tal:block tal:content="structure python: web_section.WebSection_generateNavigationHTML()"></tal:block> <tal:block tal:content="structure python: web_section.WebSection_generateNavigationHTML()"></tal:block>
<main> <main><noscript>
<p tal:content="request/portal_status_message | nothing" id="portal_status_message"/> <p tal:content="request/portal_status_message | nothing" id="portal_status_message"/>
<tal:block tal:condition="request/field_errors | nothing"> <tal:block tal:condition="request/field_errors | nothing">
...@@ -106,7 +106,7 @@ ...@@ -106,7 +106,7 @@
tal:content="python:here.Base_getFormViewDialogActionButtonTitle(form)">Submit</span> tal:content="python:here.Base_getFormViewDialogActionButtonTitle(form)">Submit</span>
</button> </button>
</form> </form>
</main> </noscript></main>
</body> </body>
</html> </html>
</tal:block> </tal:block>
......
...@@ -229,33 +229,18 @@ ...@@ -229,33 +229,18 @@
url_attribute_list = ['src', 'href', 'srcset', 'action'], url_attribute_list = ['src', 'href', 'srcset', 'action'],
url_attribute, url_attribute,
feed_url = null, feed_url = null,
new_element; new_element,
new_element_2;
//body_element = body_element.content.cloneNode(true); // Move the content of the noscript tag
// Improve img rendering by default to reduce size element = body_element.querySelector('main > noscript');
element_list = body_element.querySelectorAll('noscript');
for (i = 0; i < element_list.length; i += 1) {
element = element_list[i];
new_element = document.createElement('div'); new_element = document.createElement('div');
new_element.innerHTML = element.textContent; new_element.innerHTML = element.textContent;
element.parentNode.replaceChild(new_element, element); new_element_2 = document.createDocumentFragment();
} while (new_element.firstChild) {
new_element_2.appendChild(new_element.firstChild);
// Improve img rendering by default to reduce size
element_list = body_element.querySelectorAll('img');
for (i = 0; i < element_list.length; i += 1) {
element = element_list[i];
if (!element.getAttribute('loading')) {
element.loading = 'lazy';
}
feed_url = element.getAttribute('src');
if ((feed_url) &&
(feed_url.indexOf('/') === -1)) {
feed_url = feed_url.split('?')[0] +
'?format=jpg&display=small&quality=90';
element.src = feed_url;
}
} }
element.parentNode.replaceChild(new_element_2, element);
if (base_uri !== undefined) { if (base_uri !== undefined) {
// Rewrite relative url (copied from renderjs) // Rewrite relative url (copied from renderjs)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment