From a62fbd54d4a1eba5cf243a449a20ac4610d478c4 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Mon, 18 Dec 2017 20:48:11 +0100 Subject: [PATCH] Remove typocheck, it has to many false positives --- src/pretix/presale/forms/checkout.py | 8 +- .../presale/templates/pretixpresale/base.html | 1 - .../static/pretixpresale/js/ui/typocheck.js | 80 ------------------- 3 files changed, 3 insertions(+), 86 deletions(-) delete mode 100644 src/pretix/static/pretixpresale/js/ui/typocheck.js diff --git a/src/pretix/presale/forms/checkout.py b/src/pretix/presale/forms/checkout.py index c8ee7de717..3abe0277d5 100644 --- a/src/pretix/presale/forms/checkout.py +++ b/src/pretix/presale/forms/checkout.py @@ -30,7 +30,7 @@ class ContactForm(forms.Form): help_text=_('Make sure to enter a valid email address. We will send you an order ' 'confirmation including a link that you need in case you want to make ' 'modifications to your order or download your ticket later.'), - widget=forms.EmailInput(attrs={'data-typocheck-target': '1', 'autofocus': 'autofocus'})) + widget=forms.EmailInput(attrs={'autofocus': 'autofocus'})) def __init__(self, *args, **kwargs): self.event = kwargs.pop('event') @@ -90,9 +90,8 @@ class InvoiceAddressForm(forms.ModelForm): widgets = { 'is_business': BusinessBooleanRadio, 'street': forms.Textarea(attrs={'rows': 2, 'placeholder': _('Street and Number')}), - 'company': forms.TextInput(attrs={'data-typocheck-source': '1', - 'data-display-dependency': '#id_is_business_1'}), - 'name': forms.TextInput(attrs={'data-typocheck-source': '1'}), + 'company': forms.TextInput(attrs={'data-display-dependency': '#id_is_business_1'}), + 'name': forms.TextInput(attrs={}), 'vat_id': forms.TextInput(attrs={'data-display-dependency': '#id_is_business_1'}), 'internal_reference': forms.TextInput, } @@ -217,7 +216,6 @@ class QuestionsForm(forms.Form): max_length=255, required=event.settings.attendee_names_required, label=_('Attendee name'), initial=(cartpos.attendee_name if cartpos else orderpos.attendee_name), - widget=forms.TextInput(attrs={'data-typocheck-source': '1'}), ) if item.admission and event.settings.attendee_emails_asked: self.fields['attendee_email'] = forms.EmailField( diff --git a/src/pretix/presale/templates/pretixpresale/base.html b/src/pretix/presale/templates/pretixpresale/base.html index 4db3ed8a9c..53d0ca9b3f 100644 --- a/src/pretix/presale/templates/pretixpresale/base.html +++ b/src/pretix/presale/templates/pretixpresale/base.html @@ -27,7 +27,6 @@ - {% endcompress %} diff --git a/src/pretix/static/pretixpresale/js/ui/typocheck.js b/src/pretix/static/pretixpresale/js/ui/typocheck.js deleted file mode 100644 index cae70872bc..0000000000 --- a/src/pretix/static/pretixpresale/js/ui/typocheck.js +++ /dev/null @@ -1,80 +0,0 @@ -/*global $,gettext,ngettext */ - -function typocheck() { - var $target = $("input[data-typocheck-target]"), - $sources = $("input[data-typocheck-source]"), - orig_val = $target.val(), - words = []; - - function regexEscape(str) { - return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); - } - - $sources.each(function () { - $.each($(this).val().toLowerCase().split(' '), function (i, w) { - if (w && w.length > 5) { - words.push(w); - words.push(w.replace('-', '')); - } - }); - }); - words.push( - '@gmail.', '@web.', '@gmx.', '@hotmail.', '@live.', '@outlook.', '@yahoo.', '@msn.', '@me.', - '@verizon.', '@mac.', '@icloud.', '@inbox.', '@rocketmail.', '@bt.', '@orange.', - '@online.', '@t-online.', '@googlemail.' - ); - - var word, patterns, i, j, k, r, - val = orig_val; - for (i = 0; i < words.length; i++) { - word = words[i]; - patterns = []; - for (j = 0; j < word.length; j++) { - if (j > 0) { - patterns.push(regexEscape(word.slice(0, j)) + '.' + regexEscape(word.slice(j))); - } - if (j > 0 || word.slice(0, 1) !== '@') { - patterns.push(regexEscape(word.slice(0, j)) + '.' + regexEscape(word.slice(j + 1))); - patterns.push(regexEscape(word.slice(0, j)) + regexEscape(word.slice(j + 1, j + 2)) + regexEscape(word.slice(j, j + 1)) + regexEscape(word.slice(j + 2))); - } - patterns.push(regexEscape(word.slice(0, j)) + regexEscape(word.slice(j + 1))); - } - - // Remove conflicting patterns (i.e. gmail.com shouldn't correct email.com) - for (j = patterns.length - 1; j >= 0; j--) { - r = new RegExp(patterns[j]); - for (k = 0; k < words.length; k++) { - if (k === i) { - continue; - } - if (words[k].match(r)) { - patterns.splice(j, 1); - } - } - } - var newval = val.replace(new RegExp('(' + patterns.join('|') + ')', 'i'), word); - if (newval.split("@").length === 2) { - val = newval; - } - } - val = val.replace(/gmail\.(?!com$)[a-z]*$/i, 'gmail.com'); - - var changed = (val.toLowerCase() != orig_val.toLowerCase()); - $(".typo-alert").toggle(changed).find("[data-typosuggest]").text(val); - $(".typo-alert").find("[data-typodisplay]").text(orig_val); -} - -$(document).ready(function () { - if ($("input[data-typocheck-target]").length === 0) { - return; - } - - $('body').on('change', 'input[data-typocheck-target], input[data-typocheck-source]', function () { - typocheck(); - }); - $(".typo-alert span[data-typosuggest]").click(function () { - $("input[data-typocheck-target]").val($(this).text()); - $(".typo-alert").slideUp(); - }) - typocheck(); -});