templates: get rid of modify_attributes

The modify_attributes was used for IE to set attributes on DOM elements,
since Archweb no longer supports IE and this can be done easily with
plain JavaScript. Also drop non-standard HTML attributes since they
aren't worth keeping.

Signed-off-by: Jelle van der Waa <jelle@vdwaa.nl>
This commit is contained in:
Jelle van der Waa 2019-02-28 17:13:26 +01:00
parent 6bcd40d3a9
commit 5d24641758
2 changed files with 5 additions and 18 deletions

View File

@ -456,13 +456,3 @@ function collapseNotes(elements) {
}); });
}); });
} }
/* HTML5 input type and attribute enhancements */
function modify_attributes(to_change) {
/* jQuery doesn't let us change the 'type' attribute directly due to IE
woes, so instead we can clone and replace, setting the type. */
$.each(to_change, function(id, attrs) {
var obj = $(id);
obj.replaceWith(obj.clone().attr(attrs));
});
}

View File

@ -27,15 +27,12 @@ <h2>Developer Profile</h2>
{% endblock %} {% endblock %}
{% block script_block %} {% block script_block %}
{% load cdn %}{% jquery %}
<script type="text/javascript" src="{% static "archweb.js" %}"></script>
<script type="text/javascript" nonce={{ CSP_NONCE }}> <script type="text/javascript" nonce={{ CSP_NONCE }}>
modify_attributes({ document.addEventListener('DOMContentLoaded', function() {
'#id_email': {type: 'email'}, document.getElementById('id_email').setAttribute('type', 'email');
'#id_alias': {autocorrect: 'off', autocapitalize: 'off'}, document.getElementById('id_public_email').setAttribute('type', 'email');
'#id_public_email': {autocorrect: 'off', autocapitalize: 'off'}, document.getElementById('id_website').setAttribute('type', 'url');
'#id_website': {type: 'url'}, document.getElementById('id_yob').setAttribute('pattern', '[0-9]*');
'#id_yob': {pattern: '[0-9]*'}
}); });
</script> </script>
{% endblock %} {% endblock %}