<commit_before>###############################################################################
# Client-side form validation
###############################################################################

( ($) ->

    drmForms = {

        config: {
            speed: 300
        }

        init: (config) ->
            $.extend @.config, config
            body = $ 'body'

            body.on 'click', ':disabled', (e) ->
                e.preventDefault()

            body.on 'keyup', '.drm-valid-integer', @validateInteger
            body.on 'keyup', '.drm-valid-number', @validateNumber
            body.on 'keyup', '.drm-valid-url', @validateURL
            body.on 'keyup', '.drm-valid-phone', @validatePhone
            body.on 'keyup', '.drm-valid-email', @validateEmail
            body.on 'keyup', '.drm-valid-full-name', @validateFullName
            body.on 'keyup', '.drm-valid-alpha', @validateAlpha
            body.on 'keyup', '.drm-valid-alphanum', @validateAlphaNum
            body.on 'keyup', '.drm-valid-alphadash', @validateAlphaNumDash
            body.on 'keyup', '.drm-valid-alpha-num-underscore', @validateAlphaNumUnderscore
            body.on 'keyup', '.drm-valid-no-spaces', @validateNoSpaces
            body.on 'keyup', '.drm-valid-no-tags', @validateNoTags
            body.on 'keyup', '[required]', @validateRequired
            body.on 'keyup', ':input[data-max-value]:not([data-min-value])', @validateMaxValue
            body.on 'keyup', ':input[data-min-value]:not([data-max-value])', @validateMinValue
            body.on 'keyup', ':input[data-max-length]:not([data-min-length])', @validateMaxLength
            body.on 'keyup', ':input[data-min-length]:not([data-max-length])', @validateMinLength
            body.on 'keyup', ':input[data-min-value][data-max-value]', @validateBetweenValue
            body.on 'keyup', ':input[data-min-length][data-max-length]', @validateBetweenLength
            body.on 'keyup', ':input', @trackLength
            body.on 'blur', ':input:not([required])', @validateEmpty

        success: ->
            that = $ @
            drmForms.removeValidationClass.call that
            that.addClass 'drm-form-success'

        warning: ->
            that = $ @
            drmForms.removeValidationClass.call that
            that.addClass 'drm-form-warning'

        danger: ->
            that = $ @
            drmForms.removeValidationClass.call that
            that.addClass 'drm-form-danger'

        trackLength: ->
            that = $ @
            value = $.trim that.val()
            length = value.length
            lengthNotice = $ ".form-length-notice"
            createMessage = (length) ->
                message = if length == 1 then "#{length} character" else "#{length} characters"
                return message

            if lengthNotice.length == 0
                message = createMessage(length)
                lengthNotice = $ '<p></p>', {
                    text: message
                    class: 'form-length-notice'
                }
                
                lengthNotice.hide().insertAfter(that).show()
            else if length == 0
                lengthNotice.remove()
            else
                message = createMessage(length)
                lengthNotice.text message

        issueNotice: (status, message) ->
            that = $ @
            notice = $ ".form-#{status}-notice:contains(#{message})"
            
            if notice.length == 0
                notice = $ '<p></p>', {
                    text: message,
                    class: "form-#{status}-notice"
                }
                
                notice.hide().insertAfter(that).slideDown drmForms.config.speed
<commit_msg>fixed bug in lengthTracker method<commit_after>###############################################################################
# Client-side form validation
###############################################################################

( ($) ->

    drmForms = {

        config: {
            speed: 300
        }

        init: (config) ->
            $.extend @.config, config
            body = $ 'body'

            body.on 'click', ':disabled', (e) ->
                e.preventDefault()

            body.on 'keyup', '.drm-valid-integer', @validateInteger
            body.on 'keyup', '.drm-valid-number', @validateNumber
            body.on 'keyup', '.drm-valid-url', @validateURL
            body.on 'keyup', '.drm-valid-phone', @validatePhone
            body.on 'keyup', '.drm-valid-email', @validateEmail
            body.on 'keyup', '.drm-valid-full-name', @validateFullName
            body.on 'keyup', '.drm-valid-alpha', @validateAlpha
            body.on 'keyup', '.drm-valid-alphanum', @validateAlphaNum
            body.on 'keyup', '.drm-valid-alphadash', @validateAlphaNumDash
            body.on 'keyup', '.drm-valid-alpha-num-underscore', @validateAlphaNumUnderscore
            body.on 'keyup', '.drm-valid-no-spaces', @validateNoSpaces
            body.on 'keyup', '.drm-valid-no-tags', @validateNoTags
            body.on 'keyup', '[required]', @validateRequired
            body.on 'keyup', ':input[data-max-value]:not([data-min-value])', @validateMaxValue
            body.on 'keyup', ':input[data-min-value]:not([data-max-value])', @validateMinValue
            body.on 'keyup', ':input[data-max-length]:not([data-min-length])', @validateMaxLength
            body.on 'keyup', ':input[data-min-length]:not([data-max-length])', @validateMinLength
            body.on 'keyup', ':input[data-min-value][data-max-value]', @validateBetweenValue
            body.on 'keyup', ':input[data-min-length][data-max-length]', @validateBetweenLength
            body.on 'keyup', ':input', @trackLength
            body.on 'blur', ':input:not([required])', @validateEmpty

        success: ->
            that = $ @
            drmForms.removeValidationClass.call that
            that.addClass 'drm-form-success'

        warning: ->
            that = $ @
            drmForms.removeValidationClass.call that
            that.addClass 'drm-form-warning'

        danger: ->
            that = $ @
            drmForms.removeValidationClass.call that
            that.addClass 'drm-form-danger'

        trackLength: ->
            that = $ @
            value = $.trim that.val()
            length = value.length
            lengthNotice = that.nextUntil(':input', '.form-length-notice')
            
            createMessage = (length) ->
                message = if length == 1 then "#{length} character" else "#{length} characters"
                return message

            if lengthNotice.length == 0
                message = createMessage(length)
                lengthNotice = $ '<p></p>', {
                    text: message
                    class: 'form-length-notice'
                }
                
                lengthNotice.hide().insertAfter(that).show()
            else if length == 0
                lengthNotice.remove()
            else
                message = createMessage(length)
                lengthNotice.text message

        issueNotice: (status, message) ->
            that = $ @
            notice = $ ".form-#{status}-notice:contains(#{message})"
            
            if notice.length == 0
                notice = $ '<p></p>', {
                    text: message,
                    class: "form-#{status}-notice"
                }
                
                notice.hide().insertAfter(that).slideDown drmForms.config.speed

{'fraction_non_alphanumeric': 0.17778957144752555, 'fraction_numerical': 0.001857502985272655, 'mean_word_length': 1.799108800594133, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4221615', 'n_tokens_mistral': 2089, 'n_tokens_neox': 1946, 'n_words': 373}