Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 4cbddb8d2317590138cc1d94d8f1f6392fbedd97 Paul Kinlan committed Jun 13, 2011
Showing with 5,154 additions and 0 deletions.
  1. +21 −0 Makefile
  2. +25 −0 README.md
  3. +25 −0 SpecRunner.html
  4. +1 −0 debug.js
  5. +4 −0 examples/README.md
  6. +27 −0 examples/index.html
  7. +4 −0 examples/intents/README.md
  8. +46 −0 examples/intents/pick/action.html
  9. BIN examples/intents/pick/images/kitten1.jpg
  10. BIN examples/intents/pick/images/kitten2.jpg
  11. BIN examples/intents/pick/images/kitten3.jpg
  12. +17 −0 examples/intents/pick/index.html
  13. +50 −0 examples/intents/pick/pick.html
  14. +27 −0 examples/intents/pick/register.html
  15. +88 −0 examples/intents/share/action.html
  16. +17 −0 examples/intents/share/index.html
  17. +34 −0 examples/intents/share/register.html
  18. +17 −0 examples/intents/share/shareimage.html
  19. +16 −0 examples/intents/share/sharelink.html
  20. +45 −0 examples/intents/shorten/index.html
  21. +16 −0 examples/intents/shorten/shorten.html
  22. +219 −0 examples/lib/webintents.debug.js
  23. +218 −0 examples/lib/webintents.js
  24. +19 −0 examples/usage/declarativeMetaRegister/index.html
  25. +20 −0 examples/usage/declarativeRegister/index.html
  26. +19 −0 examples/usage/register/index.html
  27. +29 −0 examples/usage/startActivity/index.html
  28. +32 −0 examples/usage/startActivityHandleInputData/index.html
  29. +190 −0 lib/jasmine/jasmine-html.js
  30. +166 −0 lib/jasmine/jasmine.css
  31. +2,435 −0 lib/jasmine/jasmine.js
  32. +478 −0 lib/jasmine/json2.js
  33. +25 −0 run.sh
  34. +49 −0 server/cache.manifest
  35. +11 −0 server/cache.manifest.src
  36. +43 −0 server/controller.js
  37. +5 −0 server/intents.html
  38. +22 −0 server/list.html
  39. +62 −0 server/picker.html
  40. +4 −0 server/picker.js
  41. +123 −0 server/webintents.js
  42. +4 −0 tests/README.md
  43. +14 −0 tests/inittest.js
  44. +46 −0 tests/intent.js
  45. +3 −0 tests/register.js
  46. +219 −0 webintents.debug.js
  47. +218 −0 webintents.js
  48. +1 −0 webintents.min.js
