From b0cf97c5d6fa034d278e7363adb873e8e46863a6 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 15 May 2013 15:39:29 -0400 Subject: [PATCH] editing features, part 1 --- app.js | 8 ++++---- public/src/app.js | 26 ++++++++++++++++++++++++++ public/templates/header.tpl | 4 ++-- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/app.js b/app.js index 614a9dd5cd..e448a6a534 100644 --- a/app.js +++ b/app.js @@ -20,11 +20,11 @@ global.configuration = {}; if (data.categories.length === 0) { console.log('Setting up default categories...'); - fs.readFile(config.ROOT_DIRECTORY + '/install/data/categories.json', function(err, categories) { - categories = JSON.parse(categories); + fs.readFile(config.ROOT_DIRECTORY + '/install/data/categories.json', function(err, default_categories) { + default_categories = JSON.parse(default_categories); - for (var category in categories) { - categories.create(categories[category]); + for (var category in default_categories) { + categories.create(default_categories[category]); } }); diff --git a/public/src/app.js b/public/src/app.js index d5404d66ab..9555a675a1 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -274,7 +274,33 @@ var socket, }, false); // Posting + var formattingBar = document.getElementById('formatting-bar'), + postContentEl = document.getElementById('post_content'); jQuery('#post_window').slideToggle(0); + formattingBar.addEventListener('click', function(e) { + if (e.target.nodeName === 'I') { + switch(e.target.className) { + case 'icon-bold': + var cursorEnd = postContentEl.value.length; + postContentEl.value = postContentEl.value + '**bolded text**'; + postContentEl.selectionStart = cursorEnd+2; + postContentEl.selectionEnd = postContentEl.value.length - 2; + break; + case 'icon-italic': + var cursorEnd = postContentEl.value.length; + postContentEl.value = postContentEl.value + '*italicised text*'; + postContentEl.selectionStart = cursorEnd+1; + postContentEl.selectionEnd = postContentEl.value.length - 1; + break; + case 'icon-list': + var cursorEnd = postContentEl.value.length; + postContentEl.value = postContentEl.value + "\n\n* list item"; + postContentEl.selectionStart = cursorEnd+4; + postContentEl.selectionEnd = postContentEl.value.length; + break; + } + } + }, false); }) diff --git a/public/templates/header.tpl b/public/templates/header.tpl index c7b4449ad4..2a76bb593e 100644 --- a/public/templates/header.tpl +++ b/public/templates/header.tpl @@ -61,10 +61,10 @@
-
+
- +