All Marked Up

A tasty brew of web standards and internet culture.

Posts tagged with “”

jQuery URL Parser v1.0

This jQuery URL Parser is a little plugin that I wrote a while back and have now decided to release properly. It’s based on Steven Levithan’s regex-based URI parser, and allows you to quickly and painlessly access pretty much any bit of information within the URL.

Why would you need to pull information out of the URL? Well there are lots of potential reasons. I have been using it on a CodeIgniter-based CMS project recently where each page initially loads the same one JS file, which in turn selectively loads others depending on the URL (roughly mirroring the way CodeIgniter loads different controllers by parsing the URL segments). I also often use it just to get the base URL of the site so that I can use absolute URL references in my JavaScript, without having to change anything when the site moves domains – say from the testing to the production server. It also offers an easy way to access query string parameters for use in your scripts, and much more.

You can download the plugin from the project page, together with the documentation etc.

I’ll post up any updates to the plugin here, so grab the RSS feed if you want to stay updated. For bug reports or feature requests please visit the jQuery plugins page at http://plugins.jquery.com/project/url_parser, or if you have any other questions or queries, please drop me an email at mark[at]allmarkedup[dot]com and I will do my best to get back to you as soon as I can – but I’m pretty busy at the moment so please be patient!

19 Comments »

Number 1 from Kevin Pang’s Top 10 things that annoy programmers is ‘Their own code, 6 months later’:

Ever look back at some of your old code and grimace in pain? How stupid you were! How could you, who know so much now, have written this?— Kevin Pang

This is so painfully true; except most of the time it doesn’t take 6 months for me to hate my own code, it’s more like three.

Default values for HTML checkboxes

So this is a little tip that looking back on is so obvious it pains me to even write about it. However I’m sure I’m not the only one who has encountered this issue, and so I’m posting it here in the hope that it may help someone like myself.

The issue is to do with HTML checkboxes. It is obviously easy to set a value for when these are checked that gets sent to the server on form submission. But for years I never knew how to specify a default value that gets passed to the server when the checkbox is not checked.

Until the other day I was using PHP to check for the presence of the checkbox name in the POST array, and if it was not there was specifying the default value in there. Something like this (using the ternary operator):

$checkbox_value = ! empty( $_POST['my_checkbox_name'] ) ? $_POST['my_checkbox_name'] : "default_checkbox_value";

However, I’ve always felt that there should be some way to specify this in the HTML – an attribute perhaps – on the checkbox input element where you could specify the unchecked value. But unfortunately that attribute doesn’t exist. What I stumbled upon the other day, however, is a different way to achieve the same result – and it’s ridiculously easy.

The way to do it is to have a hidden <input /> element before the checkbox, with the same name and the value attribute set to the value you wish the checkbox to default to when unchecked. That’s it! So basically your html would look like this:

<input type="hidden" name="checkbox_name" value="unchecked_value">
<input type="checkbox" name="checkbox_name" value="checked_value">

When the checkbox is submitted without a value, that input does not get passed to the server. Instead the value of the hidden input gets submitted. However, when the checkbox is ticked, the value of the hidden field is overwritten so the server-side code receives only the checkbox value. Pretty sweet, and as a added bonus it is also perfectly valid XHTML 1.0 / HTML 4.01 Strict.

There is only one caveat – it won’t work when you are assigning input names as an array such as my_input_name[]. There is no way to get around this as far as I know, unless in your page you are able to explicitly assign the array key numbers in the for each input like so:

<input type="text" name="my_input_name[0]" value="item_value"> <!-- just another field -->
<input type="hidden" name="my_input_name[1]" value="unchecked_value">
<input type="checkbox" name="my_input_name[1]" value="checked_value">

So whilst it will not work in 100% of the cases, I think this a pretty useful and easy to implement way to set unchecked values for checkboxes.

No Comments »

Via AppleInsider:

When contacted by FranceInfo, an Orange representative reportedly confirmed that that the carrier has been deliberately limiting speeds for all 3G capable phones on its network to 384Kbps, saying the move was aimed at ‘preserving the stability of the network’.— AppleInsider

