OpenLayers OpenLayers

Ticket #111: safari.2.patch

File safari.2.patch, 5.2 kB (added by seang, 3 years ago)

patch for Atom feeds on Safari, FF 1.5, and IE 6

  • lib/OpenLayers/Layer/GeoRSS.js

    old new  
    5151        if (!doc || ajaxRequest.fileType!="XML") { 
    5252            doc = OpenLayers.parseXMLString(ajaxRequest.responseText); 
    5353        } 
    54         this.name = doc.getElementsByTagName("title")[0].firstChild.nodeValue;     
    55         var itemlist = doc.getElementsByTagName('item'); 
     54         
     55        this.name = null; 
     56        try { 
     57            this.name = doc.getElementsByTagNameNS('*', 'title')[0].firstChild.nodeValue; 
     58        } 
     59        catch (e) { 
     60            this.name = doc.getElementsByTagName('title')[0].firstChild.nodeValue; 
     61        } 
     62        
     63        /* Try RSS items first, then Atom entries */ 
     64        var itemlist = null; 
     65        try { 
     66            itemlist = doc.getElementsByTagNameNS('*', 'item'); 
     67        } 
     68        catch (e) { 
     69            itemlist = doc.getElementsByTagName('item'); 
     70        } 
     71 
     72        if (itemlist.length == 0) { 
     73            try { 
     74                itemlist = doc.getElementsByTagNameNS('*', 'entry'); 
     75            } 
     76            catch(e) { 
     77                itemlist = doc.getElementsByTagName('entry'); 
     78            } 
     79        } 
     80 
    5681        for (var i = 0; i < itemlist.length; i++) { 
    5782            var data = {}; 
    5883            var point = OpenLayers.Util.getNodes(itemlist[i], 'georss:point'); 
     
    7297            location = new OpenLayers.LonLat(parseFloat(location[1]), parseFloat(location[0])); 
    7398             
    7499            /* Provide defaults for title and description */ 
    75             var title = "No title"; 
     100            var title = "Untitled"; 
    76101            try { 
    77102              title = OpenLayers.Util.getNodes(itemlist[i],  
    78103                        "title")[0].firstChild.nodeValue; 
    79104            } 
    80             catch (e) { alert(e); } 
    81              
    82             var description = "No description"; 
     105            catch (e) { title="Untitled"; } 
     106            
     107            /* First try RSS descriptions, then Atom summaries */ 
     108            var descr_nodes = null; 
    83109            try { 
    84               description = OpenLayers.Util.getNodes(itemlist[i],  
    85                               "description")[0].firstChild.nodeValue
     110                descr_nodes = itemlist[i].getElementsByTagNameNS("*", 
     111                                                "description")
    86112            } 
    87             catch (e) { alert(e); } 
     113            catch (e) { 
     114                descr_nodes = itemlist[i].getElementsByTagName("description"); 
     115            } 
     116            if (descr_nodes.length == 0) { 
     117                try { 
     118                    descr_nodes = itemlist[i].getElementsByTagNameNS("*", 
     119                                                "summary"); 
     120                } 
     121                catch (e) { 
     122                    descr_nodes = itemlist[i].getElementsByTagName("summary"); 
     123                } 
     124            } 
    88125 
     126            var description = "No description."; 
     127            try { 
     128              description = descr_nodes[0].firstChild.nodeValue; 
     129            } 
     130            catch (e) { description="No description."; } 
     131 
    89132            try { var link = OpenLayers.Util.getNodes(itemlist[i], "link")[0].firstChild.nodeValue; } catch (e) { }  
    90133            data.icon = OpenLayers.Marker.defaultIcon(); 
    91             data.popupSize = new OpenLayers.Size(250, 100); 
     134            data.popupSize = new OpenLayers.Size(250, 120); 
    92135            if ((title != null) && (description != null)) { 
    93                 contentHTML = "<br />"; 
    94                 contentHTML += "<div style='margin: -0.5em 0.5em 0.5em 0.5em'>"  
    95                  
    96                 contentHTML += "<div style='height: 1.3em; overflow: hidden'>"; 
    97                 contentHTML += "<span style='font-size: 1.2em; font-weight: bold'>";  
    98                 if (link)  contentHTML += "<a href='"+link+"' target='_blank'>";  
    99                 contentHTML +=     title; 
    100                 if (link) contentHTML += "</a>"; 
    101                 contentHTML += "</span>"; 
    102                 contentHTML += "</div>"; 
    103  
    104  
    105                 contentHTML += "<span style='font-size: 0.7em; align:center'>"; 
    106                 contentHTML += description; 
    107                 contentHTML += "</span>"; 
    108  
    109                 contentHTML += "</div>" 
    110                 data['popupContentHTML'] = contentHTML; 
    111                  
    112                 //data['popupContentHTML'] = '<h2>'+title+'</h2><p>'+description+'</p>'; 
     136              contentHTML = '<div style="float:left;font-size:120%;">'; 
     137              if (link) contentHTML += '<a class="link" href="'+link+'" target="_blank">'; 
     138              contentHTML += title; 
     139              if (link) contentHTML += '</a>'; 
     140              contentHTML += '</div>'; 
     141              contentHTML += '<div style="float:right;color:gray;font-size:120%;font-family:sans-serif">[x]</div>';  
     142              contentHTML += '<div style="float:left;width:100%;overflow:auto;font-size:100%;">'; 
     143              contentHTML += description; 
     144              contentHTML += '</div>'; 
     145              data['popupContentHTML'] = contentHTML;                 
    113146            } 
    114147            var feature = new OpenLayers.Feature(this, location, data); 
    115148            this.features.push(feature);