1/* 2 * Plongo.com 3 * initial javascript 4 */ 5// class plongo 6plongo = {}; 7// global vars 8plongo.g = {}; 9// aux functions 10plongo.aux = {}; 11// aux functions 12plongo.ajax = {}; 13// 14plongo.aux.classloader = function (classname) { 15 var fileref = document.createElement('script'); 16 fileref.setAttribute("type", "text/javascript"); 17 fileref.setAttribute("src", classname); 18}; 19plongo.aux.showError = function (element_container, txt) { 20 var e = document.getElementById(element_container); 21 var n = document.createElement('div'); 22 n.id = 'err_' + element_container; 23 n.className = 'std_error_box'; 24 n.innerHTML = txt; 25 e.appendChild(n); 26}; 27plongo.aux.setPV = function (ename, v) { 28 var d = window.parent.document; 29 var e = d.getElementById(ename); 30 e.value = v; 31}; 32plongo.aux.setPFH = function (ename) { 33 var d = document; 34 var e = window.parent.document; 35 if (!e) return; 36 var f = e.getElementById('object_' + ename); 37 if (f) f.height = d.body.offsetHeight; 38}; 39plongo.aux.clearError = function (element_container) { 40 var e = document.getElementById(element_container); 41 if (!e.hasChildNodes()) return; 42 var kids = e.childNodes; 43 for (var i = 0; i < kids.length; i++) { 44 if (kids[i].className === 'std_error_box') e.removeChild(kids[i]); 45 } 46}; 47plongo.aux.checkStdImg = function (e) { 48 var p = e.parentNode; 49 for (c in p.childNodes) { 50 var d = p.childNodes[c]; 51 if (plongo.aux.hasClass(d, 'std_imagebox_img')) { 52 plongo.aux.removeClass(d, 'std_imagebox_img_checked'); 53 } 54 } 55 plongo.aux.addClass(e, 'std_imagebox_img_checked'); 56}; 57plongo.aux.checkStdImgRadio = function (e) { 58 var p = e.parentNode; 59 for (c in p.childNodes) { 60 var d = p.childNodes[c]; 61 if (plongo.aux.hasClass(d, 'std_imagebox_img')) { 62 d.childNodes[2].checked = false; 63 plongo.aux.removeClass(d, 'std_imagebox_img_checked'); 64 } 65 } 66 e.childNodes[2].checked = true; 67 plongo.aux.addClass(e, 'std_imagebox_img_checked'); 68}; 69plongo.aux.checkStdImgBox = function (e) { 70 if (e.childNodes[2].checked === true) { 71 e.childNodes[2].checked = false; 72 plongo.aux.removeClass(e, 'std_imagebox_img_checked'); 73 } else { 74 e.childNodes[2].checked = true; 75 plongo.aux.addClass(e, 'std_imagebox_img_checked'); 76 } 77}; 78plongo.aux.tabClick = function (e) { 79 var t, p = e.parentNode; 80 for (c in p.childNodes) { 81 var d = p.childNodes[c]; 82 if (plongo.aux.hasClass(d, 'std_tab_item_active')) { 83 plongo.aux.removeClass(d, 'std_tab_item_active'); 84 t = document.getElementById('tab_div_' + d.id.substr(9)); 85 plongo.aux.removeClass(t, 'std_tab_div_active'); 86 } 87 } 88 plongo.aux.addClass(e, 'std_tab_item_active'); 89 t = document.getElementById('tab_div_' + e.id.substr(9)); 90 plongo.aux.addClass(t, 'std_tab_div_active'); 91}; 92plongo.aux.getInnerSize = function (e) { 93 var h = -1; 94 var w = -1; 95 if (e.innerHeight) { // valid only if it is the window 96 h = e.innerHeight; 97 w = e.innerWidth; 98 } else if (e.clientHeight) { 99 h = e.clientHeight; 100 w = e.clientWidth; 101 } 102 return { 103 'w': w, 104 'h': h 105 }; 106}; 107plongo.aux.getClientSize = function () { 108 var h = -1; 109 var w = -1; 110 if (navigator.userAgent.match(/(Silk)|(Android)/i)) { 111 h = window.innerHeight; 112 w = window.innerWidth; 113 } else if (window.innerHeight) { 114 h = window.innerHeight; 115 w = window.innerWidth; 116 //if (document.body) w = Math.min(window.innerWidth, document.body.clientWidth); 117 } else if (document.documentElement.clientHeight) { 118 h = document.documentElement.clientHeight; 119 w = document.documentElement.clientWidth; 120 } else if (document.body.clientHeight) { 121 h = document.body.clientHeight; 122 w = document.body.clientWidth; 123 } 124 return { 125 'w': w, 126 'h': h 127 }; 128}; 129plongo.aux.adjustHight = function (element_name, reduce, minsize) { 130 var e = document.getElementById(element_name); 131 var wh = plongo.aux.getClientSize(e); 132 var h = Math.max(minsize, wh[1] - reduce); 133 e.style.height = h + 'px'; 134}; 135plongo.aux.adjustWidth = function (element_name, reduce, minsize) { 136 var e = document.getElementById(element_name); 137 var wh = plongo.aux.getClientSize(e); 138 var h = Math.max(minsize, wh[0] - reduce); 139 e.style.width = h + 'px'; 140}; 141// onload 142plongo.aux.onload = function () { 143 // focus 144 var e = document.getElementById('search_top_query'); 145 if (e) { 146 if (e) e.onfocus = function () { 147 if (this.defaultValue === this.value) this.value = ''; 148 }; 149 } 150 // body general 151 e = document.getElementById('body_general'); 152 if (e) { 153 var wh = plongo.aux.getClientSize(); 154 e.style.marginLeft = Math.min(100, Math.max(0, wh[0] - 1200)) + 'px'; 155 } 156 window.onresize = c_onLoad; 157}; 158plongo.aux.doPreventDefault = function (event) { 159 event.preventDefault(); 160}; 161plongo.aux.addClass = function (e, c) { 162 if (e && e.nodeType !== 1) return; 163 plongo.aux.removeClass(e, c); 164 e.className = e.className + ' ' + c; 165}; 166plongo.aux.removeClass = function (e, c) { 167 if (e && e.nodeType !== 1) return; 168 var r = new RegExp('(^| +)' + c + '( +|$)', 'g'); 169 e.className = e.className.replace(r, ''); 170}; 171plongo.aux.hasClass = function (e, c) { 172 if (e && e.nodeType !== 1) return false;
173 var r = new RegExp('(^| +)' + c + '( +|$)', 'g'); 174 return e.className.match(r) === null ? false : true; 175}; 176plongo.aux.cp_tabtog_last = null; 177plongo.aux.cp_tabtog = function (m, t) { 178 var p = m.parentNode; 179 for (var c in p.childNodes) 180 plongo.aux.removeClass(p.childNodes[c], 'cp_tab_active'); 181 plongo.aux.addClass(m, 'cp_tab_active'); 182 var e = document.getElementById(t); 183 p = e.parentNode; 184 for (c in p.childNodes) 185 plongo.aux.removeClass(p.childNodes[c], 'cp_tab_show'); 186 plongo.aux.addClass(e, 'cp_tab_show'); 187}; 188plongo.aux.autocomplete = function (e, c) { 189 var d = document.getElementById('cp_autocomplete_box'); 190 if (!d) { 191 d = document.createElement('div'); 192 d.id = 'cp_autocomplete_box'; 193 e.parentNode.appendChild(d); 194 } 195 plongo.aux.autocomplete_caller = e; 196 ajax.setdiv(c, 'cp_autocomplete_box'); 197// if (plongo.aux.autocomplete.timer) clearTimeout(plongo.aux.autocomplete.timer); 198// plongo.aux.autocomplete.timer=setTimeout(function() { 199// 200// },2000); 201}; 202plongo.aux.autocompletedone = function () { 203 var d = document.getElementById('cp_autocomplete_box'); 204 if (d) { 205 plongo.aux.autocomplete_caller.parentNode.removeChild(d); 206 } 207 return plongo.aux.autocomplete_caller; 208}; 209// ajax 210plongo.ajax = function () { 211 this.create = function () { 212 var xmlhttp = null; 213 if (window.XMLHttpRequest) { 214 xmlhttp = new window.XMLHttpRequest; 215 } else { 216 alert('No XMLHttpRequest'); 217 } 218 return xmlhttp; 219 }; 220 this.xmlhttp = this.create(); 221 this.start = function () { 222 if (this.xmlhttp.readyState !== 0) { 223 this.xmlhttp.abort(); 224 //delete this.xmlhttp; 225 //this.xmlhttp=this.create(); 226 } 227 }; 228 this.send = function (req) { 229 this.xmlhttp.open("GET", req, true); 230 this.xmlhttp.send(''); 231 }; 232 this.call = function (req, fnDone) { 233 this.start(); 234 this.xmlhttp.onreadystatechange = function () { 235 if (this.readyState === 4) { 236 fnDone(this.responseText); 237 } 238 }; 239 this.send(req); 240 }; 241 this.setdiv = function (req, element_name) { 242 this.start(); 243 this.xmlhttp.onreadystatechange = function () { 244 if (this.readyState === 4) { 245 if (this.responseText.length > 0) { 246 var e = document.getElementById(element_name); 247 e.innerHTML = this.responseText; 248 } 249 } 250 }; 251 this.send(req); 252 }; 253 this.setinner = function (req, e) { 254 this.start(); 255 this.xmlhttp.onreadystatechange = function () { 256 if (this.readyState === 4) { 257 if (this.responseText.length > 0) { 258 e.innerHTML = this.responseText; 259 } 260 } 261 }; 262 this.send(req); 263 }; 264 this.rundiv = function (req, element_name, callback) { 265 this.start(); 266 this.xmlhttp.onreadystatechange = function () { 267 if (this.readyState === 4) { 268 if (this.responseText.length > 0) { 269 var e = document.getElementById(element_name); 270 e.innerHTML = this.responseText; 271 for (var i in e.childNodes) 272 if (e.childNodes[i].nodeType === 1 && e.childNodes[i].nodeName === 'SCRIPT') { 273 eval(e.childNodes[i].innerHTML); 274 } 275 if (callback) callback(e); 276 } 277 } 278 }; 279 this.send(req); 280 }; 281 this.eval = function (req) { 282 this.start(); 283 this.xmlhttp.onreadystatechange = function () { 284 if (this.readyState === 4) { 285 if (this.responseText.length > 0) { 286 eval(this.responseText); 287 } 288 } 289 }; 290 this.send(req); 291 }; 292 this.getsync = function (req) 293 { 294 this.xmlhttp.open("GET", req, false); 295 this.xmlhttp.send(''); 296 if (this.xmlhttp.status === 404) return false;
297 return this.xmlhttp.responseText; 298 }; 299 this.postsync = function (req, data, dtype) 300 { 301 this.xmlhttp.open("POST", req, false); 302 if (!dtype) dtype = "application/x-www-form-urlencoded"; 303 //this.xmlhttp.setRequestHeader("Cache-Control", "no-cache"); 304 this.xmlhttp.setRequestHeader("Content-type", dtype); 305 this.xmlhttp.send(data); 306 if (this.xmlhttp.status === 404) return false; 307 return this.xmlhttp.responseText; 308 }; 309 this.getAsync = function (req, handle) 310 { 311 this.start(); 312 this.xmlhttp.onreadystatechange = function () { 313 if (this.readyState === 4) { 314 if (this.responseText.length > 0) { 315 handle = this.responseText; 316 } 317 } 318 }; 319 this.send(req); 320 }; 321 this.postreq = function (req, fnDone, postdata) { 322 this.start(); 323 var p = this.xmlhttp; 324 p.onreadystatechange = function () { 325 if (p.readyState === 4) { 326 if (p.responseText.length > 0) { 327 if (fnDone) fnDone(p.responseText, p.status); 328 } 329 } 330 }; 331 p.open("POST", req, true); 332 p.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 333 p.send(postdata); 334 }; 335 this.postform = function (req, fnDone, myform) { 336 var data = ''; 337 var tx = ''; 338 for (var i = 0; i < myform.elements.length; i++) { 339 var e = myform.elements[i]; 340 if (e.name) { 341 if (e.type === 'checkbox' || e.type === 'radio') { 342 if (e.checked) { 343 data += tx + encodeURIComponent(e.name) + '=' + encodeURIComponent(e.value); 344 tx = '&'; 345 } 346 } else if (e.type === 'button' || e.type === 'submit') { 347 if (e.isclicked) 348 data += tx + encodeURIComponent(e.name) + '=1'; 349 } else { 350 data += tx + encodeURIComponent(e.name) + '=' + encodeURIComponent(e.value); 351 tx = '&'; 352 } 353 } 354 } 355 if (typeof f_submit_button !== 'undefined') 356 data += tx + f_submit_button + '=clicked'; 357 this.postreq(req, fnDone, data); 358 return false; 359 }; 360 this.getform = function (req, fnDone, myform) { 361 var data = ''; 362 var tx = ''; 363 for (var i = 0; i < myform.elements.length; i++) { 364 var e = myform.elements[i]; 365 if (e.name) { 366 if (e.type === 'checkbox' || e.type === 'radio') { 367 if (e.checked) { 368 data += tx + encodeURIComponent(e.name) + '=' + encodeURIComponent(e.value); 369 tx = '&'; 370 } 371 } else { 372 data += tx + encodeURIComponent(e.name) + '=' + encodeURIComponent(e.value); 373 tx = '&'; 374 } 375 } 376 } 377 if (typeof f_submit_button != 'undefined') 378 data += tx + f_submit_button + '=clicked'; 379 this.call(req + '?' + data, fnDone); 380 return false; 381 }; 382 return true; 383}; 384plongo.aux.fadeout = function () { 385 d = document.createElement('div'); 386 d.classname = 'cp_fadeout'; 387 d.style.height = window.outerHeight; 388 document.appendChild(d); 389 var opa = 0; 390 var to = window.setInterval(function () { 391 d.sytle.opacity = opa; 392 opa += 0.05; 393 if (opa > 1) window.clearInterval(to); 394 }, 5); 395}; 396plongo.aux.createCookie = function (name, value, days) { 397 if (days) { 398 var date = new Date(); 399 date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); 400 var expires = "; expires=" + date.toGMTString(); 401 } else var expires = ""; 402 document.cookie = name + "=" + value + expires + "; path=/"; 403}; 404plongo.aux.readCookie = function (name) { 405 var nameEQ = name + "="; 406 var ca = document.cookie.split(';'); 407 for (var i = 0; i < ca.length; i++) { 408 var c = ca[i]; 409 while (c.charAt(0) === ' ') 410 c = c.substring(1, c.length); 411 if (c.indexOf(nameEQ) === 0) 412 return c.substring(nameEQ.length, c.length); 413 } 414 return null; 415}; 416plongo.aux.eraseCookie = function (name) { 417 createCookie(name, "", -1); 418}; 419plongo.aux.animate = function (elem, how) { 420 if (!how.time) how.time = 200; 421 if (!how.step) how.step = 10; 422 if (!how.unit) how.unit = 'px'; 423 if (!elem.style[how.what]) alert('how.what ' + 'error'); 424 how.vs = parseInt(elem.style[how.what]); 425 how.delta = (how.to - how.vs) / (how.time / how.step); 426 var loop = function (elem, how) { 427 how.vs += how.delta; 428 elem.style[how.what] = how.vs + how.unit; 429 if ((how.vs < how.to && how.delta > 0) || (how.vs > how.to && how.delta < 0)) 430 window.setTimeout(function () { 431 loop(elem, how); 432 }, how.step); 433 }; 434 loop(elem, how); 435}; 436/* 437 * form processing 438 */ 439plongo.aux.form2obj = function (myform) { 440 var o = {}; 441 for (var i = 0; i < myform.elements.length; i++) { 442 var e = myform.elements[i]; 443 if (e.id) { 444 if (e.type === 'checkbox' || e.type === 'radio') { 445 o[e.id] = e.checked; 446 } else { 447 o[e.id] = e.value; 448 } 449 } 450 } 451 return o; 452}; 453plongo.aux.obj2form = function (myform, data) { 454 for (var n in data) { 455 var e = document.getElementById(n); 456 if (e) { 457 if (e.getAttribute && e.getAttribute('extra') === 'seldiv') { 458 plongo.aux.selDivByValue(e, data[n]); 459 } else if (e.type === 'checkbox' || e.type === 'radio') { 460 e.checked = data[n]; 461 } else { 462 e.value = data[n]; 463 } 464 } 465 } 466}; 467/* 468 * stack trace 469 */ 470plongo.aux.stack = function () { 471 var e = new Error('dummy'); 472 var stack = e.stack.replace(/^[^\(]+?[\n$]/gm, '') 473 .replace(/^\s+at\s+/gm, '') 474 .replace(/^Object.<anonymous>\s*\(/gm, '{anonymous}()@') 475 .split('\n'); 476 console.log(stack); 477}; 478/* 479 * strcmp 480 */ 481plongo.aux.strcmp = function (a, b) 482{ 483 var i = 0, l = Math.min(a.length, b.length); 484 var ia, ib; 485 while (i < l) { 486 ia = a.charCodeAt(i); 487 ib = b.charCodeAt(i); 488 if (ia < ib) return -1; 489 if (ia > ib) return 1; 490 i++; 491 } 492 if (a.length < b.length) return -1; 493 if (a.length > b.length) return 1; 494 return 0; 495}; 496 497plongo.aux.hexscape = function (s) { 498 var hex = ''; 499 for (var n = 0; n < s.length; n++) {
500 var c = s.charCodeAt(n); 501 if (c < 128) { 502 hex += ('0' + c.toString(16)).substr(-2); 503 } else if ((c > 127) && (c < 2048)) { 504 hex += ('0' + ((c >> 6) | 192).toString(16)).substr(-2); 505 hex += ('0' + ((c & 63) | 128).toString(16)).substr(-2); 506 } else { 507 hex += ('0' + ((c >> 12) | 224).toString(16)).substr(-2); 508 hex += ('0' + (((c >> 6) & 63) | 128).toString(16)).substr(-2); 509 hex += ('0' + ((c & 63) | 128).toString(16)).substr(-2); 510 } 511 } 512 return hex; 513}; 514 515function loadCanvas() { 516 var cv = document.getElementsByTagName('canvas'); 517 for (var i = 0; i < cv.length; i++) { 518 var can = cv[i]; 519 var src = can.getAttribute('src'); 520 if (src) { 521 var ii = new Image(); 522 ii.src = 'data:image/jpeg;base64,' + src; 523 ii.can = can; 524 ii.onload = function () { 525 var c = this.can; 526 c.width = this.naturalWidth; 527 c.height = this.naturalHeight; 528 c.draggable = false; 529 var ctx = c.getContext("2d"); 530 ctx.width = this.naturalWidth; 531 ctx.height = this.naturalHeight; 532 ctx.drawImage(this, 0, 0); 533// watermark 534// ctx.font = "20px Arial"; 535// ctx.fillText("www.unser-stadtplan.de", 1, 20); 536 }; 537 } 538 } 539} 540 541// tests 542plongo.aux.isIos = navigator.userAgent.match(/(iphone)|(ipad)|(ipod)/i) ? true : false; 543plongo.aux.isAndroid = navigator.userAgent.match(/(android)|(silk)/i) ? true : false; 544plongo.aux.isPhone = screen.width < 900; 545plongo.aux.isApp = !/safari/.test(navigator.userAgent) && !window.navigator.standalone; 546 547function getCookie(cname) { 548 let name = cname + "="; 549 let decodedCookie = decodeURIComponent(document.cookie); 550 let ca = decodedCookie.split(';'); 551 for (let i = 0; i < ca.length; i++) { 552 let c = ca[i]; 553 while (c.charAt(0) === ' ') { 554 c = c.substring(1); 555 } 556 if (c.indexOf(name) === 0) { 557 return c.substring(name.length, c.length); 558 } 559 } 560 return ""; 561} 562 563function toggle(a) { 564 var d = document.getElementById(a); 565 document.getElementById(a).classList.toggle('none'); 566} 567 568function fileUploader(inp, timgparam, url, action) { 569 570 var file = inp.files[0]; 571 572 const reader = new FileReader(); 573 const xhr = new XMLHttpRequest(); 574 575 xhr.upload.addEventListener("progress", function (e) { 576 if (e.lengthComputable) { 577 const percentage = Math.round((e.loaded * 100) / e.total); 578 inp.nextSibling.innerText = ` ${percentage} % `; 579 console.log(percentage, e); 580 if (percentage === 100) inp.nextSibling.innerText = ' Bitte warten '; 581 } 582 }, false); 583 584 xhr.addEventListener("load", function (evt) { 585 var resp = evt.target.response; 586 inp.nextSibling.innerText = 'X'; 587 inp.previousSibling.src = resp; // image 588 inp.value = null; 589 if (action) { 590 window[action](inp, evt.target.response); 591 } else { 592 if (!resp.startsWith('data:image')) inp.nextSibling.nextSibling.value = evt.target.response; 593 inp.previousSibling.src = evt.target.response; 594 } 595 }, false); 596 597 598 inp.previousSibling.src = '/stv-res/spinner.gif'; 599 600 xhr.open("POST", decodeURIComponent(url)); 601 xhr.setRequestHeader("Content-type", file.type); 602 xhr.setRequestHeader("X-imgparam", timgparam); 603 xhr.setRequestHeader("X-filename", encodeURIComponent(file.name)); 604 xhr.setRequestHeader("X-name", encodeURIComponent(inp.name)); 605 606 reader.onload = function (evt) { 607 console.log(evt.target.result.length); 608 xhr.send(evt.target.result); 609 }; 610 setTimeout(function () { 611 reader.readAsArrayBuffer(file); 612 }, 10); 613} 614 615var img = new Image(10, 10); 616img.src = '/stv-res/spinner.gif'; 617 618function resizeIframe(iframe) { 619 iframe.style.height = (50 + iframe.contentWindow.document.body.scrollHeight) + "px"; 620} 621 622function onPostMail(frm) { 623 console.log(event.isTrusted); 624 frm.ok.value = event.isTrusted ? (new Date()).getTime() / 1000 : 1; 625 return event.isTrusted; 626} 627 628function uuidv4() { 629 return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => 630 (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16) 631 ); 632} 633 634function sortTableByThis() { 635 // get data 636 var s = this._sort; 637 var thead = s.t.firstChild; 638 const [head, ...rows] = thead.children; 639 rows.sort((a, b) => { 640 var av = a.childNodes[s.i].innerText; 641 var bv = b.childNodes[s.i].innerText; 642 if (isNaN(av) || isNaN(bv)) { 643 return av.localeCompare(bv) * s.d; 644 } 645 return (av - bv) * s.d; 646 }); 647 while (thead.childNodes.length > 1) thead.removeChild(s.t.firstChild.lastChild); 648 for (var i = 0; i < rows.length; i++) thead.appendChild(rows[i]); 649 s.d = 0 - s.d; 650} 651 652function sortListTable(tid) { 653 // find header 654 var tbl = document.getElementById(tid); 655 var hdr = tbl.getElementsByTagName('TH'); 656 { 657 for (var i = 0; i < hdr.length; i++) { 658 var h = hdr[i]; 659 h.onclick = sortTableByThis; 660 h._sort = {i: i, t: tbl, d: 1}; 661 console.log(h); 662 } 663 } 664}
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.