diff options
author | Wu Cheng-Han | 2016-09-18 16:27:21 +0800 |
---|---|---|
committer | Wu Cheng-Han | 2016-09-18 16:27:21 +0800 |
commit | c22791610c341582be5e008bd0a72200ca385747 (patch) | |
tree | 3f4f8536c11421b1bd7d87eae066a7deefb0dc82 | |
parent | 0470a266fd4965aa3de1584dad8f7042c6694dc1 (diff) |
Fix scripts load order to prevent reference error, using query callback to prevent google api call before loaded
-rw-r--r-- | public/js/index.js | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/public/js/index.js b/public/js/index.js index d5678f56..dbedd66c 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -1242,6 +1242,8 @@ if (DROPBOX_APP_KEY) { .attr('src', 'https://www.dropbox.com/static/api/2/dropins.js') .attr('id', 'dropboxjs') .attr('data-app-key', DROPBOX_APP_KEY) + .prop('async', true) + .prop('defer', true) .appendTo('body'); } else { ui.toolbar.import.dropbox.hide(); @@ -1252,16 +1254,22 @@ if (DROPBOX_APP_KEY) { if (GOOGLE_API_KEY && GOOGLE_CLIENT_ID) { $('<script>') .attr('type', 'text/javascript') - .attr('src', 'https://www.google.com/jsapi') + .attr('src', 'https://www.google.com/jsapi?callback=onGoogleAPILoaded') + .prop('async', true) + .prop('defer', true) .appendTo('body'); - +} else { + ui.toolbar.import.googleDrive.hide(); + ui.toolbar.export.googleDrive.hide(); +} + +function onGoogleAPILoaded() { $('<script>') .attr('type', 'text/javascript') .attr('src', 'https://apis.google.com/js/client:plusone.js?onload=onGoogleClientLoaded') + .prop('async', true) + .prop('defer', true) .appendTo('body'); -} else { - ui.toolbar.import.googleDrive.hide(); - ui.toolbar.export.googleDrive.hide(); } //button actions |