From c44a071a3f86d07bed9504eacc25ca9eb2105f36 Mon Sep 17 00:00:00 2001 From: Andrew Dupont Date: Fri, 15 May 2009 21:50:32 -0500 Subject: [PATCH] `Prototype.Browser.Opera` now uses stronger inference and is determined by [[Class]] of `window.opera` being - "Opera". (kangax) --- CHANGELOG | 2 ++ src/prototype.js | 22 +++++++++++++--------- test/unit/base_test.js | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index dba3771..bd4412f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* `Prototype.Browser.Opera` now uses stronger inference and is determined by [[Class]] of `window.opera` being - "Opera". (kangax) + * Fix error in event.js which prevented attaching more than one responder for an event name/element combination. [#651 state:resolved] (Rob Lineweaver) * Do not sniff when testing for IE's proprietary mouseenter/mouseleave events support. Use more robust inference instead. (kangax) diff --git a/src/prototype.js b/src/prototype.js index 166e02d..9d0b667 100644 --- a/src/prototype.js +++ b/src/prototype.js @@ -9,15 +9,19 @@ var Prototype = { Version: '<%= PROTOTYPE_VERSION %>', - Browser: { - IE: !!(window.attachEvent && - navigator.userAgent.indexOf('Opera') === -1), - Opera: navigator.userAgent.indexOf('Opera') > -1, - WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1, - Gecko: navigator.userAgent.indexOf('Gecko') > -1 && - navigator.userAgent.indexOf('KHTML') === -1, - MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/) - }, + Browser: (function(){ + var ua = navigator.userAgent; + // Opera (at least) 8.x+ has "Opera" as a [[Class]] of `window.opera` + // This is a safer inference than plain boolean type conversion of `window.opera` + var isOpera = Object.prototype.toString.call(window.opera) == '[object Opera]'; + return { + IE: !!window.attachEvent && !isOpera, + Opera: isOpera, + WebKit: ua.indexOf('AppleWebKit/') > -1, + Gecko: ua.indexOf('Gecko') > -1 && ua.indexOf('KHTML') === -1, + MobileSafari: /Apple.*Mobile.*Safari/.test(ua) + } + })(), BrowserFeatures: { XPath: !!document.evaluate, diff --git a/test/unit/base_test.js b/test/unit/base_test.js index 6ab91c7..ca07b6b 100644 --- a/test/unit/base_test.js +++ b/test/unit/base_test.js @@ -25,7 +25,7 @@ new Test.Unit.Runner({ this.assert(Prototype.Browser.WebKit); } - if(!!window.opera) { + if(Object.prototype.toString.call(window.opera) === '[object Opera]') { this.info('Running on Opera'); this.assert(Prototype.Browser.Opera); }