Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added Google news feed.

  • Loading branch information...
commit 4a272872fa600b2d369376d29d1e47914a8dea2e 1 parent 26ff61c
Dave Cross authored July 21, 2013
8  PoliticalWeb/public/js/jquery.zrssfeed.min.js
... ...
@@ -0,0 +1,8 @@
  1
+(function(l){l.fn.rssfeed=function(b,h,w){h=l.extend({limit:10,offset:1,header:!0,titletag:"h4",date:!0,dateformat:"datetime",content:!0,snippet:!0,media:!0,showerror:!0,errormsg:"",key:null,ssl:!1,linktarget:"_self",linkredirect:"",linkcontent:!1,sort:"",sortasc:!0,historical:!1},h);return this.each(function(z,q){var u=l(q),f="";h.ssl&&(f="s");u.hasClass("rssFeed")||u.addClass("rssFeed");if(null==b)return!1;0<h.offset&&(h.offset-=1);h.limit+=h.offset;f="http"+f+"://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=?&q="+
  2
+encodeURIComponent(b);f+="&num="+h.limit;h.historical&&(f+="&scoring=h");null!=h.key&&(f+="&key="+h.key);l.getJSON(f+"&output=json_xml",function(b){if(200==b.responseStatus){var f=b.responseData,e=h;if(b=f.feed){var j=[],d=0,m="",v="odd";if(e.media){var n=f.xmlString;"Microsoft Internet Explorer"==navigator.appName?(d=new ActiveXObject("Microsoft.XMLDOM"),d.async="false",d.loadXML(n)):d=(new DOMParser).parseFromString(n,"text/xml");n=d.getElementsByTagName("item")}e.header&&(m+='<div class="rssHeader"><a href="'+
  3
+b.link+'" title="'+b.description+'">'+b.title+"</a></div>");m+='<div class="rssBody"><ul>';for(f=e.offset;f<b.entries.length;f++){d=f-e.offset;j[d]=[];var g=b.entries[f],a,c="",k=g.link;switch(e.sort){case "title":c=g.title;break;case "date":c=g.publishedDate}j[d].sort=c;if(g.publishedDate)switch(c=new Date(g.publishedDate),a=c.toLocaleDateString()+" "+c.toLocaleTimeString(),e.dateformat){case "datetime":break;case "date":a=c.toLocaleDateString();break;case "time":a=c.toLocaleTimeString();break;case "timeline":a=
  4
+new Date(c);a=Math.round(((new Date).getTime()-a.getTime())/1E3);60>a?a="< 1 min":(3600>a?(a=Math.round(a/60)-1,c="min"):86400>a?(a=Math.round(a/3600)-1,c="hour"):604800>a?(a=Math.round(a/86400)-1,c="day"):(a=Math.round(a/604800)-1,c="week"),1<a&&(c+="s"),a=a+" "+c);break;default:a=c,c=new Date(a),a=e.dateformat,a=a.replace("dd",p(c.getDate())),a=a.replace("MMMM",x(c.getMonth())),a=a.replace("MM",p(c.getMonth()+1)),a=a.replace("yyyy",c.getFullYear()),a=a.replace("hh",p(c.getHours())),a=a.replace("mm",
  5
+p(c.getMinutes())),a=a.replace("ss",p(c.getSeconds()))}e.linkredirect&&(k=encodeURIComponent(k));j[d].html="<"+e.titletag+'><a href="'+e.linkredirect+k+'" title="View this feed at '+b.title+'">'+g.title+"</a></"+e.titletag+">";e.date&&a&&(j[d].html+="<div>"+a+"</div>");e.content&&(g=e.snippet&&""!=g.contentSnippet?g.contentSnippet:g.content,e.linkcontent&&(g='<a href="'+e.linkredirect+k+'" title="View this feed at '+b.title+'">'+g+"</a>"),j[d].html+="<p>"+g+"</p>");if(e.media&&0<n.length&&(k=n[f].getElementsByTagName("enclosure"),
  6
+0<k.length)){j[d].html+='<div class="rssMedia"><div>Media files</div><ul>';for(g=0;g<k.length;g++){var r=k[g].getAttribute("url"),s=k[g].getAttribute("type"),t=k[g].getAttribute("length"),c=j[d],y=j[d].html,r='<li><a href="'+r+'" title="Download this media">'+r.split("/").pop()+"</a> ("+s+", ",s=Math.floor(Math.log(t)/Math.log(1024)),t=(t/Math.pow(1024,Math.floor(s))).toFixed(2)+" "+"bytes kb MB GB TB PB".split(" ")[s];c.html=y+(r+t+")</li>")}j[d].html+="</ul></div>"}}e.sort&&j.sort(function(a,c){if(e.sortasc)var b=
  7
+a.sort,d=c.sort;else b=c.sort,d=a.sort;if("date"==e.sort)return new Date(b)-new Date(d);b=b.toLowerCase();d=d.toLowerCase();return b<d?-1:b>d?1:0});l.each(j,function(a){m+='<li class="rssRow '+v+'">'+j[a].html+"</li>";v="odd"==v?"even":"odd"});m+="</ul></div>";l(q).html(m);l("a",q).attr("target",e.linktarget)}l.isFunction(w)&&w.call(this,u)}else h.showerror&&(d=""!=h.errormsg?h.errormsg:b.responseDetails),l(q).html('<div class="rssError"><p>'+d+"</p></div>")})})};var p=function(b){b+="";2>b.length&&
  8
+(b="0"+b);return b},x=function(b){return"Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" ")[b]}})(jQuery);
27  PoliticalWeb/views/constituency.tt
... ...
@@ -1,3 +1,15 @@
  1
+    <script src="/js/jquery.zrssfeed.min.js" type="text/javascript"></script>
  2
+        <script type="text/javascript">
  3
+$(document).ready(function () {
  4
+  $('#news').rssfeed('https://news.google.com/news/feeds?ned=uk&output=rss&q=[% mp.full_name %]+MP', {
  5
+    limit: 10,
  6
+    dateformat: 'timeline',
  7
+    content: false,
  8
+    sort: 'date',
  9
+    sortasc: false
  10
+  });
  11
+});
  12
+</script>
1 13
 [% META title = 'Constituency' -%]
2 14
   <div class="span10 media">
3 15
 [% IF mp.image %]
@@ -13,12 +25,13 @@
13 25
   <div class="span6">
14 26
     <div class="tabbable">
15 27
       <ul class="nav nav-tabs">
16  
-        <li class="active"><a href="#tab1" data-toggle="tab">Default</a></li>
17  
-        <li><a href="#tab2" data-toggle="tab">Twitter</a></li>
18  
-        <li><a href="#tab3" data-toggle="tab">Blog</a></li>
  28
+        <li class="active"><a href="#default" data-toggle="tab">Default</a></li>
  29
+        <li><a href="#news" data-toggle="tab">News</a></li>
  30
+        <li><a href="#twitter" data-toggle="tab">Twitter</a></li>
  31
+        <li><a href="#blog" data-toggle="tab">Blog</a></li>
19 32
       </ul>
20 33
       <div class="tab-content">
21  
-        <div class="tab-pane active" id="tab1">
  34
+        <div class="tab-pane active" id="default">
22 35
           <ul>
23 36
 [% IF mp.extra.wikipedia_url %]
24 37
             <li><a href="[% mp.extra.wikipedia_url %]">Wikipedia entry</a></li>
@@ -41,10 +54,12 @@
41 54
 [% END -%]
42 55
           </ul>
43 56
         </div>
44  
-        <div class="tab-pane" id="tab2">
  57
+        <div class="tab-pane" id="news">
  58
+        </div>
  59
+        <div class="tab-pane" id="twitter">
45 60
           Twitter here
46 61
         </div>
47  
-        <div class="tab-pane" id="tab3">
  62
+        <div class="tab-pane" id="blog">
48 63
           Blog here
49 64
         </div>
50 65
       </div>

0 notes on commit 4a27287

Please sign in to comment.
Something went wrong with that request. Please try again.