PageSourceSearch

https://www.horoscope.com/wp-content/themes/horoscope/assets/js/frontend/free-birth-chart-form.js?ver=0.1.6

js horoscope.com collected 2026-10-02 02:46:29 UTC 7,722 bytes, 195 lines download raw bytes

1// https://stackoverflow.com/a/2117523/19500
2function uuidv4() {
3    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(
4        /[xy]/g,
5        function (c) {
6            let r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
7            return v.toString(16);
8        }
9    );
10}
11
12function formVal(selector) {
13    return jQuery(selector)[0].value;
14}
15
16function initMap() {
17    const input = document.getElementById('birth-location');
18    const options = {
19        fields: ["address_components", "geometry"],
20        strictBounds: false,
21    };
22    const autocomplete = new google.maps.places.Autocomplete(input, options);
23    autocomplete.addListener("place_changed", () => {
24        const place = autocomplete.getPlace();
25        place.address_components.forEach(component => {
26            if ( component.types[0] === 'locality' ) {
27                jQuery("#birth-location_locality").val(component.long_name);
28            }
29            if ( component.types[0] === 'administrative_area_level_1' ) {
30                jQuery('#birth-state').val(component.long_name);
31            }
32            if ( component.types[0] === 'country' ) {
33                jQuery('#birth-location_country').val(component.long_name);
34            }
35        });
36        jQuery('#birth-location_lat').val(place.geometry.location.lat());
37        jQuery('#birth-location_lng').val(place.geometry.location.lng());
38    });
39}
40
41function freeBirthChartForm() {
42    let $firstName = jQuery('#first-name').val();
43    if ( $firstName.trim() == '' ) {
44        alert('First Name can not be empty or contain only spaces');
45        return false;
46    }
47
48    var termsAccepted = jQuery('#TermOfServicesCheckBox').is(":checked");
49    if (!termsAccepted) {
50        alert("you must accept the terms of service to get a free birth chart");
51        return false;
52    }
53
54    var dateString = formVal('#date-of-birth') + ' ' + formVal('#time-of-birth');
55    var birthTime = moment.utc(dateString);
56    if (!birthTime.isValid()) {
57        alert("Please enter a valid birth date and time");
58        return false;
59    }
60    if (birthTime > moment().add(-18, 'years')) {
61        alert(
62            "Sorry, due to your age, we are unable to process your order. "
63            + "According to our terms of service, we cannot allow users under the age of 18 "
64            + "to make online purchases. We are sorry and thank you for using Astrology.com"
65        );
66        return false;
67    }
68    if (!(jQuery("input[name=birth-location_lat]").val() && jQuery("input[name=birth-location_lng]").val())) {
69        alert("Please enter a valid Birth Location.");
70        return false;
71    }
72    var gender = jQuery("#gender-selector")[0].selectedOptions[0].value;
73
74    var email = jQuery('#email').val();
75 
76    // simple regex for email format
77    const isEmailValid = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
78    if (email.trim() === '' || !isEmailValid) {
79        alert('Please enter a valid Email');
80        return false;
81    }
82    
83    var domain = window.location.hostname;
84    var isProd = "www.horoscope.com" == domain;
85    var isStage = "wp-stage.horoscope.com" == domain;
86    var isDr = "wp-dr.horoscope.com" == domain;
87    var repSubDomain = "";
88    if ( isProd ) {
89        repSubDomain = "reports";
90    } else if ( isStage ){
91        repSubDomain = "reports-stage";
92    } else if ( isDr ) {
93        repSubDomain = "reports-dr";
94    } else {
95        repSubDomain = "reports-dev";
96    }
97
98    jQuery.ajax(
99        {
100            type: "POST",
101            url: `https://${repSubDomain}.astrology.com/v1/reports/horoscope/free-zodiac`,
102            data: JSON.stringify(
103                {
104                    Querent: {
105                        BirthDate: birthTime,
106                        FirstName: formVal('#first-name'),
107                        Gender: gender === 'Male' ? 'M' : 'F',
108                        Email: formVal('#email'),
109                        ProfileKey: uuidv4(),
110                        Country: formVal('#birth-location_country'),
111                        State: formVal('#birth-state'),
112                        City: formVal('#birth-location_locality'),
113                        Longitude: formVal('#birth-location_lng'),
114                        Latitude: formVal('#birth-location_lat'),
115                        UTCOffset: 0 // required but not read
116                    },
117                    "productCode": "StEdNaLH",
118                    "requestKey": "horoscope_" + uuidv4()
119                }
120            ),
121            contentType: "application/json; charset=utf-8",
122            dataType: "json",
123            beforeSend: function () { // Before we send the request, add loading animation
124                jQuery('body').append('<style id="loadingDivCss">.loader, .loader:after {border-radius: 50%;width: 10em;height: 10em;}.loader {top:45%;left:45%;font-size: 10px;position: fixed;text-indent: -9999em;border-top: 1.1em solid rgba(255, 255, 255, 0.2);border-right: 1.1em solid rgba(255, 255, 255, 0.2);border-bottom: 1.1em solid rgba(255, 255, 255, 0.2);border-left: 1.1em solid #ffffff;-webkit-transform: translateZ(0);-ms-transform: translateZ(0);transform: translateZ(0);-webkit-animation: load8 1.1s infinite linear;animation: load8 1.1s infinite linear;}@-webkit-keyframes load8 {0% {-webkit-transform: rotate(0deg);transform: rotate(0deg);}100% {-webkit-transform: rotate(360deg);transform: rotate(360deg);}}@keyframes load8 {0% {-webkit-transform: rotate(0deg);transform: rotate(0deg);}100% {-webkit-transform: rotate(360deg);transform: rotate(360deg);}}#loadingDiv {position:fixed;top:0;left:0;width:100%;height:100%;background:rgb(0,0,0,0.8);z-index:1000;}</style>')
125                jQuery('body').append('<div id="loadingDiv"><div class="loader">Loading...</div></div>');
126                jQuery('body').addClass('overflow-hidden');
127            }
128        }
129    ).done(
130        function (response) {
131            let data = response.split("/");
132            let birthChartPath = window.location.pathname;
133            birthChartPath = birthChartPath + ("/" == birthChartPath.slice(-1) ? "" : "/");
134            window.location.href = birthChartPath + data[data.length - 1] + "/";
135            jQuery("#loadingDivCss").remove();
136            jQuery("#loadingDiv").remove();
137            jQuery('body').removeClass('overflow-hidden');
138        }
139    ).fail(
140        function () {
141            console.error("free birth chart report service call failed");
142            jQuery("#loadingDivCss").remove();
143            jQuery("#loadingDiv").remove();
144            jQuery('body').removeClass('overflow-hidden');
145        }
146    )
147
148    return false;
149}
150
151function readQueryParameters() {
152    let queryString = window.location.search.substr(1); // move past the '?'
153    if (queryString != null && queryString != "") {
154        let params = queryString.split("&");
155        let dob = "";
156        for (var i = 0; i < params.length; i++) {
157            let pair = params[i].split("=");
158            switch (pair[0]) {
159                case "bc-dob":
160                    dob = pair[1];
161                    break;
162            }
163        }
164        if (dob.length > 0) {
165            let dateOfBirth = formatDateString(dob);
166            if (dateOfBirth.length > 0) {
167                jQuery('#date-of-birth')[0].value = dateOfBirth
168            }
169        }
170    }
171}
172
173function formatDateString(dateString) {
174    if (dateString.length == 0) {
175        return;
176    }
177
178    let date = moment(dateString);
179    if (!date.isValid()) {
180        return;
181    }
182
183    return date.format("MM/DD/YYYY");
184}
185
186flatpickr("#date-of-birth", {
187    allowInput: true,
188    dateFormat: "m/d/Y",
189});
190
191flatpickr("#time-of-birth", {
192    enableTime: true,
193    noCalendar: true,
194    dateFormat: "G:i K"
195});

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.