Skip to content

Node.js based forum software built for the modern web

clean up client side + config.json

psychobunny1d35f369d997
diff --git a/public/config.json b/public/config.json
new file mode 100644
index 0000000000..e8f8030db9
--- /dev/null
+++ b/public/config.json
@@ -0,0 +1,6 @@
+{
+ "socket" : {
+ "address" : "198.199.80.41",
+ "port" : "8081"
+ }
+}
\ No newline at end of file
diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js
new file mode 100644
index 0000000000..c36334b48b
--- /dev/null
+++ b/public/src/ajaxify.js
@@ -0,0 +1,79 @@
+(function($) {
+
+ var rootUrl = document.location.protocol + '//' + (document.location.hostname || document.location.host) + (document.location.port ? ':'+document.location.port : ''),
+ content = null;
+
+
+ $('document').ready(function() {
+ if (!window.history || !window.history.pushState) return; // no ajaxification for old browsers
+
+ content = content || document.getElementById('content');
+
+ $('a').unbind('click').bind('click', function(ev) {
+ var url = this.href.replace(rootUrl +'/', '');
+ var tpl_url = (url === '') ? 'home' : url;
+
+ if (templates[tpl_url]) {
+ window.history.pushState({}, url, "/" + url);
+ content.innerHTML = templates[tpl_url];
+ exec_body_scripts(content);
+ }
+
+ ev.preventDefault();
+ return false;
+ });
+ });
+
+ function exec_body_scripts(body_el) {
+ //http://stackoverflow.com/questions/2592092/executing-script-elements-inserted-with-innerhtml
+ // Finds and executes scripts in a newly added element's body.
+ // Needed since innerHTML does not run scripts.
+ //
+ // Argument body_el is an element in the dom.
+
+ function nodeName(elem, name) {
+ return elem.nodeName && elem.nodeName.toUpperCase() ===
+ name.toUpperCase();
+ };
+
+ function evalScript(elem) {
+ var data = (elem.text || elem.textContent || elem.innerHTML || "" ),
+ head = document.getElementsByTagName("head")[0] ||
+ document.documentElement,
+ script = document.createElement("script");
+
+ script.type = "text/javascript";
+ try {
+ // doesn't work on ie...
+ script.appendChild(document.createTextNode(data));
+ } catch(e) {
+ // IE has funky script nodes
+ script.text = data;
+ }
+
+ head.insertBefore(script, head.firstChild);
+ head.removeChild(script);
+ };
+
+ // main section of function
+ var scripts = [],
+ script,
+ children_nodes = body_el.childNodes,
+ child,
+ i;
+
+ for (i = 0; children_nodes[i]; i++) {
+ child = children_nodes[i];
+ if (nodeName(child, "script" ) &&
+ (!child.type || child.type.toLowerCase() === "text/javascript")) {
+ scripts.push(child);
+ }
+ }
+
+ for (i = 0; scripts[i]; i++) {
+ script = scripts[i];
+ if (script.parentNode) {script.parentNode.removeChild(script);}
+ evalScript(scripts[i]);
+ }
+ };
+}(jQuery));
\ No newline at end of file
diff --git a/public/src/app.js b/public/src/app.js
new file mode 100644
index 0000000000..39563edad8
--- /dev/null
+++ b/public/src/app.js
@@ -0,0 +1,17 @@
+var socket,
+ config;
+
+(function() {
+
+ $.get('config.json?v=' + new Date().getTime(), function(data) {
+ config = data;
+ socket = io.connect('http://' + config.socket.address + config.socket.port? ':' + config.socket.port : '');
+
+ socket.on('event:connect', function(data) {
+
+ });
+
+ });
+
+
+}());
diff --git a/public/src/templates.js b/public/src/templates.js
new file mode 100644
index 0000000000..a62094fc8f
--- /dev/null
+++ b/public/src/templates.js
@@ -0,0 +1,19 @@
+var templates = {};
+
+function loadTemplates(templatesToLoad) {
+ var timestamp = new Date().getTime();
+
+ for (var t in templatesToLoad) {
+ (function(template) {
+ $.get('templates/' + template + '.tpl?v=' + timestamp, function(html) {
+ templates[template] = html;
+ });
+ }(templatesToLoad[t]));
+ }
+}
+
+function templates_init() {
+ loadTemplates(['register', 'home', 'login']);
+}
+
+templates_init();
\ No newline at end of file
diff --git a/public/templates/header.tpl b/public/templates/header.tpl
index 2dcfd5f10f..4982b4adc0 100644
--- a/public/templates/header.tpl
+++ b/public/templates/header.tpl
@@ -7,120 +7,14 @@
<script type="text/javascript" src="http://code.jquery.com/jquery.js"></script>
<script type="text/javascript" src="vendor/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="socket.io/socket.io.js"></script>
- <script type="text/javascript">
- (function($) {
- var templates = {};
-
- function loadTemplates(templatesToLoad) {
- var timestamp = new Date().getTime();
-
- for (var t in templatesToLoad) {
- (function(template) {
- $.get('templates/' + template + '.tpl?v=' + timestamp, function(html) {
- templates[template] = html;
- });
- }(templatesToLoad[t]));
- }
- }
-
- function templates_init() {
- loadTemplates(['register', 'home', 'login']);
- }
-
- templates_init();
-
- var rootUrl = document.location.protocol + '//' + (document.location.hostname || document.location.host) + (document.location.port ? ':'+document.location.port : ''),
- content = null;
- console.log(rootUrl);
- $('document').ready(function() {
- if (!window.history || !window.history.pushState) return; // no ajaxification for old browsers
-
-
- content = content || document.getElementById('content');
-
- $('a').unbind('click').bind('click', function(ev) {
- var url = this.href.replace(rootUrl +'/', '');
- var tpl_url = (url === '') ? 'home' : url;
-
- if (templates[tpl_url]) {
- window.history.pushState({}, url, "/" + url);
- content.innerHTML = templates[tpl_url];
- exec_body_scripts(content);
- }
-
- ev.preventDefault();
- return false;
- });
- });
-
- function exec_body_scripts(body_el) {
- //http://stackoverflow.com/questions/2592092/executing-script-elements-inserted-with-innerhtml
- // Finds and executes scripts in a newly added element's body.
- // Needed since innerHTML does not run scripts.
- //
- // Argument body_el is an element in the dom.
-
- function nodeName(elem, name) {
- return elem.nodeName && elem.nodeName.toUpperCase() ===
- name.toUpperCase();
- };
-
- function evalScript(elem) {
- var data = (elem.text || elem.textContent || elem.innerHTML || "" ),
- head = document.getElementsByTagName("head")[0] ||
- document.documentElement,
- script = document.createElement("script");
-
- script.type = "text/javascript";
- try {
- // doesn't work on ie...
- script.appendChild(document.createTextNode(data));
- } catch(e) {
- // IE has funky script nodes
- script.text = data;
- }
-
- head.insertBefore(script, head.firstChild);
- head.removeChild(script);
- };
-
- // main section of function
- var scripts = [],
- script,
- children_nodes = body_el.childNodes,
- child,
- i;
-
- for (i = 0; children_nodes[i]; i++) {
- child = children_nodes[i];
- if (nodeName(child, "script" ) &&
- (!child.type || child.type.toLowerCase() === "text/javascript")) {
- scripts.push(child);
- }
- }
-
- for (i = 0; scripts[i]; i++) {
- script = scripts[i];
- if (script.parentNode) {script.parentNode.removeChild(script);}
- evalScript(scripts[i]);
- }
- };
- }(jQuery));
- </script>
+ <script type="text/javascript" src="src/app.js"></script>
+ <script type="text/javascript" src="src/templates.js"></script>
+ <script type="text/javascript" src="src/ajaxify.js"></script>
<style type="text/css">
body {
padding-top: 60px;
}
</style>
- <script>
- var socket = io.connect('http://198.199.80.41:8081');
-
- socket.on('event:connect', function(data) {
-
- });
-
-
- </script>
</head>
<body>