aboutsummaryrefslogtreecommitdiff
path: root/catapult/third_party/polymer/components/iron-jsonp-library
diff options
context:
space:
mode:
Diffstat (limited to 'catapult/third_party/polymer/components/iron-jsonp-library')
-rw-r--r--catapult/third_party/polymer/components/iron-jsonp-library/.bower.json66
-rw-r--r--catapult/third_party/polymer/components/iron-jsonp-library/CONTRIBUTING.md77
-rw-r--r--catapult/third_party/polymer/components/iron-jsonp-library/README.md51
-rw-r--r--catapult/third_party/polymer/components/iron-jsonp-library/bower.json57
-rw-r--r--catapult/third_party/polymer/components/iron-jsonp-library/demo/index.html133
-rwxr-xr-xcatapult/third_party/polymer/components/iron-jsonp-library/hero.svg31
-rw-r--r--catapult/third_party/polymer/components/iron-jsonp-library/index.html26
-rw-r--r--catapult/third_party/polymer/components/iron-jsonp-library/iron-jsonp-library.html271
8 files changed, 712 insertions, 0 deletions
diff --git a/catapult/third_party/polymer/components/iron-jsonp-library/.bower.json b/catapult/third_party/polymer/components/iron-jsonp-library/.bower.json
new file mode 100644
index 00000000..9c383b6b
--- /dev/null
+++ b/catapult/third_party/polymer/components/iron-jsonp-library/.bower.json
@@ -0,0 +1,66 @@
+{
+ "name": "iron-jsonp-library",
+ "version": "2.0.0",
+ "description": "Loads jsonp libraries",
+ "authors": [
+ "Aleks Totic <a@totic.org>",
+ "The Polymer Authors"
+ ],
+ "keywords": [
+ "web-component",
+ "polymer",
+ "behavior"
+ ],
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/PolymerElements/iron-jsonp-library.git"
+ },
+ "main": "iron-jsonp-library.html",
+ "license": "http://polymer.github.io/LICENSE.txt",
+ "homepage": "https://github.com/PolymerElements/iron-jsonp-library/",
+ "ignore": [
+ "/.*",
+ "/test/"
+ ],
+ "dependencies": {
+ "polymer": "Polymer/polymer#1.9 - 2"
+ },
+ "devDependencies": {
+ "iron-component-page": "PolymerElements/iron-component-page#1 - 2",
+ "test-fixture": "PolymerElements/test-fixture#^3.0.0-rc.1",
+ "web-component-tester": "^6.0.0",
+ "webcomponentsjs": "webcomponents/webcomponentsjs#^1.0.0",
+ "paper-styles": "PolymerElements/paper-styles#1 - 2",
+ "paper-spinner": "PolymerElements/paper-spinner#1 - 2"
+ },
+ "variants": {
+ "1.x": {
+ "dependencies": {
+ "polymer": "Polymer/polymer#^1.9"
+ },
+ "devDependencies": {
+ "iron-component-page": "PolymerElements/iron-component-page#^1.0.0",
+ "test-fixture": "PolymerElements/test-fixture#^1.0.0",
+ "webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0",
+ "paper-styles": "PolymerElements/paper-styles#^1.0.2",
+ "paper-spinner": "PolymerElements/paper-spinner#^1.0.1",
+ "web-component-tester": "Polymer/web-component-tester#^4.0.0"
+ },
+ "resolutions": {
+ "webcomponentsjs": "^0.7"
+ }
+ }
+ },
+ "resolutions": {
+ "webcomponentsjs": "^1.0.0"
+ },
+ "_release": "2.0.0",
+ "_resolution": {
+ "type": "version",
+ "tag": "v2.0.0",
+ "commit": "61d47ed327b76bd597d1e1800d3040b2279ae329"
+ },
+ "_source": "https://github.com/PolymerElements/iron-jsonp-library.git",
+ "_target": "1 - 2",
+ "_originalSource": "PolymerElements/iron-jsonp-library"
+} \ No newline at end of file
diff --git a/catapult/third_party/polymer/components/iron-jsonp-library/CONTRIBUTING.md b/catapult/third_party/polymer/components/iron-jsonp-library/CONTRIBUTING.md
new file mode 100644
index 00000000..093090d4
--- /dev/null
+++ b/catapult/third_party/polymer/components/iron-jsonp-library/CONTRIBUTING.md
@@ -0,0 +1,77 @@
+<!--
+This file is autogenerated based on
+https://github.com/PolymerElements/ContributionGuide/blob/master/CONTRIBUTING.md
+
+If you edit that file, it will get updated everywhere else.
+If you edit this file, your changes will get overridden :)
+
+You can however override the jsbin link with one that's customized to this
+specific element:
+
+jsbin=https://jsbin.com/cagaye/edit?html,output
+-->
+
+# Polymer Elements
+## Guide for Contributors
+
+Polymer Elements are built in the open, and the Polymer authors eagerly encourage any and all forms of community contribution. When contributing, please follow these guidelines:
+
+### Filing Issues
+
+**If you are filing an issue to request a feature**, please provide a clear description of the feature. It can be helpful to describe answers to the following questions:
+
+ 1. **Who will use the feature?** _“As someone filling out a form…”_
+ 2. **When will they use the feature?** _“When I enter an invalid value…”_
+ 3. **What is the user’s goal?** _“I want to be visually notified that the value needs to be corrected…”_
+
+**If you are filing an issue to report a bug**, please provide:
+
+ 1. **A clear description of the bug and related expectations.** Consider using the following example template for reporting a bug:
+
+ ```markdown
+ The `paper-foo` element causes the page to turn pink when clicked.
+
+ ## Expected outcome
+
+ The page stays the same color.
+
+ ## Actual outcome
+
+ The page turns pink.
+
+ ## Steps to reproduce
+
+ 1. Put a `paper-foo` element in the page.
+ 2. Open the page in a web browser.
+ 3. Click the `paper-foo` element.
+ ```
+
+ 2. **A reduced test case that demonstrates the problem.** If possible, please include the test case as a JSBin. Start with this template to easily import and use relevant Polymer Elements: [https://jsbin.com/cagaye/edit?html,output](https://jsbin.com/cagaye/edit?html,output).
+
+ 3. **A list of browsers where the problem occurs.** This can be skipped if the problem is the same across all browsers.
+
+### Submitting Pull Requests
+
+**Before creating a pull request**, please ensure that an issue exists for the corresponding change in the pull request that you intend to make. **If an issue does not exist, please create one per the guidelines above**. The goal is to discuss the design and necessity of the proposed change with Polymer authors and community before diving into a pull request.
+
+When submitting pull requests, please provide:
+
+ 1. **A reference to the corresponding issue** or issues that will be closed by the pull request. Please refer to these issues in the pull request description using the following syntax:
+
+ ```markdown
+ (For a single issue)
+ Fixes #20
+
+ (For multiple issues)
+ Fixes #32, fixes #40
+ ```
+
+ 2. **A succinct description of the design** used to fix any related issues. For example:
+
+ ```markdown
+ This fixes #20 by removing styles that leaked which would cause the page to turn pink whenever `paper-foo` is clicked.
+ ```
+
+ 3. **At least one test for each bug fixed or feature added** as part of the pull request. Pull requests that fix bugs or add features without accompanying tests will not be considered.
+
+If a proposed change contains multiple commits, please [squash commits](https://www.google.com/url?q=http://blog.steveklabnik.com/posts/2012-11-08-how-to-squash-commits-in-a-github-pull-request) to as few as is necessary to succinctly express the change. A Polymer author can help you squash commits, so don’t be afraid to ask us if you need help with that!
diff --git a/catapult/third_party/polymer/components/iron-jsonp-library/README.md b/catapult/third_party/polymer/components/iron-jsonp-library/README.md
new file mode 100644
index 00000000..c93e1d6b
--- /dev/null
+++ b/catapult/third_party/polymer/components/iron-jsonp-library/README.md
@@ -0,0 +1,51 @@
+
+<!---
+
+This README is automatically generated from the comments in these files:
+iron-jsonp-library.html
+
+Edit those files, and our readme bot will duplicate them over here!
+Edit this file, and the bot will squash your changes :)
+
+The bot does some handling of markdown. Please file a bug if it does the wrong
+thing! https://github.com/PolymerLabs/tedium/issues
+
+-->
+
+[![Build status](https://travis-ci.org/PolymerElements/iron-jsonp-library.svg?branch=master)](https://travis-ci.org/PolymerElements/iron-jsonp-library)
+
+_[Demo and API docs](https://elements.polymer-project.org/elements/iron-jsonp-library)_
+
+
+## &lt;iron-jsonp-library&gt;
+
+Loads specified jsonp library.
+
+Example:
+
+```html
+<iron-jsonp-library
+ library-url="https://apis.google.com/js/plusone.js?onload=%%callback%%"
+ notify-event="api-load"
+ library-loaded="{{loaded}}"></iron-jsonp-library>
+```
+
+Will emit 'api-load' event when loaded, and set 'loaded' to true
+
+Implemented by Polymer.IronJsonpLibraryBehavior. Use it
+to create specific library loader elements.
+
+
+
+## Polymer.IronJsonpLibraryBehavior
+
+`Polymer.IronJsonpLibraryBehavior` loads a jsonp library.
+Multiple components can request same library, only one copy will load.
+
+Some libraries require a specific global function be defined.
+If this is the case, specify the `callbackName` property.
+
+You should use an HTML Import to load library dependencies
+when possible instead of using this element.
+
+
diff --git a/catapult/third_party/polymer/components/iron-jsonp-library/bower.json b/catapult/third_party/polymer/components/iron-jsonp-library/bower.json
new file mode 100644
index 00000000..ef4c8b7d
--- /dev/null
+++ b/catapult/third_party/polymer/components/iron-jsonp-library/bower.json
@@ -0,0 +1,57 @@
+{
+ "name": "iron-jsonp-library",
+ "version": "2.0.0",
+ "description": "Loads jsonp libraries",
+ "authors": [
+ "Aleks Totic <a@totic.org>",
+ "The Polymer Authors"
+ ],
+ "keywords": [
+ "web-component",
+ "polymer",
+ "behavior"
+ ],
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/PolymerElements/iron-jsonp-library.git"
+ },
+ "main": "iron-jsonp-library.html",
+ "license": "http://polymer.github.io/LICENSE.txt",
+ "homepage": "https://github.com/PolymerElements/iron-jsonp-library/",
+ "ignore": [
+ "/.*",
+ "/test/"
+ ],
+ "dependencies": {
+ "polymer": "Polymer/polymer#1.9 - 2"
+ },
+ "devDependencies": {
+ "iron-component-page": "PolymerElements/iron-component-page#1 - 2",
+ "test-fixture": "PolymerElements/test-fixture#^3.0.0-rc.1",
+ "web-component-tester": "^6.0.0",
+ "webcomponentsjs": "webcomponents/webcomponentsjs#^1.0.0",
+ "paper-styles": "PolymerElements/paper-styles#1 - 2",
+ "paper-spinner": "PolymerElements/paper-spinner#1 - 2"
+ },
+ "variants": {
+ "1.x": {
+ "dependencies": {
+ "polymer": "Polymer/polymer#^1.9"
+ },
+ "devDependencies": {
+ "iron-component-page": "PolymerElements/iron-component-page#^1.0.0",
+ "test-fixture": "PolymerElements/test-fixture#^1.0.0",
+ "webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0",
+ "paper-styles": "PolymerElements/paper-styles#^1.0.2",
+ "paper-spinner": "PolymerElements/paper-spinner#^1.0.1",
+ "web-component-tester": "Polymer/web-component-tester#^4.0.0"
+ },
+ "resolutions": {
+ "webcomponentsjs": "^0.7"
+ }
+ }
+ },
+ "resolutions": {
+ "webcomponentsjs": "^1.0.0"
+ }
+}
diff --git a/catapult/third_party/polymer/components/iron-jsonp-library/demo/index.html b/catapult/third_party/polymer/components/iron-jsonp-library/demo/index.html
new file mode 100644
index 00000000..13abb9a7
--- /dev/null
+++ b/catapult/third_party/polymer/components/iron-jsonp-library/demo/index.html
@@ -0,0 +1,133 @@
+<!doctype html>
+<!--
+@license
+Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
+This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
+The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
+The complete set of contributors may be found at http://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 http://polymer.github.io/PATENTS.txt
+-->
+<html>
+ <head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
+ <title>iron-jsonp-library Demo</title>
+ <script src="../../webcomponentsjs/webcomponents-lite.js"></script>
+ <link rel="import" href="../../paper-styles/color.html">
+ <link rel="import" href="../../paper-styles/demo-pages.html">
+ <link rel="import" href="../../paper-spinner/paper-spinner.html">
+ <link rel="import" href="../iron-jsonp-library.html">
+ <style is="custom-style">
+
+ .loading {
+ color: var(--google-grey-500);
+ }
+
+ .success {
+ color: var(--paper-green-800);
+ }
+
+ .failure {
+ color: var(--paper-red-800);
+ }
+
+ paper-spinner {
+ --paper-spinner-layer-1-color: var(--google-grey-500);
+ --paper-spinner-layer-2-color: var(--google-grey-500);
+ --paper-spinner-layer-3-color: var(--google-grey-500);
+ --paper-spinner-layer-4-color: var(--google-grey-500);
+ }
+ </style>
+ </head>
+ <body>
+
+ <div class="vertical-section vertical-section-container centered">
+ <h1>&lt;iron-jsonp-library&gt;</h1>
+ <dom-bind>
+ <template is="dom-bind">
+ <h3>Good loader</h3>
+ <iron-jsonp-library
+ library-url="https://apis.google.com/js/plusone.js?onload=%%callback%%"
+ notify-event="api-load"
+ library-loaded="{{loaded}}"
+ library-error-message="{{errorMessage}}"></iron-jsonp-library>
+ <template is="dom-if" if="{{loaded}}">
+ <p class="success">The <code>Google+ API</code> has been loaded</p>
+ </template>
+ <template is="dom-if" if="{{!loaded}}">
+ <template is="dom-if" if="{{errorMessage}}">
+ <p class="failure">{{errorMessage}}</p>
+ </template>
+ <template is="dom-if" if="{{!errorMessage}}">
+ <p class="loading">Loading...</p>
+ </template>
+ </template>
+ </template>
+ </dom-bind>
+
+ <hr>
+ <dom-bind>
+ <template is="dom-bind">
+ <h3>Bad loader</h3>
+ <iron-jsonp-library
+ library-url="https://badapis.google.com/js/plusone.js?onload=%%callback%%"
+ notify-event="api-load"
+ library-loaded="{{loaded}}"
+ library-error-message="{{errorMessage}}"></iron-jsonp-library>
+ <template is="dom-if" if="{{loaded}}">
+ <p><code>badapis</code> has been loaded</p>
+ </template>
+ <template is="dom-if" if="{{!loaded}}">
+ <template is="dom-if" if="{{errorMessage}}">
+ <p class="failure">{{errorMessage}}</p>
+ </template>
+ <template is="dom-if" if="{{!errorMessage}}">
+ <p class="loading">Loading...</p>
+ </template>
+ </template>
+ </template>
+ </dom-bind>
+
+ <hr>
+ <dom-bind>
+ <template is="dom-bind" id="delayedLoader">
+ <h3>Delayed libraryUrl loader</h3>
+ <iron-jsonp-library
+ library-url="{{libraryUrl}}"
+ library-loaded="{{loaded}}"
+ library-error-message="{{errorMessage}}">
+ </iron-jsonp-library>
+ <template is="dom-if" if="{{loaded}}">
+ <p><code>{{libraryUrl}}</code> has been loaded</p>
+ </template>
+ <template is="dom-if" if="{{!loaded}}">
+ <template is="dom-if" if="{{errorMessage}}">
+ <p class="failure">{{errorMessage}}</p>
+ </template>
+ <template is="dom-if" if="{{!errorMessage}}">
+ <p class="loading">Loading...<code>{{libraryUrl}}</code></p>
+ </template>
+ </template>
+ </template>
+ </dom-bind>
+
+ </div>
+
+ <script>
+ // kick off delayed loader by setting libraryUrl
+ window.setTimeout(function() {
+ var t = document.querySelector('#delayedLoader');
+
+ if (Polymer.Element) {
+ // value is set on the dom-bind in 2.x
+ t.parentNode.libraryUrl = 'https://apis.google.com/js/drive-realtime.js?onload=%%callback%%';
+ } else {
+ // value is set on template in Polymer 1.x
+ t.libraryUrl = 'https://apis.google.com/js/drive-realtime.js?onload=%%callback%%';
+ }
+ },
+ 1000);
+ </script>
+ </body>
+</html>
diff --git a/catapult/third_party/polymer/components/iron-jsonp-library/hero.svg b/catapult/third_party/polymer/components/iron-jsonp-library/hero.svg
new file mode 100755
index 00000000..b02c565b
--- /dev/null
+++ b/catapult/third_party/polymer/components/iron-jsonp-library/hero.svg
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Generator: Adobe Illustrator 17.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
+ viewBox="0 0 225 126" enable-background="new 0 0 225 126" xml:space="preserve">
+<g id="background" display="none">
+ <rect display="inline" fill="#B0BEC5" width="225" height="126"/>
+</g>
+<g id="label">
+</g>
+<g id="art">
+ <circle cx="112" cy="36" r="4"/>
+ <circle cx="112" cy="90" r="4"/>
+ <circle cx="91" cy="98" r="4"/>
+ <circle cx="91" cy="29" r="4"/>
+ <circle cx="133" cy="29" r="4"/>
+ <circle cx="133" cy="97" r="4"/>
+ <circle cx="56" cy="63" r="4"/>
+ <circle cx="168" cy="63" r="4"/>
+ <circle cx="99" cy="63" r="4"/>
+ <circle cx="125" cy="63" r="4"/>
+ <path d="M90.8,98.5c-19.6,0-35.5-15.9-35.5-35.5s15.9-35.5,35.5-35.5s35.5,15.9,35.5,35.5S110.3,98.5,90.8,98.5z M90.8,29.5
+ c-18.5,0-33.5,15-33.5,33.5s15,33.5,33.5,33.5s33.5-15,33.5-33.5S109.2,29.5,90.8,29.5z"/>
+ <path d="M133.2,98.5c-19.6,0-35.5-15.9-35.5-35.5s15.9-35.5,35.5-35.5s35.5,15.9,35.5,35.5S152.8,98.5,133.2,98.5z M133.2,29.5
+ c-18.5,0-33.5,15-33.5,33.5s15,33.5,33.5,33.5s33.5-15,33.5-33.5S151.7,29.5,133.2,29.5z"/>
+ <g id="ic_x5F_add_x0D_">
+ </g>
+</g>
+<g id="Guides">
+</g>
+</svg>
diff --git a/catapult/third_party/polymer/components/iron-jsonp-library/index.html b/catapult/third_party/polymer/components/iron-jsonp-library/index.html
new file mode 100644
index 00000000..487bb5c3
--- /dev/null
+++ b/catapult/third_party/polymer/components/iron-jsonp-library/index.html
@@ -0,0 +1,26 @@
+<!doctype html>
+<!--
+@license
+Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
+This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
+The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
+The complete set of contributors may be found at http://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 http://polymer.github.io/PATENTS.txt
+-->
+<html>
+<head>
+
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+
+ <script src="../webcomponentsjs/webcomponents-lite.js"></script>
+ <link rel="import" href="../iron-component-page/iron-component-page.html">
+
+</head>
+<body>
+
+ <iron-component-page></iron-component-page>
+
+</body>
+</html>
diff --git a/catapult/third_party/polymer/components/iron-jsonp-library/iron-jsonp-library.html b/catapult/third_party/polymer/components/iron-jsonp-library/iron-jsonp-library.html
new file mode 100644
index 00000000..09277da4
--- /dev/null
+++ b/catapult/third_party/polymer/components/iron-jsonp-library/iron-jsonp-library.html
@@ -0,0 +1,271 @@
+<!--
+@license
+Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
+This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
+The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
+The complete set of contributors may be found at http://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 http://polymer.github.io/PATENTS.txt
+-->
+<link rel="import" href="../polymer/polymer.html">
+
+<script>
+(function() {
+ "use strict";
+ /**
+ * `Polymer.IronJsonpLibraryBehavior` loads a jsonp library.
+ * Multiple components can request same library, only one copy will load.
+ *
+ * Some libraries require a specific global function be defined.
+ * If this is the case, specify the `callbackName` property.
+ *
+ * You should use an HTML Import to load library dependencies
+ * when possible instead of using this element.
+ *
+ * @hero hero.svg
+ * @demo demo/index.html
+ * @polymerBehavior
+ */
+ Polymer.IronJsonpLibraryBehavior = {
+
+ properties: {
+ /**
+ * True if library has been successfully loaded
+ */
+ libraryLoaded: {
+ type: Boolean,
+ value: false,
+ notify: true,
+ readOnly: true
+ },
+ /**
+ * Not null if library has failed to load
+ */
+ libraryErrorMessage: {
+ type: String,
+ value: null,
+ notify: true,
+ readOnly: true
+ }
+ // Following properties are to be set by behavior users
+ /**
+ * Library url. Must contain string `%%callback%%`.
+ *
+ * `%%callback%%` is a placeholder for jsonp wrapper function name
+ *
+ * Ex: https://maps.googleapis.com/maps/api/js?callback=%%callback%%
+ * @property libraryUrl
+ */
+ /**
+ * Set if library requires specific callback name.
+ * Name will be automatically generated if not set.
+ * @property callbackName
+ */
+ /**
+ * name of event to be emitted when library loads. Standard is `api-load`
+ * @property notifyEvent
+ */
+ /**
+ * event with name specified in `notifyEvent` attribute
+ * will fire upon successful load2
+ * @event `notifyEvent`
+ */
+ },
+
+ observers: [
+ '_libraryUrlChanged(libraryUrl)'
+ ],
+
+ _libraryUrlChanged: function(libraryUrl) {
+ // can't load before ready because notifyEvent might not be set
+ if (this._isReady && this.libraryUrl)
+ this._loadLibrary();
+ },
+
+ _libraryLoadCallback: function(err, result) {
+ if (err) {
+ Polymer.Base._warn("Library load failed:", err.message);
+ this._setLibraryErrorMessage(err.message);
+ }
+ else {
+ this._setLibraryErrorMessage(null);
+ this._setLibraryLoaded(true);
+ if (this.notifyEvent)
+ this.fire(this.notifyEvent, result, {composed: true});
+ }
+ },
+
+ /** loads the library, and fires this.notifyEvent upon completion */
+ _loadLibrary: function() {
+ LoaderMap.require(
+ this.libraryUrl,
+ this._libraryLoadCallback.bind(this),
+ this.callbackName
+ );
+ },
+
+ ready: function() {
+ this._isReady = true;
+ if (this.libraryUrl)
+ this._loadLibrary();
+ }
+ };
+
+ /**
+ * LoaderMap keeps track of all Loaders
+ */
+ var LoaderMap = {
+ apiMap: {}, // { hash -> Loader }
+
+ /**
+ * @param {Function} notifyCallback loaded callback fn(result)
+ * @param {string} jsonpCallbackName name of jsonpcallback. If API does not provide it, leave empty. Optional.
+ */
+ require: function(url, notifyCallback, jsonpCallbackName) {
+
+ // make hashable string form url
+ var name = this.nameFromUrl(url);
+
+ // create a loader as needed
+ if (!this.apiMap[name])
+ this.apiMap[name] = new Loader(name, url, jsonpCallbackName);
+
+ // ask for notification
+ this.apiMap[name].requestNotify(notifyCallback);
+ },
+
+ nameFromUrl: function(url) {
+ return url.replace(/[\:\/\%\?\&\.\=\-\,]/g, '_') + '_api';
+ }
+ };
+
+ /** @constructor */
+ var Loader = function(name, url, callbackName) {
+ this.notifiers = []; // array of notifyFn [ notifyFn* ]
+
+ // callback is specified either as callback name
+ // or computed dynamically if url has callbackMacro in it
+ if (!callbackName) {
+ if (url.indexOf(this.callbackMacro) >= 0) {
+ callbackName = name + '_loaded';
+ url = url.replace(this.callbackMacro, callbackName);
+ } else {
+ this.error = new Error('IronJsonpLibraryBehavior a %%callback%% parameter is required in libraryUrl');
+ // TODO(sjmiles): we should probably fallback to listening to script.load
+ return;
+ }
+ }
+ this.callbackName = callbackName;
+ window[this.callbackName] = this.success.bind(this);
+ this.addScript(url);
+ };
+
+ Loader.prototype = {
+
+ callbackMacro: '%%callback%%',
+ loaded: false,
+
+ addScript: function(src) {
+ var script = document.createElement('script');
+ script.src = src;
+ script.onerror = this.handleError.bind(this);
+ var s = document.querySelector('script') || document.body;
+ s.parentNode.insertBefore(script, s);
+ this.script = script;
+ },
+
+ removeScript: function() {
+ if (this.script.parentNode) {
+ this.script.parentNode.removeChild(this.script);
+ }
+ this.script = null;
+ },
+
+ handleError: function(ev) {
+ this.error = new Error("Library failed to load");
+ this.notifyAll();
+ this.cleanup();
+ },
+
+ success: function() {
+ this.loaded = true;
+ this.result = Array.prototype.slice.call(arguments);
+ this.notifyAll();
+ this.cleanup();
+ },
+
+ cleanup: function() {
+ delete window[this.callbackName];
+ },
+
+ notifyAll: function() {
+ this.notifiers.forEach( function(notifyCallback) {
+ notifyCallback(this.error, this.result);
+ }.bind(this));
+ this.notifiers = [];
+ },
+
+ requestNotify: function(notifyCallback) {
+ if (this.loaded || this.error) {
+ notifyCallback( this.error, this.result);
+ } else {
+ this.notifiers.push(notifyCallback);
+ }
+ }
+ };
+})();
+</script>
+
+<!--
+ Loads specified jsonp library.
+
+ Example:
+
+ <iron-jsonp-library
+ library-url="https://apis.google.com/js/plusone.js?onload=%%callback%%"
+ notify-event="api-load"
+ library-loaded="{{loaded}}"></iron-jsonp-library>
+
+ Will emit 'api-load' event when loaded, and set 'loaded' to true
+
+ Implemented by Polymer.IronJsonpLibraryBehavior. Use it
+ to create specific library loader elements.
+
+ @demo
+-->
+<script>
+ Polymer({
+
+ is: 'iron-jsonp-library',
+
+ behaviors: [ Polymer.IronJsonpLibraryBehavior ],
+
+ properties: {
+ /**
+ * Library url. Must contain string `%%callback%%`.
+ *
+ * `%%callback%%` is a placeholder for jsonp wrapper function name
+ *
+ * Ex: https://maps.googleapis.com/maps/api/js?callback=%%callback%%
+ */
+ libraryUrl: String,
+ /**
+ * Set if library requires specific callback name.
+ * Name will be automatically generated if not set.
+ */
+ callbackName: String,
+ /**
+ * event with name specified in 'notifyEvent' attribute
+ * will fire upon successful load
+ */
+ notifyEvent: String
+ /**
+ * event with name specified in 'notifyEvent' attribute
+ * will fire upon successful load
+ * @event `notifyEvent`
+ */
+
+ }
+ });
+
+</script>