[js] Only isIE and isOpera?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[js] Only isIE and isOpera?

Viktor Hesselbom-2
Hello guys!

For the JS target, is there a reason we have isIE and isOpera but not, for instance, isChrome?

I understand why we would want to see if it's in IE, with all their problems, and Opera I guess because of rightclick limitations.

I think it would be cleaner to have an enum for what browser it is. js.Lib.browser could be Ie, Opera, Chrome etc.

What do you think?


viktor hesselbom


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: [js] Only isIE and isOpera?

Nicolas Cannasse
Le 13/10/2011 12:20, Viktor Hesselbom a écrit :

> Hello guys!
>
> For the JS target, is there a reason we have isIE and isOpera but not,
> for instance, isChrome?
>
> I understand why we would want to see if it's in IE, with all their
> problems, and Opera I guess because of rightclick limitations.
>
> I think it would be cleaner to have an enum for what browser it is.
> js.Lib.browser could be Ie, Opera, Chrome etc.
>
> What do you think?

I think that we need to remove it and instead use js.JQuery.browser
which has better detection support

Best,
Nicolas


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: [js] Only isIE and isOpera?

jlm@justinfront.net
I am using js without jquery at the moment for my experiments, jquery is an additional file size and possible to work without for some use cases like potential banner use where file size is critical, maybe my arguments are wrong.  Enclosed is the wip class I am using for browser detection it is far from finished... so it differs from the lighter one checked in on divtastic and needs improving thinking about and mostly access to lots of browsers to test.  I would love suggestions on improvements.  I need IE version numbers for stuff like dealing with video, not sure if I need browser numbers for other browsers?

package divtastic.js;
import js.Dom;
import js.Lib;

import divtastic.js.DisplayDiv;

enum BrowserType
{
    WebKit;
    Mozilla;
    Opera;
    IE;
}

class Browser
{
        
    public static var root:                         Document = Lib.document;
    private static var _browserType:          BrowserType;
        private static var _ieVersion:                 Float;
        
    public static var browserType( get_BrowserType, null ): BrowserType;
    
    
    public static function addChild( d: Dynamic, mc: DisplayDiv ):Void
    {
                
                root.body.appendChild( mc.getInstance() );        
                
        }
        
    public static function get_BrowserType(): BrowserType
    {
        
        if( _browserType == null )
        {
            
            setBrowserType( Lib.window.navigator.userAgent );
            
        }
        
        return _browserType;
        
    }
    
    public static function setBrowserType( agent: String ): BrowserType
    {
        
        if( (~/WebKit/).match( agent ) )
        {
            _browserType = WebKit;
        }
        else if( (~/Opera/).match( agent ) )
        {
            
            _browserType = Opera;
            
        }
        else if( (~/Mozilla/).match( agent ) )
        { 
                        if ( Lib.isIE )
                        {
                                _browserType = IE;
                        }
                        else
                        {
                                _browserType = Mozilla;
                        }
                }
        else
        {
            _browserType = IE;
                        get_ieVersion();
        }
        trace( 'browser Type ' + _browserType );
        return _browserType;
        
    }
        
        public static function get_ieVersion(): Float
        {
                
                if( _ieVersion == null )
        {
            
            setIEversion( Lib.window.navigator.appVersion );
            
        }
        
        return _ieVersion;
        }
        
        public static function setIEversion( appVersion: String ): Float
        {
                
                if( appVersion.indexOf( "MSIE" ) != -1 )
                {
                    
                        _ieVersion = Std.parseFloat( appVersion.split( "MSIE" )[ 1 ] );
                    return _ieVersion;
                        
                } 
                else 
                {
                        
                        trace( 'ie version... but not sure which? 9?');
                        
                }
                return _ieVersion;
                
        }

On 13 Oct 2011, at 12:21, Nicolas Cannasse wrote:

Le 13/10/2011 12:20, Viktor Hesselbom a écrit :
Hello guys!

For the JS target, is there a reason we have isIE and isOpera but not,
for instance, isChrome?

I understand why we would want to see if it's in IE, with all their
problems, and Opera I guess because of rightclick limitations.

I think it would be cleaner to have an enum for what browser it is.
js.Lib.browser could be Ie, Opera, Chrome etc.

What do you think?

I think that we need to remove it and instead use js.JQuery.browser which has better detection support

Best,
Nicolas


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: [js] Only isIE and isOpera?

Viktor Hesselbom-2
Ah, nice one. I agree that jQuery is too much if all you need is browser type.

It's nice to have it in the core API but it makes sense not to have it all since it's not actually following any javascript standard.

Having a class like yours is perfect. Maybe make it a haxe lib? Even though it's very tiny it's very useful! :)

