From 3afd7f92a268030583d5f74c6211e4b06fc908f2 Mon Sep 17 00:00:00 2001 From: Edward Medvedev Date: Tue, 13 Feb 2018 22:31:57 +0100 Subject: [PATCH 1/2] Convert to 3.0 with Modulizer --- bower.json | 47 ----- demo/index.html | 41 ++--- google-apis.html => google-apis.js | 21 +-- google-client-loader.html | 236 ------------------------- google-client-loader.js | 194 ++++++++++++++++++++ google-js-api.html => google-js-api.js | 76 ++++---- google-legacy-loader.html | 55 ------ google-legacy-loader.js | 49 +++++ google-maps-api.html | 150 ---------------- google-maps-api.js | 146 +++++++++++++++ google-plusone-api.html | 54 ------ google-plusone-api.js | 48 +++++ google-realtime-api.html | 57 ------ google-realtime-api.js | 51 ++++++ google-youtube-api.html | 61 ------- google-youtube-api.js | 55 ++++++ package.json | 26 +++ 17 files changed, 636 insertions(+), 731 deletions(-) delete mode 100644 bower.json rename google-apis.html => google-apis.js (57%) delete mode 100644 google-client-loader.html create mode 100644 google-client-loader.js rename google-js-api.html => google-js-api.js (56%) delete mode 100644 google-legacy-loader.html create mode 100644 google-legacy-loader.js delete mode 100644 google-maps-api.html create mode 100644 google-maps-api.js delete mode 100644 google-plusone-api.html create mode 100644 google-plusone-api.js delete mode 100644 google-realtime-api.html create mode 100644 google-realtime-api.js delete mode 100644 google-youtube-api.html create mode 100644 google-youtube-api.js create mode 100644 package.json diff --git a/bower.json b/bower.json deleted file mode 100644 index d854f69..0000000 --- a/bower.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "name": "google-apis", - "version": "2.0.1", - "description": "Web components to load Google API libraries", - "homepage": "https://elements.polymer-project.org/elements/google-apis?active=google-js-api", - "main": "google-apis.html", - "authors": [ - "Scott Miles ", - "Eric Bidelman " - ], - "license": "Apache-2.0", - "ignore": [ - "/.*", - "/test/" - ], - "keywords": [ - "web-component", - "web-components", - "polymer", - "google", - "apis" - ], - "dependencies": { - "polymer": "Polymer/polymer#1.9 - 2", - "iron-jsonp-library": "PolymerElements/iron-jsonp-library#1 - 2" - }, - "devDependencies": { - "iron-component-page": "PolymerElements/iron-component-page#1 - 2" - }, - "variants": { - "1.x": { - "dependencies": { - "polymer": "Polymer/polymer#^1.0.0", - "iron-jsonp-library": "PolymerElements/iron-jsonp-library#^1.0.0" - }, - "devDependencies": { - "iron-component-page": "PolymerElements/iron-component-page#^1.0.0" - }, - "resolutions": { - "webcomponentsjs": "^0.7" - } - } - }, - "resolutions": { - "webcomponentsjs": "^1.0.0" - } -} diff --git a/demo/index.html b/demo/index.html index 0455cbb..cbea597 100644 --- a/demo/index.html +++ b/demo/index.html @@ -5,7 +5,7 @@ google-apis Demo - +
@@ -26,26 +26,27 @@ - +// Polymer 2.0 compatibility +bind.loadedShortener = t.loadedShortener; +bind.loaded = t.loaded; + diff --git a/google-apis.html b/google-apis.js similarity index 57% rename from google-apis.html rename to google-apis.js index 29f9883..c582854 100644 --- a/google-apis.html +++ b/google-apis.js @@ -1,16 +1,17 @@ - - - - - - - - - +*/ +/* Load all Google APIs, for backwards compatibility */ +; diff --git a/google-client-loader.html b/google-client-loader.html deleted file mode 100644 index cbbb6d0..0000000 --- a/google-client-loader.html +++ /dev/null @@ -1,236 +0,0 @@ - - - - - - - - diff --git a/google-client-loader.js b/google-client-loader.js new file mode 100644 index 0000000..eddcc31 --- /dev/null +++ b/google-client-loader.js @@ -0,0 +1,194 @@ +import './google-js-api.js'; + +// Stores whether the API client is done loading. +var _clientLoaded = false; + +// Loaders and loading statuses for all APIs, indexed by API name. +// This helps prevent multiple loading requests being fired at the same time +// by multiple google-api-loader elements. +var _statuses = {}; +var _loaders = {}; + +Polymer({ + + is: 'google-client-loader', + + /** + * Fired when the requested API is loaded. Override this name + * by setting `successEventName`. + * @event google-api-load + */ + + /** + * Fired if an error occurs while loading the requested API. Override this name + * by setting `errorEventName`. + * @event google-api-load-error + */ + + properties: { + /** + * Name of the API to load, e.g. 'urlshortener'. + * + * You can find the full list of APIs on the + * Google APIs + * Explorer. + */ + name: String, + + /** + * Version of the API to load, e.g. 'v1'. + */ + version: String, + + /** + * App Engine application ID for loading a Google Cloud Endpoints API. + */ + appId: String, + + /** + * Root URL where to load the API from, e.g. 'http://host/apis'. + * For App Engine dev server this would be something like: + * 'http://localhost:8080/_ah/api'. + * Overrides 'appId' if both are specified. + */ + apiRoot: String, + + /** + * Name of the event fired when API library is loaded. + */ + successEventName: { + type: String, + value: 'google-api-load' + }, + + /** + * Name of the event fired when there is an error loading the library. + */ + errorEventName: { + type: String, + value: 'google-api-load-error' + } + }, + + hostAttributes: { + hidden: true // remove from rendering tree. + }, + + // Used to fix events potentially being fired multiple times by + // iron-jsonp-library. + _waiting: false, + + /** + * Returns the loaded API. + */ + get api() { + if (window.gapi && window.gapi.client && + window.gapi.client[this.name]) { + return window.gapi.client[this.name]; + } else { + return undefined; + } + }, + + /** + * Wrapper for `gapi.auth`. + */ + get auth() { + return gapi.auth; + }, + + ready: function() { + this._loader = document.createElement('google-js-api'); + + if (!this.shadowRoot) { this.attachShadow({mode: 'open'}); } + this.shadowRoot.appendChild(this._loader); + + this.listen(this._loader, 'js-api-load', '_loadClient'); + }, + + detached: function() { + this.unlisten(this._loader, 'js-api-load', '_loadClient'); + }, + + _loadClient: function() { + gapi.load('client', this._doneLoadingClient.bind(this)); + }, + + _handleLoadResponse: function(response) { + if (response && response.error) { + _statuses[this.name] = 'error'; + this._fireError(response); + } else { + _statuses[this.name] = 'loaded'; + this._fireSuccess(); + } + }, + + _fireSuccess: function() { + this.fire(this.successEventName, + { 'name': this.name, 'version': this.version }); + }, + + _fireError: function(response) { + if (response && response.error) { + this.fire(this.errorEventName, { + 'name': this.name, + 'version': this.version, + 'error': response.error }); + } else { + this.fire(this.errorEventName, { + 'name': this.name, + 'version': this.version }); + } + }, + + _doneLoadingClient: function() { + _clientLoaded = true; + // Fix for API client load event being fired multiple times by + // iron-jsonp-library. + if (!this._waiting) { + this._loadApi(); + } + }, + + _createSelfRemovingListener: function(eventName) { + var handler = function () { + _loaders[this.name].removeEventListener(eventName, handler); + this._loadApi(); + }.bind(this); + + return handler; + }, + + _loadApi: function() { + if (_clientLoaded && this.name && this.version) { + this._waiting = false; + // Is this API already loaded? + if (_statuses[this.name] == 'loaded') { + this._fireSuccess(); + // Is a different google-api-loader already loading this API? + } else if (_statuses[this.name] == 'loading') { + this._waiting = true; + _loaders[this.name].addEventListener(this.successEventName, + this._createSelfRemovingListener(this.successEventName)); + _loaders[this.name].addEventListener(this.errorEventName, + this._createSelfRemovingListener(this.errorEventName)); + // Did we get an error when we tried to load this API before? + } else if (_statuses[this.name] == 'error') { + this._fireError(null); + // Otherwise, looks like we're loading a new API. + } else { + var root; + if (this.apiRoot) { + root = this.apiRoot; + } else if (this.appId) { + root = 'https://' + this.appId + '.appspot.com/_ah/api'; + } + _statuses[this.name] = 'loading'; + _loaders[this.name] = this; + gapi.client.load(this.name, this.version, + this._handleLoadResponse.bind(this), root); + } + } + } +}); diff --git a/google-js-api.html b/google-js-api.js similarity index 56% rename from google-js-api.html rename to google-js-api.js index 3b05a10..0d45910 100644 --- a/google-js-api.html +++ b/google-js-api.js @@ -1,16 +1,12 @@ - - - - - - - +}); diff --git a/google-legacy-loader.html b/google-legacy-loader.html deleted file mode 100644 index 02e7a5c..0000000 --- a/google-legacy-loader.html +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - diff --git a/google-legacy-loader.js b/google-legacy-loader.js new file mode 100644 index 0000000..3bca700 --- /dev/null +++ b/google-legacy-loader.js @@ -0,0 +1,49 @@ +/* +Copyright (c) 2014 The Polymer Project Authors. All rights reserved. +This code may only be used under the BSD style license found at https://polymer.github.io/LICENSE.txt +The complete set of authors may be found at https://polymer.github.io/AUTHORS.txt +The complete set of contributors may be found at https://polymer.github.io/CONTRIBUTORS.txt +Code distributed by Google as part of the polymer project is also +subject to an additional IP rights grant found at https://polymer.github.io/PATENTS.txt +*/ +/* +Dynamically loads the legacy Google JavaScript API Loader (https://developers.google.com/loader/). + +Fires `api-load` event when ready. +*/ +Polymer({ + + is: 'google-legacy-loader', + + behaviors: [ + Polymer.IronJsonpLibraryBehavior + ], + + properties: { + + /** @private */ + libraryUrl: { + type: String, + value: 'https://www.google.com/jsapi?callback=%%callback%%' + }, + + /** + * Fired when the API library is loaded and available. + * @event js-api-load + */ + /** + * Name of event fired when library is loaded and available. + */ + notifyEvent: { + type: String, + value: 'api-load' + } + }, + + /** + * Wrapper for `google` API namespace. + */ + get api() { + return google; + } +}); diff --git a/google-maps-api.html b/google-maps-api.html deleted file mode 100644 index fb9bbac..0000000 --- a/google-maps-api.html +++ /dev/null @@ -1,150 +0,0 @@ - - - - - - - diff --git a/google-maps-api.js b/google-maps-api.js new file mode 100644 index 0000000..45d22b8 --- /dev/null +++ b/google-maps-api.js @@ -0,0 +1,146 @@ +import './../iron-jsonp-library/iron-jsonp-library.js'; +import { Polymer } from '../polymer/lib/legacy/polymer-fn.js'; +/* +Copyright (c) 2014 The Polymer Project Authors. All rights reserved. +This code may only be used under the BSD style license found at https://polymer.github.io/LICENSE.txt +The complete set of authors may be found at https://polymer.github.io/AUTHORS.txt +The complete set of contributors may be found at https://polymer.github.io/CONTRIBUTORS.txt +Code distributed by Google as part of the polymer project is also +subject to an additional IP rights grant found at https://polymer.github.io/PATENTS.txt +*/ +/** +Dynamically loads the Google Maps JavaScript API, firing the `api-load` event when ready. + +#### Example + + + + +Any number of components can use `` elements, and the library will only be loaded once. + +@summary Element wrapper around Google Maps API. +*/ +Polymer({ + + is: 'google-maps-api', + + behaviors: [ + Polymer.IronJsonpLibraryBehavior, + ], + + properties: { + + /** @private */ + mapsUrl: { + type: String, + value: 'https://maps.googleapis.com/maps/api/js?callback=%%callback%%', + }, + + /** + * A Maps API key. To obtain an API key, see developers.google.com/maps/documentation/javascript/tutorial#api_key. + */ + apiKey: { + type: String, + value: '', + }, + + /** + * A Maps API for Business Client ID. To obtain a Maps API for Business Client ID, see developers.google.com/maps/documentation/business/. + * If set, a Client ID will take precedence over an API Key. + */ + clientId: { + type: String, + value: '', + }, + + /** + * Version of the Maps API to use. + */ + version: { + type: String, + value: '3.exp', + }, + + /** + * The localized language to load the Maps API with. For more information + * see https://developers.google.com/maps/documentation/javascript/basics#Language + * + * Note: the Maps API defaults to the preffered language setting of the browser. + * Use this parameter to override that behavior. + */ + language: { + type: String, + value: '', + }, + /** + * If true, sign-in is enabled. + * See https://developers.google.com/maps/documentation/javascript/signedin#enable_sign_in + */ + signedIn: { + type: Boolean, + value: false, + }, + + /** + * Fired when the Maps API library is loaded and ready. + * @event api-load + */ + /** + * Name of event fired when library is loaded and available. + */ + notifyEvent: { + type: String, + value: 'api-load', + }, + + /** @private */ + libraryUrl: { + type: String, + computed: '_computeUrl(mapsUrl, version, apiKey, clientId, language, signedIn)', + }, + }, + + _computeUrl(mapsUrl, version, apiKey, clientId, language, signedIn) { + let url = `${mapsUrl}&v=${version}`; + + // Always load all Maps API libraries. + url += '&libraries=drawing,geometry,places,visualization'; + + if (apiKey && !clientId) { + url += `&key=${apiKey}`; + } + + if (clientId) { + url += `&client=${clientId}`; + } + + // Log a warning if the user is not using an API Key or Client ID. + if (!apiKey && !clientId) { + const warning = 'No Google Maps API Key or Client ID specified. ' + + 'See https://developers.google.com/maps/documentation/javascript/get-api-key ' + + 'for instructions to get started with a key or client id.'; + console.warn(warning); + } + + if (language) { + url += `&language=${language}`; + } + + if (signedIn) { + url += `&signed_in=${signedIn}`; + } + return url; + }, + + /** + * Provides the google.maps JS API namespace. + */ + get api() { + return google.maps; + }, +}); diff --git a/google-plusone-api.html b/google-plusone-api.html deleted file mode 100644 index 205658e..0000000 --- a/google-plusone-api.html +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - diff --git a/google-plusone-api.js b/google-plusone-api.js new file mode 100644 index 0000000..4beb3a0 --- /dev/null +++ b/google-plusone-api.js @@ -0,0 +1,48 @@ +/* +Copyright (c) 2014 The Polymer Project Authors. All rights reserved. +This code may only be used under the BSD style license found at https://polymer.github.io/LICENSE.txt +The complete set of authors may be found at https://polymer.github.io/AUTHORS.txt +The complete set of contributors may be found at https://polymer.github.io/CONTRIBUTORS.txt +Code distributed by Google as part of the polymer project is also +subject to an additional IP rights grant found at https://polymer.github.io/PATENTS.txt +*/ +/* +Dynamically loads the Google+ JavaScript API, firing the `api-load` event when ready. + +Any number of components can use `` elements, and the library will only be loaded once. +*/ +Polymer({ + + is: 'google-plusone-api', + + behaviors: [ + Polymer.IronJsonpLibraryBehavior + ], + + properties: { + + /** @private */ + libraryUrl: { + type: String, + value: 'https://apis.google.com/js/plusone.js?onload=%%callback%%' + }, + + /** + * Fired when the API library is loaded and available. + * @event js-api-load + */ + /** + * Name of event fired when library is loaded and available. + */ + notifyEvent: { + type: String, + value: 'api-load' + } + + }, + + get api() { + return gapi; + } + +}); diff --git a/google-realtime-api.html b/google-realtime-api.html deleted file mode 100644 index a41fb51..0000000 --- a/google-realtime-api.html +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - - diff --git a/google-realtime-api.js b/google-realtime-api.js new file mode 100644 index 0000000..bb6b338 --- /dev/null +++ b/google-realtime-api.js @@ -0,0 +1,51 @@ +/* +Copyright (c) 2014 The Polymer Project Authors. All rights reserved. +This code may only be used under the BSD style license found at https://polymer.github.io/LICENSE.txt +The complete set of authors may be found at https://polymer.github.io/AUTHORS.txt +The complete set of contributors may be found at https://polymer.github.io/CONTRIBUTORS.txt +Code distributed by Google as part of the polymer project is also +subject to an additional IP rights grant found at https://polymer.github.io/PATENTS.txt +*/ +/* +Dynamically loads the Google Drive Realtime API, firing the `api-load` event when ready. + +Any number of components can use `` elements, and the library will only be loaded once. +*/ +Polymer({ + + is: 'google-realtime-api', + + behaviors: [ + Polymer.IronJsonpLibraryBehavior + ], + + properties: { + + /** @private */ + libraryUrl: { + type: String, + value: 'https://apis.google.com/js/drive-realtime.js?onload=%%callback%%' + }, + + /** + * Fired when the API library is loaded and available. + * @event api-load + */ + /** + * Name of event fired when library is loaded and available. + */ + notifyEvent: { + type: String, + value: 'api-load' + } + + }, + + /** + * Returns `gapi.drive.realtime` + */ + get api() { + return gapi.drive.realtime; + } + +}); diff --git a/google-youtube-api.html b/google-youtube-api.html deleted file mode 100644 index 7f8960d..0000000 --- a/google-youtube-api.html +++ /dev/null @@ -1,61 +0,0 @@ - - - - - - - diff --git a/google-youtube-api.js b/google-youtube-api.js new file mode 100644 index 0000000..5174dee --- /dev/null +++ b/google-youtube-api.js @@ -0,0 +1,55 @@ +/* +Copyright (c) 2014 The Polymer Project Authors. All rights reserved. +This code may only be used under the BSD style license found at https://polymer.github.io/LICENSE.txt +The complete set of authors may be found at https://polymer.github.io/AUTHORS.txt +The complete set of contributors may be found at https://polymer.github.io/CONTRIBUTORS.txt +Code distributed by Google as part of the polymer project is also +subject to an additional IP rights grant found at https://polymer.github.io/PATENTS.txt +*/ +/* +Dynamically loads the Google Youtube Iframe API, firing the `api-load` event when ready. + +Any number of components can use `` elements, and the library will only be loaded once. + +https://developers.google.com/youtube/iframe_api_reference +*/ +Polymer({ + + is: 'google-youtube-api', + + behaviors: [ + Polymer.IronJsonpLibraryBehavior + ], + + properties: { + + /** @private */ + libraryUrl: { + type: String, + value: 'https://www.youtube.com/iframe_api' + }, + + /** + * Fired when the API library is loaded and available. + * @event api-load + */ + /** + * Name of event fired when library loads. + */ + notifyEvent: { + type: String, + value: 'api-load' + }, + + callbackName: { + type: String, + value: 'onYouTubeIframeAPIReady' + } + + }, + + get api() { + return YT; + } + +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..74407d0 --- /dev/null +++ b/package.json @@ -0,0 +1,26 @@ +{ + "name": "@polymer/google-apis", + "flat": true, + "version": "3.0.0", + "description": "Web components to load Google API libraries", + "contributors": [ + "Scott Miles ", + "Eric Bidelman ", + "Ed Medvedev " + ], + "keywords": [ + "web-component", + "web-components", + "polymer", + "google", + "apis" + ], + "main": "google-apis.html", + "license": "Apache-2.0", + "homepage": "https://elements.polymer-project.org/elements/google-apis?active=google-js-api", + "dependencies": { + "@polymer/polymer": "^3.0.0-pre.1", + "@polymer/iron-jsonp-library": "^3.0.0-pre.1" + }, + "devDependencies": {} +} From 7e4c48a18e03396606b6a62447437ee1f947dcb3 Mon Sep 17 00:00:00 2001 From: Edward Medvedev Date: Tue, 13 Feb 2018 22:34:43 +0100 Subject: [PATCH 2/2] Import Polymer legacy --- google-apis.js | 2 +- google-client-loader.js | 84 +++++++++++++++++++++++------------------ google-js-api.js | 9 +++-- google-legacy-loader.js | 11 +++--- google-plusone-api.js | 15 ++++---- google-realtime-api.js | 17 +++++---- google-youtube-api.js | 19 +++++----- 7 files changed, 86 insertions(+), 71 deletions(-) diff --git a/google-apis.js b/google-apis.js index c582854..0336979 100644 --- a/google-apis.js +++ b/google-apis.js @@ -14,4 +14,4 @@ Code distributed by Google as part of the polymer project is also subject to an additional IP rights grant found at https://polymer.github.io/PATENTS.txt */ /* Load all Google APIs, for backwards compatibility */ -; + diff --git a/google-client-loader.js b/google-client-loader.js index eddcc31..c174cc7 100644 --- a/google-client-loader.js +++ b/google-client-loader.js @@ -1,13 +1,14 @@ +import { Polymer } from '../polymer/lib/legacy/polymer-fn.js'; import './google-js-api.js'; // Stores whether the API client is done loading. -var _clientLoaded = false; +let _clientLoaded = false; // Loaders and loading statuses for all APIs, indexed by API name. // This helps prevent multiple loading requests being fired at the same time // by multiple google-api-loader elements. -var _statuses = {}; -var _loaders = {}; +const _statuses = {}; +const _loaders = {}; Polymer({ @@ -58,7 +59,7 @@ Polymer({ */ successEventName: { type: String, - value: 'google-api-load' + value: 'google-api-load', }, /** @@ -66,12 +67,12 @@ Polymer({ */ errorEventName: { type: String, - value: 'google-api-load-error' - } + value: 'google-api-load-error', + }, }, hostAttributes: { - hidden: true // remove from rendering tree. + hidden: true, // remove from rendering tree. }, // Used to fix events potentially being fired multiple times by @@ -85,9 +86,8 @@ Polymer({ if (window.gapi && window.gapi.client && window.gapi.client[this.name]) { return window.gapi.client[this.name]; - } else { - return undefined; } + return undefined; }, /** @@ -97,24 +97,24 @@ Polymer({ return gapi.auth; }, - ready: function() { + ready() { this._loader = document.createElement('google-js-api'); - - if (!this.shadowRoot) { this.attachShadow({mode: 'open'}); } + + if (!this.shadowRoot) { this.attachShadow({ mode: 'open' }); } this.shadowRoot.appendChild(this._loader); - + this.listen(this._loader, 'js-api-load', '_loadClient'); }, - detached: function() { + detached() { this.unlisten(this._loader, 'js-api-load', '_loadClient'); }, - _loadClient: function() { + _loadClient() { gapi.load('client', this._doneLoadingClient.bind(this)); }, - _handleLoadResponse: function(response) { + _handleLoadResponse(response) { if (response && response.error) { _statuses[this.name] = 'error'; this._fireError(response); @@ -124,25 +124,29 @@ Polymer({ } }, - _fireSuccess: function() { - this.fire(this.successEventName, - { 'name': this.name, 'version': this.version }); + _fireSuccess() { + this.fire( + this.successEventName, + { name: this.name, version: this.version }, + ); }, - _fireError: function(response) { + _fireError(response) { if (response && response.error) { this.fire(this.errorEventName, { - 'name': this.name, - 'version': this.version, - 'error': response.error }); + name: this.name, + version: this.version, + error: response.error, + }); } else { this.fire(this.errorEventName, { - 'name': this.name, - 'version': this.version }); + name: this.name, + version: this.version, + }); } }, - _doneLoadingClient: function() { + _doneLoadingClient() { _clientLoaded = true; // Fix for API client load event being fired multiple times by // iron-jsonp-library. @@ -151,7 +155,7 @@ Polymer({ } }, - _createSelfRemovingListener: function(eventName) { + _createSelfRemovingListener(eventName) { var handler = function () { _loaders[this.name].removeEventListener(eventName, handler); this._loadApi(); @@ -160,7 +164,7 @@ Polymer({ return handler; }, - _loadApi: function() { + _loadApi() { if (_clientLoaded && this.name && this.version) { this._waiting = false; // Is this API already loaded? @@ -169,26 +173,32 @@ Polymer({ // Is a different google-api-loader already loading this API? } else if (_statuses[this.name] == 'loading') { this._waiting = true; - _loaders[this.name].addEventListener(this.successEventName, - this._createSelfRemovingListener(this.successEventName)); - _loaders[this.name].addEventListener(this.errorEventName, - this._createSelfRemovingListener(this.errorEventName)); + _loaders[this.name].addEventListener( + this.successEventName, + this._createSelfRemovingListener(this.successEventName), + ); + _loaders[this.name].addEventListener( + this.errorEventName, + this._createSelfRemovingListener(this.errorEventName), + ); // Did we get an error when we tried to load this API before? } else if (_statuses[this.name] == 'error') { this._fireError(null); // Otherwise, looks like we're loading a new API. } else { - var root; + let root; if (this.apiRoot) { root = this.apiRoot; } else if (this.appId) { - root = 'https://' + this.appId + '.appspot.com/_ah/api'; + root = `https://${this.appId}.appspot.com/_ah/api`; } _statuses[this.name] = 'loading'; _loaders[this.name] = this; - gapi.client.load(this.name, this.version, - this._handleLoadResponse.bind(this), root); + gapi.client.load( + this.name, this.version, + this._handleLoadResponse.bind(this), root, + ); } } - } + }, }); diff --git a/google-js-api.js b/google-js-api.js index 0d45910..4947281 100644 --- a/google-js-api.js +++ b/google-js-api.js @@ -1,3 +1,4 @@ +import { Polymer } from '../polymer/lib/legacy/polymer-fn.js'; /* Copyright (c) 2015 The Polymer Project Authors. All rights reserved. This code may only be used under the BSD style license found at https://polymer.github.io/LICENSE.txt @@ -26,7 +27,7 @@ Polymer({ is: 'google-js-api', behaviors: [ - Polymer.IronJsonpLibraryBehavior + Polymer.IronJsonpLibraryBehavior, ], properties: { @@ -34,7 +35,7 @@ Polymer({ /** @private */ libraryUrl: { type: String, - value: 'https://apis.google.com/js/api.js?onload=%%callback%%' + value: 'https://apis.google.com/js/api.js?onload=%%callback%%', }, /** @@ -46,12 +47,12 @@ Polymer({ */ notifyEvent: { type: String, - value: 'js-api-load' + value: 'js-api-load', }, }, get api() { return gapi; - } + }, }); diff --git a/google-legacy-loader.js b/google-legacy-loader.js index 3bca700..39ea100 100644 --- a/google-legacy-loader.js +++ b/google-legacy-loader.js @@ -1,3 +1,4 @@ +import { Polymer } from '../polymer/lib/legacy/polymer-fn.js'; /* Copyright (c) 2014 The Polymer Project Authors. All rights reserved. This code may only be used under the BSD style license found at https://polymer.github.io/LICENSE.txt @@ -16,7 +17,7 @@ Polymer({ is: 'google-legacy-loader', behaviors: [ - Polymer.IronJsonpLibraryBehavior + Polymer.IronJsonpLibraryBehavior, ], properties: { @@ -24,7 +25,7 @@ Polymer({ /** @private */ libraryUrl: { type: String, - value: 'https://www.google.com/jsapi?callback=%%callback%%' + value: 'https://www.google.com/jsapi?callback=%%callback%%', }, /** @@ -36,8 +37,8 @@ Polymer({ */ notifyEvent: { type: String, - value: 'api-load' - } + value: 'api-load', + }, }, /** @@ -45,5 +46,5 @@ Polymer({ */ get api() { return google; - } + }, }); diff --git a/google-plusone-api.js b/google-plusone-api.js index 4beb3a0..2381555 100644 --- a/google-plusone-api.js +++ b/google-plusone-api.js @@ -1,3 +1,4 @@ +import { Polymer } from '../polymer/lib/legacy/polymer-fn.js'; /* Copyright (c) 2014 The Polymer Project Authors. All rights reserved. This code may only be used under the BSD style license found at https://polymer.github.io/LICENSE.txt @@ -16,15 +17,15 @@ Polymer({ is: 'google-plusone-api', behaviors: [ - Polymer.IronJsonpLibraryBehavior + Polymer.IronJsonpLibraryBehavior, ], properties: { /** @private */ - libraryUrl: { + libraryUrl: { type: String, - value: 'https://apis.google.com/js/plusone.js?onload=%%callback%%' + value: 'https://apis.google.com/js/plusone.js?onload=%%callback%%', }, /** @@ -34,15 +35,15 @@ Polymer({ /** * Name of event fired when library is loaded and available. */ - notifyEvent: { + notifyEvent: { type: String, - value: 'api-load' - } + value: 'api-load', + }, }, get api() { return gapi; - } + }, }); diff --git a/google-realtime-api.js b/google-realtime-api.js index bb6b338..2240008 100644 --- a/google-realtime-api.js +++ b/google-realtime-api.js @@ -1,3 +1,4 @@ +import { Polymer } from '../polymer/lib/legacy/polymer-fn.js'; /* Copyright (c) 2014 The Polymer Project Authors. All rights reserved. This code may only be used under the BSD style license found at https://polymer.github.io/LICENSE.txt @@ -16,28 +17,28 @@ Polymer({ is: 'google-realtime-api', behaviors: [ - Polymer.IronJsonpLibraryBehavior + Polymer.IronJsonpLibraryBehavior, ], properties: { /** @private */ - libraryUrl: { + libraryUrl: { type: String, - value: 'https://apis.google.com/js/drive-realtime.js?onload=%%callback%%' + value: 'https://apis.google.com/js/drive-realtime.js?onload=%%callback%%', }, - /** + /** * Fired when the API library is loaded and available. * @event api-load */ /** * Name of event fired when library is loaded and available. */ - notifyEvent: { + notifyEvent: { type: String, - value: 'api-load' - } + value: 'api-load', + }, }, @@ -46,6 +47,6 @@ Polymer({ */ get api() { return gapi.drive.realtime; - } + }, }); diff --git a/google-youtube-api.js b/google-youtube-api.js index 5174dee..3102b9b 100644 --- a/google-youtube-api.js +++ b/google-youtube-api.js @@ -1,3 +1,4 @@ +import { Polymer } from '../polymer/lib/legacy/polymer-fn.js'; /* Copyright (c) 2014 The Polymer Project Authors. All rights reserved. This code may only be used under the BSD style license found at https://polymer.github.io/LICENSE.txt @@ -18,15 +19,15 @@ Polymer({ is: 'google-youtube-api', behaviors: [ - Polymer.IronJsonpLibraryBehavior + Polymer.IronJsonpLibraryBehavior, ], properties: { /** @private */ - libraryUrl: { + libraryUrl: { type: String, - value: 'https://www.youtube.com/iframe_api' + value: 'https://www.youtube.com/iframe_api', }, /** @@ -36,20 +37,20 @@ Polymer({ /** * Name of event fired when library loads. */ - notifyEvent: { + notifyEvent: { type: String, - value: 'api-load' + value: 'api-load', }, - callbackName: { + callbackName: { type: String, - value: 'onYouTubeIframeAPIReady' - } + value: 'onYouTubeIframeAPIReady', + }, }, get api() { return YT; - } + }, });