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;
};
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) {
/*
returns an array with two arrays as elements:
@ -367,6 +349,24 @@ Ox.find = function(arr, str) {
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() 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
var body, css, div,
options = oxUIOptions || oxUIDefaults,
userAgents = [
{name: 'Chrome', url: 'http://www.google.com/chrome/'},
{name: 'Firefox', url: 'http://www.mozilla.org/firefox/'},
//{name: 'Safari', url: 'http://www.apple.com/safari/'}
];
browsers = [
{name: 'Chrome', url: 'http://www.google.com/chrome/', version: 10},
{name: 'Firefox', url: 'http://www.mozilla.org/firefox/', version: 4},
{name: 'Safari', url: 'http://www.apple.com/safari/', version: 5}
],
options = oxUIOptions || oxUIDefaults;
if (options.display != 'none') {
body = getElement('body');
@ -234,16 +234,23 @@ Provides function Ox.UI([options], callback) that fires when
.appendTo(body);
}
getUserAgent() ? start() : stop();
checkBrowser() ? start() : stop();
function getUserAgent() {
var userAgent = '';
userAgents.forEach(function(v) {
if (navigator.userAgent.indexOf(v.name) > -1) {
userAgent = v.name;
function checkBrowser() {
var i, isSupported = false;
for (i in browsers) {
var browser = browsers[i],
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() {