PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/types/library/toolset/types/embedded/resources/js/fields-form.js

https://gitlab.com/Fraternal-Group/fraternal
JavaScript | 163 lines | 114 code | 22 blank | 27 comment | 19 complexity | fbbd44b5b563aeeb037c1759c5324088 MD5 | raw file
  1. /*
  2. * Group edit page JS
  3. *
  4. * This file should be used from now on as dedicated JS for group edit page.
  5. * Avoid adding new functionalities to basic.js
  6. *
  7. * Thanks!
  8. *
  9. * @since Types 1.1.5
  10. * @autor srdjan
  11. *
  12. *
  13. */
  14. jQuery(document).ready(function($){
  15. /**
  16. * bind validation checkboxes
  17. */
  18. $('#post-body-content').on('change', '.js-wpcf-validation-checkbox', function() {
  19. next = $(this).closest('tr');
  20. // as there different number of hidden inputs between the checkbox
  21. // and the validation error message input we need to trick
  22. for( i = 0; i < 10; i++ ) {
  23. next = next.next();
  24. // break loop if next tr is found
  25. if( next.prop( 'tagName' ).toLowerCase() == 'tr' )
  26. break;
  27. }
  28. if( next.attr( 'type' ) == 'hidden' )
  29. next = next.next();
  30. if ( $(this).is(':checked') ) {
  31. $('input', next).removeAttr('disabled').focus();
  32. } else {
  33. $('input', next).attr('disabled', 'disabled');
  34. }
  35. });
  36. // Invoke drag on mouse enter
  37. $('#wpcf-fields-sortable').on('mouseenter', '.js-types-sortable', function(){
  38. if (!$(this).parent().hasClass('ui-sortable')) {
  39. $(this).parent().sortable({
  40. revert: true,
  41. handle: '.js-types-sort-button',
  42. start: function(e, ui){
  43. ui.placeholder.height(ui.item.find('.wpcf-form-fieldset').height());
  44. }
  45. });
  46. }
  47. });
  48. // Sort and Drag
  49. $('#wpcf-fields-sortable').sortable({
  50. cursor: 'ns-resize',
  51. axis: 'y',
  52. handle: 'img.wpcf-fields-form-move-field',
  53. forcePlaceholderSize: true,
  54. tolerance: 'pointer',
  55. start: function(e, ui){
  56. ui.placeholder.height(ui.item.height() + 23);
  57. }
  58. });
  59. $.fn.typesFieldOptionsSortable = function() {
  60. $( '.wpcf-fields-radio-sortable, .wpcf-fields-select-sortable, .wpcf-fields-checkboxes-sortable', this ).sortable({
  61. cursor: 'ns-resize',
  62. axis: 'y',
  63. handle: '.js-types-sort-button',
  64. start: function(e, ui){
  65. ui.placeholder.height(ui.item.height() - 2);
  66. }
  67. });
  68. $( '.wpcf-fields-checkboxes-sortable', this ).sortable({
  69. start: function(e, ui){
  70. ui.placeholder.height(ui.item.height() + 13);
  71. }
  72. });
  73. }
  74. $.fn.typesMarkExistingField = function() {
  75. var slug = $( '.wpcf-forms-field-slug', this );
  76. if( slug.length && slug.val() != '' )
  77. slug.attr( 'data-types-existing-field', slug.val() );
  78. }
  79. $( 'body' ).typesFieldOptionsSortable();
  80. $('[data-wpcf-type="checkbox"],[data-wpcf-type=checkboxes]').each( function() {
  81. $(this).bind('change', function() {
  82. wpcf_checkbox_value_zero($(this))
  83. });
  84. wpcf_checkbox_value_zero($(this));
  85. });
  86. /**
  87. * confitonal logic button close on group edit screen
  88. */
  89. $('#conditional-logic-button-ok').live('click', function(){
  90. $(this).parent().slideUp('slow', function() {
  91. $('#conditional-logic-button-open').fadeIn();
  92. });
  93. return false;
  94. });
  95. /**
  96. * delete option
  97. */
  98. $(document).on('click', '.js-wpcf-button-delete', function() {
  99. var $thiz = $(this);
  100. if (confirm($(this).data('message-delete-confirm'))) {
  101. $thiz.closest('tr').fadeOut(function(){
  102. $(this).remove();
  103. $('.'+$thiz.data('id')).fadeOut(function(){
  104. $(this).remove();
  105. });
  106. });
  107. }
  108. return false;
  109. });
  110. });
  111. function wpcf_checkbox_value_zero(field) {
  112. var passed = true;
  113. if (jQuery(field).hasClass('wpcf-value-store-error-error')) {
  114. jQuery(field).prev().remove();
  115. jQuery(field).removeClass('wpcf-value-store-error-error');
  116. }
  117. var value = jQuery(field).val();
  118. if (value === '') {
  119. passed = false;
  120. if (!jQuery(field).hasClass('wpcf-value-store-error-error')) {
  121. jQuery(field).before('<div class="wpcf-form-error">' + jQuery(field).data('required-message') + '</div>').addClass('wpcf-value-store-error-error');
  122. var legend = jQuery(field).closest('div.ui-draggable').children('fieldset').children('legend');
  123. if ( legend.hasClass('legend-collapsed') ) {
  124. legend.click();
  125. }
  126. var fieldset = jQuery(field).closest('fieldset');
  127. if ( jQuery('legend.legend-collapsed', fieldset ) ) {
  128. jQuery('legend.legend-collapsed', fieldset).click();
  129. }
  130. }
  131. jQuery(field).focus();
  132. }
  133. if (value === '0') {
  134. passed = false;
  135. if (!jQuery(field).hasClass('wpcf-value-store-error-error')) {
  136. jQuery(field).before('<div class="wpcf-form-error">' + jQuery(field).data('required-message-0') + '</div>').addClass('wpcf-value-store-error-error');
  137. }
  138. jQuery(field).focus();
  139. }
  140. return !passed;
  141. }