/upload/themes/default/js/overall.js

https://github.com/txdv/psychostats · JavaScript · 130 lines · 92 code · 20 blank · 18 comment · 21 complexity · 01a1bb70dc9fb1460ab6d78acf6f4895 MD5 · raw file

  1. // jquery.xml2json.js
  2. (function($){$.extend({xml2json:xml2json});function xml2json(xml,root){var o={};$(root==undefined?'response':root,xml).children().each(function(){o[this.tagName]=$(this).text()});return o}})(jQuery);
  3. // When the page is loaded this is automatically called
  4. var ps_popups = new Array();
  5. var ps_popup_delay = 0.25;
  6. $(document).ready(function() {
  7. // setup handlers for the overall login/search popups
  8. $('#ps-login-link').click(function(e){ return ps_overall_popup('login'); });
  9. $('#ps-search-link').click(function(e){ return ps_overall_popup('search'); });
  10. $('#ps-login-link, #ps-login-popup, #ps-search-link, #ps-search-popup').hover(stop_popup_timer, start_popup_timer);
  11. // setup handlers for frame collapse/expand divs
  12. $('div.ps-column-frame, div.ps-table-frame').not('.no-ani').each(function(i) {
  13. var frame = this;
  14. // on the frame 'header' apply the onClick handler
  15. $('div.ps-column-header, div.ps-frame-header', this).click(function() {
  16. ps_header_handler(this, frame, null, 'slow');
  17. });
  18. });
  19. // global ajax status animations
  20. $('#ajax-status').ajaxStart(ajax_start);
  21. $('#ajax-status').ajaxStop(ajax_stop);
  22. // automatically add an mouseover/out for table rows ...
  23. $(".ps-table tr:gt(0)").mouseover(function() {$(this).addClass("over");}).mouseout(function() {$(this).removeClass("over");});
  24. // language handler
  25. $('select.language').change(function(){
  26. this.form.submit();
  27. });
  28. });
  29. // popup variables
  30. var active_popup = null;
  31. var timeout_popup = null;
  32. var timeout_seconds = 1.0;
  33. function ps_overall_popup(label) {
  34. var popup = $('#ps-' + label + '-popup');
  35. var img = $('#ps-' + label + '-img');
  36. var o = img.offset({ scroll: false });
  37. var y = img.height() + o.top + 1;
  38. var x = Math.floor(img.width() / 2 + o.left) - popup.width() + 20;
  39. if (active_popup) {
  40. if (active_popup.attr('id') != popup.attr('id')) {
  41. close_popup();
  42. } else {
  43. close_popup();
  44. return false;
  45. }
  46. }
  47. active_popup = popup;
  48. popup.css({ top: y, left: x });
  49. popup.fadeIn('fast', function(){ $('input:text', popup).focus() });
  50. // popup.slideToggle('fast', function(){ $('input:text', popup).focus() });
  51. // popup.toggle();
  52. // $('input:text', popup).focus();
  53. return false;
  54. }
  55. function close_popup() {
  56. if (!active_popup) return;
  57. // active_popup.slideUp('fast', stop_popup_timer);
  58. active_popup.fadeOut('fast');
  59. active_popup = null;
  60. timeout_popup = null;
  61. }
  62. function start_popup_timer() {
  63. if (!active_popup) return;
  64. if (timeout_popup) stop_popup_timer();
  65. timeout_popup = setTimeout('close_popup()', timeout_seconds * 1000);
  66. }
  67. function stop_popup_timer() {
  68. if (timeout_popup) clearTimeout(timeout_popup);
  69. timeout_popup = null;
  70. }
  71. // frame animation handler
  72. function ps_header_handler(header, frame, display, speed) {
  73. var hdr = $(header);
  74. var f = $(frame);
  75. var content = hdr.next();
  76. var span = $('span', hdr);
  77. var visible = content.is(":visible");
  78. if (display == null) display = !visible;
  79. if (display == visible) return; // nothing to do
  80. // update the icon in the header based on the new display state
  81. // the image filename must end in 'minus' or 'plus'.
  82. var img = span.css('backgroundImage');
  83. if (img.indexOf('minus') != -1) {
  84. img = img.replace(/minus/, 'plus');
  85. } else if (img.indexOf('plus') != -1) {
  86. img = img.replace(/plus/, 'minus');
  87. }
  88. span.css('backgroundImage', img);
  89. // toggle the display of the content
  90. if (speed) {
  91. display ? content.slideDown(speed) : content.slideUp(speed);
  92. } else {
  93. display ? content.show() : content.hide();
  94. }
  95. // update the users session
  96. var id = content.attr('id');
  97. if (id) {
  98. $.post('opt.php', { shade: id, closed: display ? 0 : 1 });
  99. }
  100. }
  101. var ajax_stopped = true;
  102. function ajax_start() {
  103. if (!ajax_stopped) return;
  104. ajax_stopped = false;
  105. $(this).fadeIn('fast');
  106. }
  107. function ajax_stop() {
  108. ajax_stopped = true;
  109. $(this).fadeOut('fast');
  110. }