-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.google.spreadsheet.min.js
executable file
·6 lines (6 loc) · 1.74 KB
/
jquery.google.spreadsheet.min.js
1
2
3
4
5
6
// jquery.google.spreadsheet.js
// version : 0.0.2
// author : Queli Coto (quelicm@gmail.com)
// license : MIT
// http://quelicoto.es
var GoogleSpreadsheet=function(e){function n(){}var t={};n.prototype.getGoogleUrl=function(){return t};n.prototype.url=function(e){t=this.getGoogleUrl();t.sourceIdentifier=e;if(t.sourceIdentifier.match(/http(s)*:/)){t.url=t.sourceIdentifier;try{t.key=t.url.match(/key=(.*?)&/)[1]}catch(n){t.key=t.url.match(/(cells|list)\/(.*?)\//)[2]}try{t.gid=t.url.match(/gid=(.?)/)[1];if(t.gid!=="0"){var r=6+parseInt(t.gid,10);t.gid="od"+r.toString()}else{t.gid="od6"}}catch(n){t.gid="od6"}}else{t.key=t.sourceIdentifier}t.jsonCellsUrl="http://spreadsheets.google.com/feeds/cells/"+t.key+"/"+t.gid+"/public/basic?alt=json-in-script";t.jsonListUrl="http://spreadsheets.google.com/feeds/list/"+t.key+"/"+t.gid+"/public/basic?alt=json-in-script"};n.prototype.load=function(){var e=arguments;var t=this;if(e.length>1&&e[0]==="cell"){this.loadCells().then(function(n){return e[1](t.loadDataCells(n))})}else{this.loadList().then(function(n){return e[0](t.loadDataList(n))})}};n.prototype.loadCells=function(n){t=this.getGoogleUrl();n=t.jsonCellsUrl+"&callback=?";return e.getJSON(n)};n.prototype.loadList=function(n){t=this.getGoogleUrl();n=t.jsonListUrl+"&callback=?";return e.getJSON(n)};n.prototype.loadDataCells=function(e){var t;var n,r,i,s;i=e.feed.entry;s=[];for(n=0,r=i.length;n<r;n++){t=i[n];var o=t.content.$t;s.push(t.content.$t)}return s};n.prototype.loadDataList=function(t){var n,r,i;var s,o,u,a;u=t.feed.entry;a={};a["items"]=[];for(s=0,o=u.length;s<o;s++){n=u[s];var f=n.content.$t;var l=n.title.$t;var c=f.split(", ");var h={id:l};for(var p=0;p<c.length;p++){var d=c[p].split(": ");h[d[0]]=e.trim(d[1])}a.items.push(h)}return a};return n}(jQuery)