From d36a81966a53d58fd830322f8b3036c60fb08110 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Fri, 24 May 2013 23:02:13 -0400 Subject: [PATCH] use ajaxify to load 404 (prevents weird refreshing bug); part 1 of client side refactor: moving all template javascript vars into dom; templates.get, templates.set for dynamic variables populated via tpls --- public/src/templates.js | 22 ++++++++++++++++++---- public/templates/account.tpl | 8 ++++++-- public/templates/accountedit.tpl | 7 +++++-- public/templates/category.tpl | 7 +++++-- public/templates/friends.tpl | 11 +++++++---- public/templates/reset_code.tpl | 9 +++++++-- public/templates/topic.tpl | 31 ++++++++++++++++++++----------- public/templates/users.tpl | 4 ---- 8 files changed, 68 insertions(+), 31 deletions(-) diff --git a/public/src/templates.js b/public/src/templates.js index 34b8784be6..b3ea78105c 100644 --- a/public/src/templates.js +++ b/public/src/templates.js @@ -5,7 +5,8 @@ var config = {}, templates, fs = null, - available_templates = []; + available_templates = [], + parsed_variables = {}; module.exports = templates = {}; @@ -153,8 +154,8 @@ (function() { jQuery.get(API_URL + api_url, function(data) { - if(!data) { - window.location.href = '/404'; + if(data === false) { + ajaxify.go('404'); return; } @@ -168,12 +169,25 @@ if (!templates[tpl_url] || !template_data) return; document.getElementById('content').innerHTML = templates[tpl_url].parse(JSON.parse(template_data)); - if (callback) callback(true); + + jQuery('#content [template-variable]').each(function(index, element) { + templates.set(element.getAttribute('template-variable'), element.value); + }); + + if (callback) { + callback(true); + } } } + templates.get = function(key) { + return parsed_variables[key]; + } + templates.set = function(key, value) { + parsed_variables[key] = value; + } //modified from https://github.com/psychobunny/dcp.templates var parse = function(data) { diff --git a/public/templates/account.tpl b/public/templates/account.tpl index b04c8572f6..f269317b50 100644 --- a/public/templates/account.tpl +++ b/public/templates/account.tpl @@ -69,12 +69,16 @@
+ + + +