browserhx - simple haxelib for browser detection.

124 views
Skip to first unread message

JLM

unread,
Jan 1, 2012, 1:04:29 PM1/1/12
to haXe
Awhile ago I posted a browser class I was using for browser sniffing,
and it was suggest it maybe useful as a tiny haXelib, overly simple
but generic enough to be useful.

I have put an hg repository up and created a simple example use with
some greyscale browser icons, please use icon for testing only.

You can see the sample test here:
http://browserhx.googlecode.com/hg/sample/deploy/browserTest.html

The haxelib is here:
http://lib.haxe.org/p/browserhx

The repository is here:
http://code.google.com/p/browserhx/

please feel free to suggest changes or improvements if you find it
useful. It seemed sensible to abstract it from divtastic or any other
dependency/or assumed library. I could be improved vastly, feel free
to contribute :)

Viktor Hesselbom

unread,
Jan 2, 2012, 3:22:19 AM1/2/12
to haxe...@googlegroups.com
Looks good!

One thing I would personally change though is to set get_BrowserType and setBrowserType as private. Since they're not really needed publicly they just clutter autocomplete.

viktor hesselbom



2012/1/1 JLM <j...@justinfront.net>

Viktor Hesselbom

unread,
Jan 2, 2012, 3:28:42 AM1/2/12
to haxe...@googlegroups.com
Looking through jQuery source I see they also fetch the browser version. Might be of interest?

Their code looks like this:

uaMatch: function( ua ) {
   ua = ua.toLowerCase();
   var match = rwebkit.exec( ua ) ||
               ropera.exec( ua ) ||
               rmsie.exec( ua ) ||
               ua.indexOf("compatible") < 0 && rmozilla.exec( ua ) ||
               [];
   return { browser: match[1] || "", version: match[2] || "0" };
}

and
// Useragent RegExp
rwebkit = /(webkit)[ \/]([\w.]+)/,
ropera = /(opera)(?:.*version)?[ \/]([\w.]+)/,
rmsie = /(msie) ([\w.]+)/,
rmozilla = /(mozilla)(?:.*? rv:([\w.]+))?/,

viktor hesselbom



2012/1/2 Viktor Hesselbom <vik...@hesselbom.net>

JLM

unread,
Jan 2, 2012, 5:08:17 AM1/2/12
to haXe
Victor

I have made the setter/getter private as per your first suggestion and
updated googlecode and haxelib.


I have decided not to use jquery source and prefer the code is non
derived. I have thought about version, but it maybe somewhat of a
redherring as it provides less useful information. Really it is
features detection that I would like to add, so version would only be
needed internally, but not something I want to work on at mo.

Maybe we can collect a list of features users actually need to test
for and browsers/versions and gather use cases for the detection, and
then add in the most useful way to minimize the interface.

If your interested in improving the library then I think it is now
fairly easy to clone google projects serverside and then merge back
changes later, I stuck with googlecode over git as I prefer the setup
of hg, and googlecode allows me to create an example link from the
repository without having to host elsewhere. It would be nice as a
principle to not derive from jquery, especially since my divtastic
experiments are not in anyway based on jquery or any javascript
library apart from core haXe and I would be using it for divtastic, so
prefer to base code on our own tests and needs, but obviously if
others actually start using it then this can be reconsidered.

Cheers

;j
Reply all
Reply to author
Forward
0 new messages