Archive for the 'JavaScript' Category

location=location

Jul 26th, 2008

location = location … and 534 other ways to reload the page with JavaScript How many ways you can think of when you want to reload the current page with JavaScript? I counted 535 before I got bored, maybe someone can pick up from there? The cases are so much that I had to write […]

 

The book, the book

Jul 25th, 2008

OOJS is almost officially out. I mean it’s out officially, but not yet up on amazon, which these days means it’s not really out, is it. It will probably take a couple more days, maybe next week. So far there has been a great interest, even enthusiasm, expressed by people running web dev sites who […]

 

My online footprint lately

Jul 23rd, 2008

This is a sort of a catch-up post for listing what I’ve been up to lately. YUI Blog just published my first article, I’m so proud. It’s about loading JavaScript in non-blocking fashion, because JavaScripts, they, you know, like, block downloads. Luckily, there’s an easy fix – DOM includes, which I’ve previously discussed, discussed and […]

 

The JavaScript book is almost there

Jul 16th, 2008

Whew, after a whole year of writing, preparation, edits, blood, sweat, tears, I finished all the latest edits and reviews for my new book, Beginning Object-Oriented JavaScript. It should be out any day now. I can’t be happier! You can pre-order with 10% off from the publisher’s site.

 

Load a photo in a canvas, then flip

May 3rd, 2008

Today our family went to the yearly photo session with the girls. We took one shot that can be looked normally, as well as upside down, so I was wondering can you flip an image using a canvas tag. Turns out, yes, you can and it’s pretty easy. » Demo is here. How to load […]

 

strftime() in JavaScript

Apr 25th, 2008

Philip “Bluesmoon” Tellis has posted a tiny (under 3K minified) JavaScript library to format dates, inspired by PHP’s strftime() Examples: d.strftime(‘%Y/%m/%d’) » en: 2008/04/25 » fr: 2008/04/25 » de: 2008/04/25 d.strftime(‘%A, %d %B’) » en: Friday, 25 April » fr: Vendredi, 25 Avril » de: Freitag, 25 April There’s also a demo to fiddle with. […]

 

When client-only validation is good for business

Apr 13th, 2008

You should never never ever rely on client-side validation only. Client-side validation is for enhancing user experience, server-side is the validation. This is a rule, never to be broken. But here’s a funny story how skipping the server-side validation actually helped. This is a real story, but the actual names have been replaced in XXX, […]

 

JSPatterns.com up again

Mar 26th, 2008

After getting 300 megs of wiki content spam, I deleted the old wiki over at http://www.jspatterns.com. Now restarted the project as a blog with static pages for the javascript patterns and blog posts for anything interesting in the ever so exciting world of JavaScript. So far nothing special there (example), but keep an eye on […]

 

JoJo: Javascript Junk generator

Mar 25th, 2008

Ever needed to be able to generate random, but valid JavaScript code? Well, today is your lucky day: meet J.J. or JoJo, the Javascript Junk code generator. All you need to specify is how many kilobytes of code you need. Available also as a web service. » tools.w3clubs.com/jojo If anyone can think of any application […]

 

sleep() in JavaScript

Mar 24th, 2008

