register.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <script>
  2. function position_overlay(target){
  3. var win_w = $(window).width();
  4. var w = target.width();
  5. if(w < win_w){
  6. var expected_left = (win_w - w) / 2;
  7. var ofs = new Object();
  8. ofs.left = expected_left;
  9. ofs.top = 50;
  10. target.offset(ofs);
  11. }else{
  12. var ofs = new Object();
  13. ofs.left = 5;
  14. ofs.top = 30;
  15. target.offset(ofs);
  16. }
  17. }
  18. function load_overlay(target, url, on_load, on_commit){
  19. $.get(url, {}, function(data){
  20. target.html(data);
  21. overlay_actions(target, url, on_commit);
  22. on_load(target);
  23. position_overlay(target.closest("div.overlay"));
  24. });
  25. }
  26. function overlay_actions(obj, target_url, on_commit){
  27. var overlay = obj.closest(".overlay");
  28. var parent_div = overlay.parent();
  29. overlay.find(".overlay-close").click(function(event){
  30. event.preventDefault();
  31. remove_overlay(parent_div);
  32. });
  33. overlay.find(".overlay-commit").click(function(event){
  34. if(on_commit){
  35. on_commit(obj);
  36. event.preventDefault();
  37. remove_overlay(parent_div);
  38. }else{
  39. remove_overlay(parent_div);
  40. }
  41. });
  42. obj.find("form").each(function(){
  43. var ac = $(this).attr("action");
  44. if (!ac){
  45. $(this).attr("action", target_url);
  46. }
  47. });
  48. if(on_commit){
  49. obj.find('form[method="post"]').submit(function(event){
  50. event.preventDefault();
  51. on_commit(obj);
  52. remove_overlay(parent_div);
  53. });
  54. obj.find('form:not([method="post"])').ajaxForm(function(data){
  55. if(data){
  56. obj.html(data);
  57. overlay_actions(obj, target_url, on_commit);
  58. }else{
  59. remove_overlay(parent_div);
  60. }
  61. });
  62. }else{
  63. obj.find("form").ajaxForm(function(data){
  64. if(data){
  65. obj.html(data);
  66. }else{
  67. remove_overlay(parent_div);
  68. }
  69. });
  70. }
  71. }
  72. function remove_overlay(obj){
  73. var dt_div = obj.parent().closest("div.data");
  74. if(dt_div.children("div").children(".must_reload").length > 0){
  75. var reload_url = dt_div.children("a.reload").attr("href");
  76. $.get(reload_url, function(data){
  77. var o = dt_div.children("div.reload-here");
  78. o.html(data);
  79. overlay_actions(o, reload_url, false);
  80. obj.remove();
  81. });
  82. }else{
  83. obj.remove();
  84. }
  85. }
  86. function show_overlay(target_url, source, on_commit){
  87. var overlay_text = "{{ overlay_text }}";
  88. var o = $("<div/>").html(overlay_text);
  89. load_overlay(o.find(".overlay-data"), target_url, function(){
  90. source.closest("div.data").append(o);
  91. }, on_commit);
  92. }
  93. $(document).ready(function(){
  94. $("body").on("click", "a.better-in-overlay", function(event){
  95. if (!event.isDefaultPrevented()){
  96. event.preventDefault();
  97. var href=$(this).attr("href");
  98. show_overlay(href, $(this), false);
  99. }
  100. });
  101. $("body").on("click", "a:not(.better-in-overlay):not(.overlay-close):not(.overlay-commit):not(.interaction)", function(event){
  102. if (!event.isDefaultPrevented()){
  103. var href=$(this).attr("href");
  104. var p = $(this).closest("div.reload-here")
  105. if (p.length > 0){
  106. event.preventDefault();
  107. load_overlay(p, href, function(){}, false);
  108. }
  109. }
  110. });
  111. });
  112. </script>