OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 Copyright 2013 The Polymer Authors. All rights reserved. |
| 3 Use of this source code is governed by a BSD-style |
| 4 license that can be found in the LICENSE file. |
| 5 --> |
| 6 <link rel="import" href="../polymer/polymer.html"> |
| 7 |
| 8 <polymer-element name="polymer-google-jsapi"> |
| 9 <script> |
| 10 (function() { |
| 11 var state = '', instances = [], f; |
| 12 function load() { |
| 13 f = document.createElement('iframe'); |
| 14 f.style.display = 'none'; |
| 15 document.body.appendChild(f); |
| 16 var d = f.contentWindow ? f.contentWindow.document : (f.contentDocument.
document ? f.contentDocument.document : f.contentDocument); |
| 17 d.open(); |
| 18 d.write(loader); |
| 19 d.close(); |
| 20 } |
| 21 var api; |
| 22 var loaded = function(google) { |
| 23 window.__polymer_google_jsapi = undefined; |
| 24 window.google = api = google; |
| 25 instances.forEach(function(i) { |
| 26 i.provide(); |
| 27 }); |
| 28 } |
| 29 var loader = |
| 30 '<script type="text/javascript" src="https://www.google.com/jsapi"></scr
' + 'ipt>' + |
| 31 '<script>parent.__polymer_google_jsapi(google);</scr' + 'ipt>' |
| 32 ; |
| 33 window.__polymer_google_jsapi = loaded; |
| 34 |
| 35 Polymer('polymer-google-jsapi', { |
| 36 ready: function() { |
| 37 switch (state) { |
| 38 case '': |
| 39 instances.push(this); |
| 40 load(); |
| 41 state = 'pending'; |
| 42 break; |
| 43 case 'pending': |
| 44 instances.push(this); |
| 45 break; |
| 46 case 'ready': |
| 47 this.provide(); |
| 48 break; |
| 49 } |
| 50 }, |
| 51 provide: function() { |
| 52 this.asyncMethod('notify'); |
| 53 }, |
| 54 notify: function() { |
| 55 this.fire('polymer-google-jsapi-loaded'); |
| 56 }, |
| 57 get google() { |
| 58 return api; |
| 59 } |
| 60 }); |
| 61 })(); |
| 62 </script> |
| 63 </polymer-element> |
OLD | NEW |