I think a lot of people are going to be very pissed off about this – including me if it turns out O2 are doing this sort of thing in the UK too. I appreciate that network stability needs to be considered, but they need to be upfront and honest about this sort of thing, rather than just letting Apple take all the flak for something that is not actually their problem.

From Seth’s Blog:

Organizations will work tirelessly to de-personalize every communication medium they encounter.— Seth Godin

Unbelievably (and sadly unavoidably) true.

Doyen of the Downs

So last night Sarah and I, as well as a couple of friends of ours, signed up to run the Doyen of the Downs (A ‘Doyen’ is apparently analogous to a ‘Dean’ – the “eldest or most senior in a group”). It’s a 50km ultra-marathon in December, and considering I am in pretty bad running shape at the moment I am a little bit scared! We did 45km a couple of years back, it was fairly tough but we were doing a lot of running back then. Since little Sadie was been born we have been pretty slack on the running front so I expect it to be a bit of a shock to the system…

Still, nothing like a challenge to get you out on them there hills. And it is on our home turf (nearly) in the beautiful hills around Arundel, so it should be a nice scenic one.

I’ll try to post some training pictures and updates here eventually for anyone who is interested. And for anyone who wants to join us there are still some places available if you’re quick!

No Comments »

PPK on the event handling in Mobile Safari:

They have to redesign the triggers for these events in terms that make sense to their interface, even if that means that the event names don’t make sense any more. — Peter-Paul Koch

I’m excited by what PPK sees as the decline of heavy mouse-based interaction on the web. But it sounds like the mapping of events such as :focus onto ‘finger down’ events is going to get very confusing (linguistically speaking) long before any new standard for event handling on the web is formulated to take into account the new touchscreen devices.

From John Resig’s blog:

A fantastic new improvement to Mozilla’s JavaScript engine (SpiderMonkey) has landed. Code-named TraceMonkey this engine utilizes a techniques, called trace trees, which adds just-in-time native code compilation to SpiderMonkey. — John Resig

This is exciting news, and combined with Safari’s upcoming SquirrelFish javascript interpreter it means JavaScript-heavy web pages and applications are going to be getting a big performance boost in the near-future.

How JavaScript is quietly taking over the world

Note: This is the first of a few articles that I will be cross-posting from my employer’s blog, where this was originally published earlier this month.

Most people, if they have heard of JavaScript at all, know it as the web scripting language that allows web pages to have nice effects on them – show/hide, fades, ‘accordion’ effects and other animations.

Those with a bit more knowledge on the subject might also be aware that JavaScript can be used to get data from a web server without refreshing the page – a technique dubbed Ajax that enhances many of today’s web-based applications and makes the whole web experience a bit smoother.

But what not many people know is that JavaScript is actually quietly taking over the world.

The fact is that JavaScript, (the standardised version of which is called ECMAScript) which was hurriedly released around 1995, is now more prevalent than you might imagine. And equally importantly, it is cropping up in different places and in forms that people never thought of way back in it’s early years.

The traditional area for JavaScript is on the web, and here it has matters pretty much sewn up in terms of market dominance. Yes, there is Adobe’s Flash, which competes for the web application/ interactivity slice of the pie. However, unlike Flash, JavaScript does not require a plugin, is supported by the W3C, and is considered an integral part of the ‘web standards’ trio of frontend web development languages. And the scripting language that powers much of modern Flash development today, ActionScript, is actually a subset of the ECMAScript standard and is closely related to JavaScript.

All of the major mapping applications such as Google Maps, Yahoo maps etc are powered by JavaScript, as are almost all of Google’s other web offerings, such as Google Mail and Google Docs. Apple’s new MobileMe service gives a desktop application-like interface whose UI is created using a JavaScript framework called SproutCore, and the extremely impressive 280slides.com online presentation-maker application is written in Objective-J, a port of Apple’s Objective C programming language to JavaScript. The growing popularity of these JavaScript frameworks is making the language more accessible to novice developers (although not without bringing their own sets of problems) and removing most of the cross-browser issues that were the bane of developers lives in the early years of it’s implementation.

