From 5bb9933f4a28092d55730ceb463da34c15897b7e Mon Sep 17 00:00:00 2001 From: psychobunny Date: Wed, 5 Jun 2013 17:00:58 -0400 Subject: [PATCH] added functionality to post button. also introduced some underlying concepts regarding modules and pulling template vars --- public/src/ajaxify.js | 3 ++- public/src/app.js | 5 +++++ public/src/modules/mobileMenu.js | 25 +++++++++++++++++++++++-- public/src/templates.js | 6 +++++- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index 1aa52e16de..9a70ebd194 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -47,7 +47,8 @@ var ajaxify = {}; } jQuery('#footer, #content').fadeOut(100); - + + templates.flush(); templates.load_template(function() { exec_body_scripts(content); diff --git a/public/src/app.js b/public/src/app.js index eb35b16652..7e315533e2 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -191,6 +191,11 @@ var socket, socket.emit('api:user.get_online_users', uids); } + // here is where all modules' onNavigate should be called, I think. + require(['mobileMenu'], function(mobileMenu) { + mobileMenu.onNavigate(); + }); + populate_online_users(); diff --git a/public/src/modules/mobileMenu.js b/public/src/modules/mobileMenu.js index 7f5183348f..2880e26464 100644 --- a/public/src/modules/mobileMenu.js +++ b/public/src/modules/mobileMenu.js @@ -4,7 +4,8 @@ define(function() { var categories = null, overlay = null, - menuBtn = null; + menuBtn = null, + postBtn = null; function loadCategories(callback) { @@ -63,9 +64,27 @@ define(function() { } + mobileMenu.onNavigate = function() { + var cid = templates.get('category_id'); + + if (cid) { + postBtn.style.display = 'inline-block'; + postBtn.onclick = function() { + require(['composer'], function(cmp) { + cmp.push(0, cid); //todo check if in post + }); + }; + } else { + postBtn.style.display = 'none'; + } + + }; + + mobileMenu.init = function() { overlay = overlay || document.getElementById('mobile-menu-overlay'); menuBtn = menuBtn || document.getElementById('mobile-menu-btn'); + postBtn = postBtn || document.getElementById('mobile-post-btn'); menuBtn.onclick = function() { animateIcons(); @@ -73,9 +92,11 @@ define(function() { loadCategories(displayCategories); + mobileMenu.onNavigate(); } return { - init: mobileMenu.init + init: mobileMenu.init, + onNavigate: mobileMenu.onNavigate } }); \ No newline at end of file diff --git a/public/src/templates.js b/public/src/templates.js index b3ea78105c..4a39277c2b 100644 --- a/public/src/templates.js +++ b/public/src/templates.js @@ -169,7 +169,7 @@ if (!templates[tpl_url] || !template_data) return; document.getElementById('content').innerHTML = templates[tpl_url].parse(JSON.parse(template_data)); - + jQuery('#content [template-variable]').each(function(index, element) { templates.set(element.getAttribute('template-variable'), element.value); }); @@ -181,6 +181,10 @@ } + templates.flush = function() { + parsed_variables = {}; + } + templates.get = function(key) { return parsed_variables[key]; }