#javascript


Decontstructing The Expressive Web

Inter­est­ing inter­view of the breakdown/process poured into mak­ing Adobe and Big Spaceship’s lat­est project: The Expres­sive Web.

Adobe Prin­ci­pal Prod­uct Man­ager Mike Cham­bers sits down with Stephen Koch, Sr. Devel­oper from dig­i­tal cre­ative agency Big Space­ship, to dis­cuss new design tools in HTML5 and CSS3 that can help you cre­ate expres­sive fea­tures in your web­pages’ UIs.

Here’s the video.

Resize to a Specific Element’s Dimensions

Here’s a snip­pet to resize a back­ground image to the dimen­sions of an ele­ment. In this case, #bkgIm­age.

var resizeBkg = function() { 
    var h = self.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; 
    var w = self.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; 
    var e = document.getElementById('bkgImage'); 
    if (w > h) { 
        e.width = w; 
        e.height = w; 
    } else { 
        e.height = h; 
        e.width = h; 
    } 
} 

Detect Operating System with JavaScript

Here’s a snip­pet of JS code that might come in handy if you, let’s say, would like to fil­ter out what type of con­tent to dis­play depend­ing on your web­site user’s OS. A real-life exam­ple would be hav­ing a down­load link show up to user’s who have a client that was only pub­lished on Windows.

// This script sets OSName variable as follows:
// "Windows"    for all versions of Windows
// "MacOS"      for all versions of Macintosh OS
// "Linux"      for all versions of Linux
// "UNIX"       for all other UNIX flavors 
// "Unknown OS" indicates failure to detect the OS

var OSName="Unknown OS";
if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";

document.write('Your OS: '+OSName);

Note: An alter­nate way can be found via PPK’s quirksmode.org