Skip navigation.

Claws, fangs, fur...

...the bear essentials

STICKY POST

Share OmegaJunior's blog

, , , ...

IE users warned to disable JavaScript

http://www.webuser.co.uk/news/top-stories/431941/ie-users-warned-to-disable-javascript

Whenever I tell my clients that they do need to build for users without javascript first, and then add on to that with javascript, they tell me that their users all have javascript enabled.

And how do they know this?

Via Google Analytics... which registers only if javascript is enabled.

Javascripted stylesheet switchers - necessary evil?

, , , ...

All web browsers that are built with ease of use in mind, sport accessibility options. Microsoft Internet Explorer has fared well in this respect, for as long as I can remember. Then Opera and Firefox started offering more. Microsoft wised up and added a stylesheet selector to its interface starting at MSIE8.

But, if you happen to be using Safari or Chrome, you're S.O.L. Apparently, the vendors don't care about user accessibility. No. They must hate you.

Why?

Because they don't offer a stylesheet switcher.

What's a stylesheet switcher?

If a web author is nice enough to think about the different machines on which their web page could be shown, the smart author offers the same well-formed web page in varying layouts. These layouts are called stylesheets. By setting the media attribute, a web author can determine whether a stylesheet should be loaded by a printer, a desktop web browser, a small-screen web browser, a big-screen projector, or something else.

Some authors offer different layouts for the same machine. Sometimes just to spice things up, and sometimes to make their web page easier to use under certain circumstances. Those stylesheets are called 'alternate stylesheets'. User-friendly web browsers recognise these, and offer a switch in their menu, to let the user switch between one layout and the other.

(The web authors know that this switch also comes in handy when testing their stylesheets for other media.)

A user-hating web browser fails to incorporate such a switch. Knowingly, they prevent the user from using something the web author has created to make their lives easier, resulting in the browser making the user's life harder.

Not good.

The web author then starts looking for ways to enable it anyway. I consider this evil: building into a web page, what the browser should've offered. We see other examples of such necessary evil: font size changers, rss feed icons, bookmarking facilities... all created to overcome browser deficiencies. Necessary evil.

Apparently, for stylesheets, the user-hating browsers seem Safari and Chrome. The way for the web author to get those browsers to offer a stylesheet switch to their users anyway, is by building it into their web page. This can be done using javascript.

All it seems to take, is look for the [rel=alternate stylesheet] and turn it into [rel=stylesheet]. (Edited to correct that: it also takes setting [disabled=false|true].) And the other way around, of course. And allow for some stylesheets to remain active while others are switched around.

I wonder what such switchers do to interface of the user-friendly browsers, that provide such a switch themselves...

Bigger screens and web browser memory

, , ,

What are the reasons for a web browser to use more memory?

Well... for instance, adding more objects to the displayed document. Or adding objects that are heavy with events. Like the duplication method in the Canvas Composition Studio. It duplicates objects that hold custom information and events, and immediately selects them, to allow continued duplication.

Fills up memory quite quickly.

That kind of memory use is expected. It'd be nice if the web browsers would release that memory after the objects are deleted, or after the window holding the page is closed. In this respect, Chrome fares a bit better than Opera, but Firefox beats both of them.

What about unexpected memory use?

For instance, when displaying the Canvas Composition Studio in Opera 10, upon firing the event that scales the studio area to the available screen, the browser all of a sudden adds 4MB up to 15MB to its memory consumption.

How come?

Apparently, the cause of this jump lies in a combination of the background images and the size of the window. Personally I had thought, that displaying a background image requires only the memory needed to read that image (which, in the case of the CCS, is 12KB). Apparently, Opera duplicates that amount for each time the image is repeated... resulting in a smaller memory use on smaller screens, and a larger memory use on larger screens.

Yay.

Not.

Worse: the jump varies from 4 to 15MB, even when testing in the same window size. Sometimes Opera uses more, and sometimes it uses less. Like as if sometimes, Opera is able to optimize based on predictions about what is going to happen, and sometimes it isn't. On the same page. One reload later.

Yay again.

Not either.

Try building a test case for that.

Javascripts and standardized object and event models

, , , ...

