From bed57803800a97343a3bf3ad5a6700e2b23606ba Mon Sep 17 00:00:00 2001 From: Joe Germuska Date: Wed, 4 Jun 2014 15:53:16 -0500 Subject: [PATCH] parse new format Google spreadsheet URLs correctly. Closes #597 --- source/js/Core/Embed/Embed.CDN.Generator.js | 2 +- source/js/VMM.Timeline.DataObj.js | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/source/js/Core/Embed/Embed.CDN.Generator.js b/source/js/Core/Embed/Embed.CDN.Generator.js index 100c49f..192a59c 100644 --- a/source/js/Core/Embed/Embed.CDN.Generator.js +++ b/source/js/Core/Embed/Embed.CDN.Generator.js @@ -81,7 +81,7 @@ function getLinkAndIframe() { /* SOURCE KEY ================================================== */ if (e_source.value.match("docs.google.com")) { - source_key = getUrlVars(e_source.value)["key"]; + source_key = VMM.Timeline.DataObj.model.googlespreadsheet.extractSpreadsheetKey(e_source.value); } else { if (e_source.value == "") { source_key = "0Agl_Dv6iEbDadHdKcHlHcTB5bzhvbF9iTWwyMmJHdkE" diff --git a/source/js/VMM.Timeline.DataObj.js b/source/js/VMM.Timeline.DataObj.js index c68bc5b..8ebd931 100644 --- a/source/js/VMM.Timeline.DataObj.js +++ b/source/js/VMM.Timeline.DataObj.js @@ -171,11 +171,24 @@ if (typeof VMM.Timeline !== 'undefined' && typeof VMM.Timeline.DataObj == 'undef model: { googlespreadsheet: { - + extractSpreadsheetKey: function(url) { + var key = VMM.Util.getUrlVars(url)["key"]; + if (!key) { + if (url.match("docs.google.com/spreadsheets/d/")) { + var pos = url.indexOf("docs.google.com/spreadsheets/d/") + "docs.google.com/spreadsheets/d/".length; + var tail = url.substr(pos); + key = tail.split('/')[0] + } + } + if (!key) { key = url} + return key; + }, getData: function(raw) { var getjsondata, key, worksheet, url, timeout, tries = 0; - key = VMM.Util.getUrlVars(raw)["key"]; + // new Google Docs URLs can specify 'key' differently. + // that format doesn't seem to have a way to specify a worksheet. + key = VMM.Timeline.DataObj.model.googlespreadsheet.extractSpreadsheetKey(raw); worksheet = VMM.Util.getUrlVars(raw)["worksheet"]; if (typeof worksheet == "undefined") worksheet = "od6"; @@ -297,7 +310,7 @@ if (typeof VMM.Timeline !== 'undefined' && typeof VMM.Timeline.DataObj == 'undef getDataCells: function(raw) { var getjsondata, key, url, timeout, tries = 0; - key = VMM.Util.getUrlVars(raw)["key"]; + key = VMM.Timeline.DataObj.model.googlespreadsheet.extractSpreadsheetKey(raw); url = "https://spreadsheets.google.com/feeds/cells/" + key + "/od6/public/values?alt=json"; timeout = setTimeout(function() {