// the semi-colon before function invocation is a safety net against concatenated // scripts and/or other plugins which may not be closed properly. ;// noinspection JSUnusedLocalSymbols (function ($, window, document, undefined) { "use strict"; // undefined is used here as the undefined global variable in ECMAScript 3 is // mutable (ie. it can be changed by someone else). undefined isn't really being // passed in so we can ensure the value of it is truly undefined. In ES5, undefined // can no longer be modified. // window and document are passed through as local variables rather than global // as this (slightly) quickens the resolution process and can be more efficiently // minified (especially when both are regularly referenced in your plugin). // Create the defaults once var pluginName = "forminatorFrontPagination", defaults = { totalSteps: 0, step: 0, hashStep: 0, inline_validation: false }; // The actual plugin constructor function ForminatorFrontPagination(element, options) { this.element = $(element); this.$el = this.element; this.totalSteps = 0; this.totalActiveSteps = 0; // Exclude hidden steps this.step = 0; this.actualStep = 0; // Exclude hidden steps this.finished = false; this.hashStep = false; this.next_button_txt = ''; this.prev_button_txt = ''; this.custom_label = []; this.form_id = 0; this.element = ''; // jQuery has an extend method which merges the contents of two or // more objects, storing the result in the first object. The first object // is generally empty as we don't want to alter the default options for // future instances of the plugin this.settings = $.extend({}, defaults, options); this._defaults = defaults; this._name = pluginName; this.init(); } // Avoid Plugin.prototype conflicts $.extend(ForminatorFrontPagination.prototype, { init: function () { var self = this; var draftPage = !! this.$el.data( 'draft-page' ) ? this.$el.data( 'draft-page' ) : 0; // Detect instant preview mode this.instantPreview = this.$el.closest( '#forminator-instant-preview' ).length > 0; this.next_button = this.settings.next_button ? this.settings.next_button : window.ForminatorFront.cform.pagination_next; this.prev_button = this.settings.prev_button ? this.settings.prev_button : window.ForminatorFront.cform.pagination_prev; if (this.$el.find('input[name=form_id]').length > 0) { this.form_id = this.$el.find('input[name=form_id]').val(); } this.$form = this.$el; this.totalSteps = this.settings.totalSteps; this.totalActiveSteps = this.totalSteps this.step = this.settings.step; this.actualStep = this.step; this.quiz = this.settings.quiz; this.element = this.$el.find('div.forminator-pagination[data-step=' + this.step + ']').data('name'); if (this.form_id && typeof window.Forminator_Cform_Paginations === 'object' && typeof window.Forminator_Cform_Paginations[this.form_id] === 'object') { this.custom_label = window.Forminator_Cform_Paginations[this.form_id]; } this.$el.on('forminator:page-break:toggled', function(e) { self.totalActiveSteps = self.$el.find('.forminator-pagination:not(.forminator-page-hidden)').length; self.calculate_bar_percentage(); }); if ( this.instantPreview ) { // Initialize for instant preview mode this.init_instant_preview(); } else { // Normal pagination initialization if ( draftPage > 0 ) { this.go_to( draftPage, true ); } else if (this.settings.hashStep && this.step > 0) { this.go_to(this.step, true); } else if ( this.quiz ) { this.go_to(0, true); } else { this.go_to(0, false); } this.render_navigation(); this.render_bar_navigation(); this.render_footer_navigation(); this.init_events(); this.update_navigation(); this.$el.find('.forminator-button.forminator-button-back, .forminator-button.forminator-button-next, .forminator-button.forminator-button-submit').on("click", function (e) { e.preventDefault(); $(this).trigger('forminator.front.pagination.move'); self.resetRichTextEditorHeight(); }); // Update progress bar percentage on form submit. this.$el.on('before:forminator:form:submit', function( e, formData ) { if( formData.get( 'save_draft' ) !== 'true' ) { self.update_progress_bar_percentage( 100 ); } }); this.$el.on('click', '.forminator-result--view-answers', function(e){ e.preventDefault(); $(this).trigger('forminator.front.pagination.move'); }); this.update_buttons(); } }, init_events: function () { var self = this; this.$el.find('.forminator-button-back').on('forminator.front.pagination.move',function (e) { self.handle_click('prev'); }); this.$el.on('forminator.front.pagination.move', '.forminator-result--view-answers', function (e) { self.handle_click('prev'); }); this.$el.find('.forminator-button-next').on('forminator.front.pagination.move', function (e) { self.handle_click('next'); }); this.$el.find('.forminator-step').on("click", function (e) { e.preventDefault(); var step = $(this).data('nav'); self.handle_step(step); }); this.$el.on('reset', function (e) { self.on_form_reset(e); }); this.$el.on('forminator:quiz:submit:success', function (e, ajaxData, formData, resultText) { if ( resultText ) { self.move_to_results(e); } }); this.$el.on('forminator.front.pagination.focus.input', function (e, input) { self.on_focus_input(e, input); }); this.$el.on( 'validation:invalid', function() { var validator = self.$el.data( 'validator' ); if ( ! validator || ! validator.errorList.length ) { return; } var errorPage = self.get_page_of_input( validator.errorList[0].element ); if ( errorPage !== self.step ) { self.go_to( errorPage, true ); self.update_buttons(); } } ); }, /** * Initialize pagination for instant preview mode * Shows all pages together with separators */ init_instant_preview: function () { var self = this; // Show all pages this.$el.find('.forminator-pagination').css({ 'height': 'auto', 'opacity': '1', 'visibility': 'visible' }).removeAttr( 'aria-hidden' ).removeAttr( 'hidden' ); this.$el.find('.forminator-pagination .forminator-pagination--content').show(); // Get all pagination steps const allSteps = this.$el.find('.forminator-pagination'); const tempElement = this.element; const tempEl = this.$el; allSteps.each(function(index) { const $page = $(this); const stepNum = $page.data('step') || 0; const pageLabel = $page.data('actual-label') || ''; const $parent = $page.wrap('
'); // Add page separator before the entire pagination element var separator = '