From 682dd00cf25011c16184753e0d3f29ccfd043012 Mon Sep 17 00:00:00 2001
From: Edward Rudd <urkle@outoforder.cc>
Date: Thu, 21 Aug 2014 02:14:01 +0000
Subject: [PATCH] change how cloud providers are registered to be more "clean" (and not browser specific)

---
 client/library/library_cloudfs.js |    5 +++--
 client/test/shell.html            |    4 ++--
 humble_cloud/humble_cloud.js      |    8 ++++++--
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/client/library/library_cloudfs.js b/client/library/library_cloudfs.js
index 01decbe..aeb006c 100644
--- a/client/library/library_cloudfs.js
+++ b/client/library/library_cloudfs.js
@@ -1,5 +1,6 @@
 var LibraryCLOUDFS = {
     $CLOUDFS__deps: ['$FS', '$MEMFS', '$PATH'],
+    $CLOUDFS__postset: "var CLOUD_PROVIDERS; if (!CLOUD_PROVIDERS) CLOUD_PROVIDERS = (typeof CLOUD_PROVIDERS !== 'undefined' ? CLOUD_PROVIDERS : null) || {};",
     $CLOUDFS: {
         mount: function(mount) {
             var provider = CLOUDFS.fetchProvider(mount);
@@ -38,10 +39,10 @@
         },
         // Utility functions
         fetchProvider: function(mount) {
-            if (mount.opts.provider === undefined || window[mount.opts.provider] === undefined) {
+            if (mount.opts.provider === undefined || CLOUD_PROVIDERS[mount.opts.provider] === undefined) {
                 return false;
             }
-            var provider = window[mount.opts.provider];
+            var provider = CLOUD_PROVIDERS[mount.opts.provider];
             var requiredMethods = ['listFiles', 'downloadFile', 'uploadFile', 'removeFile'];
             var valid = requiredMethods.every(function(method) {
                 return (method in provider);
diff --git a/client/test/shell.html b/client/test/shell.html
index 3f7ee70..04fce85 100644
--- a/client/test/shell.html
+++ b/client/test/shell.html
@@ -1306,8 +1306,8 @@
               // a list of regexes or string prefixes to synchronize
               sync: [
               ],
-              // which provider engine to use.. (looks for an object of that name in the global window object)
-              provider: 'HUMBLE_CLOUD_PROVIDER',
+              // which provider engine to use.. Looks for a provider in the CLOUD_PROVIDERS object
+              provider: 'HumbleBundle',
               // configuration sent to the provider
               cloud: {
                   applicationtoken: 'deadbeef'
diff --git a/humble_cloud/humble_cloud.js b/humble_cloud/humble_cloud.js
index da2a024..a5601c8 100644
--- a/humble_cloud/humble_cloud.js
+++ b/humble_cloud/humble_cloud.js
@@ -1,3 +1,7 @@
+// Boiler plate to setup cloud providers registry
+var CLOUD_PROVIDERS;
+if (!CLOUD_PROVIDERS) CLOUD_PROVIDERS = (typeof CLOUD_PROVIDERS !== 'undefined' ? CLOUD_PROVIDERS : null) || {};
+
 (function() {
     function xhrGET(url, onload, onerror) {
         var xhr = new XMLHttpRequest();
@@ -33,6 +37,6 @@
         }
     };
 
-    // expose out to the page
-    window.HUMBLE_CLOUD_PROVIDER = provider;
+    // register provider
+    CLOUD_PROVIDERS['HumbleBundle'] = provider;
 })();
\ No newline at end of file

--
Gitblit v1.9.3