base.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. Author: mg12
  3. Update: 2008/05/05
  4. Author URI: http://www.neoease.com/
  5. */
  6. (function() {
  7. function $(id) {
  8. return document.getElementById(id);
  9. }
  10. function setStyleDisplay(id, status) {
  11. $(id).style.display = status;
  12. }
  13. function goTop(a, t) {
  14. a = a || 0.1;
  15. t = t || 16;
  16. var x1 = 0;
  17. var y1 = 0;
  18. var x2 = 0;
  19. var y2 = 0;
  20. var x3 = 0;
  21. var y3 = 0;
  22. if (document.documentElement) {
  23. x1 = document.documentElement.scrollLeft || 0;
  24. y1 = document.documentElement.scrollTop || 0;
  25. }
  26. if (document.body) {
  27. x2 = document.body.scrollLeft || 0;
  28. y2 = document.body.scrollTop || 0;
  29. }
  30. var x3 = window.scrollX || 0;
  31. var y3 = window.scrollY || 0;
  32. var x = Math.max(x1, Math.max(x2, x3));
  33. var y = Math.max(y1, Math.max(y2, y3));
  34. var speed = 1 + a;
  35. window.scrollTo(Math.floor(x / speed), Math.floor(y / speed));
  36. if(x > 0 || y > 0) {
  37. var f = "MGJS.goTop(" + a + ", " + t + ")";
  38. window.setTimeout(f, t);
  39. }
  40. }
  41. function switchTab(showPanels, hidePanels, activeTab, activeClass, fadeTab, fadeClass) {
  42. $(activeTab).className = activeClass;
  43. $(fadeTab).className = fadeClass;
  44. var panel, panelList;
  45. panelList = showPanels.split(',');
  46. for (var i = 0; i < panelList.length; i++) {
  47. var panel = panelList[i];
  48. if ($(panel)) {
  49. setStyleDisplay(panel, 'block');
  50. }
  51. }
  52. panelList = hidePanels.split(',');
  53. for (var i = 0; i < panelList.length; i++) {
  54. panel = panelList[i];
  55. if ($(panel)) {
  56. setStyleDisplay(panel, 'none');
  57. }
  58. }
  59. }
  60. function loadCommentShortcut() {
  61. $('comment').onkeydown = function (moz_ev) {
  62. var ev = null;
  63. if (window.event){
  64. ev = window.event;
  65. } else {
  66. ev = moz_ev;
  67. }
  68. if (ev != null && ev.ctrlKey && ev.keyCode == 13) {
  69. $('submit').click();
  70. }
  71. }
  72. $('submit').value += ' (Ctrl+Enter)';
  73. }
  74. function getElementsByClassName(className, tag, parent) {
  75. parent = parent || document;
  76. var allTags = (tag == '*' && parent.all) ? parent.all : parent.getElementsByTagName(tag);
  77. var matchingElements = new Array();
  78. className = className.replace(/\-/g, '\\-');
  79. var regex = new RegExp('(^|\\s)' + className + '(\\s|$)');
  80. var element;
  81. for (var i = 0; i < allTags.length; i++) {
  82. element = allTags[i];
  83. if (regex.test(element.className)) {
  84. matchingElements.push(element);
  85. }
  86. }
  87. return matchingElements;
  88. }
  89. window['MGJS'] = {};
  90. window['MGJS']['$'] = $;
  91. window['MGJS']['setStyleDisplay'] = setStyleDisplay;
  92. window['MGJS']['goTop'] = goTop;
  93. window['MGJS']['switchTab'] = switchTab;
  94. window['MGJS']['loadCommentShortcut'] = loadCommentShortcut;
  95. window['MGJS']['getElementsByClassName'] = getElementsByClassName;
  96. })();