PageSourceSearch

https://www.birdsandblooms.com/wp-content/themes/bumblebee/js/newsletter-module.js?ver=1.1.3

js birdsandblooms.com collected 2026-10-02 05:23:42 UTC 4,814 bytes, 186 lines download raw bytes

1/* global jQuery, Permutive_Identifier */
2/**
3 * Encrypting user email on signup and set in local database
4 */
5
6/**
7 * Footer and bounce exchange click button with respective class and id
8 */
9jQuery( document.body ).on( 'click', '#subscribe-footer', set_footer_newsletter_email ).on( 'click', '.bx-input[name="email"]', set_bx_email );
10
11/**
12 * Sidebar newsletter signup button click with respective class. 
13 */
14jQuery( document.body ).on( 'click', '#subscribe', set_sidebar_newsletter_email );
15
16/**
17 * Get a value of user's email for footer
18 */
19function set_footer_newsletter_email() {
20	var footer_email = jQuery( '#email-footer' ).val();
21	set_users_email_in_local_data( footer_email );
22}
23
24/**
25 * Get a value of user's email from sidebar.
26 */
27function set_sidebar_newsletter_email() {
28	var email = jQuery( '#email' ).val();
29	set_users_email_in_local_data( email );
30}
31
32/**
33 * Set bounce exchange email after click on submit button
34 */
35function set_bx_email() {
36	jQuery( '.bx-button' ).click(
37		function() {
38			var bx_email = jQuery( '.bx-input[name="email"]' ).val();
39			set_users_email_in_local_data( bx_email );
40		}
41	);
42}
43
44/**
45 * Set a value of user's email from us brand's(newsletter signup pages).
46 *
47 * @param {*} event
48 */
49function set_email_for_us_brands ( event ) {
50	if ( event.data.site ) {
51		set_users_email_in_local_data( event.data.email );
52	}
53}
54
55( function () {
56	if ( window.addEventListener ) {
57		window.addEventListener( 'message', set_email_for_us_brands );
58	} else {
59		window.attachEvent( 'onmessage', set_email_for_us_brands );
60	}
61} )( jQuery );
62
63/**
64 * Set a value of user's email to local storage and send it to permutive.
65 *
66 * @param {*} input_email
67 * @returns
68 */
69function set_users_email_in_local_data( input_email ) {
70	var hashed_sha_256 = '';
71	var hashed_sha_1   = '';
72	if ( typeof input_email !== 'undefined' && input_email !== null && input_email !== '' ) {
73		var encoded_string = new TextEncoder().encode( input_email );
74		crypto.subtle.digest( 'SHA-256', encoded_string ).then(
75			function ( dataBuffer ) {
76				hashed_sha_256 = hex_to_string( dataBuffer );
77				if ( '' === hashed_sha_256 ) {
78					return;
79				}
80				update_email_in_local_storage( hashed_sha_256 );
81
82				crypto.subtle.digest( 'SHA-1', encoded_string ).then(
83					function ( dataBuffer ) {
84						hashed_sha_1 = hex_to_string( dataBuffer );
85						if ( '' === hashed_sha_1 ) {
86							return;
87						}
88						update_ehid_in_cookie( hashed_sha_1 );
89						if ( typeof Permutive_Identifier !== 'undefined' && jQuery.isFunction( Permutive_Identifier.identify ) ) {
90							Permutive_Identifier.identify();
91						}
92					}
93				);
94			}
95		);
96	}
97}
98
99/**
100 * Set Ehid cookie.
101 *
102 * @param {*} hashed_value
103 * @returns
104 */
105function update_ehid_in_cookie( hashed_value ) {
106	document.cookie = 'Ehid=' + hashed_value + ';path=/;domain=.' + location.host;
107}
108
109/**
110 * Convert arraybuffer to string.
111 *
112 * @param {*} hash_buffer_string
113 * @returns
114 */
115function hex_to_string( hash_buffer_string ) {
116	var hex_codes = [];
117	var view      = new DataView( hash_buffer_string );
118
119	for ( var i = 0; i < view.byteLength; i += 4 ) {
120		var value        = view.getUint32( i );
121		var string_value = value.toString( 16 );
122		var padding      = '00000000';
123		var padded_value = ( padding + string_value ).slice( -padding.length );
124		hex_codes.push( padded_value );
125	}
126	return hex_codes.join( '' );
127}
128
129/**
130 * Upadte hashed email in local database.
131 *
132 * @param {*} hashed_email
133 */
134function update_email_in_local_storage( hashed_email ) {
135	var user = JSON.parse( localStorage.getItem( 'user' ) );
136	if ( user == null ) {
137		user = {};
138	}
139	user.email = hashed_email;
140	localStorage.setItem( 'user', JSON.stringify( user ) );
141}
142
143
144jQuery( document ).ready( function() {
145	check_and_update_permutive_email_hash();
146} );
147
148/**
149 * Checks for Permhash in the URL and processes the Permutive call.
150 */
151function check_and_update_permutive_email_hash() {
152	
153	// Return if Permutive functions are not available.
154	if ( typeof Permutive_Identifier === 'undefined' || ! jQuery.isFunction( Permutive_Identifier.identify ) ) {
155		return;	
156	}
157
158	// Get the permutive email hash.
159	var permutive_email_hash = get_permutive_hash_from_url();
160	
161	if ( ! permutive_email_hash ) {
162		return;
163	}
164	// Update the hash in the localstorage.
165	update_email_in_local_storage( permutive_email_hash );
166
167	// Call Prmutive Identifier.
168	Permutive_Identifier.identify();
169}
170
171/**
172 * Extracts Permutive Email hash from the URL.
173 */
174function get_permutive_hash_from_url() {
175	var perutive_query_string = window.location.search;
176	var permutive_url_params  = new URLSearchParams( perutive_query_string );
177
178	// Check if _PermHash is set in the URL.
179	if ( ! permutive_url_params.has( '_PermHash' ) ) {
180		return false;
181	}
182	
183	// Return the _PermHash available from URL.
184	return permutive_url_params.get( '_PermHash' );
185}
186

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.