/modules/mod_base/templates/comet_subdomain.tpl

http://github.com/zotonic/zotonic · Smarty Template · 68 lines · 64 code · 4 blank · 0 comment · 5 complexity · e83716495c25466a508c0f25c2a7c671 MD5 · raw file

  1. <html>
  2. <head>
  3. <meta name="robots" content="noindex, nofollow" />
  4. <title>Comet subdomain handler of: {{ m.site.title }} </title>
  5. </head>
  6. <body>
  7. {#
  8. See: http://fettig.net/weblog/2005/11/28/how-to-make-xmlhttprequest-connections-to-another-server-in-your-domain/
  9. http://fettig.net/playground/ajax-subdomain/test5-iframe.html
  10. #}
  11. {% include "_js_include_jquery.tpl" %}
  12. <script type="text/javascript">
  13. function get_poll_count()
  14. {
  15. var old_domain = document.domain;
  16. document.domain = "{{ m.site.document_domain }}";
  17. var ws_pong_count = window.parent.z_ws_pong_count;
  18. try {
  19. document.domain = old_domain;
  20. } catch (e) {
  21. }
  22. return ws_pong_count;
  23. }
  24. function handle_poll_data(data)
  25. {
  26. var old_domain = document.domain;
  27. try {
  28. document.domain = "{{ m.site.document_domain }}";
  29. window.parent.z_comet_data(data);
  30. } catch (e) {
  31. if (window.console && window.console.log)
  32. window.console.log(e);
  33. }
  34. try {
  35. document.domain = old_domain;
  36. } catch (e) {
  37. }
  38. }
  39. function z_comet_poll_subdomain()
  40. {
  41. if (get_poll_count() === 0) {
  42. $.ajax({
  43. url: '/comet',
  44. type: 'post',
  45. data: "z_pageid={{ q.z_pageid|urlencode }}",
  46. dataType: 'text',
  47. success: function(data, textStatus)
  48. {
  49. handle_poll_data(data);
  50. setTimeout(function() { z_comet_poll_subdomain(); }, 500);
  51. },
  52. error: function(xmlHttpRequest, textStatus, errorThrown)
  53. {
  54. setTimeout(function() { z_comet_poll_subdomain(); }, 1000);
  55. }
  56. });
  57. } else {
  58. setTimeout(function() { z_comet_poll_subdomain(); }, 5000);
  59. }
  60. }
  61. z_comet_poll_subdomain();
  62. </script>
  63. </body>
  64. </html>