funLib.prototype.debug.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. Array.prototype.remove = function(element) {
  2. for (var i = 0, n = 0; i < this.length; i++) {
  3. if (this[i] != element) {
  4. this[n++] = this[i];
  5. }
  6. }
  7. if (n < i)
  8. this.length -= 1;
  9. };
  10. Array.prototype.contains = function(element) {
  11. for (var i = 0; i < this.length; i++) {
  12. if (this[i] == element) {
  13. return true;
  14. }
  15. }
  16. return false;
  17. };
  18. Array.prototype.indexOfObj = function(objKey, objVal) {
  19. if (!objKey)
  20. return -1;
  21. for (var i = 0; i < this.length; i++) {
  22. var _obj = this[i];
  23. if (typeof _obj == 'object' && _obj["" + objKey + ""] == objVal) {
  24. return i;
  25. }
  26. }
  27. return -1;
  28. };
  29. Array.prototype.getObjElements = function(objKey, objVal) {
  30. var _elements = [];
  31. if (!objKey)
  32. return 'undefined';
  33. for (var i = 0; i < this.length; i++) {
  34. var _obj = this[i];
  35. if (typeof _obj == 'object' && _obj["" + objKey + ""] == objVal) {
  36. _elements.push(_obj);
  37. }
  38. }
  39. return _elements;
  40. };
  41. String.escape = function(A) {
  42. return A.replace(/('|\\)/g, "\\$1");
  43. };
  44. String.leftPad = function(D, B, C) {
  45. var A = new String(D);
  46. if (C === null || C === undefined || C === "") {
  47. C = " ";
  48. }
  49. while (A.length < B) {
  50. A = C + A;
  51. }
  52. return A;
  53. };
  54. String.format = function(B) {
  55. var A = Array.prototype.slice.call(arguments, 1);
  56. return B.replace(/\{(\d+)\}/g, function(C, D) {
  57. return A[D];
  58. });
  59. };
  60. String.prototype.toggle = function(B, A) {
  61. return this == B ? A : B;
  62. };
  63. String.prototype.trim = function() {
  64. return this.replace(/^\s+|\s+$/g, "");
  65. };
  66. String.prototype.endWith = function (str) {
  67. var _allLen = this.length;
  68. var _strLen = str.length;
  69. var _subLen = this.lastIndexOf(str);
  70. if (_allLen == (_subLen + _strLen)) {
  71. return true;
  72. }
  73. return false;
  74. };
  75. String.prototype.startWith = function(str){
  76. if(str == null || str == "" || this.length == 0 || str.length > this.length) {
  77. return false;
  78. }
  79. if(this.substr(0,str.length) == str) {
  80. return true;
  81. }
  82. return false;
  83. };
  84. //remove comma from number string
  85. String.prototype.rawNum = function(){
  86. return this.replace(/,/g,"");
  87. };
  88. //extend window.showModalDialog
  89. var _smd = window.showModalDialog;
  90. window.showModalDialog = function(sURL, vArguments, sFeatures){
  91. var rv = _smd(sURL, vArguments, sFeatures);
  92. if(typeof rv == "undefined" || typeof rv.errorFlag == "undefined"){
  93. return rv;
  94. } else {
  95. if (typeof window.dialogArguments == "undefined") {
  96. window.top.location.href = "userlogout.action";
  97. } else {
  98. var _rv = new Object();
  99. _rv.errorFlag = true;
  100. window.returnValue = _rv;
  101. window.close();
  102. }
  103. }
  104. };