PageSourceSearch

https://www.roofpedia.com/wp-content/plugins/wp-user-frontend/assets/js/frontend-form.js?ver=7.0.5

js roofpedia.com collected 2026-10-02 18:29:27 UTC 26,991 bytes, 688 lines download raw bytes

1;(function($) {
2
3    $.fn.listautowidth = function() {
4        return this.each(function() {
5            var w = $(this).width();
6            var liw = w / $(this).children('li').length;
7            $(this).children('li').each(function(){
8                var s = $(this).outerWidth(true)-$(this).width();
9                $(this).width(liw-s);
10            });
11        });
12    };
13
14    var WP_User_Frontend = {
15        init: function() {
16
17            //enable multistep
18            this.enableMultistep(this);
19
20            // clone and remove repeated field
21            $('.wpuf-form').on('click', 'img.wpuf-clone-field', this.cloneField);
22            $('.wpuf-form').on('click', 'img.wpuf-remove-field', this.removeField);
23            $('.wpuf-form').on('click', 'a.wpuf-delete-avatar', this.deleteAvatar);
24            $('.wpuf-form').on('click', 'a#wpuf-post-draft', this.draftPost);
25
26            $('.wpuf-form-add').on('submit', this.formSubmit);
27            $('form#post').on('submit', this.adminPostSubmit);
28            $( '.wpuf-form').on('keyup', '#pass1', this.check_pass_strength );
29
30            this.ajaxCategory();
31            // image insert
32            // this.insertImage();
33
34            //comfirmation alert for canceling subscription
35            $( ':submit[name="wpuf_cancel_subscription"]').click(function(){
36                if ( !confirm( 'Are you sure you want to cancel your current subscription ?' ) ) {
37                    return false;
38                }
39
40            });
41        },
42
43        check_pass_strength : function() {
44            var pass1 = $('#pass1').val(), strength;
45
46            $('#pass-strength-result').removeClass('short bad good strong');
47            if ( ! pass1 ) {
48                $('#pass-strength-result').html( ' ' );
49                return;
50            }
51
52            strength = wp.passwordStrength.meter( pass1, wp.passwordStrength.userInputBlacklist(), pass1 );
53
54            switch ( strength ) {
55                case 2:
56                    $('#pass-strength-result').addClass('bad').html( pwsL10n.bad );
57                    break;
58                case 3:
59                    $('#pass-strength-result').addClass('good').html( pwsL10n.good );
60                    break;
61                case 4:
62                    $('#pass-strength-result').addClass('strong').html( pwsL10n.strong );
63                    break;
64                case 5:
65                    $('#pass-strength-result').addClass('short').html( pwsL10n.mismatch );
66                    break;
67                default:
68                    $('#pass-strength-result').addClass('short').html( pwsL10n['short'] );
69            }
70
71        },
72
73        enableMultistep: function(o) {
74
75            var js_obj = this;
76            var step_number = 0;
77            var progressbar_type = $(':hidden[name="wpuf_multistep_type"]').val();
78
79            if ( progressbar_type == null ) {
80                return;
81            }
82
83            // first fieldset doesn't have prev button,
84            // last fieldset doesn't have next button
85            $('fieldset:first .wpuf-multistep-prev-btn').remove();
86            $('fieldset:last .wpuf-multistep-next-btn').remove();
87
88            // at first first fieldset will be shown, and others will be hidden
89            $('.wpuf-form fieldset').hide().first().show();
90
91            if ( progressbar_type == 'progressive' && $('.wpuf-form .wpuf-multistep-fieldset').length != 0 ) {
92
93                var firstLegend = $('fieldset.wpuf-multistep-fieldset legend').first();
94                $('.wpuf-multistep-progressbar').html('<div class="wpuf-progress-percentage"></div>' );
95
96                var progressbar = $( ".wpuf-multistep-progressbar" ),
97                    progressLabel = $( ".wpuf-progress-percentage" );
98
99                $( ".wpuf-multistep-progressbar" ).progressbar({
100                    change: function() {
101                        progressLabel.text( progressbar.progressbar( "value" ) + "%" );
102                    }
103                });
104
105                $('.wpuf-multistep-fieldset legend').hide();
106
107            } else {
108                $('.wpuf-form').each(function() {
109                    var this_obj = $(this);
110                    var progressbar = $('.wpuf-multistep-progressbar', this_obj);
111                    var nav = '';
112
113                    progressbar.addClass('wizard-steps');
114                    nav += '<ul class="wpuf-step-wizard">';
115
116                    $('.wpuf-multistep-fieldset', this).each(function(){
117                        nav += '<li>' + $.trim( $('legend', this).text() ) + '</li>';
118                        $('legend', this).hide();
119                    });
120
121                    nav += '</ul>';
122                    progressbar.append( nav );
123
124                    $('.wpuf-step-wizard li', progressbar).first().addClass('active-step');
125                    $('.wpuf-step-wizard', progressbar).listautowidth();
126                });
127            }
128
129            this.change_fieldset(step_number, progressbar_type);
130
131            $('fieldset .wpuf-multistep-prev-btn, fieldset .wpuf-multistep-next-btn').click(function(e) {
132
133                // js_obj.formSubmit();
134                if ( $(this).hasClass('wpuf-multistep-next-btn') ) {
135                    var result = js_obj.formStepCheck( '', $(this).parent() );
136
137                    if ( result != false ) {
138                        o.change_fieldset(++step_number,progressbar_type);
139                    }
140
141                } else if ( $(this).hasClass('wpuf-multistep-prev-btn') ) {
142                    o.change_fieldset( --step_number,progressbar_type );
143                }
144
145                return false;
146            });
147        },
148
149        change_fieldset: function(step_number, progressbar_type) {
150            $('fieldset').hide().eq(step_number).show();
151
152            $('.wpuf-step-wizard li').each(function(){
153                if ( $(this).index() <= step_number ){
154                    progressbar_type == 'step_by_step'? $(this).addClass('passed-wpuf-ms-bar') : $('.wpuf-ps-bar',this).addClass('passed-wpuf-ms-bar');
155                } else {
156                    progressbar_type == 'step_by_step'? $(this).removeClass('passed-wpuf-ms-bar') : $('.wpuf-ps-bar',this).removeClass('passed-wpuf-ms-bar');
157                }
158            });
159
160            $('.wpuf-step-wizard li').removeClass('wpuf-ms-bar-active active-step completed-step');
161            $('.passed-wpuf-ms-bar').addClass('completed-step').last().addClass('wpuf-ms-bar-active');
162            $('.wpuf-ms-bar-active').addClass('active-step');
163
164            var legend = $('fieldset.wpuf-multistep-fieldset').eq(step_number).find('legend').text();
165                legend = $.trim( legend );
166
167            if ( progressbar_type == 'progressive' && $('.wpuf-form .wpuf-multistep-fieldset').length != 0 ) {
168                var progress_percent = ( step_number + 1 ) * 100 / $('fieldset.wpuf-multistep-fieldset').length ;
169                var progress_percent = Number( progress_percent.toFixed(2) );
170                $( ".wpuf-multistep-progressbar" ).progressbar({value: progress_percent });
171                $( '.wpuf-progress-percentage' ).text( legend + ' 
171(' + progress_percent + '%)');
172            }
173        },
174
175        ajaxCategory: function () {
176
177            var el = '.cat-ajax',
178                wrap = '.category-wrap';
179
180            $(wrap).on('change', el, function(){
181                currentLevel = parseInt( $(this).parent().attr('level') );
182                WP_User_Frontend.getChildCats( $(this), 'lvl', currentLevel+1, wrap, 'category');
183            });
184        },
185
186        getChildCats: function (dropdown, result_div, level, wrap_div, taxonomy) {
187
188            cat = $(dropdown).val();
189            results_div = result_div + level;
190            taxonomy = typeof taxonomy !== 'undefined' ? taxonomy : 'category';
191            field_attr = $(dropdown).siblings('span').data('taxonomy');
192
193            $.ajax({
194                type: 'post',
195                url: wpuf_frontend.ajaxurl,
196                data: {
197                    action: 'wpuf_get_child_cat',
198                    catID: cat,
199                    nonce: wpuf_frontend.nonce,
200                    field_attr: field_attr
201                },
202                beforeSend: function() {
203                    $(dropdown).parent().parent().next('.loading').addClass('wpuf-loading');
204                },
205                complete: function() {
206                    $(dropdown).parent().parent().next('.loading').removeClass('wpuf-loading');
207                },
208                success: function(html) {
209                    //console.log( html ); return;
210                    $(dropdown).parent().nextAll().each(function(){
211                        $(this).remove();
212                    });
213
214                    if(html != "") {
215                        $(dropdown).parent().addClass('hasChild').parent().append('<div id="'+result_div+level+'" level="'+level+'"></div>');
216                        dropdown.parent().parent().find('#'+results_div).html(html).slideDown('fast');
217                    }
218                }
219            });
220        },
221
222        cloneField: function(e) {
223            e.preventDefault();
224
225            var $div = $(this).closest('tr');
226            var $clone = $div.clone();
227            // console.log($clone);
228
229            //clear the inputs
230            $clone.find('input').val('');
231            $clone.find(':checked').attr('checked', '');
232            $div.after($clone);
233        },
234
235        removeField: function() {
236            //check if it's the only item
237            var $parent = $(this).closest('tr');
238            var items = $parent.siblings().andSelf().length;
239
240            if( items > 1 ) {
241                $parent.remove();
242            }
243        },
244
245        adminPostSubmit: function(e) {
246            e.preventDefault();
247
248            var form = $(this),
249                form_data = WP_User_Frontend.validateForm(form);
250
251            if (form_data) {
252                return true;
253            }
254        },
255
256        draftPost: function (e) {
257            e.preventDefault();
258
259            var self = $(this),
260                form = $(this).closest('form'),
261                form_data = form.serialize() + '&action=wpuf_draft_post',
262                post_id = form.find('input[type="hidden"][name="post_id"]').val();
263
264            var rich_texts = [],
265                temp, val;
266
267            // grab rich texts from tinyMCE
268            $('.wpuf-rich-validation').each(function (index, item) {
269                temp = $(item).data('id');
270                val = $.trim( tinyMCE.get(temp).getContent() );
271
272                rich_texts.push(temp + '=' + encodeURIComponent( val ) );
273            });
274
275            // append them to the form var
276            form_data = form_data + '&' + rich_texts.join('&');
277
278
279            self.after(' <span class="wpuf-loading"></span>');
280            $.post(wpuf_frontend.ajaxurl, form_data, function(res) {
281                // console.log(res, post_id);
282                if ( typeof post_id === 'undefined') {
283                    var html = '<input type="hidden" name="post_id" value="' + res.post_id +'">';
284                        html += '<input type="hidden" name="post_date" value="' + res.date +'">';
285                        html += '<input type="hidden" name="post_author" value="' + res.post_author +'">';
286                        html += '<input type="hidden" name="comment_status" value="' + res.comment_status +'">';
287
288                    form.append( html );
289                }
290
291                self.next('span.wpuf-loading').remove();
292
293                self.after('<span class="wpuf-draft-saved">&nbsp; Post Saved</span>');
294                $('.wpuf-draft-saved').delay(2500).fadeOut('fast', function(){
295                    $(this).remove();
296                });
297            })
298        },
299
300        formStepCheck : function(e,fieldset) {
301            var form = fieldset,
302                submitButton = form.find('input[type=submit]');
303                form_data = WP_User_Frontend.validateForm(form);
304                if( form_data == false ) {
305                    WP_User_Frontend.addErrorNotice( self, 'bottom' );
306                }
307                return form_data;
308        },
309
310        formSubmit: function(e) {
311            e.preventDefault();
312
313            var form = $(this),
314                submitButton = form.find('input[type=submit]')
315                form_data = WP_User_Frontend.validateForm(form);
316
317            if (form_data) {
318
319                // send the request
320                form.find('li.wpuf-submit').append('<span class="wpuf-loading"></span>');
321                submitButton.attr('disabled', 'disabled').addClass('button-primary-disabled');
322
323                $.post(wpuf_frontend.ajaxurl, form_data, function(res) {
324                    // var res = $.parseJSON(res);
325
326                    if ( res.success) {
327
328                        // enable external plugins to use events
329                        $('body').trigger('wpuf:postform:success', res);
330
331                        if( res.show_message == true) {
332                            form.before( '<div class="wpuf-success">' + res.message + '</div>');
333                            form.slideUp( 'fast', function() {
334                                form.remove();
335                            });
336
337                            //focus
338                            $('html, body').animate({
339                                scrollTop: $('.wpuf-success').offset().top - 100
340                            }, 'fast');
341
342                        } else {
343                            window.location = res.redirect_to;
344                        }
345
346                    } else {
347
348                        if ( typeof res.type !== 'undefined' && res.type === 'login' ) {
349
350                            if ( confirm(res.error) ) {
351                                window.location = res.redirect_to;
352                            } else {
353                                submitButton.removeAttr('disabled');
354                                submitButton.removeClass('button-primary-disabled');
355                                form.find('span.wpuf-loading').remove();
356                            }
357
358                            return;
359                        } else {
360                            alert( res.error );
361                        }
362
363                        submitButton.removeAttr('disabled');
364                    }
365
366                    submitButton.removeClass('button-primary-disabled');
367                    form.find('span.wpuf-loading').remove();
368                });
369            }
370        },
371
372        validateForm: function( self ) {
373
374            var temp,
375                temp_val = '',
376                error = false,
377                error_items = [];
378
379            // remove all initial errors if any
380            WP_User_Frontend.removeErrors(self);
381            WP_User_Frontend.removeErrorNotice(self);
382
383            // ===== Validate: Text and Textarea ========
384            var required = self.find('[data-required="yes"]:visible');
385
386            required.each(function(i, item) {
387                // temp_val = $.trim($(item).val());
388
389                // console.log( $(item).data('type') );
390                var data_type = $(item).data('type')
391                    val = '';
392
393                switch(data_type) {
394                    case 'rich':
395                        var name = $(item).data('id')
396                        val = $.trim( tinyMCE.get(name).getContent() );
397
398                        if ( val === '') {
399                            error = true;
400
401                            // make it warn collor
402                            WP_User_Frontend.markError(item);
403                        }
404                        break;
405
406                    case 'textarea':
407                    case 'text':
408                        val = $.trim( $(item).val() );
409
410                        if ( val === '') {
411                            error = true;
412
413                            // make it warn collor
414                            WP_User_Frontend.markError(item);
415                        }
416                        break;
417
418                    case 'select':
419                        val = $(item).val();
420
421                        // console.log(val);
422                        if ( !val || val === '-1' ) {
423                            error = true;
424
425                            // make it warn collor
426                            WP_User_Frontend.markError(item);
427                        }
428                        break;
429
430                    case 'multiselect':
431                        val = $(item).val();
432
433                        if ( val === null || val.length === 0 ) {
434                            error = true;
435
436                            // make it warn collor
437                            WP_User_Frontend.markError(item);
438                        }
439                        break;
440
441                    case 'tax-checkbox':
442                        var length = $(item).children().find('input
442:checked').length;
443
444                        if ( !length ) {
445                            error = true;
446
447                            // make it warn collor
448                            WP_User_Frontend.markError(item);
449                        }
450                        break;
451
452                    case 'radio':
453                        var length = $(item).find('input:checked').length;
454
455                        if ( !length ) {
456                            error = true;
457
458                            // make it warn collor
459                            WP_User_Frontend.markError(item);
460                        }
461                        break;
462
463                    case 'file':
464                        var length = $(item).find('ul').children().length;
465
466                        if ( !length ) {
467                            error = true;
468
469                            // make it warn collor
470                            WP_User_Frontend.markError(item);
471                        }
472                        break;
473
474                    case 'email':
475                        var val = $(item).val();
476
477                        if ( val !== '' ) {
478                            //run the validation
479                            if( !WP_User_Frontend.isValidEmail( val ) ) {
480                                error = true;
481
482                                WP_User_Frontend.markError(item);
483                            }
484                        } else if( val === '' ) {
485                            WP_User_Frontend.markError(item);
486                        }
487                        break;
488
489
490                    case 'url':
491                        var val = $(item).val();
492
493                        if ( val !== '' ) {
494                            //run the validation
495                            if( !WP_User_Frontend.isValidURL( val ) ) {
496                                error = true;
497
498                                WP_User_Frontend.markError(item);
499                            }
500                        }
501                        break;
502
503                };
504
505            });
506
507            // if already some error found, bail out
508            if (error) {
509                // add error notice
510                WP_User_Frontend.addErrorNotice(self,'end');
511
512                return false;
513            }
514
515            var form_data = self.serialize(),
516                rich_texts = [];
517
518            // grab rich texts from tinyMCE
519            $('.wpuf-rich-validation').each(function (index, item) {
520                temp = $(item).data('id');
521                val = $.trim( tinyMCE.get(temp).getContent() );
522
523                rich_texts.push(temp + '=' + encodeURIComponent( val ) );
524            });
525
526            // append them to the form var
527            form_data = form_data + '&' + rich_texts.join('&');
528            return form_data;
529        },
530
531        /**
532         *
533         * @param form
534         * @param position (value = bottom or end) end if form is onepare, bottom, if form is multistep
535         */
536        addErrorNotice: function( form, position ) {
537            if( position == 'bottom' ) {
538                $('.wpuf-multistep-fieldset:visible').append('<div class="wpuf-errors">' + wpuf_frontend.error_message + '</div>');
539            } else {
540                $(form).find('li.wpuf-submit').append('<div class="wpuf-errors">' + wpuf_frontend.error_message + '</div>');
541            }
542
543        },
544
545        removeErrorNotice: function(form) {
546            $(form).find('.wpuf-errors').remove();
547        },
548
549        markError: function(item) {
550            $(item).closest('li').addClass('has-error');
551            $(item).focus();
552        },
553
554        removeErrors: function(item) {
555            $(item).find('.has-error').removeClass('has-error');
556        },
557
558        isValidEmail: function( email ) {
559            var pattern = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i);
560            return pattern.test(email);
561        },
562
563        isValidURL: function(url) {
564            var urlregex = new RegExp("^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.|http:\/\/|https:\/\/){1}([0-9A-Za-z]+\.)");
565            return urlregex.test(url);
566        },
567
568        insertImage: function() {
569
570            var button = 'wpuf-insert-image',
571                container = 'wpuf-insert-image-container';
572            if ( !$('#' + button).length) {
573                return;
574            };
575
576            var imageUploader = new plupload.Uploader({
577                runtimes: 'html5,html4',
578                browse_button: button,
579                container: container,
580                multipart: true,
581                multipart_params: {
582                    action: 'wpuf_insert_image'
583                },
584                multiple_queues: false,
585                multi_selection: false,
586                urlstream_upload: true,
587                file_data_name: 'wpuf_file',
588                max_file_size: '2mb',
589                url: wpuf_frontend_upload.plupload.url,
590                flash_swf_url: wpuf_frontend_upload.flash_swf_url,
591                filters: [{
592                    title: 'Allowed Files',
593                    extensions: 'jpg,jpeg,gif,png,bmp'
594                }]
595            });
596
597            imageUploader.bind('Init', function(up, params) {
598                // console.log("Current runtime environment: " + params.runtime);
599            });
600
601            imageUploader.bind('FilesAdded', function(up, files) {
602                var $container = $('#' + container);
603
604                $.each(files, function(i, file) {
605                    $container.append(
606                        '<div class="upload-item" id="' + file.id + '"><div class="progress progress-striped active"><div class="bar"></div></div></div>');
607                });
608
609                up.refresh();
610                up.start();
611            });
612
613            imageUploader.bind('QueueChanged', function (uploader) {
614                imageUploader.start();
615            });
616
617            imageUploader.bind('UploadProgress', function(up, file) {
618                var item = $('#' + file.id);
619
620                $('.bar', item).css({ width: file.percent + '%' });
621                $('.percent', item).html( file.percent + '%' );
622            });
623
624            imageUploader.bind('Error', function(up, error) {
625                alert('Error #' + error.code + ': ' + error.message);
626            });
627
628            imageUploader.bind('FileUploaded', function(up, file, response) {
629
630                $('#' + file.id).remove();
631
632                if(response.response !== 'error' ) {
633                    var success = false;
634
635                    if ( typeof tinyMCE !== 'undefined' ) {
636
637                        if ( typeof tinyMCE.execInstanceCommand !== 'function' ) {
638                            // tinyMCE 4.x
639                            tinyMCE.get('post_content').insertContent(response.response);
640                        } else {
641                            // tinyMCE 3.x
642                            tinyMCE.execInstanceCommand('post_content', 'mceInsertContent', false, response.response);
643                        }
644                    }
645
646                    // insert failed to the edit, perhaps insert into textarea
647                    var post_content = $('#post_content');
648                    post_content.val( post_content.val() + response.response );
649
650                } else {
651                    alert('Something went wrong');
652                }
653            });
654
655            imageUploader.init();
656        },
657
658        deleteAvatar: function(e) {
659            e.preventDefault();
660
661            if ( confirm( $(this).data('confirm') ) ) {
662                $.post(wpuf_frontend.ajaxurl, {action: 'wpuf_delete_avatar', _wpnonce: wpuf_frontend.nonce}, function() {
663                    window.location.reload();
664                });
665            }
666        }
667    };
668
669    $(function() {
670        WP_User_Frontend.init();
671        WP_User_Frontend.insertImage();
672
673        // payment gateway selection
674        $('ul.wpuf-payment-gateways').on('click', 'input[type=radio]', function(e) {
675            $('.wpuf-payment-instruction').slideUp(250);
676
677            $(this).parents('li').find('.wpuf-payment-instruction').slideDown(250);
678        });
679
680        if( !$('ul.wpuf-payment-gateways li').find('input[type=radio]').is(':checked') ) {
681            $('ul.wpuf-payment-gateways li').first().find('input[type=radio]').click()
682        } else {
683            var el = $('ul.wpuf-payment-gateways li').find('input[type=radio]:checked');
684            el.parents('li').find('.wpuf-payment-instruction').slideDown(250);
685        }
686    });
687
688})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.