@@ -0,0 +1,21 @@
+all: webintents.min.js server/cache.manifest debug
+
+debug: webintents.debug.js
+
+webintents.debug.js: webintents.js debug.js
+ cat debug.js webintents.js > webintents.debug.js
+ rm examples/lib/webintents.debug.js
+ ln webintents.debug.js examples/lib/webintents.debug.js
+
+webintents.min.js: webintents.js
+ uglifyJs $^ > $@
+ rm examples/lib/webintents.js
+ ln webintents.js examples/lib/webintents.js
+
+# Manifest depends on changes to other files, so include them in the dependency chain
+server/cache.manifest: server/cache.manifest.src server/picker.html server/picker.js server/webintents.js server/intents.html
+ cat server/cache.manifest.src >> server/cache.manifest
+ echo '#' `date` >> server/cache.manifest
+
+clean:
+ rm webintents.min.js webintents.debug.js server/cache.manifest
@@ -0,0 +1,25 @@
+Web Intents
+===========
+
+Web Intents is a discovery mechanism and extremely light-weight RPC system between web apps, modeled after the similarly-named system in Android. An Intent is an action to be performed by a provider. Intents provides a declarative syntax that allows providers to list the Intents they handle and a registration system that enumerates available providers. A client requests an Intent be handled, the User Agent allows the user to select which provider to use, and the provider performs the action of the Intent, possibly using data passed as input in the Intent. The provider may return data as output to the client.
+
+Examples
+========
+
+To run the examples:
+ ./run.sh start
+
+Navigate to http://0.0.0.0:8000/
+
+To stop the example server:
+ ./run.sh stop
+
+Tests
+=====
+
+To run the tests:
+
+ python -m SimpleHTTPServer
+
+Navigate to: http://0.0.0.0:8000/SpecRunner.html
+
@@ -0,0 +1,25 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+ "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+ <title>Jasmine Test Runner</title>
+ <link rel="stylesheet" type="text/css" href="lib/jasmine/jasmine.css">
+ <script type="text/javascript" src="lib/jasmine/jasmine.js"></script>
+ <script type="text/javascript" src="lib/jasmine/jasmine-html.js"></script>
+
+ <!-- include source files here... -->
+ <script type="text/javascript" src="webintents.js"></script>
+
+ <!-- include spec files here... -->
+ <script type="text/javascript" src="tests/inittest.js"></script>
+ <script type="text/javascript" src="tests/intent.js"></script>
+ <script type="text/javascript" src="tests/register.js"></script>
+</head>
+<body>
+<script type="text/javascript">
+ jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
+ jasmine.getEnv().execute();
+</script>
+
+</body>
+</html>
@@ -0,0 +1 @@
+__WEBINTENTS_DEBUG__ = "http://0.0.0.0:8080/";
@@ -0,0 +1,4 @@
+Web Intents Examples
+====================
+
+Examples of Web Intents
@@ -0,0 +1,27 @@
+<!doctype html>
+<html>
+ <title>Examples</title>
+ <body>
+ <h1>Examples</h1>
+ <h2>Usage: Registration</h2>
+ <p>A collection of examples that show you the different ways to register an intent.</p>
+ <ul>
+ <li><a href="usage/register/index.html">Register an action for an intent</a></li>
+ <li><a href="usage/declarativeRegister/index.html">Declaratively Register an action for an intent</a></li>
+ <li><a href="usage/declarativeMetaRegister/index.html">Declaratively Register an action for an intent using a meta tag.</a></li>
+ </ul>
+ <h2>Usage: Start Activity</h2>
+ <p>A suite of examples that show you how to quickly start an activity</p>
+ <ul>
+ <li><a href="usage/startActivity/index.html">Starts an Action</a></li>
+ <li><a href="usage/startActivityHandleInputData/index.html">Starts an Action and handles the data that is sent with the activity</a></li>
+ </ul>
+ <h2>Intents</h2>
+ <p>A collection of examples demonstrating use-cases for Web Intents</p>
+ <ul>
+ <li><a href="intents/share/index.html">Simple Share</a> - Demonstrates the ability to open an app that shares links</li>
+ <li><a href="intents/shorten/index.html">Shorten URL</a> - Demonstrates the ability to open an app that shares a link, and the service shortens it and returns a response</li>
+ <li><a href="intents/pick/index.html">Pick an Image from a cloud service</a> - Demonstrates the ability to integrate with cloud file hosts and pick a file to include in your client application</li>
+ </ul>
+ </body>
+</html>
@@ -0,0 +1,4 @@
+Web Intents Examples
+====================
+
+Examples of how to use web intents.
@@ -0,0 +1,46 @@
+<!doctype html>
+<html>
+ <head>
+ <title>Intent: Pick</title>
+ <script src="/lib/webintents.debug.js"></script>
+ <script>
+ window.addEventListener("load", function() {
+ var pickImage = document.getElementById("pickImage");
+ pickImage.addEventListener("click", function() {
+ var intent = new Intent();
+ intent.action = "http://webintents.org/pick";
+ intent.type = "image/*";
+
+ window.navigator.intents.startActivity(intent, intentResponse);
+
+ return false;
+ });
+
+ var intentResponse = function (intentData) {
+ var output = document.getElementById("output");
+ output.src = intentData.data.images[0];
+ focus();
+ };
+ });
+ </script>
+ </head>
+ <body>
+ <h2>Pick an image from a remote service to use in this application</h2>
+ <button id="pickImage">Pick an Image</button>
+ <h3>Response will appear here:</h3>
+ <img id="output" />
+
+ <h3>Code</h3>
+ <pre>var intent = new Intent();
+intent.action = "http://webintents.org/pick";
+intent.type = "image/*";
+
+window.navigator.intents.startActivity(intent, intentResponse);
+
+var intentResponse = function (intentData) {
+ var output = document.getElementById("output");
+ output.src = intentData.data.images[0];
+};</pre>
+ </body>
+</html>
+
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,17 @@
+<!doctype html>
+<html>
+ <head>
+ <title>Intent: Pick</title>
+ <style>
+ iframe {
+ width: 45%;
+ height: 80%;
+ }
+ </style>
+ </head>
+ <body>
+ <h2>This is an example app that lets the user pick files from a cloud storage solution</h2>
+ <iframe src="register.html"></iframe>
+ <iframe src="action.html"></iframe>
+ </body>
+</html>
@@ -0,0 +1,50 @@
+<!doctype html>
+<html>
+ <title>Pick an Image</title>
+ <script src="/lib/webintents.debug.js"></script>
+ <script>
+ var intentToReturn;
+
+ window.navigator.intents.onActivity = function(intent) {
+ intentToReturn = intent;
+ };
+
+ var getImageData = function(img) {
+ var canvas = document.createElement("canvas");
+ canvas.width = img.width;
+ canvas.height = img.height;
+ var context = canvas.getContext("2d");
+
+ context.drawImage(img, 0, 0);
+ return canvas.toDataURL("image/png");
+ };
+
+ var returnImage = function(e) {
+ if(!!intentToReturn) {
+ // Do some magic to return the raw data.
+ var data = { images : [ getImageData(e.target) ] };
+
+ intentToReturn.postResult(data);
+ setTimeout(function() { window.close();}, 500);
+ }
+ };
+
+ window.addEventListener("load", function() {
+ var img1 = document.getElementById("img1");
+ var img2 = document.getElementById("img2");
+ var img3 = document.getElementById("img3");
+
+ img1.addEventListener("click", returnImage);
+ img2.addEventListener("click", returnImage);
+ img3.addEventListener("click", returnImage);
+ });
+
+ </script>
+ <body>
+ <h1>Kinlan's Cloud File Store</h1>
+ <p>Select a file for the app to use</p>
+ <img id="img1" src="images/kitten1.jpg">
+ <img id="img2" src="images/kitten2.jpg">
+ <img id="img3" src="images/kitten3.jpg">
+ </body>
+</html>
@@ -0,0 +1,27 @@
+<!doctype html>
+<html>
+ <head>
+ <title>Intent: Pick</title>
+ <script src="/lib/webintents.debug.js"></script>
+ <intent
+ action="http://webintents.org/pick"
+ type="image/*"
+ href="pick.html"
+ title="Cat Image picker" />
+ </script>
+ </head>
+
+
+ <body>
+ <h1>Service</h1>
+ <p>This is a service you use. It has registered it's intent to be able to handle the share action for "image/*" datatypes.</p>
@FND
FND Jul 3, 2011

