javascript.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. function Navigate(url) {
  2. window.location = url;
  3. }
  4. function CreateCookie(name, value, days) {
  5. var expires;
  6. if (days) {
  7. var date = new Date();
  8. date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
  9. expires = "; expires=" + date.toGMTString();
  10. }
  11. else {
  12. expires = "";
  13. }
  14. document.cookie = name + "=" + value + expires + "; path=/";
  15. }
  16. function round(value, decimals) {
  17. return Number(Math.round(value + 'e' + decimals) + 'e-' + decimals);
  18. }
  19. function isNumber(value){
  20. return isFinite(String(value));
  21. }
  22. String.prototype.upperCaseFirst = function() {
  23. var lower = this.toLowerCase();
  24. return lower.charAt(0).toUpperCase() + lower.slice(1);
  25. };
  26. function twoDigitZeroPad(input){
  27. input=input.toString();
  28. return [!input[1] && '0' || "", input].join('');
  29. }
  30. Date.prototype.oldToString = Date.prototype.toString;
  31. Date.prototype.toString = function(format) {
  32. if (!format)
  33. return this.oldToString();
  34. var me=this;
  35. return format.replace(/./g, function(match) {
  36. switch(match){
  37. case 'd': return twoDigitZeroPad(me.getDate());
  38. case 'm': return twoDigitZeroPad(me.getMonth()+1);
  39. case 'y': return me.getFullYear();
  40. case "H": return twoDigitZeroPad(me.getHours());
  41. case "i": return twoDigitZeroPad(me.getMinutes());
  42. case "s": return twoDigitZeroPad(me.getSeconds());
  43. default: return match;
  44. }
  45. });
  46. };
  47. Number.prototype.oldToString=Number.prototype.toString;
  48. Number.prototype.toString=function(input, shouldRound){
  49. if (!shouldRound)
  50. return this.oldToString(input);
  51. return round(this, input);
  52. };
  53. $(function() {
  54. var panels = $("nav > dl > .sub-pages");
  55. var goIndicators = $("nav > dl > dt .go");
  56. var expandIndicators = $("nav > dl > dt .expand");
  57. panels.hide();
  58. expandIndicators.show();
  59. $("nav > dl > dt").click(function(e) {
  60. var next = $(this).next();
  61. if (!next.hasClass("sub-pages")) {
  62. Navigate($(this).children("a").attr("href"));
  63. return;
  64. }
  65. panels.slideUp();
  66. goIndicators.hide();
  67. expandIndicators.show();
  68. if (next.is(":visible")) {
  69. return;
  70. }
  71. next.slideDown();
  72. $(this).children(".go").show();
  73. $(this).children(".expand").hide();
  74. });
  75. $("nav dd").click(function(e) {
  76. Navigate($(this).children("a").attr("href"));
  77. });
  78. $("nav a").click(function(e) {
  79. $(this).parent().click();
  80. return false;
  81. });
  82. $("#body").css("padding-bottom", window.innerHeight - $("#buttons-right").offset().top);
  83. $("form[ajaxForm]").submit(function(e) {
  84. e.preventDefault();
  85. form = $(this);
  86. $.ajax({
  87. url: form.attr("action"),
  88. method: form.attr("method"),
  89. data: form.serialize(),
  90. success: function(data) {
  91. var successFunction = form.attr("onsuccess");
  92. if (successFunction !== undefined && window[successFunction] !== undefined)
  93. window[successFunction](data);
  94. },
  95. error: function() {
  96. var errorFunction = form.attr("onerror");
  97. if (errorFunction !== undefined && window[errorFunction] !== undefined)
  98. window[errorFunction]();
  99. },
  100. });
  101. var postFunction = form.attr("onpost");
  102. if (postFunction !== undefined && window[postFunction] !== undefined)
  103. window[postFunction]();
  104. });
  105. $("td").each(function() {
  106. var elem = $(this);
  107. if (/^[+-]?\d+(\.\d+)?$/.test(elem.text())) {
  108. elem.addClass("number");
  109. }
  110. });
  111. });
  112. $(document).delegate('.allowTabInput', 'keydown', function(e) {
  113. var keyCode = e.keyCode || e.which;
  114. console.log(e);
  115. if (keyCode == 9) {
  116. e.preventDefault();
  117. var start = $(this).get(0).selectionStart;
  118. var end = $(this).get(0).selectionEnd;
  119. // set textarea value to: text before caret + tab + text after caret
  120. $(this).val($(this).val().substring(0, start)
  121. + "\t"
  122. + $(this).val().substring(end));
  123. // put caret at right position again
  124. $(this).get(0).selectionStart =
  125. $(this).get(0).selectionEnd = start + 1;
  126. }
  127. });