1class dhrequest { 2 static post(url, params) { 3 if (typeof url !== "string" || url.length < 1) { 4 url = window.location.href; 5 } 6 7 let list = Array(); 8 //list.push(encodeURIComponent("csrf_token") + "=" + encodeURIComponent(csrf_token)); 9 if (typeof params === "object") { 10 for (let i in params) { 11 list.push( 12 encodeURIComponent(i) + "=" + encodeURIComponent(params[i]) 13 ); 14 } 15 } 16 17 return new Promise((resolve, reject) => { 18 let xhr = new XMLHttpRequest(); 19 20 xhr.open("POST", url, true); 21 xhr.setRequestHeader( 22 "Content-type", 23 "application/x-www-form-urlencoded" 24 ); 25 //xhr.setRequestHeader("Content-length", list.length); 26 //xhr.setRequestHeader("Connection", "close"); 27 28 xhr.onload = () => { 29 if (xhr.status == 200) { 30 resolve(xhr.responseText); 31 } else { 32 reject({ status: xhr.status, statusText: xhr.statusText }); 33 } 34 }; 35 36 xhr.onerror = () => { 37 reject({ status: xhr.status, statusText: xhr.statusText }); 38 }; 39 40 xhr.send(list.join("&")); 41 }); 42 } 43 static create(type, attributes, styles, setattributes) { 44 var el = document.createElement(type); 45 46 if (typeof attributes === "object") { 47 for (var j in attributes) { 48 el[j] = attributes[j]; 49 } 50 } 51 52 if (typeof styles === "object") { 53 for (var j in styles) { 54 el.style[j] = styles[j]; 55 } 56 } 57 58 if (typeof setattributes === "object") { 59 for (var j in setattributes) { 60 el.setAttribute(j, setattributes[j]); 61 } 62 } 63 64 return el; 65 } 66 static number_format(number, decimals, dec_point, thousands_sep) { 67 number = (number + "").replace(/[^0-9+\-Ee.]/g, ""); 68 69 var n = !isFinite(+number) ? 0 : +number, 70 prec = !isFinite(+decimals) ? 0 : Math.abs(decimals), 71 sep = typeof thousands_sep === "undefined" ? "," : thousands_sep, 72 dec = typeof dec_point === "undefined" ? "." : dec_point, 73 s = "", 74 toFixedFix = function (n, prec) { 75 var k = Math.pow(10, prec); 76 return "" + Math.round(n * k) / k; 77 }; 78 s = (prec ? toFixedFix(n, prec) : "" + Math.round(n)).split("."); 79 if (s[0].length > 3) { 80 s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep); 81 } 82 if ((s[1] || "").length < prec) { 83 s[1] = s[1] || ""; 84 s[1] += new Array(prec - s[1].length + 1).join("0"); 85 } 86 return s.join(dec); 87 } 88 static create_address(line1, line2, city, state, postal_code, country) { 89 let d = dhrequest.create("div"); 90 if (line1.trim().length > 0) { 91 let d0 = dhrequest.create("div", { innerText: line1.trim() }); 92 d.appendChild(d0); 93 } 94 if (line2.trim().length > 0) { 95 let d1 = dhrequest.create("div", { innerText: line2.trim() }); 96 d.appendChild(d1); 97 } 98 if ( 99 city.trim().length > 0 || 100 state.trim().length > 0 || 101 postal_code.trim().length > 0 || 102 country.trim().length > 0 103 ) { 104 let r = []; 105 if (city.trim().length > 0) { 106 r.push(city.trim()); 107 } 108 109 let r2 = []; 110 if (state.trim().length > 0) { 111 r2.push(state.trim()); 112 } 113 if (postal_code.trim().length > 0) { 114 r2.push(postal_code.trim()); 115 } 116 r2 = r2.join(" "); 117 118 if (r2.length > 0) { 119 r.push(r2); 120 } 121 122 if (country.trim().length > 0) { 123 r.push(country.trim()); 124 } 125 126 r = r.join(", "); 127 128 let d2 = dhrequest.create("div", { innerText: r }); 129 d.appendChild(d2); 130 } 131 return d; 132 } 133 static create_url(url) { 134 if (typeof url !== "string") { 135 return ""; 136 } 137 138 url = url.trim(); 139 if (url.length > 0) { 140 url = "//" + url.replace(/^https?:\/\//i, "").replace(/^\/+/, ""); 141 } 142 return url; 143 } 144 static create_phone(phone) { 145 if (typeof phone !== "string") { 146 return ""; 147 } 148 phone = phone.trim(); 149 if (phone.length > 0) { 150 var p = phone.replace(/[^\d]/g, ""); 151 152 if (p.length == 7) { 153 return p.substr(0, 3) + "-" + p.substr(3); 154 } else if (p.length == 10) { 155 return ( 156 p.substr(0, 3) + "-" + p.substr(3, 3) + "-" + p.substr(6) 157 ); 158 } else if (p.length == 11) { 159 return ( 160 p.substr(0, 1) + 161 "-" + 162 p.substr(1, 3) + 163 "-" + 164 p.substr(4, 3) + 165 "-" + 166 p.substr(7) 167 ); 168 } 169 } 170 return phone; 171 } 172}
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.