PHP has a sleep() function, but JavaScript doesn’t. Well, this is because it’s useless, you might say, and you’ll be right. But for simulating heavy processing and for misc performance measurements, it could be useful. So here’s how you can go about creating a sleep() in JavaScript. The code function sleep(milliseconds) { var start = […]

 

PHP-style $GLOBALS in Javascript?

Mar 8th, 2008

Javascript has implied globals. When you skip the var in var a = 1; and go a = 1;, then a becomes a global variable. Some consider this an error in the language. Global variables should be avoided because they tend to overwrite each other in unexpected places, especially if the project grows in LOC […]

 

Canvas pie with tooltips

Mar 8th, 2008

This is very flattering: Greg Houston took my script for DIY canvas pie and added tooltips and better colors logic. Here’s the result, it’s really nice, built with some MooTools. The tooltips are not supported in <canvas> but Creg used an image that overlays the pie and set the tooltips with an image map. Clever, […]

 

replace selected text (Firefox)

Mar 6th, 2008

A quick function to replace the selected text (in Firefox). Accepts: string to replace the selection, or callback function that takes the selected text and returns a string to replace the selection function replaceSelection(t) { if (typeof t === ‘function’) { t = t(window.getSelection().toString()); } var range = window.getSelection().getRangeAt(0); range.deleteContents(); range.insertNode(document.createTextNode(t)); } Usage: 1. Replace […]

 

Canvas pie

Feb 5th, 2008

UPDATE: Translation in Brazilian Portuguese here, thanks Maujor! OK, so you have an HTML table. Let’s turn it into a pie chart with a bit of javascript. We’ll be using the canvas tag, so the browser has to support it. For IE – well, you still have the table. That’s why we’ll call it progressive […]

 

MP3 player from Yahoo! – bookmarklet

Jan 23rd, 2008

Update Jan 30, 2008: updated code based on comments and code from Carl Update Dec 11, 2008: updated the code thanks to the comment from Nolan Here’s the scenario: you have a page that links to some .mp3 files. You add a line of code in your page and lo and behold, there’s a nice […]

 

YUI pie chart example

Jan 16th, 2008

If case you haven’t noticed – YUI Charts hit the streets. As with everything new, it’s best shown and understood by example. So here’s the simplest example of using a pie chart. Basically I took the example from the YUI page, changed all the paths to point to yahooapis.com (where YUI is hosted for free) […]

 

Table to chart via JavaScript

Jan 8th, 2008

A javascript by Christian Heilmann that takes a table from your page and constructs the URL to request a chart from Google APIs. Slick and accessible. Check it out.

 

Netflix – how many movies you’ve rented

Dec 30th, 2007

Netflix is a great service, it’s a shame they don’t seem to provide any APIs. Oh, well, we’ll have to resort to other means of extracting data. A little javascript to count how many movies you’ve rented: document .getElementById(‘returned_movies’) .getElementsByTagName(‘tbody’)[0] .getElementsByTagName(‘tr’) .length You can put this code in a bookmarklet or simply type in the […]

 

Fancy formatting

Dec 21st, 2007

Writing readable code means proper indentation. Usually you’d tab (or use 2 or 4 or 3 spaces) after every curly bracket. Something like this: if (true) { // indent if (false) { // another indent // and some more } } Same goes when you have a bigger hash/object sort of thing: var memememe = […]

 

The Front-end Cerberus

Oct 25th, 2007

Some smart guys picture the distinction of content (HTML), presentation (CSS) and behaviour (JavaScript) as a three-legged stool. This is totally fine, but can’t we draw a more heroic picture of today’s Front-end developer? I found the image here, if anyone knows the original author, let me know so I can give proper credit. BTW, […]

 

My performance article up on SitePoint

Oct 25th, 2007

click

 

JS/PHP string concatenation mistype

Oct 25th, 2007

Another one from the “this is not a syntax error” department. The front-end developer is a strange beast who has to jiggle to and fro and code in several languages literally at the same time – javascript, html, css, php or some other server side language, some SQL dialect… No wonder that sometimes we make […]

 

“Save AnyThing” offline with a Google Gears bookmarklet

Oct 19th, 2007

Here’s a little bookmarklet I came up with, I called “SAT”, stands for “Save AnyThing (for offline reading)”. It uses Google Gears and works like this: you’re about to go offline (maybe boarding a plane) and want to catch up on some reading you visit any page you click the SAT bookmaklet it saves all […]

 

IE has a problem with getElementsByName

Oct 3rd, 2007

Yes, it does. Sometimes it’s convenient to use “HTML arrays”, meaning to name fields like: <input name=”something[]” /> Then on the server side you loop through the array $_POST[‘something’] This allows for a flexibility where your app doesn’t know the number of inputs in advance, but works fine regardless of the actual number. Even cooler […]

 

Make your javascript a Windows .exe

Aug 31st, 2007

These days an average web developer needs to have a broad matrix of skills in order to do his/her job. HTML, CSS, JavaScript, AJAX, XML, some server side language, some linux skills, some apache, some database skills, standards, accessibility, SEO, the list goes on. Parts of the list are also multiplied by (or raised to […]