Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1250)

Unified Diff: polymer_1.0.4/bower_components/google-url-shortener/google-url-shortener.html

Issue 1205703007: Add polymer 1.0 to npm_modules (Closed) Base URL: https://chromium.googlesource.com/infra/third_party/npm_modules.git@master
Patch Set: Renamed folder to 1.0.4 Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: polymer_1.0.4/bower_components/google-url-shortener/google-url-shortener.html
diff --git a/polymer_1.0.4/bower_components/google-url-shortener/google-url-shortener.html b/polymer_1.0.4/bower_components/google-url-shortener/google-url-shortener.html
new file mode 100644
index 0000000000000000000000000000000000000000..711fa0d1f1ed2b17fbc2fa5b88d1cf4d9e84c2b2
--- /dev/null
+++ b/polymer_1.0.4/bower_components/google-url-shortener/google-url-shortener.html
@@ -0,0 +1,163 @@
+<link rel="import" href="../polymer/polymer.html">
+<link rel="import" href="../google-apis/google-client-loader.html">
+
+<!--
+`google-url-shortener` is a web component that shortens URLs with the
+<a href="https://developers.google.com/url-shortener/">Google URL Shortener API
+</a>.
+
+##### Example
+
+ <google-url-shortener id="shortener"></google-url-shortener>
+
+ <script>
+ var shortener = document.getElementById('shortener');
+
+ shortener.addEventListener('google-url-shorten', function(event) {
+ console.log(event.detail.shortUrl);
+ });
+
+ // Shorten the current page URL.
+ shortener.longUrl = document.URL;
+ shortener.shorten();
+ </script>
+
+##### Example using `auto` and binding.
+
+ <google-url-shortener id="shortener" longUrl="{{longUrl}}" auto>
+ </google-url-shortener>
+
+ <script>
+ var shortener = document.getElementById('shortener');
+
+ shortener.addEventListener('google-url-shorten', function(event) {
+ // This will be called automatically every time `longUrl` changes.
+ console.log(event.detail.shortUrl);
+ });
+ </script>
+
+@demo
+-->
+<dom-module id="google-url-shortener">
+ <template>
+ <google-client-loader id="urlshortener" name="urlshortener" version="v1"
+ on-google-api-load="_readyForAction"
+ on-google-api-load-error="_apiLoadError">
+ </google-api-loader>
+ </template>
+</dom-module>
+
+<script>
+
+ (function() {
+ 'use strict';
+
+ // Stores whether the URL Shortener API is done loading.
+ var apiLoaded_ = false;
+
+ Polymer({
+
+ is: 'google-url-shortener',
+
+ /**
+ * Fired when the component is ready for shortening.
+ *
+ * @event google-url-shortener-ready
+ */
+
+ /**
+ * Fired when the URL gets successfully shortened.
+ *
+ * @event google-url-shorten
+ */
+
+ /**
+ * Fired if an attempt to shorten a URL results in an error.
+ *
+ * @event google-url-shorten-error
+ */
+
+ properties: {
+ /**
+ * The URL to be shortened.
+ */
+ longUrl: {
+ type: String,
+ value: '',
+ observer: '_longUrlChanged'
+ },
+
+ /**
+ * Shortened URL
+ */
+ shortUrl: {
+ type: String,
+ value: '',
+ notify: true
+ },
+
+ /**
+ * Error when url was shortened
+ */
+ error: {
+ type: String,
+ value: '',
+ notify: true
+ },
+ /**
+ * If true, automatically performs the shortening request when `longUrl`
+ * changes.
+ */
+ auto: {
+ type: Boolean,
+ value: false
+ }
+ },
+
+ _readyForAction: function() {
+ apiLoaded_ = true;
+ this.fire('google-url-shortener-ready');
+ },
+
+ _apiLoadError: function(event) {
+ this.fire('api-error', {
+ 'error': {
+ 'message': 'Error loading URL Shortener API',
+ 'innerError': event.detail
+ }
+ });
+ },
+
+ _longUrlChanged: function() {
+ if (this.auto) {
+ this.shorten();
+ }
+ },
+
+ /**
+ * Shortens the URL in `longUrl`. Use if `auto` is not set.
+ */
+ shorten: function() {
+ if (apiLoaded_) {
+ if (this.longUrl) {
+ var request = this.$.urlshortener.api.url.insert(
+ {resource: {longUrl: this.longUrl}});
+
+ request.execute(function(response) {
+ if (response && response.id) {
+ this.shortUrl = response.id;
+ this.error = '';
+ this.fire('google-url-shorten', {shortUrl: response.id});
+ } else {
+ this.error = response && response.error ? response.error.message : 'Unknown error';
+ this.fire('google-url-shorten-error', {error: this.error});
+ }
+ }.bind(this));
+ }
+ }
+ }
+
+ });
+ })();
+
+</script>

Powered by Google App Engine
This is Rietveld 408576698