These applications all make use of client-side JavaScript. However it is now showing up on the server-side (1) as well, with pure solutions such as the Aptana Jaxer project bringing the power of JavaScript to bear on server architecture, creating solutions optimised to today’s heavy use of Ajax in web sites an applications. It’s ‘embeddability’ means that it can also be easily embedded in other server side languages such as PHP (PHP-JS), Java (Rhino), and Perl (JE) amongst many others.

But that’s not ‘taking over the world’ – that’s just taking over the web. Where else does JavaScript feature outside of websites?

Lots of places, as it happens. Still on a web-related theme, Mozilla’s Firefox browser uses JavaScript to power its Graphical User Interface (GUI), and developers can create extensions for the browser using JavaScript. On the desktop, Mac OS X’s dashboard widgets are all powered by JavaScript, as are Microsoft’s Vista Gadgets, Yahoo’s Widgets and Google’s Desktop Gadgets. Adobe released the 1.0 version of AIR, their cross-platform runtime environment for creating desktop applications, in February this year; this allows developers to use web technologies such as HTML and JavaScript to create rich desktop applications.

JavaScript is also showing up as a way for people to add functionality to existing applications, as companies build scripting capability into their products to allow for greater customisation. For example, Adobe’s ever-popular Photoshop application allows users to write scripts in JavaScript, a plugin for Illustrator allows JavaScript to be used to create and manipulate images and tools, and PDFs now support JavaScript scripting and interaction.

This use of JavaScript outside of the web browser looks set to increase – through web development many people already have the skills needed to write the scripts, and it is a language that is well suited to manipulating graphical elements in the interfaces that the modern desktop operating systems provide. There is also a good sense of convergence here: As more and more applications are becoming web based (or at least are offering web-based versions of their desktop software), the desktop is starting to become powered by technology that was born for use in the web.

So it looks like we are going to be seeing a lot more of JavaScript in the coming years, both on and off the web. Not bad for a language that has be derided over the years by ‘real’ programmers, who considered it an ‘amateur’ language because of its unstructured nature and early use to provide whizzy effects for web pages. You’ve come a long way, baby.

——————-

(1) The web is based on a client/server model – there are lots of web servers being run in the ‘cloud’ that process requests from the ‘clients’, the browsers that we use to view the web. Traditionally JavaScript has been run on the client side of this equation, processed by the browser.

No Comments »

Skillswap Goes Pretty

So I just got back from the latest Brighton SkillSwap. Entitled ‘SkillSwap Goes Pretty’, it involved two talks, one by Elliot Jay Stocks and one by Paul Annett of Clearleft.

This was my second SkillSwap, and have to say they are very enjoyable events, even though I don’t know many people there! And free beer courtesy of the sponsors Madgex always helps the evening pass smoothly.

Elliot’s talk was titled ‘I care because you do’ and was about what makes you inject care and attention into a project, and how to keep that ‘care’ factor running throughout the lifespan of the project. The talk sparked off a lively discussion in which people variously mentioned: pushing your technical limits to keep you motivated; working on your own site as a way of putting yourself into a clients shoes; various ways in which you can help to educate your client and help them to understand the value of your work; and much more.

Paul’s talk was entitled ‘Oooh, That’s Clever! (Unnatural Experiments in Web Design)’ and was a look into some of the more subtle but clever CSS/HTML tricks that people (including Paul himself) put into their sites, often just as an ‘Easter Egg’ for other developers to find. The ‘parallax effect’ featured on the Silverback website was mentioned, as well as a number of other sites that have gone to town on a small detail that may only be noticed by a few people, but nonetheless add a certain special value to the site.

So all in all an interesting evening, many thanks to those involved and I look forward to the next one, whatever it may be on! And if you haven’t yet been to a SkillSwap yet, I strongly recommend checking out whether there is one in your local area (Brighton and Bristol are two I know of) and going along.

No Comments »

« Older Entries