|
15 | 15 |
|
16 | 16 | Any number of components can use `<google-client-api>` elements, and the library will only be loaded once. |
17 | 17 |
|
| 18 | +##### Example |
| 19 | +
|
| 20 | + <google-client-api></google-client-api> |
| 21 | + <script> |
| 22 | + var client = document.querySelector('google-client-api'); |
| 23 | + client.addEventListener('api-load', function(e) { |
| 24 | + // this.api === gapi.client |
| 25 | + // this.auth === gapi.auth |
| 26 | + }); |
| 27 | + </script> |
| 28 | +
|
18 | 29 | @element google-client-api |
19 | 30 | @extends core-shared-lib |
| 31 | +@homepage https://googlewebcomponents.github.io/google-apis |
20 | 32 | --> |
21 | 33 | <polymer-element name="google-client-api" extends="core-shared-lib"> |
22 | 34 | <script> |
23 | 35 | Polymer({ |
24 | 36 | defaultUrl: 'https://apis.google.com/js/client.js?onload=%%callback%%', |
| 37 | + |
| 38 | + /** |
| 39 | + * Fired when the API library is loaded and available. |
| 40 | + * @event api-load |
| 41 | + */ |
25 | 42 | notifyEvent: 'api-load', |
| 43 | + |
| 44 | + /** |
| 45 | + * Wrapper for `gapi.client`. |
| 46 | + * @property api |
| 47 | + * @type gapi.client |
| 48 | + */ |
26 | 49 | get api() { |
27 | 50 | return gapi.client; |
28 | 51 | }, |
| 52 | + /** |
| 53 | + * Wrapper for `gapi.auth`. |
| 54 | + * @property auth |
| 55 | + * @type gapi.auth |
| 56 | + */ |
29 | 57 | get auth() { |
30 | 58 | return gapi.auth; |
31 | 59 | } |
|
38 | 66 |
|
39 | 67 | ##### Example |
40 | 68 |
|
41 | | - <google-api-loader id="shortener" name="urlshortener" version="v1"> |
42 | | - </google-api-loader> |
| 69 | + <google-api-loader id="shortener" name="urlshortener" |
| 70 | + version="v1"></google-api-loader> |
43 | 71 |
|
44 | 72 | <script> |
45 | 73 | var shortener = document.getElementById('shortener'); |
46 | 74 | shortener.addEventListener('google-api-load', function(event) { |
47 | | - var request = shortener.api.url.get({'shortUrl': 'http://goo.gl/fbsS'}); |
48 | | - request.execute(function(resp) { console.log(resp); }); |
| 75 | + var request = shortener.api.url.get({ |
| 76 | + shortUrl: 'http://goo.gl/fbsS' |
| 77 | + }); |
| 78 | + request.execute(function(resp) { |
| 79 | + console.log(resp); |
| 80 | + }); |
49 | 81 | }); |
50 | 82 | </script> |
51 | 83 |
|
52 | 84 | @element google-api-loader |
53 | | -@status alpha |
54 | 85 | @extends google-client-api |
55 | | -@homepage http://polymerlabs.github.io/google-apis |
| 86 | +@homepage https://googlewebcomponents.github.io/google-apis |
56 | 87 | --> |
57 | 88 | <polymer-element name="google-api-loader" |
58 | 89 | attributes="name version appId root" |
|
73 | 104 |
|
74 | 105 | Polymer('google-api-loader', { |
75 | 106 | /** |
76 | | - * Fired when the requested API is loaded. |
| 107 | + * Fired when the requested API is loaded. Override this name |
| 108 | + * by setting `successEventName`. |
77 | 109 | * @event google-api-load |
78 | 110 | */ |
79 | 111 |
|
80 | 112 | /** |
81 | | - * Fired if an error occurs while loading the requested API. |
| 113 | + * Fired if an error occurs while loading the requested API. Override this name |
| 114 | + * by setting `errorEventName`. |
82 | 115 | * @event google-api-load-error |
83 | 116 | */ |
84 | 117 |
|
|
123 | 156 | // core-shared-lib. |
124 | 157 | waiting: false, |
125 | 158 |
|
| 159 | + /** |
| 160 | + * Used to override the event that is fired when the API lib is successfully loaded. |
| 161 | + * @property successEventName |
| 162 | + * @type string |
| 163 | + * @default 'google-api-load' |
| 164 | + */ |
126 | 165 | successEventName: 'google-api-load', |
| 166 | + |
| 167 | + /** |
| 168 | + * Used to override the event that is fired when there is an error loading the API. |
| 169 | + * @property errorEventName |
| 170 | + * @type string |
| 171 | + * @default 'google-api-load-error' |
| 172 | + */ |
127 | 173 | errorEventName: 'google-api-load-error', |
128 | 174 |
|
129 | 175 | /** |
130 | 176 | * Returns the loaded API. |
131 | | - * @method api |
| 177 | + * @property api |
| 178 | + * @type gapi.client |
132 | 179 | */ |
133 | 180 | get api() { |
134 | 181 | if (window.gapi && window.gapi.client && |
|
0 commit comments