Skip to content

Commit

Permalink
Started refactoring tabltop to support multiple instances of it in th…
Browse files Browse the repository at this point in the history
…e same page. Update gitignore to ignore vim swap files.
  • Loading branch information
Scott Seaward committed Feb 3, 2012
1 parent 934cf4e commit 9fce16f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
.DS_Store
.swp
24 changes: 16 additions & 8 deletions src/tabletop.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function(tabletop) {
(function(global) {

/*
Initialize with Tabletop.init( { key: '0AjAPaAU9MeLFdHUxTlJiVVRYNGRJQnRmSnQwTlpoUXc' } )
Expand All @@ -7,26 +7,30 @@
OR!
Initialize with Tabletop.init('0AjAPaAU9MeLFdHUxTlJiVVRYNGRJQnRmSnQwTlpoUXc')
*/

tabletop.init = function(options) {

var Tabletop = global.Tabletop = global.Tabletop || function(options) {
if(this === global) {
return new Tabletop(options);
}

if(typeof(options) == 'string') {
options = { key : options };
}

this.callback = options.callback;
this.key = options.key;
this.simpleSheet = !!options.simpleSheet;
this.parseNumbers = !!options.parseNumbers;
this.postProcess = options.postProcess;
this.debug = !!options.debug;

/* Be friendly about what you accept */
if(/key=/.test(this.key)) {
if(this.debug)
console.debug("You passed a key as a URL! Attempting to parse.");
this.key = this.key.match("key=(.*?)&")[1];
}

if(!this.key) {
alert("You need to pass Tabletop a key!");
return;
Expand All @@ -37,13 +41,17 @@

this.models = {};
this.model_names = [];

var callback = "Tabletop.loadSheets";
var json_url = "https://spreadsheets.google.com/feeds/worksheets/" + this.key + "/public/basic?alt=json-in-script&callback=" + callback;

this.injectScript(json_url);
};

Tabletop.init = function(options) {
return new Tabletop(options);
};

/*
Insert the URL into the page as a script tag. Once it's loaded the spreadsheet data
it triggers the callback. This helps you avoid cross-domain errors
Expand Down Expand Up @@ -198,4 +206,4 @@
return array;
};

}(window.Tabletop = window.Tabletop || {}));
}(this);

0 comments on commit 9fce16f

Please sign in to comment.