On Development


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

WordPresss Plugins Search

Search­ing for Word­Press Plu­g­ins seems to not be very help­ful. The results that comes up on the page ain’t help­ing out. Although, there’s a “you may also try your search at Google” link below the results page—it should be eas­ier to find the right ones.

Hmmm… will see if I have time to cre­ate maybe a boor­marklet. Unless there’s one already… any­one? For the time being, book­mark­ing or copy-and-pasting the fol­low­ing would be best and make things efficient:

http://www.google.com/search?hl=en&q=site%3Awordpress.org%2Fextend%2Fplugins%2F+

Note: You should be able to add your search keyword(s) after the “+” plus-sign. For example:

http://www.google.com/search?hl=en&q=site%3Awordpress.org%2Fextend%2Fplugins%2F+test

CSS Naming Convention for Classes and IDs?

Well, just re-reading some of the cur­rent book­marks in my bag. To note:

I am try­ing to clean up and make things more effi­cient here at work. One goal would be to have a base CSS that will serve as a start­ing point for our Pro­duc­ers and Fron­tend peeps. Another goal would prob­a­bly be a con­ven­tion on how to use it and/or cre­ate new classes and IDs.

One of the things that keeps com­ing up lately would be the nam­ing con­ven­tion of classes and IDs. I used to imple­ment this kind of for­mat “class_name”. Then, only to switch to “class-name” in early ’06. Fast-forward to a cou­ple of months into the year dur­ing a project, I came to find out that if you are refer­ring to either a class­name or an ID (i.e. getEle­ment­ById, or some­thing like that) that the value’s hyphen get stripped out. Can some­one con­firm this phe­nom­ena and/or myth? That is, for exam­ple, doing “id-name” would be imple­mented like so:

document.getElementById("idname")

With that how­ever, would it be more read­able using a camel­Cased name? Although against Tantek’s step #4 in terms of sav­ing the user(s) poten­tial headaches. But would there be prob­lems if there was a stan­dard within one’s orga­ni­za­tion? That is, classes and IDs writ­ten as a vari­able, i.e. some­thing­LikeThis; no hyphens and no underscore.

I look for­ward to hear­ing your end­less wis­dom on this sub­ject sirs and madams. Thanks in advance.