check browser version

This commit is contained in:
rolux 2011-04-23 17:51:58 +02:00
parent 0e3f49f134
commit a2dfb0367d
2 changed files with 39 additions and 32 deletions

View file

@ -329,24 +329,6 @@ Ox.filter = function(obj, fn) {
return ret; return ret;
}; };
Ox.flatten = function(arr) {
/*
>>> Ox.flatten([1, [2, [3], 4], 5])
[1, 2, 3, 4, 5]
*/
var ret = [];
arr.forEach(function(v) {
if (Ox.isArray(v)) {
Ox.flatten(v).forEach(function(v) {
ret.push(v);
});
} else {
ret.push(v);
}
});
return ret;
}
Ox.find = function(arr, str) { Ox.find = function(arr, str) {
/* /*
returns an array with two arrays as elements: returns an array with two arrays as elements:
@ -367,6 +349,24 @@ Ox.find = function(arr, str) {
return ret; return ret;
}; };
Ox.flatten = function(arr) {
/*
>>> Ox.flatten([1, [2, [3], 4], 5])
[1, 2, 3, 4, 5]
*/
var ret = [];
arr.forEach(function(v) {
if (Ox.isArray(v)) {
Ox.flatten(v).forEach(function(v) {
ret.push(v);
});
} else {
ret.push(v);
}
});
return ret;
}
Ox.forEach = function(obj, fn) { Ox.forEach = function(obj, fn) {
/* /*
Ox.forEach() works for arrays, objects and strings, Ox.forEach() works for arrays, objects and strings,

View file

@ -196,12 +196,12 @@ Provides function Ox.UI([options], callback) that fires when
// runs when the document is ready // runs when the document is ready
var body, css, div, var body, css, div,
options = oxUIOptions || oxUIDefaults, browsers = [
userAgents = [ {name: 'Chrome', url: 'http://www.google.com/chrome/', version: 10},
{name: 'Chrome', url: 'http://www.google.com/chrome/'}, {name: 'Firefox', url: 'http://www.mozilla.org/firefox/', version: 4},
{name: 'Firefox', url: 'http://www.mozilla.org/firefox/'}, {name: 'Safari', url: 'http://www.apple.com/safari/', version: 5}
//{name: 'Safari', url: 'http://www.apple.com/safari/'} ],
]; options = oxUIOptions || oxUIDefaults;
if (options.display != 'none') { if (options.display != 'none') {
body = getElement('body'); body = getElement('body');
@ -234,16 +234,23 @@ Provides function Ox.UI([options], callback) that fires when
.appendTo(body); .appendTo(body);
} }
getUserAgent() ? start() : stop(); checkBrowser() ? start() : stop();
function getUserAgent() { function checkBrowser() {
var userAgent = ''; var i, isSupported = false;
userAgents.forEach(function(v) { for (i in browsers) {
if (navigator.userAgent.indexOf(v.name) > -1) { var browser = browsers[i],
userAgent = v.name; version;
if (navigator.userAgent.indexOf(browser.name) > -1) {
if (new RegExp((
browser.name == 'Safari' ? 'Version' : browser.name
) + '\\/(\\d+)\\.')(navigator.userAgent)[1] >= browser.version) {
isSupported = true;
break;
}
} }
}); }
return userAgent; return isSupported;
} }
function start() { function start() {