Plugin Directory

Changeset 2457979


Ignore:
Timestamp:
01/18/2021 02:54:57 AM (5 years ago)
Author:
GusRuss89
Message:

v3.6.4

Location:
material-design-for-contact-form-7/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • material-design-for-contact-form-7/trunk/README.txt

    r2457965 r2457979  
    107107
    108108== Changelog ==
     109= 2.6.4 =
     110* Update deprecated jQuery APIs
     111
    109112= 2.6.3 =
    110113* Update Freemius SDK
  • material-design-for-contact-form-7/trunk/assets/js/cf7-material-design.js

    r1941737 r2457979  
    66// Don't delete it
    77(function ($) {
    8   // Do stuff
    9   $(document).ready(function () {
    10     // === Running ID === //
    11     window.cf7mdId = 0; // === Form formatting === //
    12 
    13     $('.cf7md-form').each(function () {
    14       var $this = $(this); // Remove empty p tags inside, before and after
    15 
    16       $this.siblings('p').add($this.find('p')).filter(function () {
    17         return $.trim(this.innerHTML) == "";
    18       }).remove(); // Add `required` attribute to all required fields
    19 
    20       $('.cf7md-text, .cf7md-textarea').find('.wpcf7-validates-as-required').each(function () {
    21         $(this).attr('required', 'required');
    22       });
    23     }); // === Generic item formatting === //
    24 
    25     $('.cf7md-item').each(function () {
    26       var $this = $(this),
    27           $span = $this.find('.wpcf7-form-control-wrap'); // Remove breaks
    28 
    29       $this.find('br').remove(); // Add md class to span
    30 
    31       $span.addClass('mdc-form-field cf');
    32     }); // === Prepare text inputs and textareas for MD Init === //
    33 
    34     $('.cf7md-text, .cf7md-textarea').each(function () {
    35       var $this = $(this),
    36           $input = $this.find('input, textarea'),
    37           $span = $this.find('.wpcf7-form-control-wrap'),
    38           $tpl = $this.find('.cf7md-text-html').find('> div'),
    39           $label = $tpl.find('label'); // Move input
    40 
    41       $input.detach().prependTo($tpl); // Insert template
    42 
    43       $tpl.detach().appendTo($span); // Add md class to input
    44 
    45       $input.addClass('mdc-textfield__input'); // Add 'for' to label
    46 
    47       $label.attr('for', $input.attr('name')); // Add autosize to textareas
    48 
    49       if ($this.hasClass('cf7md-textarea-autosize')) {
    50         $input.attr('rows', '2');
    51         autosize($input);
    52       }
    53 
    54       var textField = new _textfield.MDCTextField(this);
    55     }); // === Make html5 date inputs play nice with our text fields === //
    56 
    57     $('.cf7md-text [type="date"]').each(function () {
    58       var $this = $(this);
    59       $this.change(function () {
    60         if ($this.val() !== '') {
    61           $this.addClass('cf7md-has-input');
    62         } else {
    63           $this.removeClass('cf7md-has-input');
    64         }
    65       });
    66     }); // === Prepare selects === //
    67 
    68     $('.cf7md-select').each(function () {
    69       var $this = $(this),
    70           $select = $this.find('select'),
    71           label = $this.find('.cf7md-select-label').text(),
    72           $option1 = $select.children('option').first();
    73 
    74       if ($select.hasClass('wpcf7-validates-as-required')) {
    75         label += '*';
    76       }
    77 
    78       if ($this.hasClass('cf7md-select--multi')) {
    79         // Add class and size for multi
    80         $select.addClass('mdc-multi-select mdc-list');
    81         $select.attr('size', '5');
    82       } else {
    83         // Add class for standard select
    84         $select.addClass('mdc-select'); // Add blank option as label
    85 
    86         if ($option1.attr('value') === '') {
    87           $option1.text(label);
    88         } else {
    89           $option1.before('<option default selected value="">' + label + '</option>');
    90         }
    91       }
    92     }); // === Prepare checkboxes === //
    93 
    94     $('.cf7md-checkbox, .cf7md-radio').each(function () {
    95       var $this = $(this),
    96           type = $this.hasClass('cf7md-radio') ? 'radio' : 'checkbox',
    97           $items = $this.find('.wpcf7-list-item'),
    98           tpl = $this.find('.cf7md-' + type + '-html').html();
    99       $items.each(function () {
    100         var $item = $(this),
    101             $checkbox = $item.find('input'),
    102             $label = $item.find('.wpcf7-list-item-label'),
    103             $labelWrap = $label.parents('label'),
    104             label = $label.text(),
    105             $html = $(tpl).clone(),
    106             $wrap = $('<div class="mdc-' + type + '"></div>'),
    107             mdcCheckbox = $wrap[0],
    108             id = 'cf7md' + ++cf7mdId; // Add classes and ID
    109 
    110         $checkbox.addClass('mdc-' + type + '__native-control').attr('id', id);
    111         $item.addClass('cf7md-' + type + '-item mdc-form-field cf'); // Rearrange markup
    112 
    113         $item.append($wrap);
    114         $label.remove();
    115         $labelWrap.remove();
    116         $checkbox.detach().appendTo($wrap);
    117         $wrap.append($html);
    118         $wrap.after('<label class="cf7md-' + type + '-label" for="' + id + '">' + label + '</label>'); // Instantiate mdc checkbox js
    119         // We're not doing this right now because it's harder to customize colours for
    120         // and doesn't add all that much pizazz
    121         //mdc.checkbox.MDCCheckbox.attachTo(mdcCheckbox);
    122       });
    123     }); // === Prepare switches === //
    124 
    125     $('.cf7md-switch').each(function () {
    126       var $this = $(this),
    127           type = 'switch',
    128           $items = $this.find('.wpcf7-list-item'),
    129           tpl = $this.find('.cf7md-switch-html').html();
    130       $items.each(function () {
    131         var $item = $(this),
    132             $checkbox = $item.find('input'),
    133             $label = $item.find('.wpcf7-list-item-label'),
    134             $labelWrap = $label.parents('label'),
    135             label = $label.text(),
    136             $html = $(tpl).clone(),
    137             $switch_wrap = $html.find('.mdc-switch'),
    138             id = 'cf7md' + ++cf7mdId,
    139             $newlabel = $('<label for="' + id + '" class="cf7md-switch-label">' + label + '</label>'); // Add classes and ID
    140 
    141         $checkbox.addClass('mdc-' + type + '__native-control').attr('id', id);
    142         $item.addClass('cf7md-' + type + '-item cf'); // Rearrange markup
    143 
    144         $item.append($html);
    145         $checkbox.detach().prependTo($switch_wrap);
    146         $newlabel.appendTo($html);
    147         $label.remove();
    148       });
    149     }); // === Prepare acceptance === //
    150 
    151     $('.cf7md-accept').each(function () {
    152       var $this = $(this),
    153           $form = $this.closest('#cf7md-form'),
    154           $span = $this.find('.wpcf7-form-control-wrap'),
    155           $control = $span.find('.wpcf7-form-control'),
    156           $checkbox = $this.find('input'),
    157           $tpl = $this.find('.cf7md-checkbox-html').find('> div'),
    158           $mdWrap = $('<div class="cf7md-accept--inner"></div>'),
    159           $wrap = $('<div class="mdc-checkbox"></div>'),
    160           $label = $this.find('.cf7md-accept-label'),
    161           $cf7Label = $span.find('.wpcf7-list-item-label'),
    162           id = 'cf7md' + ++cf7mdId; // Use the cf7 label over the shortcode label if it exists
    163 
    164       if ($cf7Label.length && $cf7Label.html().length) {
    165         $label.html($cf7Label.html());
    166         $cf7Label.detach();
    167       } // Add class to md wrap
    168 
    169 
    170       $mdWrap.addClass('mdc-form-field'); // Update checkbox input
    171 
    172       $checkbox.addClass('mdc-checkbox__native-control').attr('id', id); // Insert tpl
    173 
    174       $span.append($mdWrap);
    175       $mdWrap.append($wrap); // Move checkbox into wrap
    176 
    177       $checkbox.detach().appendTo($wrap); // Move tpl into wrap
    178 
    179       $wrap.append($tpl); // Add `for` to label
    180 
    181       $label.attr('for', id); // Move label
    182 
    183       $label.detach().insertAfter($wrap); // Hide original control
    184 
    185       if ($this.hasClass('cf7md-is-wpcf7v5')) {
    186         $control.hide();
    187       } // Watch and toggle submit enabled/disabled
    188 
    189 
    190       $checkbox.click(function () {
    191         toggleSubmit($form);
    192       });
    193       toggleSubmit($form);
    194     }); // Acceptance toggle function
    195 
    196     function toggleSubmit($form) {
    197       // v5+ logic
    198       if ($form.find('.cf7md-accept').hasClass('cf7md-is-wpcf7v5')) {
    199         var $acceptances = $form.find('.wpcf7-acceptance'),
    200             $submit = $form.find('.cf7md-submit-btn'),
    201             $formTag = $form.closest('form.wpcf7-form'); // Straight outta wpcf7
    202 
    203         if ($formTag.hasClass('wpcf7-acceptance-as-validation')) {
    204           return;
    205         }
    206 
    207         $submit.removeAttr('disabled');
    208         $acceptances.each(function (i, span) {
    209           var $span = $(span),
    210               $input = $span.closest('.wpcf7-form-control-wrap').find('input'); // Straight outta wpcf7
    211 
    212           if (!$span.hasClass('optional')) {
    213             if ($span.hasClass('invert') && $input.is(':checked') || !$span.hasClass('invert') && !$input.is(':checked')) {
    214               $submit.attr('disabled', 'disabled');
    215               return false;
    216             }
    217           }
    218         });
    219       } else {
    220         // Pre wpcf7 v5 logic
    221         var $acceptances = $form.find('input:checkbox.wpcf7-acceptance'),
    222             $submit = $form.find('.cf7md-submit-btn'); // Logic taken from wpcf7
    223 
    224         $submit.removeAttr('disabled');
    225         $acceptances.each(function (i, node) {
    226           $this = $(node);
    227 
    228           if ($this.hasClass('wpcf7-invert') && $this.is(':checked') || !$this.hasClass('wpcf7-invert') && !$this.is(':checked')) {
    229             $submit.attr('disabled', 'disabled');
    230           }
    231         });
    232       }
    233     } // === File fields === //
    234 
    235 
    236     $('.cf7md-file').each(function () {
    237       var $this = $(this),
    238           $file = $this.find('[type="file"]'),
    239           $value = $this.find('.cf7md-file--value'),
    240           $btn = $this.find('.cf7md-file--btn'),
    241           $label = $this.find('.cf7md-label--static'),
    242           $wrap = $this.find('.cf7md-file--label'),
    243           $error = $this.find('.wpcf7-not-valid-tip'); // Move the error in the DOM
    244 
    245       $error.detach().insertAfter($wrap); // Position value
    246 
    247       $value.css({
    248         paddingLeft: $btn.outerWidth() + 12 + 'px',
    249         top: $btn.outerHeight() / 2 + 'px'
    250       }); // Update the value on load
    251 
    252       if ($file.val()) {
    253         fileName = $file.val().split('\\').pop();
    254         $value.text(fileName);
    255       } // Update the value on change
    256 
    257 
    258       $file.on('change', function (e) {
    259         if (e.target.value) {
    260           fileName = e.target.value.split('\\').pop();
    261           $value.text(fileName);
    262         }
    263       });
    264     }); // === Prepare quiz === //
    265     // TODO: Inputs are being duplicated every refresh
    266 
    267     function cf7mdQuiz(refresh) {
    268       $('.cf7md-quiz').each(function () {
    269         var $this = $(this),
    270             $input = $this.find('.wpcf7-quiz'),
    271             $newInput = $input.clone(),
    272             $span = $this.find('.wpcf7-form-control-wrap'),
    273             $tpl = $this.find('.mdc-textfield'),
    274             $label = $tpl.find('label'),
    275             $question = $this.find('.wpcf7-quiz-label'),
    276             $cf7label = $span.find('> label'); // Update label
    277 
    278         $label.attr('for', $input.attr('name'));
    279         $label.text($question.text());
    280         $question.hide(); // Move input and question
    281 
    282         $input.detach().prependTo($tpl);
    283         $question.detach().prependTo($tpl); // Insert template
    284 
    285         $tpl.detach().appendTo($span); // Add md class to input
    286 
    287         $input.addClass('mdc-textfield__input'); // Remove empty cf7 label
    288 
    289         $cf7label.hide();
    290       });
    291     }
    292 
    293     cf7mdQuiz(false); // Update the quiz label when the form refreshes
    294 
    295     $(window).on('wpcf7submit', function (e) {
    296       cf7mdQuiz(true);
    297     }); // === Prepare submit buttons for MD Init === //
    298 
    299     $('.cf7md-submit').each(function () {
    300       var $this = $(this),
    301           $form = $this.closest('#cf7md-form'),
    302           $inputs = $this.find('input, button');
    303       $inputs.each(function () {
    304         var $input = $(this),
    305             $val = $input.is('input') ? $input.attr('value') : $input.text(),
    306             $svg = $this.find('svg'),
    307             $btn = $('<button>' + $val + '</button>'); // Copy atts from input to button
    308 
    309         $btn.addClass($input[0].className);
    310         $btn.attr('id', $input.attr('id'));
    311         $btn.attr('type', $input.attr('type')); // @todo Copy events to button -> https://stackoverflow.com/a/16944385/1466282
    312         // Add data init for ripple
    313 
    314         $btn.attr('data-mdc-auto-init', 'MDCRipple'); // Add md classes
    315 
    316         $btn.addClass('cf7md-submit-btn mdc-button mdc-button--raised mdc-button--primary mdc-ripple-surface'); // Replace input with button
    317 
    318         $input.replaceWith($btn);
    319 
    320         if ($input.attr('type') === 'submit') {
    321           // maybe disable
    322           toggleSubmit($form); // Add click handler to button
    323 
    324           $btn.click(function () {
    325             // Move svg into spinner
    326             var $spinner = $(this).parents('.cf7md-submit').find('.ajax-loader');
    327             $svg.detach().appendTo($spinner);
    328           });
    329         }
    330       });
    331     }); // === Update textfields that loaded with a default value === //
    332 
    333     setTimeout(function () {
    334       $('.mdc-textfield').each(function () {
    335         var $label = $(this).find('.mdc-textfield__label'),
    336             $field = $(this).find('.mdc-textfield__input'),
    337             val = $field.val();
    338 
    339         if (val) {
    340           $label.addClass('mdc-textfield__label--float-above');
    341         }
    342       });
    343     }, 200); // === Mutation observer for things like conditional fields for CF7 === //
    344     // Run this when a field group is toggled
    345 
    346     function conditionalFieldGroupToggled(event) {
    347       // Update file inputs
    348       $('.cf7md-file').each(function () {
    349         var $this = $(this),
    350             $file = $this.find('[type="file"]'),
    351             $value = $this.find('.cf7md-file--value'),
    352             $btn = $this.find('.cf7md-file--btn'); // Position value
    353 
    354         $value.css({
    355           paddingLeft: $btn.outerWidth() + 12 + 'px',
    356           top: $btn.outerHeight() / 2 + 'px'
    357         });
    358       });
    359     } // Feature detection for mutation observers - https://gist.github.com/stucox/5231211
    360 
    361 
    362     var MutationObserver = function () {
    363       var prefixes = ['WebKit', 'Moz', 'O', 'Ms', ''];
    364 
    365       for (var i = 0; i < prefixes.length; i++) {
    366         if (prefixes[i] + 'MutationObserver' in window) {
    367           return window[prefixes[i] + 'MutationObserver'];
    368         }
    369       }
    370 
    371       return false;
    372     }(); // Setup mutation observers
    373 
    374 
    375     if (MutationObserver) {
    376       var groups = $('[data-class="wpcf7cf_group"]');
    377       groups.each(function (i, element) {
    378         var observer = new MutationObserver(conditionalFieldGroupToggled);
    379         observer.observe(element, {
    380           attributes: true,
    381           attributeFilter: ['class'],
    382           childList: false,
    383           characterData: false
    384         });
    385       });
    386     } // Handle hiding the customize preview link
    387 
    388 
    389     if (typeof ajax_object !== 'undefined') {
    390       $('.cf7md-hide-customize-message').click(function (e) {
    391         e.preventDefault();
    392         $(this).closest('.cf7md-admin-customize-message').hide();
    393         $.post(ajax_object.ajax_url, {
    394           action: 'cf7md_close_customize_link'
    395         }, function (response) {
    396           console.log('Close link response: ', response);
    397         });
    398       });
    399     } // === Initialize components === //
    400 
    401 
    402     window.mdc.autoInit();
    403   });
     8    // Do stuff
     9    $(document).ready(function () {
     10        // === Running ID === //
     11        window.cf7mdId = 0; // === Form formatting === //
     12
     13        $(".cf7md-form").each(function () {
     14            var $this = $(this); // Remove empty p tags inside, before and after
     15
     16            $this
     17                .siblings("p")
     18                .add($this.find("p"))
     19                .filter(function () {
     20                    return this.innerHTML.trim() === "";
     21                })
     22                .remove(); // Add `required` attribute to all required fields
     23
     24            $(".cf7md-text, .cf7md-textarea")
     25                .find(".wpcf7-validates-as-required")
     26                .each(function () {
     27                    $(this).attr("required", "required");
     28                });
     29        }); // === Generic item formatting === //
     30
     31        $(".cf7md-item").each(function () {
     32            var $this = $(this),
     33                $span = $this.find(".wpcf7-form-control-wrap"); // Remove breaks
     34
     35            $this.find("br").remove(); // Add md class to span
     36
     37            $span.addClass("mdc-form-field cf");
     38        }); // === Prepare text inputs and textareas for MD Init === //
     39
     40        $(".cf7md-text, .cf7md-textarea").each(function () {
     41            var $this = $(this),
     42                $input = $this.find("input, textarea"),
     43                $span = $this.find(".wpcf7-form-control-wrap"),
     44                $tpl = $this.find(".cf7md-text-html").find("> div"),
     45                $label = $tpl.find("label"); // Move input
     46
     47            $input.detach().prependTo($tpl); // Insert template
     48
     49            $tpl.detach().appendTo($span); // Add md class to input
     50
     51            $input.addClass("mdc-textfield__input"); // Add 'for' to label
     52
     53            $label.attr("for", $input.attr("name")); // Add autosize to textareas
     54
     55            if ($this.hasClass("cf7md-textarea-autosize")) {
     56                $input.attr("rows", "2");
     57                autosize($input);
     58            }
     59
     60            var textField = new _textfield.MDCTextField(this);
     61        }); // === Make html5 date inputs play nice with our text fields === //
     62
     63        $('.cf7md-text [type="date"]').each(function () {
     64            var $this = $(this);
     65            $this.change(function () {
     66                if ($this.val() !== "") {
     67                    $this.addClass("cf7md-has-input");
     68                } else {
     69                    $this.removeClass("cf7md-has-input");
     70                }
     71            });
     72        }); // === Prepare selects === //
     73
     74        $(".cf7md-select").each(function () {
     75            var $this = $(this),
     76                $select = $this.find("select"),
     77                label = $this.find(".cf7md-select-label").text(),
     78                $option1 = $select.children("option").first();
     79
     80            if ($select.hasClass("wpcf7-validates-as-required")) {
     81                label += "*";
     82            }
     83
     84            if ($this.hasClass("cf7md-select--multi")) {
     85                // Add class and size for multi
     86                $select.addClass("mdc-multi-select mdc-list");
     87                $select.attr("size", "5");
     88            } else {
     89                // Add class for standard select
     90                $select.addClass("mdc-select"); // Add blank option as label
     91
     92                if ($option1.attr("value") === "") {
     93                    $option1.text(label);
     94                } else {
     95                    $option1.before(
     96                        '<option default selected value="">' + label + "</option>"
     97                    );
     98                }
     99            }
     100        }); // === Prepare checkboxes === //
     101
     102        $(".cf7md-checkbox, .cf7md-radio").each(function () {
     103            var $this = $(this),
     104                type = $this.hasClass("cf7md-radio") ? "radio" : "checkbox",
     105                $items = $this.find(".wpcf7-list-item"),
     106                tpl = $this.find(".cf7md-" + type + "-html").html();
     107            $items.each(function () {
     108                var $item = $(this),
     109                    $checkbox = $item.find("input"),
     110                    $label = $item.find(".wpcf7-list-item-label"),
     111                    $labelWrap = $label.parents("label"),
     112                    label = $label.text(),
     113                    $html = $(tpl).clone(),
     114                    $wrap = $('<div class="mdc-' + type + '"></div>'),
     115                    mdcCheckbox = $wrap[0],
     116                    id = "cf7md" + ++cf7mdId; // Add classes and ID
     117
     118                $checkbox.addClass("mdc-" + type + "__native-control").attr("id", id);
     119                $item.addClass("cf7md-" + type + "-item mdc-form-field cf"); // Rearrange markup
     120
     121                $item.append($wrap);
     122                $label.remove();
     123                $labelWrap.remove();
     124                $checkbox.detach().appendTo($wrap);
     125                $wrap.append($html);
     126                $wrap.after(
     127                    '<label class="cf7md-' +
     128                        type +
     129                        '-label" for="' +
     130                        id +
     131                        '">' +
     132                        label +
     133                        "</label>"
     134                ); // Instantiate mdc checkbox js
     135                // We're not doing this right now because it's harder to customize colours for
     136                // and doesn't add all that much pizazz
     137                //mdc.checkbox.MDCCheckbox.attachTo(mdcCheckbox);
     138            });
     139        }); // === Prepare switches === //
     140
     141        $(".cf7md-switch").each(function () {
     142            var $this = $(this),
     143                type = "switch",
     144                $items = $this.find(".wpcf7-list-item"),
     145                tpl = $this.find(".cf7md-switch-html").html();
     146            $items.each(function () {
     147                var $item = $(this),
     148                    $checkbox = $item.find("input"),
     149                    $label = $item.find(".wpcf7-list-item-label"),
     150                    $labelWrap = $label.parents("label"),
     151                    label = $label.text(),
     152                    $html = $(tpl).clone(),
     153                    $switch_wrap = $html.find(".mdc-switch"),
     154                    id = "cf7md" + ++cf7mdId,
     155                    $newlabel = $(
     156                        '<label for="' +
     157                            id +
     158                            '" class="cf7md-switch-label">' +
     159                            label +
     160                            "</label>"
     161                    ); // Add classes and ID
     162
     163                $checkbox.addClass("mdc-" + type + "__native-control").attr("id", id);
     164                $item.addClass("cf7md-" + type + "-item cf"); // Rearrange markup
     165
     166                $item.append($html);
     167                $checkbox.detach().prependTo($switch_wrap);
     168                $newlabel.appendTo($html);
     169                $label.remove();
     170            });
     171        }); // === Prepare acceptance === //
     172
     173        $(".cf7md-accept").each(function () {
     174            var $this = $(this),
     175                $form = $this.closest("#cf7md-form"),
     176                $span = $this.find(".wpcf7-form-control-wrap"),
     177                $control = $span.find(".wpcf7-form-control"),
     178                $checkbox = $this.find("input"),
     179                $tpl = $this.find(".cf7md-checkbox-html").find("> div"),
     180                $mdWrap = $('<div class="cf7md-accept--inner"></div>'),
     181                $wrap = $('<div class="mdc-checkbox"></div>'),
     182                $label = $this.find(".cf7md-accept-label"),
     183                $cf7Label = $span.find(".wpcf7-list-item-label"),
     184                id = "cf7md" + ++cf7mdId; // Use the cf7 label over the shortcode label if it exists
     185
     186            if ($cf7Label.length && $cf7Label.html().length) {
     187                $label.html($cf7Label.html());
     188                $cf7Label.detach();
     189            } // Add class to md wrap
     190
     191            $mdWrap.addClass("mdc-form-field"); // Update checkbox input
     192
     193            $checkbox.addClass("mdc-checkbox__native-control").attr("id", id); // Insert tpl
     194
     195            $span.append($mdWrap);
     196            $mdWrap.append($wrap); // Move checkbox into wrap
     197
     198            $checkbox.detach().appendTo($wrap); // Move tpl into wrap
     199
     200            $wrap.append($tpl); // Add `for` to label
     201
     202            $label.attr("for", id); // Move label
     203
     204            $label.detach().insertAfter($wrap); // Hide original control
     205
     206            if ($this.hasClass("cf7md-is-wpcf7v5")) {
     207                $control.hide();
     208            } // Watch and toggle submit enabled/disabled
     209
     210            $checkbox.on("click", function () {
     211                toggleSubmit($form);
     212            });
     213            toggleSubmit($form);
     214        }); // Acceptance toggle function
     215
     216        function toggleSubmit($form) {
     217            // v5+ logic
     218            if ($form.find(".cf7md-accept").hasClass("cf7md-is-wpcf7v5")) {
     219                var $acceptances = $form.find(".wpcf7-acceptance"),
     220                    $submit = $form.find(".cf7md-submit-btn"),
     221                    $formTag = $form.closest("form.wpcf7-form"); // Straight outta wpcf7
     222
     223                if ($formTag.hasClass("wpcf7-acceptance-as-validation")) {
     224                    return;
     225                }
     226
     227                $submit.prop("disabled", false);
     228                $acceptances.each(function (i, span) {
     229                    var $span = $(span),
     230                        $input = $span.closest(".wpcf7-form-control-wrap").find("input"); // Straight outta wpcf7
     231
     232                    if (!$span.hasClass("optional")) {
     233                        if (
     234                            ($span.hasClass("invert") && $input.is(":checked")) ||
     235                            (!$span.hasClass("invert") && !$input.is(":checked"))
     236                        ) {
     237                            $submit.attr("disabled", "disabled");
     238                            return false;
     239                        }
     240                    }
     241                });
     242            } else {
     243                // Pre wpcf7 v5 logic
     244                var $acceptances = $form.find("input:checkbox.wpcf7-acceptance"),
     245                    $submit = $form.find(".cf7md-submit-btn"); // Logic taken from wpcf7
     246
     247                $submit.prop("disabled", false);
     248                $acceptances.each(function (i, node) {
     249                    $this = $(node);
     250
     251                    if (
     252                        ($this.hasClass("wpcf7-invert") && $this.is(":checked")) ||
     253                        (!$this.hasClass("wpcf7-invert") && !$this.is(":checked"))
     254                    ) {
     255                        $submit.attr("disabled", "disabled");
     256                    }
     257                });
     258            }
     259        } // === File fields === //
     260
     261        $(".cf7md-file").each(function () {
     262            var $this = $(this),
     263                $file = $this.find('[type="file"]'),
     264                $value = $this.find(".cf7md-file--value"),
     265                $btn = $this.find(".cf7md-file--btn"),
     266                $label = $this.find(".cf7md-label--static"),
     267                $wrap = $this.find(".cf7md-file--label"),
     268                $error = $this.find(".wpcf7-not-valid-tip"); // Move the error in the DOM
     269
     270            $error.detach().insertAfter($wrap); // Position value
     271
     272            $value.css({
     273                paddingLeft: $btn.outerWidth() + 12 + "px",
     274                top: $btn.outerHeight() / 2 + "px",
     275            }); // Update the value on load
     276
     277            if ($file.val()) {
     278                fileName = $file.val().split("\\").pop();
     279                $value.text(fileName);
     280            } // Update the value on change
     281
     282            $file.on("change", function (e) {
     283                if (e.target.value) {
     284                    fileName = e.target.value.split("\\").pop();
     285                    $value.text(fileName);
     286                }
     287            });
     288        }); // === Prepare quiz === //
     289        // TODO: Inputs are being duplicated every refresh
     290
     291        function cf7mdQuiz(refresh) {
     292            $(".cf7md-quiz").each(function () {
     293                var $this = $(this),
     294                    $input = $this.find(".wpcf7-quiz"),
     295                    $newInput = $input.clone(),
     296                    $span = $this.find(".wpcf7-form-control-wrap"),
     297                    $tpl = $this.find(".mdc-textfield"),
     298                    $label = $tpl.find("label"),
     299                    $question = $this.find(".wpcf7-quiz-label"),
     300                    $cf7label = $span.find("> label"); // Update label
     301
     302                $label.attr("for", $input.attr("name"));
     303                $label.text($question.text());
     304                $question.hide(); // Move input and question
     305
     306                $input.detach().prependTo($tpl);
     307                $question.detach().prependTo($tpl); // Insert template
     308
     309                $tpl.detach().appendTo($span); // Add md class to input
     310
     311                $input.addClass("mdc-textfield__input"); // Remove empty cf7 label
     312
     313                $cf7label.hide();
     314            });
     315        }
     316
     317        cf7mdQuiz(false); // Update the quiz label when the form refreshes
     318
     319        $(window).on("wpcf7submit", function (e) {
     320            cf7mdQuiz(true);
     321        }); // === Prepare submit buttons for MD Init === //
     322
     323        $(".cf7md-submit").each(function () {
     324            var $this = $(this),
     325                $form = $this.closest("#cf7md-form"),
     326                $inputs = $this.find("input, button");
     327            $inputs.each(function () {
     328                var $input = $(this),
     329                    $val = $input.is("input") ? $input.attr("value") : $input.text(),
     330                    $svg = $this.find("svg"),
     331                    $btn = $("<button>" + $val + "</button>"); // Copy atts from input to button
     332
     333                $btn.addClass($input[0].className);
     334                $btn.attr("id", $input.attr("id"));
     335                $btn.attr("type", $input.attr("type")); // @todo Copy events to button -> https://stackoverflow.com/a/16944385/1466282
     336                // Add data init for ripple
     337
     338                $btn.attr("data-mdc-auto-init", "MDCRipple"); // Add md classes
     339
     340                $btn.addClass(
     341                    "cf7md-submit-btn mdc-button mdc-button--raised mdc-button--primary mdc-ripple-surface"
     342                ); // Replace input with button
     343
     344                $input.replaceWith($btn);
     345
     346                if ($input.attr("type") === "submit") {
     347                    // maybe disable
     348                    toggleSubmit($form); // Add click handler to button
     349
     350                    $btn.on("click", function () {
     351                        // Move svg into spinner
     352                        var $spinner = $(this)
     353                            .parents(".cf7md-submit")
     354                            .find(".ajax-loader");
     355                        $svg.detach().appendTo($spinner);
     356                    });
     357                }
     358            });
     359        }); // === Update textfields that loaded with a default value === //
     360
     361        setTimeout(function () {
     362            $(".mdc-textfield").each(function () {
     363                var $label = $(this).find(".mdc-textfield__label"),
     364                    $field = $(this).find(".mdc-textfield__input"),
     365                    val = $field.val();
     366
     367                if (val) {
     368                    $label.addClass("mdc-textfield__label--float-above");
     369                }
     370            });
     371        }, 200); // === Mutation observer for things like conditional fields for CF7 === //
     372        // Run this when a field group is toggled
     373
     374        function conditionalFieldGroupToggled(event) {
     375            // Update file inputs
     376            $(".cf7md-file").each(function () {
     377                var $this = $(this),
     378                    $file = $this.find('[type="file"]'),
     379                    $value = $this.find(".cf7md-file--value"),
     380                    $btn = $this.find(".cf7md-file--btn"); // Position value
     381
     382                $value.css({
     383                    paddingLeft: $btn.outerWidth() + 12 + "px",
     384                    top: $btn.outerHeight() / 2 + "px",
     385                });
     386            });
     387        } // Feature detection for mutation observers - https://gist.github.com/stucox/5231211
     388
     389        var MutationObserver = (function () {
     390            var prefixes = ["WebKit", "Moz", "O", "Ms", ""];
     391
     392            for (var i = 0; i < prefixes.length; i++) {
     393                if (prefixes[i] + "MutationObserver" in window) {
     394                    return window[prefixes[i] + "MutationObserver"];
     395                }
     396            }
     397
     398            return false;
     399        })(); // Setup mutation observers
     400
     401        if (MutationObserver) {
     402            var groups = $('[data-class="wpcf7cf_group"]');
     403            groups.each(function (i, element) {
     404                var observer = new MutationObserver(conditionalFieldGroupToggled);
     405                observer.observe(element, {
     406                    attributes: true,
     407                    attributeFilter: ["class"],
     408                    childList: false,
     409                    characterData: false,
     410                });
     411            });
     412        } // Handle hiding the customize preview link
     413
     414        if (typeof ajax_object !== "undefined") {
     415            $(".cf7md-hide-customize-message").on("click", function (e) {
     416                e.preventDefault();
     417                $(this).closest(".cf7md-admin-customize-message").hide();
     418                $.post(
     419                    ajax_object.ajax_url,
     420                    {
     421                        action: "cf7md_close_customize_link",
     422                    },
     423                    function (response) {
     424                        console.log("Close link response: ", response);
     425                    }
     426                );
     427            });
     428        } // === Initialize components === //
     429
     430        window.mdc.autoInit();
     431    });
    404432})(jQuery);
  • material-design-for-contact-form-7/trunk/cf7-material-design.php

    r2417854 r2457979  
    1111 * Plugin URI:        https://cf7materialdesign.com
    1212 * Description:       Add Google's Material Design to your Contact Form 7 forms
    13  * Version:           2.6.3
     13 * Version:           2.6.4
    1414 * Author:            Addons for Contact Form 7
    1515 * Author URI:        https://profiles.wordpress.org/contactform7addons/
     
    3333         * Set constants
    3434         */
    35         define( 'CF7MD_VER', '2.6.3' );
     35        define( 'CF7MD_VER', '2.6.4' );
    3636        define( 'CF7MD_UPDATE_MESSAGE', '1' );
    3737        // Increment this every time a release is made that has a 'new features' message on the plugin page
  • material-design-for-contact-form-7/trunk/languages/POT.pot

    r2417854 r2457979  
    1 # Copyright (C) 2020 Material Design for Contact Form 7
     1# Copyright (C) 2021 Material Design for Contact Form 7
    22# This file is distributed under the same license as the Material Design for Contact Form 7 package.
    33msgid ""
Note: See TracChangeset for help on using the changeset viewer.