Montag, 1. Oktober 2012

node.js socket.io boilerplate

Yesterday i created a boilerplate for node.js, it uses the most common modules.
express.js - awesome http middleware which makes handling sessions and requests very easy
socket.io - most popular websockets implementation for node.js
jade - a template engine inspired by HAML
stylus - css template engine, same markup as jade and makes css writing less painfull, nearly fun ;)

Just clone the repo and get started.
git clone git://github.com/gocoffeecup/nodesocketioboilerplate.git

Additional information on the frameworks used can be found here:

Socket.io
express.js
jade
stylus

emulating whitespace in span elements

today a came across a very anoying problem, I'm currently working on a WYSIWYG editor, my approach is to wrap every single character in an <span></span> tag which works fine for every char except a whitespace.

at first i added &nbsp; but my markup is fairly complex and the editor allows you to float image elements, so non breaking spaces are not an option since the text won't float correctly arround wrapper elements which are floated.

adding only a whitespace in the span tag doesn't make the cursor jump on key input, and adding more spans in a row collapse to only one space.

i solved this by emulating a white space by adding a whitespace followed by a BOM character.
<span>*\ufeff</span>

where * is the whitespace itself.


this seems to work accross all browsers.