-
Notifications
You must be signed in to change notification settings - Fork 1
/
tamufeed.min.js
1 lines (1 loc) · 11.6 KB
/
tamufeed.min.js
1
(function(f,h,e){var g=typeof module=="object"&&typeof require=="function";if(g){module.exports=e(f,h)}else{if(typeof define==="function"&&typeof define.amd==="object"){define(e)}else{h[f]=e(f,h)}}}("PubSub",(typeof window!=="undefined"&&window)||this,function definition(x,w){var m={name:"PubSubJS",version:"1.3.2"},r={},o=-1;function n(b){return function a(){throw b}}function u(d,c,b){try{d(c,b)}catch(a){setTimeout(n(a),0)}}function q(a,c,b){a(c,b)}function s(h,e,d,b){var c=r[e],a=b?q:u,f,g;if(!r.hasOwnProperty(e)){return}for(f=0,g=c.length;f<g;f++){a(c[f].func,h,d)}}function t(a,d,b){return function c(){var e=String(a),f=e.lastIndexOf(".");s(a,a,d,b);while(f!==-1){e=e.substr(0,f);f=e.lastIndexOf(".");s(a,e,d)}}}function p(c){var d=String(c),b=r.hasOwnProperty(d),a=d.lastIndexOf(".");while(!b&&a!==-1){d=d.substr(0,a);a=d.lastIndexOf(".");b=r.hasOwnProperty(d)}return b}function v(e,d,f,b){var c=t(e,d,b),a=p(e);if(!a){return false}if(f===true){c()}else{setTimeout(c,0)}return true}m.publish=function(a,b){return v(a,b,false,m.immediateExceptions)};m.publishSync=function(a,b){return v(a,b,true,m.immediateExceptions)};m.subscribe=function(b,c){if(!r.hasOwnProperty(b)){r[b]=[]}var a=String(++o);r[b].push({token:a,func:c});return a};m.unsubscribe=function(a){var c=typeof a==="string",d=c?"token":"func",b=c?a:true,g=false,h,e,f;for(h in r){if(r.hasOwnProperty(h)){for(e=r[h].length-1;e>=0;e--){if(r[h][e][d]===a){r[h].splice(e,1);g=b;if(c){return g}}}}}return g};return m}));var tamufeed=(function(R,I,h){var w="0.1.7";var g,ac=[],r={},q="tamufeed";var L=tamufeed;var d=L.debugging||false;var n=L.feed||[];var P=L.entries||[];var i=L.language||"en";var C=L.sort||"";var k=L.fetchEntries||4;var M=L.wantEntries||99;var m=L.overWantedClass="over";var s=L.truncatedStringMaxLength||300;var K=L.minutesBeforeHistorical*60000||1800000;var j=L.selector||{};if("string"===typeof j){j={stage:j}}var X=L.url;if("string"===typeof X){X=[X]}var u=[],A=[],z=[],y=[],Z=[];u.en=["th","st","nd","rd","th","th","th","th","th","th"];u.es=["","","","","","","","","",""];z.en=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];z.es=["Do","Lu","Ma","Mi","Ju","Vi","Sa"];A.en=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];A.es=["domingo","lunes","martes","miércoles","jueves","viernes","sábado"];Z.en=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];Z.es=["Ene","Feb","Mar","Abr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dic"];y.en=["January","February","March","April","May","June","July","August","September","October","November","December"];y.es=["enero","febrero","marzo","abril","mayo","junio","julio","agosto","septiembre","octubre","noviembre","diciembre"];Date.valueOf=Date.now=Date.now||function(){return +new Date};if(!Array.prototype.forEach){Array.prototype.forEach=function(af,ae){for(var ad=0,t=this.length;ad<t;++ad){af.call(ae,this[ad],ad,this)}}}var E={debug:("undefined"===typeof console||"undefined"===typeof console.log?function(){}:function(t){if(d){return console.log(t)}})};j.stage=j.stage||"#tamufeed";j.propertyTemplate=j.propertyTemplate||"#propertyTemplate";j.entryTemplate=j.entryTemplate||"#entryTemplate";j.feedTemplate=j.feedTemplate||"#feedTemplate";j.dateTemplate=j.dateTemplate||"#dateTemplate";j.encasedTemplate=j.encasedTemplate||"#encasedTemplate";j.dateBlockTemplate=j.dateBlockTemplate||"#dateBlockTemplate";var Y=I(j.dateTemplate).html();var p=I(j.propertyTemplate).html();var o=I(j.feedTemplate).html();var D=I(j.entryTemplate).html();var f=I(j.encasedTemplate).html()||'<table class="{{key}}"><tbody><tr><td class="{{key}}" {{dataAttr}}>{{value}}</td></tr></tbody></table>';var v=I(j.dateBlockTemplate).html();if(!X){X=["http://codemaroon.tamu.edu/feed.xml"]}var Q=function(t,ae){if("string"!==typeof t){throw"t() 1st parameter must be a string; not "+typeof t}for(var ad in ae){t=t.replace(new RegExp("{{"+ad+"}}","g"),ae[ad])}return t.replace(/({{[^{]*}})/ig,"")};var l=function(al){if(!al.getMinutes){error("Invalid dt(parameter) was "+typeof al)}var ag=al.getMinutes();var an=al.getHours();var am="a.m.";if(an>=12){an-=12;am="p.m.";if(!an){an=12}}var ae=al.getDate();var ad=u[i][ae%10];if(ag<10){ag="0"+ag}var ak=(ae<10)?"0"+ae:ae;var ai=al.getDay();var ap=z[i][ai];var ah=A[i][ai];var aj=al.getMonth();var af=Z[i][aj];var ao=y[i][aj];aj++;var t=(aj<=9)?"0"+(aj):aj;return{w:ai,S:ad,j:ae,d:ak,D:ap,l:ah,n:aj,m:t,M:af,F:ao,Y:al.getFullYear(),i:ag,g:an,a:am,U:al.getTime()}};var H=function(ae,ag,t){var af,ad;if("undefined"===typeof ag){ag=s}af=ae.length>ag;if(!ae||!af){return ae}if("undefined"===typeof t){t=true}ad=ae.substr(0,ag-1);ad=t?ad.substr(0,ad.lastIndexOf(" ")):ad;return ad+"…"};var a=function(t){if("string"!==typeof t||!t){return""}var ad={"<":"lt",">":"gt",'"':"quot","'":"apos","&":"amp"};return t.replace(/[&<>"']/g,function(ae){return"&"+ad[ae]+";"})};var N=function(t){if("string"!==typeof t||!t){return""}t=t.replace(/<\/?script/ig,"<script");t=t.replace(/<\/?style/ig,"<style");t=t.replace(/<\/?frameset/ig,"<frameset");t=t.replace(/<\/?iframe/ig,"<iframe");t=t.replace(/<\/?embed/ig,"<embed");t=t.replace(/<\/?object/ig,"<object");return t};var J=function(ad,t){return !!(0.5-Math.random())};var O=function(ad,t){ad="object"===typeof ad.pubDate?ad.pubDate.getTime():0;t="object"===typeof t.pubDate?t.pubDate.getTime():0;return ad>t};var G=function(ad,t){ad="object"===typeof ad.pubDate?ad.pubDate.getTime():0;t="object"===typeof t.pubDate?t.pubDate.getTime():0;return ad<t};var x=function(t,ag,ae,ad){if(!ad){ad=p}var af="";if("undefined"!==typeof ae){I.each(ae,function(ah,ai){af+=" data-"+ah+'="'+ai+'"'})}return !ag?"":Q(ad,{key:t,value:ag,dataAttr:af})};var B=function(af,aj,t){var ah,ag,ak,ae,ai;var ad=["odd ","even"][af%2];if(aj.type.indexOf("event")>=0){ad+=" vevent"}else{if(aj.type.indexOf("person")>=0){ad+=" vcard"}}if(aj.historical){ad+=" historical"}E.debug("» viewEntry #"+(af+1)+" ("+aj.type+"), #images="+aj.images.length);I.each(aj.images,function(am,al){E.debug(" img src="+al.src)});if(aj.dtstart){ag=ak=x("dtstart",aj.dtstart,{iso8601:aj.dtstartISO8601});if("Invalid Date"===aj.start.toLocaleDateString()){ah=aj.publishedDate||aj.dstartISO8601}else{ah=Q(Y,l(aj.start))}ai=Q(v,l(aj.start));if(aj.dtend){ae=x("dtend",aj.dtend,{iso8601:aj.dtendISO8601});ag=ag+"–"+ae}ah=x("date",ah);ag=ah+ag}else{ag=x("date",Q(Y,l(new Date(aj.publishedDate))))}return{title:aj.title,link:aj.link,linkencoded:encodeURIComponent(aj.link),tags:"",categories:"",description:aj.description,index:af+1,quantity:t,attributes:ad,dtstart:ak,dtend:ae,date:ah,dateBlock:x("dateBlock",ai),time:x("time",ag),bookmark:x("bookmark",aj.link),subtitle:x("subtitle",aj.subtitle),summary:x("summary",aj.summary,{},f),location:x("location",aj.location),pubDate:x("pubDate",aj.publishedDate),author:x("author",aj.author)}};var c=function(ag){E.debug("» viewFeed #"+(ag+1));var ai=0,ae="",af=0;var ad=["odd ","even"][ag%2];ad+=" "+n[ag]["type"];var ah=n[ag]["quantity"];if(!ah){ae='<p class="noentry">Nothing to report.</p>';ad+=" empty"}else{for(ai;ai<n[ag]["quantity"];ai++){var t=B(ai,P[ag][ai],n[ag]["quantity"]);if(t.attributes.indexOf("historical")<1){af++}if(af>M){t.attributes+=" "+m}ae+=Q(D,t)}}return{feedIndex:"feed"+(ag+1),attributes:ad,index:ag+1,feedQuantity:n.quantity,quantity:ah,entries:ae,feedUrl:n[ag]["feedUrl"],title:n[ag]["title"],author:n[ag]["author"],description:n[ag]["description"]}};var b=function(){E.debug("» View response");I(function(){I.each(X,function(ad,t){W(r.stage,Q(o,c(ad)));r.stage.attr("data-tamufeed",w)})})};var W=function(ae,ad,t){E.debug("» putDOM "+(!!t?"overwrite":"append"));if(t){ae.html(ad)}else{ae.append(ad)}};var e=function(ag,ah){E.debug("» modelEntry feed #"+(ag+1)+" entry #"+(ah+1));var af=ac[ag].feed.entries[ah];var ai;var ae={publishedDate:af.publishedDate||0,title:a(H(af.title)),link:a(H(af.link)),author:a(H(af.author))};if(!af.content){return ae}ae.content=N(af.content.replace(/\brel="/ig,' class="'));ae.description=x("description",ae.content);var t=I(ae.description).find(".dtstart");if(t){ae.dtstart=t.text();if("ABBR"===t.prop("tagName")){ai="title"}else{ai="data-iso8601"}ae.dtstartISO8601=t.attr(ai);ae.start=new Date(ae.publishedDate);var ad=I(ae.description).find(".dtend");if(ad){if("ABBR"===ad.prop("tagName")){ai="title"}else{ai="data-iso8601"}ae.dtend=ad.text();ae.dtendISO8601=ad.attr(ai)}}ae.pubDate=new Date(ae.publishedDate);ae.images=[];I(ae.description).find("img").each(function(ak,aj){var am,al=I(aj);aj={};aj.src=encodeURI(al.attr("src")||"");if(aj.src.indexOf("gravatar.com/avatar")>0){al.addClass("photo gravatar")}aj.clas=a(al.attr("class"));aj.style=a(al.attr("style"));aj.title=a(al.attr("title"));aj.alt=a(al.attr("alt"))||aj.title||aj.clas||aj.src;aj.width=a(al.attr("width"));aj.height=a(al.attr("height"));am=aj.src.indexOf("feedburner.com/~")>0;if(am){E.debug("[invalid] "+aj.src)}else{}});ae.location=a(H(I(ae.description).find(".location").text()));ae.fn=a(H(I(ae.description).find(".fn").text()));ae.type="";if(ae.location){ae.type+="event ";ae.historical=ae.start.getTime()<+Date.now()+K;ae.summary=H(I(ae.description).find(".summary").text())}else{if(ae.fn){ae.type+="person ";ae.bday=a(H(I(ae.description).find(".bday").text()));ae.n=N(H(I(ae.description).find(".n").text()));ae.adr=N(H(I(ae.description).find(".adr").text()));ae.note=a(H(I(ae.description).find(".note").text()))}else{ae.type+="story ";ae.summary=N(H(af.content))}}ae.url=a(H(I(ae.description).find(".url").text()));ae.org=a(H(I(ae.description).find(".org").text()));ae.tel=a(H(I(ae.description).find(".tel").text()));ae.subtitle=a(H(I(ae.description).find(".subtitle").text()));ae.description=x("description",ae.content);return ae};var aa=function(ad){var af=ac[ad].feed.entries.length;E.debug("» modelFeed #"+(ad+1)+" has "+af+" entries");var t="";var ae=0;P[ad]=[];for(ae;ae<af;ae++){P[ad][ae]=e(ad,ae);t=P[ad][ae].type}if("shuffle"===C){P[ad].sort(J)}else{if("reverse"===C){if(t.indexOf("event")>=0){P[ad].sort(G)}else{P[ad].sort(O)}}else{if(t.indexOf("event")>=0){P[ad].sort(O)}else{P[ad].sort(G)}}}return{feedUrl:a(H(ac[ad].feed.feedUrl)),title:a(H(ac[ad].feed.title)),author:a(H(ac[ad].feed.author)),description:a(H(ac[ad].feed.description)),type:t,quantity:af}};var F=function(t){E.debug("» controllerFeed #"+(t+1));if(ac[t].error){E.debug("- result.error "+ac[t].error.code+": "+ac[t].error.message);return W(r.stage,Q(o,{feedUrl:"",entries:"",feedIndex:"error"+ac[t].error.code,title:"Error "+ac[t].error.code+": "+ac[t].error.message,description:"Error "+ac[t].error.code+": "+ac[t].error.message+" in feed #"+t}))}n[t]=aa(t);if(!--n.countdown){b();S()}};var U=function(){if(n.quantity){n.countdown=n.quantity}else{n.quantity=n.countdown=X.length}E.debug("» controller of request - for "+n.quantity+" feeds");W(r.stage,"","overwrite");I.each(X,function(ad,t){if("undefined"!==typeof ac[ad]&&"undefined"!==typeof ac[ad].error){F(ad)}else{var ae=new g.Feed(t);ae.setNumEntries(k);ae.load(function(af){V(af,ad)})}})};var T=function(ad,t){E.debug("» init");if("undefined"===typeof h){throw"FAIL! google.com/jsapi failed to load before tamufeed.js"}r.stage=I(j.stage);if("undefined"!==typeof h.feeds){ab()}if(r.stage){h.load("feeds","1",{callback:ab,nocss:true})}else{E.debug("INFO: tamufeed.element.stage not found.")}};var S=function(){E.debug("» destroy");ac=[];r.stage={}};var ab=function(){E.debug("» putAPI");if("undefined"===typeof h.feeds){E.debug("CRIT: google.feeds failed to initialize.");throw"google.feeds API failure"}g=h.feeds;U()};var V=function(ad,t){E.debug("» putFeed #"+(t+1));if("undefined"===typeof ad){E.debug("CRIT: google.feeds.load failed to return payload.");throw"google.feeds.load service failure."}ac[t]=ad;F(t)};return{VERSION:w,init:T}})(window,$,google);if(typeof define==="function"&&define.amd){define("tamufeed",["jquery","google"],function(b,a){return tamufeed})};