viktor hesselbom



2011/10/13 [hidden email] <[hidden email]>
I am using js without jquery at the moment for my experiments, jquery is an additional file size and possible to work without for some use cases like potential banner use where file size is critical, maybe my arguments are wrong.  Enclosed is the wip class I am using for browser detection it is far from finished... so it differs from the lighter one checked in on divtastic and needs improving thinking about and mostly access to lots of browsers to test.  I would love suggestions on improvements.  I need IE version numbers for stuff like dealing with video, not sure if I need browser numbers for other browsers?

package divtastic.js;
import js.Dom;
import js.Lib;

import divtastic.js.DisplayDiv;

enum BrowserType
{
    WebKit;
    Mozilla;
    Opera;
    IE;
}

class Browser
{
        
    public static var root:                         Document = Lib.document;
    private static var _browserType:          BrowserType;
        private static var _ieVersion:                 Float;
        
    public static var browserType( get_BrowserType, null ): BrowserType;
    
    
    public static function addChild( d: Dynamic, mc: DisplayDiv ):Void
    {
                
                root.body.appendChild( mc.getInstance() );        
                
        }
        
    public static function get_BrowserType(): BrowserType
    {
        
        if( _browserType == null )
        {
            
            setBrowserType( Lib.window.navigator.userAgent );
            
        }
        
        return _browserType;
        
    }
    
    public static function setBrowserType( agent: String ): BrowserType
    {
        
        if( (~/WebKit/).match( agent ) )
        {
            _browserType = WebKit;
        }
        else if( (~/Opera/).match( agent ) )
        {
            
            _browserType = Opera;
            
        }
        else if( (~/Mozilla/).match( agent ) )
        { 
                        if ( Lib.isIE )
                        {
                                _browserType = IE;
                        }
                        else
                        {
                                _browserType = Mozilla;
                        }
                }
        else
        {
            _browserType = IE;
                        get_ieVersion();
        }
        trace( 'browser Type ' + _browserType );
        return _browserType;
        
    }
        
        public static function get_ieVersion(): Float
        {
                
                if( _ieVersion == null )
        {
            
            setIEversion( Lib.window.navigator.appVersion );
            
        }
        
        return _ieVersion;
        }
        
        public static function setIEversion( appVersion: String ): Float
        {
                
                if( appVersion.indexOf( "MSIE" ) != -1 )
                {
                    
                        _ieVersion = Std.parseFloat( appVersion.split( "MSIE" )[ 1 ] );
                    return _ieVersion;
                        
                } 
                else 
                {
                        
                        trace( 'ie version... but not sure which? 9?');
                        
                }
                return _ieVersion;

                
        }

On 13 Oct 2011, at 12:21, Nicolas Cannasse wrote:

Le 13/10/2011 12:20, Viktor Hesselbom a écrit :
Hello guys!

For the JS target, is there a reason we have isIE and isOpera but not,
for instance, isChrome?

I understand why we would want to see if it's in IE, with all their
problems, and Opera I guess because of rightclick limitations.

I think it would be cleaner to have an enum for what browser it is.
js.Lib.browser could be Ie, Opera, Chrome etc.

What do you think?

I think that we need to remove it and instead use js.JQuery.browser which has better detection support

Best,
Nicolas


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: [js] Only isIE and isOpera?

Johann Borck
On 10/13/2011 04:16 PM, Viktor Hesselbom wrote:
Ah, nice one. I agree that jQuery is too much if all you need is browser type.

It's nice to have it in the core API but it makes sense not to have it all since it's not actually following any javascript standard.

Having a class like yours is perfect. Maybe make it a haxe lib? Even though it's very tiny it's very useful! :)

viktor hesselbom



Yes, please don't make haxe depend on jquery or any other JS library for that matter.


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: [js] Only isIE and isOpera?

Bruno Garcia-2
In reply to this post by Nicolas Cannasse
On 10/13/2011 04:21 AM, Nicolas Cannasse wrote:
> I think that we need to remove it and instead use js.JQuery.browser
> which has better detection support

+1

Bruno

--
haXe - an open source web programming language
http://haxe.org