PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

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