Skip to content

Commit

Permalink
Making Dropbox login work from CDN
Browse files Browse the repository at this point in the history
  • Loading branch information
nathancarter committed Oct 13, 2017
1 parent a86719c commit 757a278
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ need a different toolkit.
Import the relevant files into your page. You can use a CDN, like so:
```html
<!-- The main file, essential: -->
<script src='https://cdn.jsdelivr.net/gh/lurchmath/cloud-storage@v1.0.0/cloud-storage.js'></script>
<script src='https://cdn.jsdelivr.net/gh/lurchmath/cloud-storage@v1/cloud-storage.js'></script>
<!-- If you want the Dropbox backend, which you probably do: -->
<script src='https://unpkg.com/dropbox/dist/Dropbox-sdk.min.js'></script>
<script src='https://cdn.jsdelivr.net/gh/lurchmath/cloud-storage@v1.0.0/dropbox-backend.js'></script>
<script src='https://cdn.jsdelivr.net/gh/lurchmath/cloud-storage@v1/dropbox-backend.js'></script>
<!-- If you want the LocalStorage backend also: -->
<script src='https://cdn.jsdelivr.net/gh/lurchmath/cloud-storage@v1.0.0/localstorage-backend.js'></script>
<script src='https://cdn.jsdelivr.net/gh/lurchmath/cloud-storage@v1/localstorage-backend.js'></script>
```

Call `openFile()` or `saveFile()`. That's it! Obviously, you'll want to
Expand Down
13 changes: 11 additions & 2 deletions dropbox-backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,19 @@
* This function stores the client ID in this object for use by a Dropbox
* instance to be created later, once an access token is gained by the
* login process in `getAccess()`.
*
* The second parameter is optional, but can provide a URL to use for the
* Dropbox login page. By default, it uses the page in this same folder.
* However, if you have loaded this project from a CDN, then you may not
* have that file in your project. In such a case, you can provide the CDN
* URL to teh Dropbox login page as the second parameter here. For your
* convenience, that URL is:
* https://cdn.jsdelivr.net/gh/lurchmath/cloud-storage@v1/dropbox-login.html
*/
function DropboxFileSystem ( clientID )
function DropboxFileSystem ( clientID, loginURL )
{
this.clientID = clientID;
this.loginURL = loginURL || './dropbox-login.html';
}

/*
Expand All @@ -44,7 +53,7 @@ function DropboxFileSystem ( clientID )
DropboxFileSystem.prototype.getAccess = function ( successCB, failureCB )
{
if ( this.dropbox ) return successCB();
var loginWindow = window.open( './dropbox-login.html' );
var loginWindow = window.open( this.loginURL );
var that = this;
if ( !this.installedEventHandler ) {
window.addEventListener( 'message', function ( event ) {
Expand Down

0 comments on commit 757a278

Please sign in to comment.