Changeset 23

Show
Ignore:
Timestamp:
12/04/09 12:19:01 (9 months ago)
Author:
guillaume
Message:
  • improve browser detection (window.mozilla and widow.opera are not safe)
  • compatibility with epiphany browser . epiphany identify itself as safari (use the same engine) . but 'elementFromPoint' javascript function behave like mozilla one
Location:
trunk/jslib
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/jslib/browser-compat.js

    r11 r23  
    2121        this._browser                   = undefined; 
    2222 
    23         /* DETECT BROWSER */ 
    24         console.log(window.navigator.product); 
    25         console.log(window.navigator.userAgent); 
    26         console.log('net=' + window.netscape); 
    27         console.log('ie=' + window.ie); 
    28         console.log('op=' + window.opera); 
     23        /* DETECT BROWSER  
     24                window.mozilla & window.opera browser detect methods are not safe: 
     25                        if you declare an HTML tag with 'opera' id, window.opera will be set even 
     26                        if you do not use opera 
    2927 
    30         // WARNING: opera also set netscape 
    31         if (window.opera) 
    32         { this._browser = 'opera'; } 
    33         else if (window.netscape) 
    34         { this._browser = 'mozilla'; } 
    35         else 
    36         { this._browser = 'unknown'; } 
     28                NOTES: 
     29                        epiphany & chromium use safari user-agent 
     30        */ 
     31        browsers = [ 
     32                ['Firefox', 'mozilla'], ['MSIE' , 'ie'], 
     33                ['Chrome' , 'chrome'] , ['Opera', 'opera'], ['Apple', 'safari'] 
     34        ] 
    3735 
     36        console.log(navigator.userAgent); 
     37        this._browser = 'undefined'; 
     38        for (var i = 0; i < browsers.length; i++) 
     39        { 
     40                if(navigator.userAgent.indexOf(browsers[i][0]) != -1) 
     41                { this._browser = browsers[i][1]; break; } 
     42        } 
    3843        console.log('browser=' + this._browser); 
    3944 
     
    4550        this.viewportElementFromPoint = function(doc, win, xpos, ypos) 
    4651                { 
    47                         if (this._browser == 'opera') 
    48                         {       ypos += win.pageYOffset; } 
     52                        if (this._browser == 'opera' || this._browser == 'safari') 
     53                        {        
     54                                // while epiphany identify itself as safari, it behave as firefox 
     55                                // for this function 
     56                                // so we must fallback to the default method if we found no HTML element 
     57                                elt = doc.elementFromPoint(xpos, ypos + win.pageYOffset); 
     58                                if(elt) 
     59                                { return(elt); } 
     60                        } 
    4961 
    5062                        return doc.elementFromPoint(xpos, ypos); 
  • trunk/jslib/dare-dare.js

    r20 r23  
    398398        if(ylineup >= 0) 
    399399        { 
    400                 img = this.content.getElementById('page' + ylineup); 
     400                var img = this.content.getElementById('page' + ylineup); 
    401401                console.log('img=' + img) 
    402                 top = img.offsetTop + img.offsetHeight; 
     402                var top = img.offsetTop + img.offsetHeight; 
    403403                // little move 
    404404                top += ((pagenum - (pagenum % this._viewport[0])) / this._viewport[0]) % 2; 
     
    430430        var img = this.compat.viewportElementFromPoint(this.content, this.contentw, 20, 30); 
    431431        console.log('vp.img= ' + img) 
     432        if(img != null) 
     433        { console.log('img idx=' + img.getAttribute('pagenum')); } 
    432434        var start = img == null ? 0 : parseInt(img.getAttribute('pagenum')); 
    433435