1(function ($) { 2 var SUCCESS_STATUS = "mail_sent"; 3 var AJAX_ACTION = "getDownloadButton"; 4 var SUPPORTED_VERSIONS = [5, 6]; 5 6 function warnVersion(version) { 7 console.warn( 8 "[CF7 GATED CONTENT]: This version of CF7 is not supported: " + version 9 ); 10 } 11 12 function parseVersions(detail) { 13 var version = detail.pluginVersion; 14 var versionParts = version.split(".").map(v => parseInt(v, 10)); 15 16 // Warn if we are in a non-supported version of CF7 17 if (!SUPPORTED_VERSIONS.includes(versionParts[0])) { 18 warnVersion(version); 19 } 20 21 // Return version object 22 return { 23 string: version, 24 major: versionParts[0], 25 minor: versionParts[1], 26 patch: versionParts[2], 27 }; 28 } 29 30 function parseStatus(detail) { 31 var version = parseVersions(detail); 32 33 switch (version.major) { 34 case 6: 35 case 5: 36 return detail.apiResponse.status; 37 38 case 4: 39 return detail.status; 40 41 default: 42 return null; 43 } 44 } 45 46 function parseTarget(detail) { 47 var version = parseVersions(detail); 48 49 switch (version.major) { 50 case 6: 51 case 5: 52 return $(detail.apiResponse.into); 53 54 case 4: 55 return $("#" + detail.id); 56 57 default: 58 return null; 59 } 60 } 61 62 document.addEventListener( 63 "wpcf7submit", 64 function (event) { 65 var detail = event.detail; 66 var status = parseStatus(detail); 67 var $target = parseTarget(detail); 68 69 // bail early if we didn't succeed 70 if (status !== SUCCESS_STATUS || $target === null) { 71 return false; 72 } 73 74 var downloadId = "wpcf7-download-" + detail.unitTag; 75 76 // Set a cookie 77 document.cookie = wpcf7gc.cookieKey + detail.contactFormId + "=1"; 78 79 $.ajax({ 80 type: "post", 81 dataType: "json", 82 url: wpcf7gc.ajaxurl, 83 data: { 84 action: AJAX_ACTION, 85 contactFormId: detail.contactFormId, 86 }, 87 error: function (res) { 88 console.error("Error Fetching Gated Content: ", res); 89 90 alert( 91 "There was an error fetching your download. Please refresh the page." 92 ); 93 }, 94 success: function (res) { 95 if (res.data != null) { 96 if ($target && $("#" + downloadId).length < 1) { 97 var $downloadContainer = $("<div></div>", { id: downloadId }); 98 $downloadContainer.append(res.data).appendTo($target); 99 } 100 } 101 }, 102 }); 103 }, 104 false 105 ); 106})(jQuery);
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.