Changeset 631 for trunk/phpbms/common
- Timestamp:
- 08/03/09 13:06:33 (3 years ago)
- Files:
-
- 1 modified
-
trunk/phpbms/common/javascript/common.js (modified) (55 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/phpbms/common/javascript/common.js
r422 r631 66 66 67 67 loadXMLDoc: function(url,readyStateFunction,async) { 68 68 69 69 if(!readyStateFunction) 70 70 readyStateFunction= null; 71 71 72 72 if(!async) 73 73 async = false; 74 74 75 75 // branch for native XMLHttpRequest object 76 76 if (window.XMLHttpRequest) { … … 90 90 } 91 91 },//end function loadXMLDoc 92 92 93 93 nameFunctions: function (namespace) { 94 94 var base = namespace.NAME; … … 109 109 } 110 110 },//endfunction 111 112 111 112 113 113 htmlDecode: function(string){ 114 114 … … 122 122 123 123 reportError: function(error){ 124 124 125 125 if(console){ 126 126 if(console.log) … … 128 128 } else 129 129 alert(error); 130 130 131 131 }//end method - reportError 132 132 … … 145 145 146 146 var all = module.EXPORT; 147 147 148 148 for (var i = 0; i < all.length; i++) { 149 149 globals[all[i]] = module[all[i]]; … … 153 153 phpBMS.base.__new__ = function () { 154 154 var m = this; 155 155 156 156 m.nameFunctions(this); 157 157 } … … 167 167 168 168 phpBMS.base.update(phpBMS.dom, { 169 169 170 170 getObjectFromID: function(id){ 171 171 var theObject; 172 172 173 173 if(document.getElementById) 174 174 theObject=document.getElementById(id); … … 177 177 return theObject; 178 178 },//end method 179 180 179 180 181 181 getElementsByClassName: function(clsName){ 182 182 var retVal = new Array(); … … 194 194 } 195 195 return retVal; 196 }//endMethod 197 196 }//endMethod 197 198 198 })//end update 199 199 … … 206 206 this._document = document; 207 207 this._window = win; 208 208 209 209 m.nameFunctions(this); 210 210 } … … 228 228 229 229 phpBMS.base.update(phpBMS.signal.e.prototype,{ 230 230 231 231 src: function () { 232 232 return this._src; … … 255 255 return undefined; 256 256 }, 257 257 258 258 stop: function () { 259 259 this.stopPropagation(); … … 276 276 } 277 277 } 278 278 279 279 })//end subclass 280 280 … … 288 288 if(observers[i][0] == obj && observers[i][1] == eventName) 289 289 return observers[i]; 290 290 291 291 return false; 292 292 293 293 },//end method 294 294 … … 297 297 var self = phpBMS.signal; 298 298 var observers = self._observers; 299 299 300 300 for (var i = 0; i < observers.length; i++) { 301 301 self._disconnect(observers[i]); 302 302 } 303 303 304 304 delete self._observers; 305 305 306 306 try { 307 307 window.onload = undefined; … … 315 315 // pass 316 316 } 317 317 318 318 },//end method 319 319 … … 321 321 _listener: function(srcObj, func){ 322 322 var E = phpBMS.signal.e; 323 323 324 324 if(!srcObj || !func){ 325 325 326 326 reportError("ListnerError srcObj:" + srcObj + " func:" + func); 327 327 return false; 328 328 329 329 }//endif 330 330 331 331 return function (nativeEvent) { 332 332 return func.apply(srcObj, [new E(srcObj, nativeEvent)]); … … 336 336 337 337 connect: function(srcObj, eventName, func){ 338 338 339 339 if(!srcObj || !eventName || !func){ 340 340 341 341 var err = "Invalid Entry for connect: srcObj:" + srcObj + " eventName:" + eventName + " func:" + func 342 reportError(err); 343 342 reportError(err); 343 344 344 return false; 345 346 }//endif 347 345 346 }//endif 347 348 348 var self = phpBMS.signal; 349 349 350 350 var listener = self._listener(srcObj, func); 351 351 352 352 if (srcObj.addEventListener) { 353 353 srcObj.addEventListener(eventName.substr(2), listener, false); … … 355 355 srcObj.attachEvent(eventName, listener); // useCapture unsupported 356 356 }//end if 357 357 358 358 var ident = [srcObj, eventName, listener]; 359 359 self._observers.push(ident); 360 360 return ident; 361 361 362 362 }, 363 363 … … 373 373 } else if (src.detachEvent) { 374 374 src.detachEvent(sig, listener); // useCapture unsupported 375 } 375 } 376 376 }, 377 377 … … 380 380 var self = phpBMS.signal; 381 381 var observers = self._observers; 382 382 383 383 for (var i = 0; i < observers.length; i++) { 384 384 var pident = observers[i]; … … 395 395 396 396 trigger: function(src, sig){ 397 397 398 398 var self = phpBMS.signal; 399 399 var observers = self._observers; … … 410 410 }//endif 411 411 }//endfor 412 412 413 413 }//end method - signal 414 414 415 415 })//end class 416 416 … … 446 446 // php equivilant to htmlEntitties 447 447 String.prototype.htmlEntities = function() 448 { 448 { 449 449 newString = this; 450 450 var chars = new Array(); … … 461 461 myRegExp = new RegExp(); 462 462 myRegExp.compile(chars[i],'g'); 463 463 464 464 newString = newString.replace (myRegExp, '&#' + chars[i].charCodeAt(0) + ';'); 465 465 } 466 466 467 467 return newString; 468 468 } … … 477 477 offsetTrail = offsetTrail.offsetParent; 478 478 } 479 if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined") 479 if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined") 480 480 offsetLeft += document.body.TopMargin; 481 481 return offsetTop; … … 490 490 offsetTrail = offsetTrail.offsetParent; 491 491 } 492 if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined") 492 if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined") 493 493 offsetLeft += document.body.leftMargin; 494 494 return offsetLeft; … … 502 502 if(theObj.childNodes[i].offsetHeight) 503 503 totalHeight+=theObj.childNodes[i].offsetHeight; 504 return totalHeight; 504 return totalHeight; 505 505 } 506 506 … … 512 512 } 513 513 if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight; 514 if (document.body) return document.body.clientHeight; 515 return window.undefined; 514 if (document.body) return document.body.clientHeight; 515 return window.undefined; 516 516 } 517 517 function getViewportWidth() { … … 521 521 //return i; 522 522 } 523 if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 524 if (document.body) return document.body.clientWidth; 525 return window.undefined; 523 if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 524 if (document.body) return document.body.clientWidth; 525 return window.undefined; 526 526 } 527 527 … … 533 533 tempButton=getObjectFromID("saveButton2"); 534 534 if(tempButton) 535 tempButton.disabled=true; 536 } 537 538 539 function setLoginRefresh(){ 535 tempButton.disabled=true; 536 } 537 538 539 function setLoginRefresh(){ 540 540 window.setInterval(doRefresh,(LOGIN_REFRESH*60*1000)); 541 541 } … … 623 623 if(!format) format=DATE_FORMAT; 624 624 var sdate=""; 625 625 626 626 if(thedate){ 627 627 var sep; … … 630 630 switch(format){ 631 631 case "SQL": 632 sep="-"; 632 sep="-"; 633 633 month=thedate.getMonth()+1; 634 634 if(month<10) month="0"+month; 635 635 day=thedate.getDate(); 636 if(day<10) day="0"+day; 636 if(day<10) day="0"+day; 637 637 sdate= thedate.getFullYear()+sep+month+sep+day; 638 638 break; 639 639 640 640 case "English, US": 641 641 sep="/"; … … 643 643 if(month<10) month="0"+month; 644 644 day=thedate.getDate(); 645 if(day<10) day="0"+day; 645 if(day<10) day="0"+day; 646 646 sdate= month+sep+day+sep+thedate.getFullYear(); 647 647 break; 648 648 649 649 case "English, UK": 650 650 sep="/"; … … 652 652 if(month<10) month="0"+month; 653 653 day=thedate.getDate(); 654 if(day<10) day="0"+day; 654 if(day<10) day="0"+day; 655 655 sdate= day+sep+month+sep+thedate.getFullYear(); 656 656 break; 657 657 658 658 case "Dutch, NL": 659 659 sep="-"; … … 661 661 if(month<10) month="0"+month; 662 662 day=thedate.getDate(); 663 if(day<10) day="0"+day; 663 if(day<10) day="0"+day; 664 664 sdate= day+sep+month+sep+thedate.getFullYear(); 665 665 break; … … 680 680 thetime=new Date(0,0,0,parseInt(timeArray[0],10),parseInt(timeArray[1],10),parseInt(timeArray[2],10)); 681 681 break; 682 682 683 683 case "12 Hour": 684 684 timeadd=0; … … 690 690 if(timeArray.length==2){ 691 691 var hour=parseInt(timeArray[0],10); 692 if(hour==12) hour=0; 692 if(hour==12) hour=0; 693 693 hour=hour+timeadd; 694 695 thetime=new Date(0,0,0,hour,parseInt(timeArray[1],10)); 694 695 thetime=new Date(0,0,0,hour,parseInt(timeArray[1],10)); 696 696 } 697 697 break; … … 716 716 sTime=hours+sep+minutes+sep+seconds; 717 717 break; 718 718 719 719 case "12 Hour": 720 720 var ampm=" AM"; … … 724 724 hours=hours-12; 725 725 if (hours==0) hours=12; 726 if(minutes<10) minutes="0"+minutes; 726 if(minutes<10) minutes="0"+minutes; 727 727 sTime=""+hours+sep+minutes+ampm; 728 728 break; … … 734 734 /* ----------------------------------------------------------------------------- */ 735 735 function roundForCurrency(number){ 736 736 737 737 return Math.round( number * Math.pow(10,CURRENCY_ACCURACY) ) / Math.pow(10,CURRENCY_ACCURACY); 738 738 739 739 } 740 740 741 741 742 742 function numberToCurrency(number){ 743 743 744 744 var currency=""; 745 745 746 746 if(isNaN(parseFloat(number))) number=0; 747 747 … … 751 751 number = Math.abs(number); 752 752 currency += CURRENCY_SYM; 753 753 754 754 if(number>0 && number <0) 755 755 currency+="0"; … … 757 757 var lessthanone = Math.round( (number-parseInt(number)) * (Math.pow(10,CURRENCY_ACCURACY)) ); 758 758 number = parseInt(number); 759 759 760 760 if(lessthanone >= Math.pow(10,CURRENCY_ACCURACY)){ 761 761 762 762 number++; 763 763 764 764 lessthanone -= Math.pow(10,CURRENCY_ACCURACY); 765 765 766 766 }//end if 767 767 768 768 lessthanone = lessthanone.toString() 769 769 770 770 while(lessthanone.length<CURRENCY_ACCURACY) 771 lessthanone = "0" + lessthanone; 771 lessthanone = "0" + lessthanone; 772 772 773 773 var withThousands = parseInt(number).toString(); … … 776 776 while(objRegExp.test(withThousands)) 777 777 withThousands = withThousands.replace(objRegExp, '$1'+THOUSANDS_SEPARATOR+'$2'); 778 778 779 779 currency+=withThousands; 780 780 781 781 if(CURRENCY_ACCURACY!=0) 782 782 currency+=DECIMAL_SYMBOL+lessthanone; 783 783 784 784 return currency; 785 785 786 786 } 787 787 … … 820 820 } 821 821 showModal.box.width="400px"; 822 822 823 823 var tempDiv=document.createElement("div"); 824 824 tempDiv.id="modalTitle"; … … 840 840 showModal.maskFade.setOpacity(0); 841 841 document.body.appendChild(showModal.mask); 842 842 843 843 showModal.boxFade.setOpacity(0); 844 844 document.body.appendChild(showModal.box); 845 845 846 846 showModal.maskFade.custom(0,0.7); 847 847 848 848 centerModal(); 849 849 850 850 showModal.listeners =[ 851 851 connect(window,"onresize",centerModal), 852 connect(window,"onscroll",centerModal) 852 connect(window,"onscroll",centerModal) 853 853 ] 854 854 } … … 863 863 for(var i=0; i<showModal.listeners.length; i++) 864 864 disconnect(showModal.listeners[i]) 865 865 866 866 document.body.removeChild(showModal.mask); 867 867 document.body.removeChild(showModal.box); … … 870 870 871 871 delete showModal.mask; 872 delete showModal.box; 872 delete showModal.box; 873 873 } 874 874 … … 878 878 var fullHeight = getViewportHeight(); 879 879 var fullWidth = getViewportWidth(); 880 880 881 881 var theBody = document.documentElement; 882 882 883 883 var scTop = parseInt(theBody.scrollTop,10); 884 884 var scLeft = parseInt(theBody.scrollLeft,10); 885 885 886 886 showModal.mask.style.height = fullHeight + "px"; 887 887 showModal.mask.style.width = fullWidth + "px"; … … 890 890 if(window.innerHeight!=window.undefined){ 891 891 if(showModal.mask.scrollWidth>fullWidth) 892 showModal.mask.style.height=(fullHeight-20)+"px"; 892 showModal.mask.style.height=(fullHeight-20)+"px"; 893 893 if(document.body.scrollHeight>fullHeight) 894 894 showModal.mask.style.width=(fullWidth-20)+"px"; … … 899 899 } 900 900 901 function hideSelectBoxes() { 901 function hideSelectBoxes() { 902 902 if (typeof document.body.style.maxHeight == "undefined") { 903 903 for(var i = 0; i < document.all.length; i++) { 904 904 if(document.all[i].tagName) 905 if(document.all[i].tagName == "SELECT") 905 if(document.all[i].tagName == "SELECT") 906 906 document.all[i].style.visibility="hidden"; 907 907 } 908 } 908 } 909 909 } 910 910 function displaySelectBoxes() { … … 919 919 920 920 function modalAlert(text){ 921 921 922 922 text=""+text; 923 923 text.replace("\n","<br />"); 924 924 text+="<DIV align=\"right\"><button id=\"modalOK\" accesskey=\"o\" type=\"button\" class=\"Buttons\" onclick=\"closeModal()\" style=\"width:75px\"> ok </button></DIV>"; 925 925 showModal(text,"Alert",250); 926 926 927 927 var okButton = getObjectFromID("modalOK"); 928 928 try{ … … 933 933 } 934 934 935 /* JS Equivalents to PHP Functions --------------------- */ 936 /* ----------------------------------------------------- */ 937 function dirname(path) { 938 // Returns the directory name component of the path 939 // 940 // version: 810.114 941 // discuss at: http://phpjs.org/functions/dirname 942 // + original by: Ozh 943 // + improved by: XoraX (http://www.xorax.info) 944 // * example 1: dirname('/etc/passwd'); 945 // * returns 1: '/etc' 946 // * example 2: dirname('c:/Temp/x'); 947 // * returns 2: 'c:/Temp' 948 // * example 3: dirname('/dir/test/'); 949 // * returns 3: '/dir' 950 951 return path.replace(/\\/g,'/').replace(/\/[^\/]*\/?$/, ''); 952 } 953 954 function basename(path, suffix) { 955 // Returns the filename component of the path 956 // 957 // version: 812.316 958 // discuss at: http://phpjs.org/functions/basename 959 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) 960 // + improved by: Ash Searle (http://hexmen.com/blog/) 961 // + improved by: Lincoln Ramsay 962 // + improved by: djmix 963 // * example 1: basename('/www/site/home.htm', '.htm'); 964 // * returns 1: 'home' 965 var b = path.replace(/^.*[\/\\]/g, ''); 966 967 if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) { 968 b = b.substr(0, b.length-suffix.length); 969 } 970 971 return b; 972 } 973 974 935 975 /* Function Overloads and Extensions --------------------- */ 936 976 /* ------------------------------------------------------- */ … … 950 990 951 991 spinner = new Image; 952 spinner.src = APP_PATH+"common/image/spinner.gif"; 953 954 } 955 956 957 958 992 spinner.src = APP_PATH+"common/image/spinner.gif"; 993 994 } 995 996 997 998 959 999 })//end listner