Saturday, August 21, 2010

Canvas Loading Image Replacement Plugin

I know I mentioned this before, but I've recently released a simple jQuery plugin that replaces the standard ajax loading images with a canvas version that works in places where animated GIFs do not (read: Android WebKit).  Well, after posting about it in a certain Google Group to do with Mobile Web Development I received a lot of feedback, mainly that JQuery is a hefty requirement for a mobile website, so I re-wrote it without JQuery. The results can be found here:
http://jamund.com/canvas-loader/no.jquery.html

Here's how it works:





 window.onload = function() {
  var img = document.getElementById("imgLoader");
  var span = document.getElementById("spanLoader");
  canvasLoaderReplace(img, {color:'red'});
  canvasLoaderReplace(span, {backgroundColor:'red', radius:'40'});
 };

  • Before

    X
  • After

    X

NodeJS Based IM server

Goal

Simple and fast messaging over web sockets.

Approach


I recently developed an AJAX-based messaging client for a large social networking type website I am developing for a client at Rain. It works fine, but using AJAX to constantly poll the server is slow and creates a fair amount of overhead for the browser. Using web-sockets with a flash back-up for older browsers combined with NodeJS on the server side should create fast and simple solution for my messaging problem. It would also make it easier to separate the messaging server from the web application server to increase scalability.

Results


After getting lost in a la-la land of non-supported NodeJS 1.x based web socket and chat clients, I stumbled on Socket.IO, a library that contains both front-end and back-end code for delivering high speed chat over web sockets using NodeJS 2.x.

Getting Started

Following these simple steps in terminal got me a working chat server up and running in about 5 minutes.

# install node
cd ~/dev;
git clone git://github.com/ry/node.git;
cd node;
./configure;
make;
sudo make install;

# install socket io
cd ~/dev;
git clone git://github.com/LearnBoost/Socket.IO-node.git;

# start socket io
cd Socket.IO-node/example;
node server.js;
cd ~/dev;

# install the socket io web client
git clone http://github.com/LearnBoost/Socket.IO.git;


# copy the javascript over to the example directory
cp Socket.IO/socket.io.js Socket.IO-node/example/client/;

Witness the awesomeness here: http://localhost:8080/chat.html



Moving forward


I love how easy it is to get started with NodeJS and Socket.IO. I intend to put it to use to build my messaging client. One key feature that might provide a problem is logging the messages. Currently Ithey are being stored in MySQL on a separate database server. Because the storage doesn't need to be real time, only the messaging, I could continue using AJAX to log messages. I might also be able to hook into MySQL directly from the socket.io-node server in a way that does not slow down communication. More research will be needed to determine how practical an approach this will be and how it competes with AJAX/PHP on resources, scalability, and browser support. At the moment I'm excited about the potential and hope to write more about it if I get it up and running!

Resources


http://nodejs.org/ - Server-side Javascript engine.

http://socket.io/ - A great module for NodeJS that adds support for web-socket communications.


http://thechangelog.com/post/456659159/socket-io-multi-transport-socket-server-for-node-js  - A good tutorial on how to get started with Socket IO for NodeJS.

Monday, August 16, 2010

psd2html.com form element mis-hap

When PSD2HTML.com cuts up your HTML, don't assume that just because a form has a submit button that that button will submit the parent form element; It might have some inline javascript that directs it to submit some other random form on the page. #fail

Monday, August 2, 2010

SVG saga

I made some really good progress on a site I was working on using embedded SVGs.





This was for a mobile web project I am doing for work. Unfortunately Android's webkit (<2.2) does not support SVG, so I had to go back to using PNGs.

BOO!

Saturday, July 31, 2010

Semantically awesome ordered lists

So if you were ever trying to style an ordered list <ol> and get rid of those pesky periods after the numbers you may have wanted to give up.


Do not give up!

Much better than manually adding the numbers and styling them in a very un-semantic way. Now of course this works in Firefox and Webkit and not much else, but that's okay. I need it for an iPhone app, so we're good!



<style>
nav {
  margin-left: 20px;
  margin-right: 30px;
  color: #666;
 }
  
 ol { counter-reset: item }

 li {
  display: block;
  margin-top: 10px;
 }
 nav ol li span {
  font-family: 'GothamBook', Arial;
  font-size: 1.6em;
 }
 ol li::before {
   content: counter(item) " | ";
   counter-increment: item;
   font-family: 'GothamLight', Arial;
   font-size: 2.2em;
 }
</style>

<nav>
   <ol>
    <li><a href="#">Why mobile?</a> <span>Quotes and figures to astound your clients.</span></li>
    <li><a href="#">Focus.</a>  <span>Using constraints to improve design across the board.</span></li>
    <li><a href="#">Capabilities.</a>  <span>What can mobile phones do now-a-days?</span></li>
    <li><a href="#">Native vs. Web App.</a>  <span>Which is a better fit for your needs?</span></li>
    <li><a href="#">Workflow.</a>  <span>What happens to your app when it comes through our door.</span></li>
    <li><a href="#">Cost.</a> <span>An arm and a ...</span></li>
    <li><a href="#">Know before you start.</a> <span>10 essentials that can save your app.</span></li>
    <li><a href="#">What's on the horizon?</a> <span>Mobile trends to keep in mind.</span></li>
    <li><a href="#">Help me.</a> <span>We’re here to help you with all your Mobile needs..</span></li>
   </ol>
  </nav>











Thank you:

http://efreedom.com/Question/1-3153019/Remove-decimal-from-ordered-ol-list-via-CSS

http://www.w3.org/TR/CSS2/generate.html

Saturday, July 24, 2010

jQuery Canvas Loader Plugin

 Hi everyone,

I want to tell you about a new jQuery plugin I just released yesterday. It's called Canvas Loader and it provides a canvas replacement to the  standard Ajax Loading images we're all used to seeing around the web. This is helpful for the mobile space because Android for example does not support animated gifs, but it does support the canvas tag. It's also neat because by default it's transparent and is easily customizable. The actual un-minified size is likely bigger than the a small loader image, but not by much and if included with the main javascript of the site it should actually download faster.


While the plug-in takes a lot of options. The main functionality can be triggered by calling this simple method. It tires to match the width and height of an existing image.  Currently, you must have an actual image that is being replaced!

$("img.ajaxLoader").canvasLoader();


Check it out for an example and the code:
 http://jamund.com/canvas-loader/