From a2dfb0367d178046e7d68045e7f0cbccdf115440 Mon Sep 17 00:00:00 2001 From: rolux Date: Sat, 23 Apr 2011 17:51:58 +0200 Subject: [PATCH] check browser version --- source/js/Ox.js | 36 ++++++++++++++++++------------------ source/js/OxUI.js | 35 +++++++++++++++++++++-------------- 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/source/js/Ox.js b/source/js/Ox.js index 51d465ff..5a3ed2d3 100644 --- a/source/js/Ox.js +++ b/source/js/Ox.js @@ -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, diff --git a/source/js/OxUI.js b/source/js/OxUI.js index 0bffba40..60c8d174 100644 --- a/source/js/OxUI.js +++ b/source/js/OxUI.js @@ -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() {