From 31e845f4b025e2fc5e566f5d6915efce79bf27ab Mon Sep 17 00:00:00 2001 From: psychobunny Date: Wed, 8 May 2013 16:33:29 +0000 Subject: [PATCH] added regex matching to templates/ajaxify. needs cleanup, just unblocking baris --- public/src/ajaxify.js | 3 ++- public/src/templates.js | 23 ++++++++++++++--------- public/templates/config.json | 1 + 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index 9423be6c23..4bb3b76f94 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -31,8 +31,9 @@ var ajaxify = {}; app.enter_room('global'); var url = url.replace(/\/$/, ""); - var tpl_url = (url === '' || url === '/') ? 'home' : url.split('/')[0]; tpl_url = templates.get_custom_map(tpl_url); + var tpl_url = (url === '' || url === '/') ? 'home' : url.split('/')[0]; + if (templates[tpl_url]) { window.history.pushState({}, url, "/" + url); diff --git a/public/src/templates.js b/public/src/templates.js index e2e374c18e..ca9a721c4b 100644 --- a/public/src/templates.js +++ b/public/src/templates.js @@ -5,7 +5,15 @@ var templates = {}; config = {}; templates.get_custom_map = function(tpl) { - return (config['custom_mapping'] && config['custom_mapping'][tpl]) ? config['custom_mapping'][tpl] : tpl; + if (config['custom_mapping'] && tpl) { + for (var pattern in config['custom_mapping']) { + console.log(pattern); + if (tpl.match(pattern)) { + return (config['custom_mapping'][pattern]); + } + } + } + return false; } templates.ready = function(callback) { @@ -156,18 +164,15 @@ function load_template(callback, custom_tpl) { jQuery.get(API_URL + url, function(data) { - - var splits = url.split('/'); - var tpl = url; - - if(splits.length) { - tpl = splits[0]; - tpl = templates.get_custom_map(tpl); + var tpl = templates.get_custom_map(url); + if (tpl == false) { + tpl = url.split('/')[0]; } if (custom_tpl && custom_tpl != "undefined") tpl = custom_tpl; - + + document.getElementById('content').innerHTML = templates[tpl].parse(JSON.parse(data)); if (callback) callback(); }); diff --git a/public/templates/config.json b/public/templates/config.json index 78bf9e0551..8d23609092 100644 --- a/public/templates/config.json +++ b/public/templates/config.json @@ -1,5 +1,6 @@ { "custom_mapping": { + "users[^]*edit": "accountedit", "users": "account", "latest": "category", "popular": "category",