mirror of
https://github.com/wahyd4/cdnjs.git
synced 2026-08-09 04:46:00 +10:00
Add tabletop.js
This commit is contained in:
+1
@@ -0,0 +1 @@
|
||||
(function(a){"use strict";Array.prototype.indexOf||(Array.prototype.indexOf=function(a,b){null==b?b=0:0>b&&(b=Math.max(0,this.length+b));for(var c=b,d=this.length;d>c;c++)if(this[c]===a)return c;return-1});var b=a.Tabletop=function(a){return this&&this instanceof b?("string"==typeof a&&(a={key:a}),this.callback=a.callback,this.wanted=a.wanted||[],this.key=a.key,this.simpleSheet=!!a.simpleSheet,this.parseNumbers=!!a.parseNumbers,this.wait=!!a.wait,this.postProcess=a.postProcess,this.debug=!!a.debug,this.query=a.query||"",/key=/.test(this.key)&&(this.log("You passed a key as a URL! Attempting to parse."),this.key=this.key.match("key=(.*?)&")[1]),this.key?(this.log("Initializing with key "+this.key),this.models={},this.model_names=[],this.base_json_url="https://spreadsheets.google.com/feeds/worksheets/"+this.key+"/public/basic?alt=json-in-script",this.wait||this.fetch(),void 0):(this.log("You need to pass Tabletop a key!"),void 0)):new b(a)};b.callbacks={},b.init=function(a){return new b(a)},b.sheets=function(){this.log("Times have changed! You'll want to use var tabletop = Tabletop.init(...); tabletop.sheets(...); instead of Tabletop.sheets(...)")},b.prototype={fetch:function(a){a!==void 0&&(this.callback=a),this.injectScript(this.base_json_url,this.loadSheets)},injectScript:function(a,c){var d=document.createElement("script"),e=this,f="tt"+ +new Date+Math.floor(1e5*Math.random());b.callbacks[f]=function(){var a=Array.prototype.slice.call(arguments,0);c.apply(e,a),d.parentNode.removeChild(d),delete b.callbacks[f]},a=a+"&callback="+"Tabletop.callbacks."+f,d.src=a,document.getElementsByTagName("script")[0].parentNode.appendChild(d)},isWanted:function(a){return 0===this.wanted.length?!0:-1!=this.wanted.indexOf(a)},data:function(){return 0===this.model_names.length?void 0:this.simpleSheet?(this.model_names.length>1&&this.debug&&console.debug("WARNING You have more than one sheet but are using simple sheet mode! Don't blame me when something goes wrong."),this.models[this.model_names[0]].all()):this.models},addWanted:function(a){-1==this.wanted.indexOf(a)&&this.wanted.push(a)},loadSheets:function(a){var b,c,d=[];for(b=0,c=a.feed.entry.length;c>b;b++)if(this.isWanted(a.feed.entry[b].content.$t)){var e=a.feed.entry[b].link[3].href.substr(a.feed.entry[b].link[3].href.length-3,3),f="https://spreadsheets.google.com/feeds/list/"+this.key+"/"+e+"/public/values?alt=json-in-script&sq="+this.query;this.log(f),d.push(f)}for(this.sheetsToLoad=d.length,b=0,c=d.length;c>b;b++)this.injectScript(d[b],this.loadSheet)},sheets:function(a){return a===void 0?this.models:this.models[a]===void 0?void 0:this.models[a]},loadSheet:function(a){var c=new b.Model({data:a,parseNumbers:this.parseNumbers,postProcess:this.postProcess,tabletop:this});this.models[c.name]=c,-1==this.model_names.indexOf(c.name)&&this.model_names.push(c.name),this.sheetsToLoad--,0===this.sheetsToLoad&&this.doCallback()},doCallback:function(){0===this.sheetsToLoad&&this.callback.apply(this.callbackContext||this,[this.data(),this])},log:function(){this.debug&&"undefined"!=typeof console&&console.log!==void 0&&Function.prototype.apply.apply(console.log,[console,arguments])}},b.Model=function(a){var b,c,d,e;if(this.column_names=[],this.name=a.data.feed.title.$t,this.elements=[],this.raw=a.data,a.data.feed.entry===void 0)return a.tabletop.log("Missing data for "+this.name+", make sure you didn't forget column headers"),this.elements=[],void 0;for(var f in a.data.feed.entry[0])/^gsx/.test(f)&&this.column_names.push(f.replace("gsx$",""));for(b=0,d=a.data.feed.entry.length;d>b;b++){for(var g=a.data.feed.entry[b],h={},c=0,e=this.column_names.length;e>c;c++){var i=g["gsx$"+this.column_names[c]];h[this.column_names[c]]=i!==void 0?a.parseNumbers&&""!==i.$t&&!isNaN(i.$t)?+i.$t:i.$t:""}void 0===h.rowNumber&&(h.rowNumber=b+1),a.postProcess&&a.postProcess(h),this.elements.push(h)}},b.Model.prototype={all:function(){return this.elements},toArray:function(){var b,c,d,e,a=[];for(b=0,d=this.elements.length;d>b;b++){var f=[];for(c=0,e=this.column_names.length;e>c;c++)f.push(this.elements[b][this.column_names[c]]);a.push(f)}return a}}})(this);
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "tabletop.js",
|
||||
"filename": "tabletop.min.js",
|
||||
"homepage" : "http://github.com/jsoma/tabletop",
|
||||
"description": "Tabletop.js takes a Google Spreadsheet and makes it easily accessible through JavaScript.",
|
||||
"keywords": [ "database", "storage" ],
|
||||
"version": "1.1.0",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "Jonathan Soma",
|
||||
"email": "jonathan.soma@gmail.com",
|
||||
"web": "http://twitter.com/dangerscarf"
|
||||
}
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/jsoma/tabletop.git"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user