OpenLayers OpenLayers

Ticket #111: safari.patch

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

patch for Safari and Atom feeds

  • 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        this.name = doc.getElementsByTagNameNS('*', 'title')[0].firstChild.nodeValue;     
     55        
     56        /* Try RSS items first, then Atom entries */ 
     57        var itemlist = doc.getElementsByTagNameNS('*', 'item'); 
     58        if (itemlist.length == 0) { 
     59            itemlist = doc.getElementsByTagNameNS('*', 'entry'); 
     60        } 
     61 
    5662        for (var i = 0; i < itemlist.length; i++) { 
    5763            var data = {}; 
    5864            var point = OpenLayers.Util.getNodes(itemlist[i], 'georss:point'); 
     
    7278            location = new OpenLayers.LonLat(parseFloat(location[1]), parseFloat(location[0])); 
    7379             
    7480            /* Provide defaults for title and description */ 
    75             var title = "No title"; 
     81            var title = "Untitled"; 
    7682            try { 
    7783              title = OpenLayers.Util.getNodes(itemlist[i],  
    7884                        "title")[0].firstChild.nodeValue; 
    7985            } 
    80             catch (e) { alert(e); } 
    81              
    82             var description = "No description"; 
     86            catch (e) { title="Untitled"; } 
     87            
     88            /* First try RSS descriptions, then Atom summaries */ 
     89            var descr_nodes = itemlist[i].getElementsByTagNameNS("*", 
     90                                                "description"); 
     91            if (descr_nodes.length == 0) { 
     92                descr_nodes = itemlist[i].getElementsByTagNameNS("*","summary"); 
     93            } 
     94 
     95            var description = "No description."; 
    8396            try { 
    84               description = OpenLayers.Util.getNodes(itemlist[i],  
    85                               "description")[0].firstChild.nodeValue; 
     97              description = descr_nodes[0].firstChild.nodeValue; 
    8698            } 
    87             catch (e) { alert(e); } 
     99            catch (e) { description="No description."; } 
    88100 
    89101            try { var link = OpenLayers.Util.getNodes(itemlist[i], "link")[0].firstChild.nodeValue; } catch (e) { }  
    90102            data.icon = OpenLayers.Marker.defaultIcon(); 
    91             data.popupSize = new OpenLayers.Size(250, 100); 
     103            data.popupSize = new OpenLayers.Size(250, 120); 
    92104            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>'; 
     105              contentHTML = '<div style="float:left;font-size:120%;">'; 
     106              if (link) contentHTML += '<a class="link" href="'+link+'" target="_blank">'; 
     107              contentHTML += title; 
     108              if (link) contentHTML += '</a>'; 
     109              contentHTML += '</div>'; 
     110              contentHTML += '<div style="float:right;color:gray;font-size:120%;font-family:sans-serif">[x]</div>';  
     111              contentHTML += '<div style="float:left;width:100%;overflow:auto;font-size:100%;">'; 
     112              contentHTML += description; 
     113              contentHTML += '</div>'; 
     114              data['popupContentHTML'] = contentHTML;                 
    113115            } 
    114116            var feature = new OpenLayers.Feature(this, location, data); 
    115117            this.features.push(feature);