So, we've got Ecmascript defining the language commonly known as Javascript. We've got W3C defining the DOM, the document object model, which represents an (x)html document loaded in a web browser, as well as the javascript interface to manipulate that document. And we've got the window model, which was developed before the more abstract DOM, but is still implemented and improved to this day.

So why can't browser vendors reach an understanding on how to do things? What possible advantage does it serve to make it harder on the web authors, to get stuff accomplished? I'm sure there's some benefit, beit monetary (doubtful, since in this case, the deviant is both open-sourced and free) or pride (also doubtful, since in this case, the deviant was rebuilt from the ground up), or something else (please enlighten me?).

What on earth am I talking about?

Events. Javascript events. More specifically: the click event, which happens when users click on a screen element, usually using a point-and-click device like a mouse, a pen, or their fingers.

What about it?

Coordinates. It seems very hard for browsers to let the web author know, what the coordinates are where the click was registered. And if we need that information to, for instance, drag an element around the screen, or collect the exact pixel information, we are faced with browsers that insist on doing things differently.

The other day, I added a colour picker to the Canvas Composition Studio.


Image: CCS Colour Picker

Based on the new colour picker in My Opera's style designer (which from the looks of it is part of the Yahoo User Interface library), it presents a swatch of colours and greys, from which the user can choose by simply clicking the desired colour.

In Opera, Safari, and Chrome, the click event holds the attributes offsetX and offsetY. This tells the web author exactly where the element was clicked. That coordinate can then be used for the Canvas method getImageData(x,y,width,height), which returns an rgba representation of the colour.

Firefox also returns supports the getImageData() method, also returning the rgba representation of the colour chosen. However, its click event does not hold the attributes offsetX and offsetY. Instead, it holds layerX and layerY. Yay, Netscape legacy. In itself, that isn't bad. A quick test for support of an attribute fixes the problem.

Not.

See, in the specific situation of the colour picker in the Canvas Composition Studio, layerX and layerY don't tell the web author where the element was clicked. As a matter of fact, layerY returns a value that puts it way outside of the clicked element...

Why? I don't know. All I know is that the coordinates provided by these attributes are useless. And the event also fails to provide any information as to how the coordinates are offset. So we're left to calculate the coordinate by ourselves.

To do so, we must match the event.clientX to the eventTarget.offsetLeft... which anyone would agree is (start sarcasm) totally obvious (end sarcasm) from cracking open the event and eventTarget objects...

Thank you, Firefox building team, for making this web author's job harder.

I haven't even tried catching this coordinate in Microsoft's excuse for a web browser, yet. Maybe that'll be easier, for a change.

Canvas Gradients and CSS3 HSL

, , , ...

What would you expect when you see this javascript?

/* assume context is an HTML5 Canvas 2d context */
var g = context.createLinearGradient(0,0,width,height);
g.addColorStop(0,'hsl(0,0%,0%)');
g.addColorStop(1,'hsl(0,100%,100%)');
return g;


Would you expect a gradient flowing from black to white, with grades of red in the middle? Me too!

For a yet unknown reason, all tested Canvas-supporting browsers decided to show only shades of grey. No red.

In order to see red, we actually need to add a specific colour stop between the two already present:

var g = context.createLinearGradient(0,0,width,height);
g.addColorStop(0,'hsl(0,0%,0%)');
g.addColorStop(0.5,'hsl(0,50%,50%)');
g.addColorStop(1,'hsl(0,100%,100%)');
return g;


But that, obviously, fails to show a fully saturated red anywhere in the gradient.

On a slightly related topic: why we need to pass the hsl() (or the rgb()) colour creator as a string beats me. Why not just add an hsl() function to your javascript parser? Only because javascript refuses to accept 0% and 100% as numbers? Well, then let us specify those as fractions between 0 and 1, just like alpha transparancy.

But no... that would make the notation inconsistent with the CSS3 notation... and we all know that the CSS3 colour module has been a fixed recommendation for years, right?

Not.

Multi-select far from easy

, , , ...

For my Canvas Composition Studio over at Pantheon Online Games, the very first of its kind on the internet, I decided to implement multi-select. I wanted to allow a user to select more than one composition items and treat them at the same time.

Boy was I in for a surprise.

Read more...

Download Opera, the fastest and most secure browser