Advertisement
Guest User

Untitled

a guest
Aug 11th, 2020
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.07 KB | None | 0 0
  1. /*!
  2. * Bootstrap for Contact Form 7 (https://wordpress.org/plugins/bootstrap-for-contact-form-7/)
  3. * By Felix Arntz (https://leaves-and-love.net)
  4. * Licensed under GNU General Public License v2 (or later) (http://www.gnu.org/licenses/gpl-2.0.html)
  5. */
  6. (function($) {
  7. 'use strict'
  8.  
  9. window.wpcf7.notValidTip = function(target, message) {
  10. var $target = $(target)
  11.  
  12. $target.addClass('has-error')
  13. $('.wpcf7-not-valid-tip', $target).remove()
  14.  
  15. if (!$target.parents('.wpcf7-form').hasClass('form-inline')) {
  16. if ($target.parents('.wpcf7-form').hasClass('form-horizontal')) {
  17. $target.children('div').append('<span class="help-block wpcf7-not-valid-tip">' + message + '</span>')
  18. } else {
  19. $target.append('<span class="help-block wpcf7-not-valid-tip">' + message + '</span>')
  20. }
  21.  
  22. if ($target.is('.use-floating-validation-tip *')) {
  23. var fadeOut = function(target) {
  24. $(target).not(':hidden').animate({
  25. opacity: 0
  26. }, 'fast', function() {
  27. $(this).css({'z-index': -100})
  28. })
  29. }
  30.  
  31. $target.on('mouseover', '.wpcf7-not-valid-tip', function() {
  32. fadeOut(this)
  33. })
  34.  
  35. $target.on('focus', ':input', function() {
  36. fadeOut($('.wpcf7-not-valid-tip', $target))
  37. })
  38. }
  39. }
  40. }
  41.  
  42. window.wpcf7.clearResponse = function(form) {
  43. var $form = $(form)
  44. var $close = $form.find('div.wpcf7-response-output .close')
  45.  
  46. $form.removeClass('invalid spam sent failed')
  47. $form.siblings('.screen-reader-response').html('').attr('role', '')
  48.  
  49. $('.wpcf7-not-valid-tip', $form).remove()
  50. $('[aria-invalid]', $form).attr('aria-invalid', 'false')
  51. $('.wpcf7-form-control', $form).removeClass('wpcf7-not-valid')
  52. $('div.form-group', $form).removeClass('has-error')
  53. $('img.ajax-loader', $form).removeClass('is-active')
  54.  
  55. $('.wpcf7-response-output', $form)
  56. .hide().empty().removeAttr('role')
  57. .removeClass('wpcf7-mail-sent-ok wpcf7-mail-sent-ng wpcf7-validation-errors wpcf7-spam-blocked alert-warning alert-success alert-danger')
  58.  
  59. if (0 < $close.length) {
  60. $form.find('div.wpcf7-response-output').append($close)
  61. }
  62. }
  63.  
  64. // add Bootstrap Alert classes to response output
  65. $(function() {
  66. var wpcf7Elm = document.querySelectorAll('.wpcf7')
  67. $.each(wpcf7Elm, function(i, form) {
  68. form.addEventListener('wpcf7invalid', function(event) {
  69. $(this).find('div.wpcf7-response-output').addClass('alert-warning')
  70. }, false)
  71. form.addEventListener('wpcf7spam', function(event) {
  72. $(this).find('div.wpcf7-response-output').addClass('alert-warning')
  73. }, false)
  74. form.addEventListener('wpcf7mailsent', function(event) {
  75. $(this).find('div.wpcf7-response-output').addClass('alert-success')
  76. }, false)
  77. form.addEventListener('wpcf7mailfailed', function(event) {
  78. $(this).find('div.wpcf7-response-output').addClass('alert-danger')
  79. }, false)
  80. })
  81.  
  82. $('div.wpcf7').on('click', 'div.wpcf7-response-output .close', function(e) {
  83. $(this).parent().hide()
  84. e.preventDefault()
  85. })
  86. })
  87.  
  88. // WPCF7 Function Override: Adjusted for Bootstrap Help Block Output and Status Class
  89. $.fn.wpcf7NotValidTip = function(message) {
  90. return this.each(function() {
  91. var $into = $(this)
  92. $into.addClass('has-error')
  93.  
  94. if (!$into.parents('.wpcf7-form').hasClass('form-inline')) {
  95. $into.find('span.wpcf7-not-valid-tip').remove()
  96. if ($into.parents('.wpcf7-form').hasClass('form-horizontal')) {
  97. $into.children('div').append('<span class="help-block wpcf7-not-valid-tip">' + message + '</span>')
  98. } else {
  99. $into.append('<span class="help-block wpcf7-not-valid-tip">' + message + '</span>')
  100. }
  101. $into.slideDown('fast')
  102.  
  103. if ($into.is('.use-floating-validation-tip *')) {
  104. $('.wpcf7-not-valid-tip', $into).mouseover(function() {
  105. $(this).wpcf7FadeOut()
  106. })
  107.  
  108. $(':input', $into).focus(function() {
  109. $('.wpcf7-not-valid-tip', $into).not(':hidden').wpcf7FadeOut()
  110. })
  111. }
  112. }
  113. })
  114. }
  115.  
  116. // WPCF7 Function Override: Different DOM Element is required
  117. $.fn.wpcf7RefillQuiz = function(quiz) {
  118. return this.each(function() {
  119. var form = $(this)
  120.  
  121. $.each(quiz, function(i, n) {
  122. form.find(':input[name="' + i + '"]').clearFields()
  123. form.find(':input[name="' + i + '"]').siblings('p.wpcf7-quiz-label').text(n[0])
  124. form.find('input:hidden[name="_wpcf7_quiz_answer_' + i + '"]').attr('value', n[1])
  125. })
  126. })
  127. }
  128.  
  129. // WPCF7 Function Override: Adjusted for Bootstrap Alert classes and Status Class
  130. $.fn.wpcf7ClearResponseOutput = function() {
  131. return this.each(function() {
  132. var $close = $(this).find('div.wpcf7-response-output .close')
  133. $(this).find('div.wpcf7-response-output').hide().empty().removeClass('wpcf7-mail-sent-ok wpcf7-mail-sent-ng wpcf7-validation-errors wpcf7-spam-blocked alert-warning alert-success alert-danger').removeAttr('role')
  134. if (0 < $close.length) {
  135. $(this).find('div.wpcf7-response-output').append($close)
  136. }
  137. $(this).find('div.form-group').removeClass('has-error')
  138. $(this).find('span.wpcf7-not-valid-tip').remove()
  139. $(this).find('img.ajax-loader').removeClass('is-active')
  140. })
  141. }
  142.  
  143. })(jQuery)
  144.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement