1//------------------------------------------------------------------------ 2// Written by Ray Wilson 3// Copyright Music From Outer Space LLC 2010. 4// https://www.musicfromouterspace.com/mfosweb/home.action 5// Mini-Browser Independent DOM API 6// Utility Object Pack. 7// Javascript DEBUGGER 8// Author: Ray Wilson 11-2010 9//---------------------------------------------------------------- 10var mozilla = document.getElementById && !document.all; 11var ie = document.all; 12var chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1; 13 14function validString(s) 15{ 16 return (s && s.trim().length > 0); 17} 18 19function IsRightButtonClicked(e) // e : mouse event 20{ 21 var rightclick = false; 22 e = e || window.event; 23 if (e.which) 24 { 25 rightclick = (e.which == 3); 26 } 27 else if (e.button) 28 { 29 rightclick = (e.button == 2); 30 } 31 return rightclick; 32} 33 34function disableSelection(target) 35{ 36 if (typeof target.onselectstart!="undefined") 37 { 38 // IE 39 target.onselectstart=function(){return false;}; 40 } 41 else if (typeof target.style.MozUserSelect!="undefined") 42 { 43 // Firefox 44 target.style.MozUserSelect="none"; 45 } 46 else 47 { 48 // Others... 49 target.onmousedown=function(){return false;}; 50 } 51 target.style.cursor = "default"; 52} 53 54// --------------------------------------------------- 55// Load a script on demand. 56// Example usage: loadscript("myscript.js"); 57// --------------------------------------------------- 58var GLOBAL_SCRIPTSLOADED = []; 59function loadscript(scriptsrc, callback) 60{ 61 if(scriptloaded(scriptsrc)) 62 { 63 callback(); 64 return; 65 } 66 67 var fileref = document.createElement('script'); 68 if(typeof fileref!="undefined") 69 { 70 GLOBAL_SCRIPTSLOADED.push(scriptsrc); 71 } 72 73 fileref.setAttribute("type","text/javascript"); 74 fileref.setAttribute("src", scriptsrc); 75 if(document.all && callback) 76 { 77 fileref.onreadystatechange = function() 78 { 79 if (fileref.readyState == 'loaded' || fileref.readyState == 'complete') 80 { 81 fileref.onreadystatechange = ""; 82 callback(); 83 } 84 }; 85 } 86 else 87 { 88 fileref.onload = (callback || function(){return;}); 89 } 90 document.getElementsByTagName("head")[0].appendChild(fileref); 91 92 //------------------------------------------------------------ 93 // Uncomment to see post script add innerHTML of the HEAD tag. 94 //------------------------------------------------------------ 95 /* 96 DEBUGWRITE(document.getElementsByTagName("head")[0].innerHTML); 97 */ 98 99} 100 101function scriptloaded(scriptsrc) 102{ 103 for(var i=0; i<GLOBAL_SCRIPTSLOADED.length; ++i) 104 { 105 if(GLOBAL_SCRIPTSLOADED[i] == scriptsrc) 106 return true; 107 } 108 return false; 109} 110 111function getValidString(m) 112{ 113 return (m && (m.length > 0) && (m != "EMPTY")) ? m : ""; 114} 115 116function isSupportedBrowser() 117{ 118 return (ie || mozilla || chrome); 119} 120 121function has_scrollbar(elem) 122{ 123 return (elem.clientHeight < elem.scrollHeight); 124} 125 126function hasChildren(elem) 127{ 128 return elem.hasChildNodes(); 129} 130 131function getElementParent(elem) 132{ 133 return (mozilla) ? elem.parentNode : elem.parentElement; 134} 135 136function getElementChildren(elem) 137{ 138 return (mozilla) ? elem.childNodes : elem.children; 139} 140 141function setElementAttribute(elem, attname, attvalue) 142{ 143 elem.setAttribute(attname, attvalue); 144} 145 146function getElementAttribute(elem, attname) 147{ 148 if(elem.hasAttribute || elem.attributes) 149 { 150 if(mozilla) 151 { 152 if(elem.hasAttribute(attname)) 153 { 154 return elem.getAttribute(attname); 155 } 156 } 157 else 158 { 159 if(elem.attributes[attname]) 160 { 161 return elem.attributes[attname].value; 162 } 163 } 164 } 165 return null; 166} 167 168function getEvent(e) 169{ 170 if(!e) 171 { 172 return window.event; 173 } 174 return e; 175} 176 177// --------------------------------------- 178// e MUST BE AN EVENT ALREADY. 179// e = getEvent(e) ALREADY CALLED. 180// --------------------------------------- 181function stopEventBubble(e) 182{ 183 if (mozilla) 184 { 185 e.stopPropagation(); 186 if(e.preventDefault) 187 { 188 e.preventDefault(); 189 } 190 } 191 else if (ie) 192 { 193 e.cancelBubble = true; 194 e.returnValue = false; 195 } 196} 197 198function getEventSource(e) 199{ 200 return (mozilla) ? e.target : e.srcElement; 201} 202 203//-------------------------------------------------------- 204// 205// 206// BINDING AND ADDING EVENT LISTENER CODE. 207// 208// 209//-------------------------------------------------------- 210Function.prototype.bindEventListenerWithArgs = function (object) { 211 var method = this; 212 var oldArguments = pseudoArrayToArray(arguments).slice(1); 213 return function (e) {return method.apply(object, [e || window.event].concat(oldArguments));}; 214}; 215 216Function.prototype.bind = function(object){ 217 var method = this; 218 return function(){method.apply(object, arguments);}; 219}; 220 221Function.prototype.bindEventListener = function(object){ 222 var method = this; 223 return function(event){method.call(object, event || window.event);}; 224}; 225 226function pseudoArrayToArray(pseudoArray) 227{ 228 var result = []; 229 for (var i = 0; i < pseudoArray.length; i++) 230 { 231 result.push(pseudoArray[i]); 232 } 233 return result; 234} 235
236function addEvent(obj, evType, fn) 237{ 238 239 if(obj && obj.addEventListener) 240 { 241 obj.addEventListener(evType, fn, false); 242 return true; 243 } 244 else if (obj && obj.attachEvent) 245 { 246 var r = obj.attachEvent("on"+evType, fn); 247 return r; 248 } 249 else 250 { 251 return false; 252 } 253} 254function removeEvent(obj, evType, fn, useCapture) 255{ 256 if (obj.removeEventListener) 257 { 258 obj.removeEventListener(evType, fn, useCapture); 259 return true; 260 } 261 else if (obj.detachEvent) 262 { 263 var r = obj.detachEvent("on"+evType, fn); 264 return r; 265 } 266 else 267 { 268 return false; 269 } 270} 271 272function ignorethis(e) 273{ 274 e = getEvent(e); 275 var target = getEventSource(e); 276 stopEventBubble(e); 277 return false; 278} 279 280function getViewportHeight() 281{ 282 if (window.innerHeight!=window.undefined) 283 return window.innerHeight; 284 if (document.compatMode=='CSS1Compat') 285 return document.documentElement.clientHeight; 286 if (document.body) 287 return document.body.clientHeight; 288 289 return window.undefined; 290} 291 292function getViewportWidth() { 293 var offset = 17; 294 var width = null; 295 if (window.innerWidth!=window.undefined) 296 return window.innerWidth; 297 if (document.compatMode=='CSS1Compat') 298 return document.documentElement.clientWidth; 299 if (document.body) 300 return document.body.clientWidth; 301} 302 303function getScrollTop() 304{ 305 if (self.pageYOffset) 306 { 307 return self.pageYOffset; 308 } 309 else if (document.documentElement && document.documentElement.scrollTop) 310 { 311 return document.documentElement.scrollTop; 312 } 313 else if (document.body) 314 { 315 return document.body.scrollTop; 316 } 317} 318 319function getScrollLeft() 320{ 321 if (self.pageXOffset) 322 { 323 return self.pageXOffset; 324 } 325 else if (document.documentElement && document.documentElement.scrollLeft) 326 { 327 return document.documentElement.scrollLeft; 328 } 329 else if (document.body) 330 { 331 return document.body.scrollLeft; 332 } 333} 334 335function getUpperLeftPoint(o) 336{ 337 return new Point(getPosition_LEFT(o), getPosition_TOP(o)); 338} 339 340function getPosition_LEFT(htmlObj) 341{ 342 var iLeftPixel = 0; 343 while ( htmlObj != null ) 344 { 345 iLeftPixel += htmlObj.offsetLeft; 346 htmlObj = htmlObj.offsetParent; 347 } 348 return iLeftPixel; 349} 350 351function getPosition_TOP(htmlObj) 352{ 353 var iTopPixel = 0; 354 while ( htmlObj != null ) 355 { 356 iTopPixel += htmlObj.offsetTop; 357 htmlObj = htmlObj.offsetParent; 358 } 359 return iTopPixel; 360} 361 362function getNewId() 363{ 364 var alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 365 var nums = "1234567890"; 366 var newid = ""; 367 for(var i=0; i<16; ++i) 368 { 369 newid += alpha.charAt(Math.floor(Math.random() * alpha.length)); 370 newid += nums.charAt(Math.floor(Math.random() * nums.length)); 371 } 372 return newid; 373} 374 375// ******************************************** 376// Point object 377// ******************************************** 378function Point(x,y) 379{ 380 this.x = parseInt(x); 381 this.y = parseInt(y); 382} 383Point.prototype.toString = function() 384{ 385 return this.x + "," + this.y; 386}; 387Point.prototype.myToString = function() 388{ 389 return "X:" + this.x + ",Y:" + this.y; 390}; 391Point.prototype.isEqual = function(pt) 392{ 393 return (this.x == pt.x && this.y == pt.y); 394}; 395 396// ******************************************** 397// Size object 398// ******************************************** 399function Size(width, height) 400{ 401 this.width = width; 402 this.height = height; 403} 404Point.prototype.toString = function() 405{ 406 return this.width + ',' + this.height; 407}; 408Point.prototype.isEqual = function(sz) 409{ 410 return (this.width == sz.width && this.height == sz.height); 411}; 412 413// ******************************************** 414// ArrayList object 415// ******************************************** 416function ArrayList() 417{ 418 this.data = new Array(); 419} 420ArrayList.prototype.empty = function() 421{ 422 for(var i=0;i<this.data.length; ++i) 423 { 424 this.data[i] = null; 425 } 426 this.data.length = 0; 427}; 428ArrayList.prototype.size = function() 429{ 430 return this.data.length; 431}; 432ArrayList.prototype.add = function(o) 433{ 434 var m = this.data.length + 1; 435 this.data.length = m; 436 this.data[m-1] = o; 437}; 438ArrayList.prototype.get = function(i) 439{ 440 if(i >= 0 && i < this.data.length) 441 { 442 return this.data[i]; 443 } 444 return null; 445}; 446ArrayList.prototype.pop = function() 447{ 448 if(this.data.length > 0) 449 { 450 return this.data.pop(); 451 } 452 return null; 453}; 454 455// ----------------------------------------------------------------------------------------- 456// Remove an object reference from the ArrayList and return the removed object 457// reference. 458// ----------------------------------------------------------------------------------------- 459ArrayList.prototype.remove = function(obj) 460{ 461 var objref = null; 462 var len = this.data.length - 1; 463 for(var i=0; i<this.data.length; ++i) 464 { 465 if(obj === this.data[i]) 466 { 467 objref = this.data[i]; 468 for(var m=i; m<len; ++m) 469 { 470 this.data[m] = this.data[m + 1]; 471 } 472 this.data.length = len; 473 break; 474 } 475 } 476 return objref; 477}; 478 479// ******************************************** 480// RowCol object 481// ******************************************** 482function RowCol(row, col) 483{ 484 this.row = row; 485 this.col = col; 486} 487RowCol.prototype.toString = function() 488{ 489 return 'row=' + this.row + ', col=' + this.col; 490}; 491RowCol.prototype.isEqual = function(rc) 492{ 493 return (this.row == rc.row && this.col == rc.col); 494}; 495 496 497// ******************************************** 498// Rectangle object 499// ******************************************** 500function Rectangle(x, y, width, height) 501{ 502 this.x = x; 503 this.y = y; 504 this.width = parseInt(width); 505 this.height = parseInt(height); 506} 507Rectangle.fromDomObject = function(o) 508{ 509 var x = parseInt(getIntegers(o.style.left)); 510 var y = parseInt(getIntegers(o.style.top)); 511 var w = parseInt(getIntegers(o.style.width)); 512 var h = parseInt(getIntegers(o.style.height)); 513 514 return new Rectangle(x, y, w, h); 515}; 516Rectangle.prototype.toString = function() 517{ 518 return this.x + ',' + this.y + ',' + this.width + ',' + this.height; 519}; 520Rectangle.prototype.containsPoint = function(pt) 521{ 522 return pt.x >= this.x && pt.x <= (this.x + this.width) && pt.y >= this.y && pt.y <= (this.y + this.height); 523}; 524 525 526// ******************************************** 527// String trim 528// ******************************************** 529String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); }; 530 531// ******************************************** 532// StringBuffer object 533// ******************************************** 534function StringBuffer() 535{ 536 this.buffer = []; 537} 538StringBuffer.prototype.append = function(s) 539{ 540 this.buffer.push(s); 541}; 542StringBuffer.prototype.toString = function() 543{ 544 return this.buffer.join(""); 545}; 546StringBuffer.prototype.clear = function() 547{ 548 this.buffer.length = 0; 549}; 550StringBuffer.prototype.getLength = function() 551{ 552 return this.buffer.length; 553}; 554 555// --------------------------------------- 556// Return any of "0123456789" found in s
557// --------------------------------------- 558function getIntegers(s) 559{ 560 var m = ""; 561 for(var i=0; i<s.length; ++i) 562 { 563 if("0123456789".indexOf(s.charAt(i)) < 0) 564 { 565 continue; 566 } 567 m += s.charAt(i); 568 } 569 return m; 570} 571 572function getInternetExplorerVersion() 573{ 574 var rv = -1; 575 if (navigator.appName == 'Microsoft Internet Explorer') 576 { 577 var ua = navigator.userAgent; 578 var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); 579 if (re.exec(ua) != null) 580 { 581 rv = parseFloat( RegExp.$1 ); 582 } 583 } 584 return rv; 585} 586 587var MFOS_DEBUGWINDOW = null; 588function DEBUGWRITE(debugstring) 589{ 590 try 591 { 592 if(MFOS_DEBUGWINDOW) 593 { 594 MFOS_DEBUGWINDOW.showMessage(debugstring); 595 } 596 else 597 { 598 var htmlArray = new Array(); 599 htmlArray.push("<html>"); 600 htmlArray.push("<head>"); 601 htmlArray.push("<title>MFOS Debug Window</title>"); 602 htmlArray.push("<style type='text/css'>"); 603 htmlArray.push(".btn {border:1px solid #999999;font-size:8pt;font-family:Verdana;}"); 604 htmlArray.push("body {background-color:#DDDDDD; margin:0px;}"); 605 htmlArray.push("td {font-size:8pt;font-family:Verdana;}"); 606 htmlArray.push("</style>"); 607 htmlArray.push("<scr" + "ipt type='text/javascript'>"); 608 htmlArray.push("function showMessage(msg)"); 609 htmlArray.push("{"); 610 htmlArray.push(" var debugtext = document.getElementById('DEBUGTEXT');"); 611 htmlArray.push(" if(!document.getElementById('RUN').checked)"); 612 htmlArray.push(" return;"); 613 htmlArray.push(" var content = msg;"); 614 htmlArray.push(" var txtNode = document.createTextNode(content);"); 615 htmlArray.push(" var brNode = document.createElement('br');"); 616 htmlArray.push(" if(!document.getElementById('APPEND').checked)"); 617 htmlArray.push(" {"); 618 htmlArray.push(" debugtext.innerHTML = \"\";"); 619 htmlArray.push(" }"); 620 htmlArray.push(" debugtext.appendChild(txtNode);"); 621 htmlArray.push(" debugtext.appendChild(brNode);"); 622 htmlArray.push(" debugtext.scrollTop = debugtext.scrollHeight;"); 623 htmlArray.push("}"); 624 htmlArray.push("</scr" + "ipt>"); 625 htmlArray.push("</head>"); 626 htmlArray.push("<body>"); 627 htmlArray.push("<table style='width:100%;height:90%' cellpadding='5' cellspacing='0' border='0'>"); 628 htmlArray.push("<tr>"); 629 htmlArray.push("<td>"); 630 htmlArray.push("<div ID='DEBUGTEXT' style='border:solid 1px black;background-color:white;height:500px;width:100%;font-family:Courier New;font-size:8pt;overflow:auto;color:black;'></div>"); 631 htmlArray.push("</td>"); 632 htmlArray.push("</tr>"); 633 htmlArray.push("<tr style='height:24px;background-color:#DDDDDD;'><td>"); 634 htmlArray.push("<table><tr>"); 635 htmlArray.push("<td><input class='btn' type='BUTTON' value=' Clear ' onclick='document.getElementById(\"DEBUGTEXT\").innerHTML=\"\";'></td>"); 636 htmlArray.push("<td><input CHECKED type='CHECKBOX' id='RUN'></td>"); 637 htmlArray.push("<td>Active</td>"); 638 htmlArray.push("<td><input CHECKED type='CHECKBOX' id='APPEND'></td>"); 639 htmlArray.push("<td>Append</td>"); 640 htmlArray.push("</tr></table>"); 641 htmlArray.push("</td></tr>"); 642 htmlArray.push("</table>"); 643 htmlArray.push("</body>"); 644 htmlArray.push("</html>"); 645 646 MFOS_DEBUGWINDOW = window.open("", "DEBUGGER", "width=350,height=560,resizable",false); 647 MFOS_DEBUGWINDOW.document.open(); 648 MFOS_DEBUGWINDOW.document.write(htmlArray.join("\n")); 649 MFOS_DEBUGWINDOW.document.close(); 650 651 MFOS_DEBUGWINDOW.showMessage(debugstring); 652 } 653 } 654 catch(e) 655 { 656 MFOS_DEBUGWINDOW = null; 657 } 658} 659 660function getHTMLFragmentFromServer(url, clickTarget) 661{ 662 var req; 663 if(mozilla) 664 { 665 req = new XMLHttpRequest(); 666 } 667 else 668 { 669 req = new ActiveXObject("Microsoft.XMLHTTP"); 670 } 671 req.open('GET', url, true); 672 req.onreadystatechange = function () { 673 if (req.readyState == 4) 674 { 675 if(req.status == 200) 676 { 677 var htmlString = req.responseText; 678 insertHTMLAfterElement(clickTarget, htmlString); 679 postHTMLInsert(clickTarget); 680 } 681 else 682 { 683 alert("Method getHTMLFragmentFromServer failed."); 684 } 685 } 686 }; 687 req.send(null); 688} 689 690function insertHTMLAfterElement(clickTarget, htmlString) 691{ 692 if(mozilla) 693 { 694 var parent = getElementParent(clickTarget); 695 var range = document.createRange(); 696 range.selectNode(parent); 697 var documentFragment = range.createContextualFragment(htmlString); 698 parent.appendChild(documentFragment); 699 } 700 else 701 { 702 getElementParent(clickTarget).insertAdjacentHTML("BeforeEnd", htmlString); 703 } 704} 705 706function parseQueryString() 707{ 708 var queryString = new Object(); 709 var qs = self.location.search; 710 if(qs.charAt(0) == "?") 711 { 712 qs = qs.substring(1); 713 } 714 if (qs.length == 0) 715 { 716 return queryString; 717 } 718 qs = qs.replace(/\+/g, ' '); 719 var args = qs.split('&'); 720 for (var i=0; i<args.length; ++i) 721 { 722 var value; 723 var pair = args[i].split('='); 724 var name = unescape(pair[0]); 725 if (pair.length == 2) 726 { 727 value = unescape(pair[1]); 728 } 729 else 730 { 731 value = name; 732 } 733 queryString[name] = value; 734 } 735 return queryString; 736} 737 738 739/******************************************************************************* 740 * Cookie code from QuirksMode.org Personal site of Peter-Paul Koch 741 * http://www.quirksmode.org 742 ******************************************************************************/ 743function createCookie(name, value, days) 744{ 745 var expires; 746 if (days) 747 { 748 var date = new Date(); 749 date.setTime(date.getTime()+(days*24*60*60*1000)); 750 expires = "; expires="+date.toGMTString(); 751 } 752 else 753 { 754 expires = ""; 755 } 756 document.cookie = name+"="+value+expires+"; path=/"; 757} 758 759function getCookieOrDefault(cookiename, defaultvalue) 760{ 761 var cookievalue = readCookie(cookiename); 762 if(cookievalue) 763 { 764 if(cookievalue.length > 0) 765 { 766 return cookievalue; 767 } 768 } 769 return defaultvalue; 770} 771 772function readCookie(name) 773{ 774 var nameEQ = name + "="; 775 var ca = document.cookie.split(';'); 776 for(var i=0;i < ca.length;i++) 777 { 778 var c = ca[i]; 779 while (c.charAt(0)==' ') 780 { 781 c = c.substring(1,c.length); 782 } 783 if (c.indexOf(nameEQ) == 0) 784 { 785 return c.substring(nameEQ.length,c.length); 786 } 787 } 788 return null; 789} 790
791function eraseCookie(name) 792{ 793 createCookie(name,"",-1); 794} 795 796function contact(subj) 797{ 798 var href = "mailto:" + 799 "raywilson" + 800 "@" + 801 "musicfromouterspace" + 802 "." + 803 "com"; 804 805 if(subj != "") 806 { 807 subj = subj.replace(/ /g,"%20"); 808 href += "?subject=" + subj; 809 } 810 document.location.href = href; 811} 812 813// ------------------------------------------------------------------ 814// Adjust the centerElement's top and left so that it is centered 815// in the BODY element. 816// If vertOffset and/or horzOffset are present add them to the 817// top and left respectively. 818// ------------------------------------------------------------------ 819function centerElementInBody(centerElement, vertOffset, horzOffset) 820{ 821 vOffset = 0; 822 hOffset = 0; 823 if(arguments.length == 3) 824 { 825 vOffset = vertOffset; 826 hOffset = horzOffset; 827 } 828 else if(arguments.length == 2) 829 { 830 vOffset = vertOffset; 831 } 832 if(centerElement) 833 { 834 var width = centerElement.offsetWidth; 835 var height = centerElement.offsetHeight; 836 var theBody = document.getElementsByTagName("BODY")[0]; 837 var scTop = parseInt(getScrollTop(),10); 838 var scLeft = parseInt(theBody.scrollLeft,10); 839 var fullHeight = getViewportHeight(); 840 var fullWidth = getViewportWidth(); 841 centerElement.style.top = (scTop + ((fullHeight - height) / 2) + vOffset) + "px"; 842 centerElement.style.left = (scLeft + ((fullWidth - width) / 2) + hOffset) + "px"; 843 } 844} 845 846function setBodyMaskSize(maskElement) 847{ 848 var theBody = document.getElementsByTagName("BODY")[0]; 849 var maskHigh = (getViewportHeight() > theBody.scrollHeight) ? getViewportHeight() : theBody.scrollHeight; 850 var maskWide = (getViewportWidth() > theBody.scrollWidth) ? getViewportWidth() : theBody.scrollWidth; 851 maskElement.style.height = maskHigh + "px"; 852 maskElement.style.width = maskWide + "px"; 853} 854 855// ------------------------------------------------------------------ 856// Adjust the centerElement's top and left so that 857// it is centered in the targetElement. 858// ------------------------------------------------------------------ 859function centerElementInElement(centerElement, targetElement) 860{ 861 var cRect = Rectangle.fromDomObject(centerElement); 862 var tRect = Rectangle.fromDomObject(targetElement); 863 var newL = tRect.x + ((tRect.width - cRect.width)/2); 864 var newT = tRect.y + ((tRect.height - cRect.height)/2); 865 centerElement.style.left = newL + "px"; 866 centerElement.style.top = newT + "px"; 867} 868
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.