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,OAAc,CACnC,IAAI0G,EAAShM,EAAEiM,MAAO5J,UAAW2J,OAAOE,kBACxClM,EAAEwI,KAAMwD,GAAQ,SAAUtB,EAAOvH,GACT,QAAnBA,EAAMgJ,WACTpM,OAAOgM,WAAWnB,KAAMzH,EAAMiJ,QAEhC,IACApM,EAAGqC,UAAWgK,IAAK,yBACpB,CAEArM,EAAEwI,KAAMzI,OAAOgM,YAAY,SAAUrB,EAAOvH,GAC3CA,EAAOA,EAAOnC,EAAQoE,EACvB,GAED,CA2BC,CA9lBF,CA8lBKwG,O","sources":["webpack:///./js/src/frontend-jquery-ui.js"],"sourcesContent":["/**\n* Nested Forms, mama!\n*/\nconst ko = window.ko;\n\n( function( $ ) {\n\n\t/*\n\t * String.format was deprecated in GF 2.7.1 and will be removed in GF 2.8 in favor of String.prototype.gformFormat.\n\t *\n\t * As we support older versions of GF, we need to add String.prototype.gformFormat if it doesn't exist.\n\t */\n\tif (!String.prototype.gformFormat) {\n\t\tString.prototype.gformFormat = function () {\n\t\t\tvar args = arguments;\n\t\t\treturn this.replace(/{(\\d+)}/g, function (match, number) {\n\t\t\t\treturn typeof args[number] != 'undefined' ? args[number] : match;\n\t\t\t});\n\t\t};\n\t}\n\n\twindow.GPNestedForms = function( args ) {\n\n\t\tvar self = this;\n\n\t\t// copy all args to current object: formId, fieldId\n\t\tfor( const prop in args ) {\n\t\t\tif( args.hasOwnProperty( prop ) )\n\t\t\t\tself[prop] = args[prop];\n\t\t}\n\n\t\tself.init = function() {\n\n\t\t\tself.initSession();\n\n\t\t\t// Handle init when form is reloaded via AJAX.\n\t\t\tif( typeof window[ 'GPNestedForms_{0}_{1}'.gformFormat( self.formId, self.fieldId ) ] !== 'undefined' ) {\n\t\t\t\tvar oldGPNF = window[ 'GPNestedForms_{0}_{1}'.gformFormat( self.formId, self.fieldId ) ];\n\t\t\t\tself.entries = oldGPNF.entries;\n\t\t\t\tgform.removeFilter( 'gform_calculation_formula', 10, 'gpnf_{0}_{1}'.gformFormat( self.formId, self.fieldId ) );\n\t\t\t\t/* Hack: fixes issue when Beaver Builder triggers ready event again without reloading UI */\n\t\t\t\tself.viewModel = oldGPNF.viewModel;\n\t\t\t}\n\n\t\t\tself.parentFormContainer = $( '#gform_wrapper_' + self.formId );\n\t\t\tself.fieldContainer = $( '#field_' + self.formId + '_' + self.fieldId );\n\t\t\tself.modalElem = $( '.gpnf-nested-form-' + self.formId + '-' + self.fieldId );\n\t\t\tself.editDialogElem = $( '.gpnf-edit-form-' + self.formId + '-' + self.fieldId );\n\t\t\tself.formHtml = self.getFormHtml();\n\t\t\tself.entriesInput = $( '#input_' + self.formId + '_' + self.fieldId );\n\t\t\tself.scrollY = 0;\n\t\t\tself.modalArgs = gform.applyFilters( 'gpnf_modal_args', {\n\t\t\t\tautoOpen: false,\n\t\t\t\tmodal: true,\n\t\t\t\twidth: self.modalWidth < $( document ).width() ? self.modalWidth : $( document ).width() - 40,\n\t\t\t\theight: self.modalHeight,\n\t\t\t\ttitle: self.modalTitle,\n\t\t\t\tcloseText: 'Close',\n\t\t\t\tbuttons: { },\n\t\t\t\tposition: self.getPosition(),\n\t\t\t\tdialogClass: self.modalClass,\n\t\t\t\tdraggable: false,\n\t\t\t\tresizable: false,\n\t\t\t\tclose: function( event, ui ) {\n\t\t\t\t\t// Any time either dialog is closed, remove the dialog's form completely from the UI so there are\n\t\t\t\t\t// never two of the same form on the page at the same time.\n\t\t\t\t\tself.modalDialog.html( '' );\n\t\t\t\t\tself.editDialog.html( '' );\n\t\t\t\t\t$( '.ui-widget-overlay' ).removeClass( self.modalClass );\n\t\t\t\t\twindow.scroll( 0, self.scrollY );\n\t\t\t\t},\n\t\t\t\topen: function() {\n\n\t\t\t\t\tif( self.modalHeaderColor ) {\n\t\t\t\t\t\tself.modalDialog.siblings( '.ui-dialog-titlebar' ).css( 'background-color', self.modalHeaderColor );\n\t\t\t\t\t\tself.editDialog.siblings( '.ui-dialog-titlebar' ).css( 'background-color', self.modalHeaderColor );\n\t\t\t\t\t}\n\n\t\t\t\t\t$( '.ui-widget-overlay' ).addClass( self.modalClass );\n\n\t\t\t\t\tif( self.hasConditionalLogic ) {\n\n\t\t\t\t\t\t$( document ).on( 'gform_post_conditional_logic', function( event, formId ) {\n\t\t\t\t\t\t\tif( self.nestedFormId == formId ) {\n\t\t\t\t\t\t\t\tself.repositionModals();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} );\n\n\t\t\t\t\t} else {\n\n\t\t\t\t\t\tself.repositionModals();\n\n\t\t\t\t\t}\n\n\t\t\t\t}\n\t\t\t}, self.formId, self.fieldId, self );\n\n\t\t\t/**\n\t\t\t * Fix conflict when Bootstrap is loaded AFTER jQuery UI; the close button on jQuery UI does not appear.\n\t\t\t * https://stackoverflow.com/questions/17367736/jquery-ui-dialog-missing-close-icon\n\t\t\t */\n\t\t\tif( $.fn.button.noConflict ) {\n\t\t\t\t$.fn.bootstrapBtn = $.fn.button.noConflict();\n\t\t\t}\n\n\t\t\tself.modalDialog = self.modalElem.dialog( self.modalArgs );\n\t\t\tself.editDialog = self.editDialogElem.dialog( $.extend( {}, self.modalArgs, { title: self.editModalTitle } ) );\n\n\t\t\tif( ! self.isBound( self.fieldContainer[0] ) ) {\n\t\t\t\tself.viewModel = new EntriesModel( self.prepareEntriesForKnockout( self.entries ), self );\n\t\t\t\tko.applyBindings( self.viewModel, self.fieldContainer[0] );\n\t\t\t}\n\n\t\t\t// Click handler for add entry button.\n\t\t\t$( document ).on( 'click', '#field_' + self.formId + '_' + self.fieldId + ' .gpnf-add-entry', function( event ) {\n\n\t\t\t\tevent.preventDefault();\n\n\t\t\t\t// Save scroll position so we can return to it when closing the modal.\n\t\t\t\tself.scrollY = window.scrollY ? window.scrollY : window.pageYOffset;\n\n\t\t\t\tself.modalElem.html( self.formHtml );\n\t\t\t\tself.modalDialog.dialog( 'open' );\n\t\t\t\tself.initFormScripts();\n\t\t\t\tself.modalElem.find( 'input[name=\"gpnf_nested_form_field_id\"]' ).val( self.fieldId );\n\n\t\t\t} );\n\n\t\t\t// Re-init modaled forms; 'gpnf_post_render' triggered on any nested form's first load every time a nested\n\t\t\t// form is retrieved via ajax (aka editing, first load and each page load).\n\t\t\t$( document ).bind( 'gpnf_post_render', function( event, formId, currentPage ) {\n\n\t\t\t\tvar $nestedForm = $( '#gform_wrapper_' + formId );\n\t\t\t\tif( formId == self.nestedFormId && $nestedForm.length > 0 ) {\n\t\t\t\t\t$( document ).trigger( 'gform_post_render', [ self.nestedFormId, currentPage ] );\n\t\t\t\t}\n\n self.handleParentMergeTag();\n\t\t\t\tself.repositionModals();\n\n\t\t\t} );\n\n\t\t\t// Reposition modals when window is resized.\n\t\t\t$( window ).resize( function() {\n\t\t\t\tself.repositionModals();\n\t\t\t} );\n\n\t\t\t// Init calculation functionality.\n\t\t\tgform.addFilter( 'gform_calculation_formula', self.parseCalcs, 10, 'gpnf_{0}_{1}'.gformFormat( self.formId, self.fieldId ) );\n\n\t\t\tself.runCalc( self.formId );\n\n\t\t\tself.parentFormContainer.data( 'GPNestedForms_' + self.fieldId, self );\n\n\t\t\twindow[ 'GPNestedForms_{0}_{1}'.gformFormat( self.formId, self.fieldId ) ] = self;\n\n\t\t};\n\n\t\tself.initSession = function() {\n\t\t\t$.post( self.ajaxUrl, self.sessionData, function( response ) { } );\n\t\t};\n\n\t\tself.repositionModals = function() {\n\n\t\t\t// Repositioning the modal will scroll the body up to the top of the modal. This isn't a problem for small\n\t\t\t// modals but for large models that exceed the height of the window, this creates a very confusing UX.\n\t\t\t// Solution? The getPosition() method will now determine if the modal is larger than than window and return\n\t\t\t// a \"dnr\" (do not reposition) property.\n\t\t\tvar position = self.getPosition( self.modalDialog );\n\t\t\tif( ! position.dnr ) {\n\t\t\t\tself.modalDialog.dialog( 'option', 'position', position );\n\t\t\t}\n\n\t\t\tposition = self.getPosition( self.editDialog );\n\t\t\tif( ! position.dnr ) {\n\t\t\t\tself.editDialog.dialog( 'option', 'position', position );\n\t\t\t}\n\n\n\t\t};\n\n\t\tself.getPosition = function( $dialog ) {\n\n\t\t\tif( ! $dialog ) {\n\t\t\t\treturn { my: 'center', at: 'center', of: window };\n\t\t\t}\n\n\t\t\tvar windowHeight = $( window ).height(),\n\t\t\t\t/*documentHeight = $( document ).height(),*/\n\t\t\t\tmodalHeight = $dialog.parents( '.ui-dialog' ).height(),\n\t\t\t\talignment = 'center',\n\t\t\t of = window,\n\t\t\t\tdnr = false;\n\n\t\t\t/*if ( modalHeight >= documentHeight ) {\n\t\t\t\talignment = 'center top';\n\t\t\t\tof = document;\n\t\t\t\t$dialog.data( 'do-not-reposition', false );\n\t\t\t} else */\n\t\t\tif ( modalHeight >= windowHeight ) {\n\t\t\t\talignment = 'center top';\n\t\t\t\tof = window;\n\t\t\t\tif( $dialog.data( 'do-not-reposition' ) ) {\n\t\t\t\t\tdnr = true;\n\t\t\t\t} else {\n\t\t\t\t\t$dialog.data( 'do-not-reposition', true );\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t$dialog.data( 'do-not-reposition', false );\n\t\t\t}\n\n\t\t\tvar position = { my: alignment, at: alignment, of: of, dnr: dnr };\n\n\t\t\treturn position;\n\t\t};\n\n\t\tself.isBound = function( elem ) {\n\t\t\treturn !! ko.dataFor( elem );\n\t };\n\n\t\tself.prepareEntriesForKnockout = function( entries ) {\n\t\t\tfor( var i = 0; i < entries.length; i++ ) {\n\t\t\t\tentries[i] = self.prepareEntryForKnockout( entries[i] );\n\t\t\t}\n\t\t\treturn entries;\n\t\t};\n\n\t\tself.prepareEntryForKnockout = function( entry ) {\n\n\t\t\t// IE8 hack to fix recursive loop issue; props to Josh Casey\n\t\t\tvar entryTemplate = $.extend( {}, entry );\n\n\t\t\tfor( var prop in entryTemplate ) {\n\t\t\t\tif( entry.hasOwnProperty( prop ) ) {\n\t\t\t\t\tvar item = entry[ prop ];\n\t\t\t\t\tif( item.label === false ) {\n\t\t\t\t\t\titem.label = '';\n\t\t\t\t\t}\n entry['f' + prop] = item;\n }\n\t\t\t}\n\n return entry;\n\t\t};\n\n\t\tself.refreshMarkup = function() {\n\n\t\t\t$.post( self.ajaxUrl, {\n\t\t\t\taction: 'gpnf_refresh_markup',\n\t\t\t\tnonce: GPNFData.nonces.refreshMarkup,\n\t\t\t\tgpnf_parent_form_id: self.formId,\n\t\t\t\tgpnf_nested_form_field_id: self.fieldId\n\t\t\t}, function( response ) {\n\t\t\t\tself.formHtml = response.formHtml;\n\t\t\t} );\n\n\t\t};\n\n self.editEntry = function( entryId, $trigger ) {\n\n \tvar $spinner = new AjaxSpinner( $trigger, self.spinnerUrl, '' );\n\t $trigger.css( { visibility: 'hidden' } );\n\n $.post( self.ajaxUrl, {\n action: 'gpnf_edit_entry',\n\t nonce: GPNFData.nonces.editEntry,\n gpnf_entry_id: entryId,\n gpnf_parent_form_id: self.formId,\n gpnf_nested_form_field_id: self.fieldId\n }, function( response ) {\n\n \t$spinner.destroy();\n\t $trigger.css( { visibility: 'visible' } );\n\n\t\t\t\t// Save scroll position so we can return to it when closing the modal.\n\t\t\t\tself.scrollY = window.scrollY ? window.scrollY : window.pageYOffset;\n\n self.editDialog\n\t .html( response.formHtml )\n\t .dialog( 'open' );\n\n self.initFormScripts();\n\n } );\n\n };\n\n self.deleteEntry = function( item, $trigger ) {\n\n\t var $spinner = new AjaxSpinner( $trigger, self.spinnerUrl, '' );\n\t $trigger.css( { visibility: 'hidden' } );\n\n \t$.post( self.ajaxUrl, {\n\t\t action: 'gpnf_delete_entry',\n\t\t nonce: GPNFData.nonces.deleteEntry,\n\t\t gpnf_entry_id: item.id\n\t }, function( response ) {\n\n\t\t $spinner.destroy();\n\t\t $trigger.css( { visibility: 'visible' } );\n\n\t\t if( ! response ) {\n\t\t\t console.log( 'Error: no response.' );\n\t\t\t return;\n\t\t } else if( ! response.success ) {\n\t\t\t console.log( 'Error:' + response.data );\n\t\t\t return;\n\t\t }\n\n\t\t // Success!\n\t\t self.viewModel.entries.remove( item );\n\n\t\t self.refreshMarkup();\n\n\t } );\n\n };\n\n self.getFormHtml = function() {\n\n // check stash for HTML first, required for AJAX-enabled parent forms\n var formHtml = self.modalElem.data( 'formHtml' );\n if( ! formHtml ) {\n formHtml = self.modalElem.html();\n }\n\n // stash for AJAX-enabled parent forms\n self.modalElem.data( 'formHtml', formHtml );\n\n // clear the existing markup to prevent tabindex and script conflicts from multiple IDs existing in the same DOM\n self.modalElem.html( '' );\n\n return formHtml;\n };\n\n self.handleParentMergeTag = function () {\n\n self.modalElem.find(':input').each(function () {\n var $this = $(this);\n var value = $this.data('gpnf-value');\n\n if ($this.data('gpnf-changed')) {\n return true;\n }\n\n if (!value) {\n return true;\n }\n\n var parentMergeTagMatches = /{Parent:(\\d+(\\.\\d+)?)}/gi.exec(value);\n\n if (!parentMergeTagMatches) {\n return true;\n }\n\n var inputId = parentMergeTagMatches[1];\n\n if (isNaN(inputId)) {\n return true;\n }\n\n var $parentInput = self.parentFormContainer.find('#input_' + self.formId + '_' + inputId.split('.').join('_'));\n if( $parentInput.hasClass( 'gfield_radio' ) ) {\n\t\t\t\t\t$parentInput = $parentInput.find( 'input:checked' );\n\t\t\t\t}\n\n var currentValue = $(this).val(),\n\t\t\t\t\t/**\n\t\t\t\t\t * Filter the value of the parent merge tag before it is replaced in the field.\n\t\t\t\t\t *\n\t\t\t\t\t * @since 1.0-beta-8.0\n\t\t\t\t\t *\n\t\t\t\t\t * @param string value Value that will replace the parent merge tag in the field.\n\t\t\t\t\t * @param float inputId ID of the field/input targeted by the parent merge tag.\n\t\t\t\t\t * @param int formId ID of the current form.\n\t\t\t\t\t * @param {GPNestedForms} gpnf Current instance of the GPNestedForms object.\n\t\t\t\t\t */\n parentValue = gform.applyFilters( 'gpnf_parent_merge_tag_value', $parentInput.val(), inputId, self.formId, self );\n\n if (currentValue != parentValue) {\n $(this).val(parentValue).change();\n }\n\n $(this).on('change', function () {\n $(this).data('gpnf-changed', true);\n });\n });\n\n };\n\n self.initFormScripts = function( currentPage ) {\n\t\t\twindow.gform.doAction( 'gpnf_init_nested_form', self.nestedFormId );\n\n\t\t\t// @todo: add support for multi-page forms by updating \"1\" to the currrent page ID\n\t\t\t$(document).trigger( 'gform_post_render', [ self.nestedFormId, 1 ] );\n if( window['gformInitDatepicker'] ) {\n gformInitDatepicker();\n }\n\n self.handleParentMergeTag();\n };\n\n\t\t/**\n\t\t * We really need a better way to trigger calculations.\n\t\t */\n\t\tself.runCalc = function() {\n\t\t\t$( document ).trigger( 'gform_post_conditional_logic', [ self.formId, [], false ] );\n\t\t};\n\n\t\tself.parseCalcs = function( formula, formulaField, formId, calcObj ) {\n\n\t\t\tvar matches = getMatchGroups( formula, /{[^{]*?:([0-9]+):(sum|total|count)=?([0-9]*)}/i );\n\t\t\t$.each( matches, function( i, group ) {\n\n\t\t\t\tvar search = group[0],\n\t\t\t\t\tnestedFormFieldId = group[1],\n\t\t\t\t\tfunc = group[2],\n\t\t\t\t\ttargetFieldId = group[3],\n\t\t\t\t\treplace = 0;\n\n\t\t\t\tif( nestedFormFieldId != self.fieldId ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tswitch( func ) {\n\t\t\t\t\tcase 'sum':\n\t\t\t\t\t\tvar total = 0;\n\t\t\t\t\t\tself.viewModel.entries().forEach( function( entry ) {\n\t\t\t\t\t\t\tvar value = 0;\n\t\t\t\t\t\t\tif( typeof entry[ targetFieldId ] !== 'undefined' ) {\n\t\t\t\t\t\t\t\tvalue = entry[ targetFieldId ].value ? entry[ targetFieldId ].value : 0;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\ttotal += parseFloat( value );\n\t\t\t\t\t\t} );\n\t\t\t\t\t\treplace = total;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'total':\n\t\t\t\t\t\tvar total = 0;\n\t\t\t\t\t\tself.viewModel.entries().forEach( function( entry ) {\n\t\t\t\t\t\t\ttotal += parseFloat( entry.total );\n\t\t\t\t\t\t} );\n\t\t\t\t\t\treplace = total;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'count':\n\t\t\t\t\t\treplace = self.viewModel.entries().length;\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tformula = formula.replace( search, replace );\n\n\t\t\t} );\n\n\t\t\treturn formula;\n\t\t};\n\n\t\t/**\n\t\t * Static function called via the confirmation of the nested form. Loads the newly created entry into the\n\t\t * Nested Form field displayed on the parent form.\n\t\t *\n\t\t * @param args\n\t\t */\n\t\tGPNestedForms.loadEntry = function( args ) {\n\n\t\t\tvar gpnf = $( '#gform_wrapper_' + args.formId ).data( 'GPNestedForms_' + args.fieldId );\n\n\t\t\tconst entry = gpnf.prepareEntryForKnockout( args.fieldValues );\n\t\t\tentry.id = args.entryId;\n\n\t\t\t// edit\n\t\t\tif( args.mode == 'edit' ) {\n\n\t\t\t\t// get index of entry\n\t\t\t\tvar entryEditing = $( 'table.gpnf-nested-entries [data-entryid=\"' + entry.id + '\"]' );\n\t\t\t\tvar replacementIndex = entryEditing.index();\n\n\t\t\t\t// remove old entry, add updated\n\t\t\t\tgpnf.viewModel.entries.remove( function( item ) { return item.id == entry.id } );\n\t\t\t\tgpnf.viewModel.entries.splice( replacementIndex, 0, entry );\n\n\t\t\t\t// close dialog\n\t\t\t\tgpnf.editDialog.dialog( 'close' );\n\n\t\t\t}\n\t\t\t// add\n\t\t\telse {\n\n\t\t\t\tgpnf.modalDialog.dialog( 'close' );\n\t\t\t\tgpnf.viewModel.entries.push( entry );\n\n\t\t\t\tgpnf.refreshMarkup();\n\n\t\t\t}\n\n\t\t};\n\n\t\tself.init();\n\n\t};\n\n\tvar EntriesModel = function( entries, gpnf ) {\n\n var self = this;\n\n self.entries = ko.observableArray( entries );\n\n\t\t/**\n\t\t * Trigger change event on the form when entries change. This helps notify other plugins that the form has\n\t\t * updated if they're listening to the form 'change' events.\n\t\t */\n\t\tself.entries.subscribe(function () {\n\t\t\tgpnf.parentFormContainer.children('form').trigger('change');\n\t\t});\n\n self.isMaxed = ko.computed( function() {\n \tvar max = gform.applyFilters( 'gpnf_entry_limit_max', gpnf.entryLimitMax, gpnf.formId, gpnf.fieldId, gpnf );\n\n\t return max !== '' && self.entries().length >= max;\n } );\n\n self.entryIds = ko.computed( function() {\n var entryIds = [];\n $.each( self.entries(), function( i, item ) {\n entryIds.push( item.id );\n } );\n return entryIds;\n }, self );\n\n /**\n\t\t * Run calculations anytime entries modified.\n\t\t */\n\t\tself.runCalc = ko.computed( function() {\n\t gpnf.runCalc();\n\t return self.entries().length;\n }, self );\n\n self.editEntry = function( item, event ) {\n gpnf.editEntry( item.id, $( event.target ) );\n };\n\n self.deleteEntry = function( item, event ) {\n\t\t\tgpnf.deleteEntry( item, $( event.target ) );\n }\n\n };\n\n\t/**\n\t * Event Handler\n\t *\n\t * GPNF outputs all inline scripts to the footer for the Nested Form. This means that scripts binding directly to\n\t * the document gform_post_render event will trigger before GF's default gform_post_render function which handles\n\t * setting various form data (i.e. conditional logic, number formats). If those scripts are using that data it will\n\t * generate errors since that data has not yet been defined.\n\t *\n\t * Our first attempt at solving this involved using $._data() to prioritize our namespaced gform_post_render functions.\n\t * This proved to be unreliable (though I'd be willing to revisit).\n\t *\n\t * Our current solution is the Event Handler. We bind to gform_post_render as early as possible (see\n\t * GP_Nested_Forms::handle_event_handler()) and call our gpnfEventHandler(). This function will\n\t * a) get an array of all of our namespaced gform_post_render.gpnf bindings\n\t * b) unbind them, and\n\t * c) call them any time this function is called.\n\t *\n\t * To recreate, enable the Gravity Forms Dependency Fields add-on on a nested form and disable this function.\n\t */\n\twindow.gpnfEventHandler = function( event, formId, currentPage ) {\n\n\t\tif( typeof window.gpnfEvents == 'undefined' ) {\n\t\t\twindow.gpnfEvents = [];\n\t\t}\n\n\t\tif( window.gpnfEvents.length == 0 ) {\n\t\t\tvar events = $._data( document ).events.gform_post_render;\n\t\t\t$.each( events, function( index, event ) {\n\t\t\t\tif( event.namespace == 'gpnf' ) {\n\t\t\t\t\twindow.gpnfEvents.push( event.handler );\n\t\t\t\t}\n\t\t\t} );\n\t\t\t$( document ).off( 'gform_post_render.gpnf' );\n\t\t}\n\n\t\t$.each( window.gpnfEvents, function( index, event ) {\n\t\t\tevent( event, formId, currentPage );\n\t\t} );\n\n\t};\n\n\n\n // # GENERAL HELPERS\n\n\tfunction AjaxSpinner( elem, imageSrc, inlineStyles ) {\n\n\t\timageSrc = typeof imageSrc == 'undefined' || ! imageSrc ? gf_global.base_url + '/images/spinner.gif' : imageSrc;\n\t\tinlineStyles = typeof inlineStyles != 'undefined' ? inlineStyles : '';\n\n\t\tthis.elem = elem;\n\t\tthis.image = '';\n\n\t\tthis.init = function() {\n\t\t\tthis.spinner = jQuery(this.image);\n\t\t\tjQuery(this.elem).after(this.spinner);\n\t\t\treturn this;\n\t\t};\n\n\t\tthis.destroy = function() {\n\t\t\tjQuery(this.spinner).remove();\n\t\t};\n\n\t\treturn this.init();\n\t}\n\n} )( jQuery );\n"],"names":["ko","window","$","String","prototype","gformFormat","args","arguments","this","replace","match","number","GPNestedForms","self","prop","hasOwnProperty","init","initSession","formId","fieldId","oldGPNF","entries","gform","removeFilter","viewModel","parentFormContainer","fieldContainer","modalElem","editDialogElem","formHtml","getFormHtml","entriesInput","scrollY","modalArgs","applyFilters","autoOpen","modal","width","modalWidth","document","height","modalHeight","title","modalTitle","closeText","buttons","position","getPosition","dialogClass","modalClass","draggable","resizable","close","event","ui","modalDialog","html","editDialog","removeClass","scroll","open","modalHeaderColor","siblings","css","addClass","hasConditionalLogic","on","nestedFormId","repositionModals","fn","button","noConflict","bootstrapBtn","dialog","extend","editModalTitle","isBound","EntriesModel","prepareEntriesForKnockout","applyBindings","preventDefault","pageYOffset","initFormScripts","find","val","bind","currentPage","$nestedForm","length","trigger","handleParentMergeTag","resize","addFilter","parseCalcs","runCalc","data","post","ajaxUrl","sessionData","response","dnr","$dialog","my","at","of","windowHeight","parents","alignment","elem","dataFor","i","prepareEntryForKnockout","entry","entryTemplate","item","label","refreshMarkup","action","nonce","GPNFData","nonces","gpnf_parent_form_id","gpnf_nested_form_field_id","editEntry","entryId","$trigger","$spinner","AjaxSpinner","spinnerUrl","visibility","gpnf_entry_id","destroy","deleteEntry","id","success","remove","console","log","each","$this","value","parentMergeTagMatches","exec","inputId","isNaN","$parentInput","split","join","hasClass","currentValue","parentValue","change","doAction","gformInitDatepicker","formula","formulaField","calcObj","matches","getMatchGroups","group","search","nestedFormFieldId","func","targetFieldId","total","forEach","parseFloat","loadEntry","gpnf","fieldValues","mode","replacementIndex","index","splice","push","observableArray","subscribe","children","isMaxed","computed","max","entryLimitMax","entryIds","target","imageSrc","inlineStyles","gf_global","base_url","image","spinner","jQuery","after","gpnfEventHandler","gpnfEvents","events","_data","gform_post_render","namespace","handler","off"],"sourceRoot":""}