PageSourceSearch

https://liveinfocusedenergy.com/wp-content/plugins/happyforms-upgr…/inc/assets/js/frontend/modal.js?ver=1.38.9

js liveinfocusedenergy.com collected 2026-09-28 07:55:37 UTC 3,508 bytes, 131 lines download raw bytes

1( function( $, settings ) {
2
3	var modalTemplate = '#happyforms-modal-template';
4
5	var HappyFormsModal = function( el, formId ) {
6		this.formId = formId;
7		this.el = el;
8		this.$el = $( el );
9		this.$inner = $( '.happyforms-modal__inner', this.$el );
10		this.$container = $( '.happyforms-modal__form-container', this.$el );
11		this.$closeButton = $( '.happyforms-modal__close-button', this.$el );
12		this.$form = null;
13
14		this.open();
15		this.bindEvents();
16
17		$.get( settings.ajaxUrl, {
18			action: settings.action,
19			form_id: this.formId,
20		}, function( html ) {
21			this.$container.html( html );
22			this.$closeButton.css( 'display', 'block' );
23			this.focus();
24		}.bind( this ) );
25	}
26
27	HappyFormsModal.prototype.open = function() {
28		$( 'body' ).append( this.$el );
29		$( 'body' ).addClass( 'happyforms-modal-open' );
30	}
31
32	HappyFormsModal.prototype.bindEvents = function() {
33		this.$closeButton.on( 'click', this.onCloseClick.bind( this ) );
34		// this.$el.on( 'click', '.happyforms-form', this.onInsideClick.bind( this ) );
35		this.$el.on( 'click', this.onOutsideClick.bind( this ) );
36		$( document ).on( 'keydown.happyforms', this.onKeyDown.bind(this) );
37		$( this.$el ).on( 'mousewheel touchmove', this.onScroll.bind(this) );
38	}
39
40	HappyFormsModal.prototype.onScroll = function() {
41		var $form = $( 'form', this.$el );
42		var formScrollTop = Math.abs( $form.offset().top - $form.parent().offset().top );
43
44		if ( formScrollTop > 0 ) {
45			this.$closeButton.addClass('scrolled');
46		} else {
47			this.$closeButton.removeClass('scrolled');
48		}
49	}
50
51	HappyFormsModal.prototype.focus = function() {
52		var $firstPart = $( '.happyforms-part', this.$form ).first();
53
54		switch ( $firstPart.attr( 'data-happyforms-type' ) ) {
55			case 'single_line_text':
56			case 'multi_line_text':
57			case 'number':
58			case 'email':
59				$( 'input:visible, textarea:visible', $firstPart ).trigger( 'focus' );
60				break;
61			default:
62				break;
63		}
64	}
65
66	HappyFormsModal.prototype.unbindEvents = function() {
67		$( document ).off( 'keydown.happyforms' );
68	}
69
70	HappyFormsModal.prototype.close = function() {
71		$( '.happyforms-form [data-happyforms-type]', this.$el ).trigger( 'happyforms.detach' );
72		this.$el.remove();
73		$( 'body' ).removeClass( 'happyforms-modal-open' );
74	}
75
76	HappyFormsModal.prototype.onInsideClick = function( e ) {
77		e.stopPropagation();
78	}
79
80	HappyFormsModal.prototype.onCloseClick = function( e ) {
81		e.preventDefault();
82
83		this.close();
84		this.unbindEvents();
85	}
86
87	HappyFormsModal.prototype.onOutsideClick = function( e ) {
88		var container = this.$container.get( 0 );
89		var eventPath = e.originalEvent.composedPath();
90
91		if ( -1 !== eventPath.indexOf( container ) ) {
92			return;
93		}
94
95		e.preventDefault();
96
97		this.close();
98		this.unbindEvents();
99	}
100
101	HappyFormsModal.prototype.onKeyDown = function( e ) {
102		if ( 27 === e.keyCode ) {
103			e.preventDefault();
104			this.close();
105			this.unbindEvents();
106		}
107	}
108
109	$.fn.happyFormsModal = function( formId ) {
110		this.each(function() {
111			$.data( this, 'HappyFormsModal', new HappyFormsModal( this, formId ) );
112		} );
113	}
114
115	$( function() {
116		$( document ).on( 'click', 'a[href^="#happyforms-"]', function( e ) {
117			e.stopPropagation();
118			e.preventDefault();
119
120			var formId = $( e.target ).attr( 'data-form-id' );
121
122			if ( ! formId ) {
123				formId = $( e.target ).attr( 'href' ).replace( '#happyforms-', '' );
124			}
125
126			var html = $( '#happyforms-modal-template-' + formId ).html();
127			var $modal = $( html ).happyFormsModal( formId );
128		} );
129	} );
130
131} )( jQuery, _happyformsModalSettings );

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.