s/it's intent/its intent/

+ <p>Imaging one of the services is a Picasa, or Flickr style image hosting service. We want to be able to select one of images to use in the application (think attach picture to gmail).</p>
@FND
FND Jul 3, 2011

s/one of images/one of the images/?

+ <h2>Pick Intent Registration</h2>
+ <pre>&lt;intent
+ action="http://webintents.org/pick"
+ type="image/*"
+ href="pick.html"
+ title="Cat Image picker" /&gt;</pre>
+
+ </body>
+</html>
@@ -0,0 +1,88 @@
+<!doctype html>
+<html>
+ <head>
+ <title>Intent: Share</title>
+ <script src="/lib/webintents.debug.js"></script>
+ <script>
+ window.addEventListener("load", function() {
+
+ var shareLink = document.getElementById("shareLink");
+ shareLink.addEventListener("click", function() {
+ var url = document.getElementById("url").value;
+
+ var intent = new Intent();
+ intent.action = "http://webintents.org/share";
+ intent.type = "text/uri-list";
+ intent.data = { uris : [ url ] };
+
+ window.navigator.intents.startActivity(intent);
+ return false;
+ });
+
+
+ var shareImage = document.getElementById("shareImage");
+ var imageList = document.getElementById("imageList");
+ var imageData;
+
+ shareImage.addEventListener("click", function(e) {
+ if(!!imageData == false) {
+ alert("Please select a file");
+ return false;
+ }
+ // We are going to send the ACTUAL data, not just a link.
+ var intent = new Intent();
+ intent.action = "http://webintents.org/share";
+ intent.type = "image/*";
+ intent.data = { images : [ imageData ] };
+
+ window.navigator.intents.startActivity(intent);
+ return false;
+ });
+
+ imageList.addEventListener("change", function(e) {
+ // Get the data
+ var fileData = e.target.files[0];
+ var reader = new FileReader();
+
+ // Closure to capture the file information.
+ reader.onload = function(evt) {
+ imageData = evt.target.result;
+ };
+
+ reader.readAsDataURL(fileData);
+
+ });
+ });
+
+ </script>
+
+ </head>
+ <body>
+ <h1>Client App</h1>
+ <p>This is an external app that needs to share links. It has no prior knowledge of any other sharing application.</p>
+
+ <section>
+ <h2>Share a link</h2>
+ <input id="url" name="url" type="url" value="http://paul.kinlan.me" />
+ <button id="shareLink">Share link</button>
+ <pre>var intent = new Intent();
+intent.action = "http://webintents.org/share";
+intent.type = "text/uri-list";
+intent.data = { uris : [ url ] };
+
+window.navigator.intents.startActivity(intent);</pre>
+ </section>
+ <section>
+ <h2>Share an image</h2>
+ <p>Pick an image to share.</p>
+ <input id="imageList" type="file" accept="image/*" />
+ <button id="shareImage">Share Image</button>
+ <pre>var intent = new Intent();
+intent.action = "http://webintents.org/share";
+intent.type = "image/*";
+intent.data = { images : [ imageData ] };
+
+window.navigator.intents.startActivity(intent);</pre>
+ </section>
+ </body>
+</html>
@@ -0,0 +1,17 @@
+<!doctype html>
+<html>
+ <head>
+ <title>Intent: Share</title>
+ <style>
+ iframe {
+ width: 45%;
+ height: 80%;
+ }
+ </style>
+ </head>
+ <body>
+ <h2>This is an example app that needs to share links</h2>
+ <iframe src="register.html"></iframe>
+ <iframe src="action.html"></iframe>
+ </body>
+</html>
@@ -0,0 +1,34 @@
+<!doctype html>
+<html>
+ <head>
+ <title>Share Intent Registration Page</title>
+ <intent
+ action="http://webintents.org/share"
+ type="image/*"
+ href="shareimage.html"
+ title="Kinlan's Image Share" />
+ <intent
+ action="http://webintents.org/share"
+ type="text/uri-list"
+ href="sharelink.html"
+ title="Kinlan's Link Share" />
+
+ </head>
+ <body>
+ <h1>Service</h1>
+ <p>This is a service you use. It has registered it's intent to be able to handle the share action for "image/*" and "text/uri-list" datatypes.</p>
+ <h2>Share Intent Registration</h2>
+ <pre>&lt;intent
+ action="http://webintents.org/share"
+ type="image/*"
+ href="shareimage.html"
+ title="Kinlan's Image Share" /&gt;
+&lt;intent
+ action="http://webintents.org/share"
+ type="text/uri-list"
+ href="sharelink.html"
+ title="Kinlan's Link Share" /&gt;</pre>
+
+ <p>Any application that launches a startActivity with an action of "http://webintents.org/share" will see these applications listed.</p>
+ </body>
+</html>
Oops, something went wrong. Retry.

0 comments on commit 4cbddb8

Please sign in to comment.