Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

merged from PaulKinlan

  • Loading branch information...
commit 824dc816aac77a796719299bca490aade90a9627 2 parents 421f6f8 + 1efe2ad
@lonestarsoftware lonestarsoftware authored
Showing with 597 additions and 4,560 deletions.
  1. +7 −0 .gitignore
  2. +24 −33 Makefile
  3. +10 −11 README.md
  4. BIN  assets/share.pxm
  5. BIN  assets/share16.png
  6. BIN  assets/share32.png
  7. +68 −0 examples/css/embedbase.css
  8. BIN  examples/favicon.ico
  9. +2 −2 examples/index.html
  10. +3 −1 examples/intents/discover/action.html
  11. +7 −1 examples/intents/discover/discover.html
  12. +39 −9 examples/intents/discover/index.html
  13. +0 −28 examples/intents/discover/register.html
  14. +12 −2 examples/intents/pick/action.html
  15. +2 −16 examples/intents/pick/google.html
  16. +32 −5 examples/intents/pick/index.html
  17. +6 −1 examples/intents/pick/pick.html
  18. +1 −1  examples/intents/pick/register.html
  19. +4 −2 examples/intents/share/action.html
  20. +31 −3 examples/intents/share/index.html
  21. +0 −35 examples/intents/share/register.html
  22. +7 −1 examples/intents/share/shareimage.html
  23. +8 −2 examples/intents/share/sharelink.html
  24. +4 −4 examples/intents/shorten/index.html
  25. +6 −1 examples/intents/shorten/shorten.html
  26. +0 −828 examples/lib/webintents.debug.js
  27. +0 −828 examples/lib/webintents.js
  28. +0 −15 examples/lib/webintents.min.js
  29. +1 −1  examples/usage/declarativeRegister/index.html
  30. +1 −1  examples/usage/startActivity/index.html
  31. +0 −23 examples/usage/startActivityForm/index.html
  32. +1 −1  examples/usage/startActivityHandleInputData/index.html
  33. +0 −3  server/cache.manifest.src
  34. +2 −2 server/discover
  35. +3 −3 server/edit
  36. +66 −0 server/faq.html
  37. BIN  server/favicon.ico
  38. BIN  server/images/star.png
  39. BIN  server/images/unstar.png
  40. +19 −11 server/index.html
  41. +1 −1  server/pick
  42. +15 −0 server/picker.html
  43. +54 −0 server/save
  44. +18 −36 server/script/controller.js
  45. +1 −2  server/script/picker.js
  46. +18 −25 server/script/webintents-server.js
  47. +2 −2 server/share
  48. +1 −1  server/view
  49. +4 −0 src/debug.js
  50. +38 −61 src/webintents.js
  51. +11 −10 tools/chrome/extensions/share/background.html
  52. +18 −0 tools/chrome/extensions/share/handlers/twitter.html
  53. +9 −3 tools/chrome/extensions/share/manifest.json
  54. BIN  tools/chrome/extensions/share/openshareicon-128x128.png
  55. BIN  tools/chrome/extensions/share/openshareicon-16x16.png
  56. BIN  tools/chrome/extensions/share/openshareicon-48x48.png
  57. +16 −15 tools/chrome/extensions/share/plus.js
  58. +2 −16 tools/chrome/extensions/share/startActivity.js
  59. +6 −11 tools/chrome/extensions/share/twitter.js
  60. +11 −0 tools/chrome/extensions/share/webintents-inject.js
  61. +0 −828 tools/chrome/extensions/share/webintents.js
  62. +0 −828 webintents.debug.js
  63. +0 −828 webintents.js
  64. +0 −15 webintents.min.js
  65. +5 −3 widgets/embed/share.html
  66. BIN  widgets/favicon.ico
  67. BIN  widgets/images/share.png
  68. BIN  widgets/images/share16.png
  69. BIN  widgets/images/share32.png
  70. +1 −1  widgets/share.js
View
7 .gitignore
@@ -1,3 +1,10 @@
.DS_Store
*.pid
*.bpkg
+webintents.js
+webintents.debug.js
+webintents.min.js
+tools/chrome/extensions/share/webintents.js
+examples/lib/webintents*
+widgets/lib/webintents*
+server/lib/webintents*
View
57 Makefile
@@ -1,46 +1,37 @@
RELEASE := $(shell cat ./src/release.js)
DEBUG := $(shell cat ./src/debug.js)
-all: webintents.js webintents.min.js server/cache.manifest webintents.debug.js examples tools
+all: server/cache.manifest production
-examples: examples/lib/webintents.js examples/lib/webintents.debug.js examples/lib/webintents.min.js
-
-tools: tools/chrome/extensions/share/webintents.js
-
-examples/lib/webintents.js: webintents.js
- ln -f webintents.js examples/lib/webintents.js
-
-examples/lib/webintents.debug.js: webintents.debug.js
- ln -f webintents.debug.js examples/lib/webintents.debug.js
-
-examples/lib/webintents.min.js: webintents.min.js
- ln -f webintents.min.js examples/lib/webintents.min.js
-
-webintents.js: ./src/release.js ./src/webintents.js ./src/json2.js ./src/base64.js
+release: ./src/webintents.js ./src/json2.js ./src/base64.js
cat ./src/webintents.js ./src/json2.js ./src/base64.js | sed 's|// __WEBINTENTS_ROOT|$(RELEASE)|' > webintents.js
+ cp webintents.js server/webintents.js
+ cp webintents.js widgets/lib/webintents.js
+ cp webintents.js examples/lib/webintents.js
+ cp webintents.js tools/chrome/extensions/share/webintents.js
-webintents.debug.js: ./src/webintents.js ./src/debug.js ./src/json2.js ./src/base64.js
- cat ./src/webintents.js ./src/json2.js ./src/base64.js | sed 's|// __WEBINTENTS_ROOT|$(DEBUG)|' > webintents.debug.js
+debug: ./src/webintents.js ./src/debug.js ./src/json2.js ./src/base64.js
+ cat ./src/debug.js ./src/webintents.js ./src/json2.js ./src/base64.js | sed 's|// __WEBINTENTS_ROOT|$(DEBUG)|' | sed 's|//DEBUG(|DEBUG(|' > webintents.js
+ cp webintents.js server/webintents.js
+ cp webintents.js widgets/lib/webintents.js
+ cp webintents.js examples/lib/webintents.js
+ cp webintents.js tools/chrome/extensions/share/webintents.js
-webintents.min.js: webintents.js
- uglifyJs $^ > $@
+production: release
+ uglifyjs webintents.js > server/webintents.min.js
-tools/chrome/extensions/share/webintents.js: webintents.js
- ln -f webintents.js tools/chrome/extensions/share/webintents.js
+server/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/script/picker.js server/webintents.js server/intents.html server/script/json2.js server/script/webintents-server.js server/webintents.min.js server/webintents.debug.js server/script/controller.js server/script/base64.js
+server/cache.manifest: server/cache.manifest.src server/picker.html server/script/picker.js server/webintents.js server/intents.html server/script/json2.js server/script/webintents-server.js server/script/controller.js server/script/base64.js
cat server/cache.manifest.src >> server/cache.manifest
echo '#' `date` >> server/cache.manifest
-server/webintents.js: webintents.js
- ln -f webintents.js server/webintents.js
-
-server/webintents.debug.js: webintents.debug.js
- ln -f webintents.debug.js server/webintents.debug.js
-
-server/webintents.min.js: webintents.min.js
- ln -f webintents.min.js server/webintents.min.js
-
-clean: webintents.js webintents.min.js webintents.debug.js server/cache.manifest examples/lib/webintents.debug.js examples/lib/webintents.min.js examples/lib/webintents.js server/webintents.js server/webintents.min.js server/webintents.debug.js
- rm $^
+clean:
+ rm -f webintents.js
+ rm -f server/cache.manifest
+ rm -f server/webintents.js
+ rm -f server/webintents.min.js
+ rm -f examples/lib/webintents.js
+ rm -f widgets/lib/webintents.js
+ rm -f tools/chrome/extensions/share/webintents.js
View
21 README.md
@@ -6,6 +6,14 @@ Web Intents is a discovery mechanism and extremely light-weight RPC system betwe
Usage
=====
+To use today
+------------
+No browsers currently support this API natively. To use this system simple drop the following code in to your site:
+
+ <script src="http://webintents.org/webintents.min.js"></script>
+
+When browsers start to implement this natively the Shim will defer all its functionality to the native interface.
+
Declaration
-----------
@@ -25,19 +33,10 @@ To build a client application that can use the share functionality, it is as sim
var intent = new Intent(
"http://webintents.org/share",
"image/*",
- {
- uris : ["http://upload.wikimedia.org/wikipedia/commons/thumb/f/f8/Three_jolly_kittens.png/800px-Three_jolly_kittens.png"]
- }
+ "http://upload.wikimedia.org/wikipedia/commons/thumb/f/f8/Three_jolly_kittens.png/800px-Three_jolly_kittens.png"
);
window.navigator.startActivity(intent);
-You can even use a FORM so you don't have to do any coding.
-
- <form method="intent" action="http://webintents.org/share" enctype="image/*">
- <input name="uris" type="file" accepts="image/*" />
- <input type="submit" />
- </form>
-
Service
-------
@@ -49,7 +48,7 @@ That's it.
To send data back to the client that invoked it, it is as simple as calling postResult() on the intent.
- window.intent.postResult({ data: "something cool" });
+ window.intent.postResult("something cool");
Examples
========
View
BIN  assets/share.pxm
Binary file not shown
View
BIN  assets/share16.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  assets/share32.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
68 examples/css/embedbase.css
@@ -0,0 +1,68 @@
+body {
+}
+
+h1 {
+ margin-top: 10px;
+ font-size: 3em;
+ margin-bottom: 15px;
+}
+
+a {
+ color: #1465A3;
+}
+
+nav.sub a:active {
+ background-color: red;
+}
+
+h2 {
+ font-size: 2em;
+ margin-bottom: 15px;
+ margin-top: 25px;
+}
+
+h3 {
+ font-size: 1.6em;
+ margin-bottom: 15px;
+ margin-top: 15px;
+}
+
+dl {
+line-height: 20px;
+}
+
+p {
+ margin-top: 10px;
+ margin-bottom: 10px;
+ line-height: 20px;
+}
+
+pre {
+ padding: 5px;
+ font-family: Courier New;
+ background-color: #eee;
+ border: solid 1px #ccc;
+ line-height: 20px;
+ margin-top: 10px;
+ margin-bottom: 10px;
+}
+
+dt {
+ font-weight: 700;
+}
+
+dd {
+ padding-left: 10px;
+}
+
+ul {
+ list-style-type: disc;
+ list-style-position: inside;
+
+ margin-top: 10px;
+ margin-bottom: 10px;
+}
+
+ul li {
+ margin-bottom: 3px;
+}
View
BIN  examples/favicon.ico
Binary file not shown
View
4 examples/index.html
@@ -14,6 +14,7 @@
<span><a href="http://webintents.org">Specification</a></span>
<span><a href="http://examples.webintents.org">Examples</a></span>
<span><a href="http://usecases.webintents.org">Use Cases</a></span>
+ <span><a href="http://webintents.org/faq.html">FAQ</a></span>
</nav>
<nav class="sub">
@@ -35,7 +36,7 @@
</ul>
<h2>Usage: Registration</h2>
- <p>A collection of examples that show you the different ways to register an intent.</p>
+ <p>A collection of examples that show you the different ways to register an intent</p>
<ul>
<li><a href="usage/declarativeRegister/index.html">Declaratively Register an action for an intent</a></li>
</ul>
@@ -45,7 +46,6 @@
<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>
- <li><a href="usage/startActivityForm/index.html">Starts an Action using a FORM</a></li>
</ul>
</section>
</body>
View
4 examples/intents/discover/action.html
@@ -2,7 +2,9 @@
<html>
<head>
<title>Intent: Discover</title>
- <script src="/lib/webintents.debug.js"></script>
+ <link rel="stylesheet" href="/css/reset.css" />
+ <link rel="stylesheet" href="/css/embedbase.css" />
+ <script src="/lib/webintents.js"></script>
<script src="/lib/events.js"></script>
<script>
attachEventListener(window, "load", function() {
View
8 examples/intents/discover/discover.html
@@ -1,7 +1,13 @@
<!doctype html>
<html>
<title>Discovery</title>
- <script src="/lib/webintents.debug.js"></script>
+ <script src="/lib/webintents.js"></script>
+ <intent
+ action="http://webintents.org/discover"
+ type="application/JSON"
+ href="discover.html"
+ title="Example.com's APIs"
+ />
<script src="/lib/events.js"></script>
<script>
View
48 examples/intents/discover/index.html
@@ -1,21 +1,51 @@
<!doctype html>
<html>
<head>
+ <link rel="stylesheet" href="/css/reset.css" />
+ <link rel="stylesheet" href="/css/base.css" />
+ <script src="/lib/webintents.js"></script>
<title>Intent: Discover</title>
+ <intent
+ action="http://webintents.org/discover"
+ type="application/JSON"
+ href="discover.html"
+ title="Webintents.org's APIs"
+ />
<style>
- body {
- height: 100%;
- }
-
iframe {
- width: 45%;
- height: 80%;
+ width: 100%;
+ height: 800px;
+ }
+
+ #register {
}
</style>
</head>
<body>
- <h2>This is an example app that lets the user discover services that other API's offer</h2>
- <iframe src="register.html"></iframe>
- <iframe src="action.html"></iframe>
+ <header>
+ <h1>Discover intent example</h1>
+ <nav>
+ <a href="http://webintents.org/">Web Intents</a>
+ <a href="http://webintents.org/discover">Discover Intent documentation</a>
+ <a href="http://examples.webintents.org/">Examples</a>
+ <a href="http://webintents.org/faq.html">FAQ</a>
+ </nav>
+ </header>
+ <section>
+ <p>This is an example app that lets the user discover services that other
+ APIs offer</p>
+ <div>
+ <div id="register">
+ <h2>Discover Intent Registration</h2>
+ <pre>&lt;intent
+ action="http://webintents.org/discover"
+ type="application/JSON"
+ href="discover.html"
+ title="Example.com's APIs"
+ /&gt;</pre>
+ </div>
+ <iframe src="action.html"></iframe>
+ </div>
+ </section>
</body>
</html>
View
28 examples/intents/discover/register.html
@@ -1,28 +0,0 @@
-<!doctype html>
-<html>
- <head>
- <title>Intent: Pick</title>
- <script src="/lib/webintents.debug.js"></script>
- <intent
- action="http://webintents.org/discover"
- type="application/JSON"
- href="discover.html"
- title="Example.com's APIs"
- />
- </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 "application/JSON" datatypes.</p>
- <h2>Discover Intent Registration</h2>
- <pre>&lt;intent
- action="http://webintents.org/discover"
- type="application/JSON"
- href="discover.html"
- title="Example.com's APIs"
- /&gt;</pre>
-
- </body>
-</html>
View
14 examples/intents/pick/action.html
@@ -2,8 +2,15 @@
<html>
<head>
<title>Intent: Pick</title>
- <script src="/lib/webintents.debug.js"></script>
+ <intent
+ action="http://webintents.org/pick"
+ type="image/*"
+ href="google.html" />
+
+ <script src="/lib/webintents.js"></script>
<script src="/lib/events.js"></script>
+ <link rel="stylesheet" href="/css/reset.css" />
+ <link rel="stylesheet" href="/css/embedbase.css" />
<script>
attachEventListener(window, "load", function() {
var pickImage = document.getElementById("pickImage");
@@ -26,7 +33,9 @@
</script>
</head>
<body>
- <h2>Pick an image from a remote service to use in this application</h2>
+ <section>
+ <h2>Client App</h2>
+ <p>Pick an image from a remote service to use in this application</p>
<button id="pickImage">Pick an Image</button>
<h3>Response will appear here:</h3>
<img id="output" />
@@ -42,6 +51,7 @@
var output = document.getElementById("output");
output.src = intentData.data[0];
};</pre>
+ </section>
</body>
</html>
View
18 examples/intents/pick/google.html
@@ -4,7 +4,7 @@
<!--script
src="https://www.google.com/jsapi?key=ABQIAAAAFTbNNpUTYWRw9jdG-0kTfRSs7LgCgiaTQIQPWqybRxS3H3zfqRSCIvzXzge1CIW7mxn9PWmB7bxLSw"
/-->
- <script src="/lib/webintents.debug.js"></script>
+ <script src="/lib/webintents.js"></script>
<script src="/lib/events.js"></script>
<script
src="https://www.google.com/jsapi?key=ABQIAAAAFTbNNpUTYWRw9jdG-0kTfRS5zkozs6sQsOJ2dExE7jTK_xtuGxSV9o6iOAEZOe200o8gHTMinin9ug"></script>
@@ -35,23 +35,9 @@
}
}
- function getImageData(url) {
- var img = new Image();
- img.src = '/proxy?url=' + url;
- attachEventListener(img, "load", function() {
- var canvas = document.createElement("canvas");
- canvas.width = img.width;
- canvas.height = img.height;
- var context = canvas.getContext("2d");
-
- context.drawImage(img, 0, 0);
- returnImage(canvas.toDataURL("image/png"));
- });
- }
-
function pickerCallback(data) {
if (data.action == google.picker.Action.PICKED) {
- returnImage(data.docs[0].thumbnails[4].url);
+ returnImage(data.docs[0].thumbnails[3].url);
}
}
</script>
View
37 examples/intents/pick/index.html
@@ -1,25 +1,52 @@
<!doctype html>
<html>
<head>
+ <script src="/lib/webintents.js"></script>
+ <intent
+ action="http://webintents.org/pick"
+ type="image/*"
+ href="pick.html"
+ title="Cat Image picker" />
+ <intent
+ action="http://webintents.org/pick"
+ type="image/*"
+ href="google.html"
+ title="Google Image picker" />.
+
<link rel="stylesheet" href="/css/reset.css" />
<link rel="stylesheet" href="/css/base.css" />
<style>
iframe {
- float:left;
- width: 50%;
+ width: 100%;
height: 800px;
}
+
+ #register {
+ }
</style>
<title>Intent: Pick</title>
</head>
<body>
<header>
- <h1>Intent Pick: example</h1>
+ <h1>Pick intent example</h1>
+ <nav>
+ <a href="http://webintents.org/">Web Intents</a>
+ <a href="http://webintents.org/pick">Pick Intent documentation</a>
+ <a href="http://examples.webintents.org/">Examples</a>
+ <a href="http://webintents.org/faq.html">FAQ</a>
+ </nav>
</header>
<section>
- <p>This example demonstates a cloud-based file picker.</p>
+ <p>This example demonstrates a cloud-based file picker.</p>
<div>
- <iframe src="register.html"></iframe>
+ <div id="register">
+ <h2>Pick Intent Registration</h2>
+ <pre>&lt;intent
+ action="http://webintents.org/pick"
+ type="image/*"
+ href="pick.html"
+ title="Cat Image picker" /&gt;</pre>
+ </div>
<iframe src="action.html"></iframe>
</div>
</section>
View
7 examples/intents/pick/pick.html
@@ -1,7 +1,12 @@
<!doctype html>
<html>
<title>Pick an Image</title>
- <script src="/lib/webintents.debug.js"></script>
+ <script src="/lib/webintents.js"></script>
+ <intent
+ action="http://webintents.org/pick"
+ type="image/*"
+ href="pick.html"
+ title="Cat Image picker" />
<script src="/lib/events.js"></script>
<link rel="stylesheet" href="/css/reset.css" />
<link rel="stylesheet" href="/css/base.css" />
View
2  examples/intents/pick/register.html
@@ -2,7 +2,7 @@
<html>
<head>
<title>Intent: Pick</title>
- <script src="/lib/webintents.debug.js"></script>
+ <script src="/lib/webintents.js"></script>
<intent
action="http://webintents.org/pick"
type="image/*"
View
6 examples/intents/share/action.html
@@ -2,7 +2,9 @@
<html>
<head>
<title>Intent: Share</title>
- <script src="/lib/webintents.debug.js"></script>
+ <link rel="stylesheet" href="/css/reset.css" />
+ <link rel="stylesheet" href="/css/embedbase.css" />
+ <script src="/lib/webintents.js"></script>
<script src="/lib/events.js"></script>
<script>
attachEventListener(window, "load", function() {
@@ -59,7 +61,7 @@
</head>
<body>
- <h1>Client App</h1>
+ <h2>Client App</h2>
<p>This is an external app that needs to share links. It has no prior knowledge of any other sharing application.</p>
<section>
View
34 examples/intents/share/index.html
@@ -2,12 +2,26 @@
<html>
<head>
<title>Intent: Share</title>
+ <script src="/lib/webintents.js"></script>
+ <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"
+ disposition="inline"
+ title="Kinlan's Link Share" />
<link rel="stylesheet" href="/css/reset.css" />
<link rel="stylesheet" href="/css/base.css" />
<style>
+ #register {
+ }
+
iframe {
- float:left;
- width: 50%;
+ width: 100%;
height: 800px;
}
</style>
@@ -19,6 +33,7 @@
<a href="http://webintents.org/">Web Intents</a>
<a href="http://webintents.org/share">Share Intent documentation</a>
<a href="http://examples.webintents.org/">Examples</a>
+ <a href="http://webintents.org/faq.html">FAQ</a>
</nav>
</header>
<section>
@@ -28,7 +43,20 @@
applications that request Share functionality.
</p>
<div>
- <iframe src="register.html"></iframe>
+ <div id="register">
+ <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>
+ </div>
<iframe src="action.html"></iframe>
</div>
</section>
View
35 examples/intents/share/register.html
@@ -1,35 +0,0 @@
-<!doctype html>
-<html>
- <head>
- <title>Share Intent Registration Page</title>
- <script src="/lib/webintents.debug.js"></script>
- <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>
View
8 examples/intents/share/shareimage.html
@@ -1,7 +1,13 @@
<!doctype html>
<html>
<title>Share Link</title>
- <script src="/lib/webintents.debug.js"></script>
+ <script src="/lib/webintents.js"></script>
+ <intent
+ action="http://webintents.org/share"
+ type="text/uri-list"
+ href="sharelink.html"
+ title="Kinlan's Link Share" />
+
<script src="/lib/events.js"></script>
<script>
attachEventListener(window, "load", function(e) {
View
10 examples/intents/share/sharelink.html
@@ -1,7 +1,13 @@
<!doctype html>
<html>
<title>Share Link</title>
- <script src="/lib/webintents.debug.js"></script>
+ <script src="/lib/webintents.js"></script>
+ <intent
+ action="http://webintents.org/share"
+ type="text/uri-list"
+ href="sharelink.html"
+ disposition="inline"
+ title="Kinlan's Link Share" />
<script src="/lib/events.js"></script>
<script src="/lib/common.js"></script>
<script>
@@ -12,7 +18,7 @@
else
setText(output, intent.data);
- intent.data.postResult(intent.data);
+ intent.postResult(intent.data);
}, false);
</script>
<link rel="stylesheet" href="/css/reset.css" />
View
8 examples/intents/shorten/index.html
@@ -2,14 +2,13 @@
<html>
<head>
<title>Intent: Shorten</title>
- <script src="/lib/webintents.debug.js"></script>
+ <script src="/lib/webintents.js"></script>
<script src="/lib/events.js"></script>
<link rel="stylesheet" href="/css/reset.css" />
<link rel="stylesheet" href="/css/base.css" />
<style>
iframe {
- float:left;
- width: 50%;
+ width: 100%;
height: 800px;
}
</style>
@@ -45,11 +44,12 @@
</head>
<body>
<header>
- <h1>Example: Shorten</h1>
+ <h1>Shorten intent example</h1>
<nav>
<a href="http://webintents.org/">Web Intents</a>
<a href="http://webintents.org/shorten">Shorten Intent documentation</a>
<a href="http://examples.webintents.org/">Examples</a>
+ <a href="http://webintents.org/faq.html">FAQ</a>
</nav>
</header>
<section>
View
7 examples/intents/shorten/shorten.html
@@ -1,7 +1,12 @@
<!doctype html>
<html>
<title>Kinlan's Link Shortener</title>
- <script src="/lib/webintents.debug.js"></script>
+ <script src="/lib/webintents.js"></script>
+ <intent
+ action="http://webintents.org/shorten"
+ type="text/uri-list"
+ href="shorten.html"
+ title="Kinlan's Link Shortener" />
<script src="/lib/events.js"></script>
<script src="/lib/common.js"></script>
<link rel="stylesheet" href="/css/reset.css" />
View
828 examples/lib/webintents.debug.js
@@ -1,828 +0,0 @@
-/*
- Copyright 2011 Google Inc.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-(function() {
- if(!!window.Intent) return;
-
- var addEventListener = function(obj, type, func, capture) {
- if(!!window.addEventListener) {
- obj.addEventListener(type, func, capture);
- }
- else {
- obj.attachEvent("on" + type, func);
- }
- };
-
- /* Copyright 2011 Google Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ if(document.location.hostname == "127.0.0.1") { var __WEBINTENTS_ROOT = "https://127.0.0.1:8080/"; } else { var __WEBINTENTS_ROOT = "http://webintents.org/"; }
-
- var server = __WEBINTENTS_ROOT;
- var serverSource = server + "intents.html";
- var pickerSource = server + "picker.html";
- var iframe;
- var channels = {};
- var intents = {};
-
- var encodeNameTransport = function(data) {
- return window.btoa(unescape(encodeURIComponent(JSON.stringify(data)))).replace(/=/g, "_");
- };
-
- var decodeNameTransport = function(str) {
- return JSON.parse(window.atob(str.replace(/_/g, "=")));
- };
-
- var Intents = function() {
- };
-
- /*
- * Starts an activity.
- */
- Intents.prototype.startActivity = function (intent, onResult) {
- var id = "intent" + new Date().valueOf();
- var params = "directories=no,menubar=no,status=0,location=0,fullscreen=no,width=300,height=300";
-
- intent._id = id;
- intents[id] = { intent: intent };
-
- var w = window.open(pickerSource, encodeNameTransport(intent), params);
-
- if(onResult) {
- iframe.contentWindow.postMessage(
- _str({"request": "registerCallback", "id": id }),
- serverSource );
- intents[id].callback = onResult;
- }
- };
-
- var _str = function(obj) {
- return JSON.stringify(obj);
- };
-
- var handler = function(e) {
- try {
- var data = JSON.parse(e.data);
- if(!!intents[data.intent._id] == true &&
- data.request &&
- data.request == "response") {
-
- intents[data.intent._id].callback(data.intent);
- }
- } catch (err) {
- // TODO(tpayne): filter on the origin. For now, just swallow JSON parse
- // errors that get thrown.
- }
- };
-
- addEventListener(window, "message", handler, false);
-
- var loadIntentData = function(data) {
- var intent = new Intent();
- intent._id = data._id;
- intent.action = data.action;
- intent.type = data.type;
- intent.data = data.data;
- // This will recieve the intent data.
- window.intent = intent;
- };
-
- var register = function(action, type, url, title, icon) {
- if(!!url == false) url = document.location.toString();
- if(url.substring(0, 7) != "http://" &&
- url.substring(0, 8) != "https://") {
- if(url.substring(0,1) == "/") {
- // absolute path
- url = document.location.origin + url;
- }
- else {
- // relative path
- path = document.location.href;
- path = path.substring(0, path.lastIndexOf('/') + 1);
- url = path + url;
- }
- }
-
- iframe.contentWindow.postMessage(
- _str({
- request: "register",
- intent: { action: action, type: type, url: url, title: title, icon: icon, domain: window.location.host }
- }),
- serverSource);
- };
-
- var Intent = function(action, type, data) {
- var me = this;
- var closed = false;
- this.action = action;
- this.type = type;
- this.data = data;
-
- this.postResult = function (data) {
- if(closed) return;
-
- var returnIntent = new Intent();
- returnIntent._id = me._id;
- returnIntent.action = me.action;
- returnIntent.data = data;
-
- iframe.contentWindow.postMessage(
- _str({
- request: "intentResponse",
- intent: returnIntent
- }),
- serverSource);
-
- closed = true;
- };
- };
-
- Intent.SHARE = "http://webintents.org/share";
- Intent.SEND = "http://webintents.org/send";
- Intent.EDIT = "http://webintents.org/edit";
- Intent.VIEW = "http://webintents.org/view";
- Intent.PICK = "http://webintents.org/pick";
-
- var getFavIcon = function() {
- var links = document.getElementsByTagName("link");
- var link;
- for(var i = 0; link = links[i]; i++) {
- if((link.rel == "icon" || link.rel == "shortcut") && !!link.href ) {
- var url = link.href;
- if(url.substring(0, 7) != "http://" &&
- url.substring(0, 8) != "https://") {
- if(url.substring(0,1) == "/") {
- // absolute path
- return document.location.origin + url;
- }
- else {
- // relative path
- path = document.location.href;
- path = path.substring(0, path.lastIndexOf('/') + 1);
- url = path + url;
- }
- }
- else {
- return url;
- }
- }
- }
-
- return window.location.origin + "/favicon.ico";
- };
-
- var parseIntentTag = function(intent) {
- var title = intent.getAttribute("title") || document.title;
- var href = intent.getAttribute("href") || document.location.href;
- var action = intent.getAttribute("action");
- var type = intent.getAttribute("type");
- var icon = intent.getAttribute("icon") || getFavIcon();
-
- if(!!action == false) return;
-
- register(action, type, href, title, icon);
- };
-
- var parseIntentsDocument = function() {
- var intents = document.getElementsByTagName("intent");
- var intent;
- for(var i = 0; intent = intents[i]; i++) {
- parseIntentTag(intent);
- }
- };
-
- var handleFormSubmit = function(e) {
- var form = e.target;
-
- if(form.method.toLowerCase() == "intent") {
- if(!!e.preventDefault)
- e.preventDefault();
- else
- e.returnValue = false;
- var action = form.action;
- var enctype = form.getAttribute("enctype");
- var data = {};
- var element;
-
- for(var i = 0; element = form.elements[i]; i++) {
- if(!!element.name) {
- var name = element.name;
- if(!!data[name]) {
- // If the element make it an array
- if(data[name] instanceof Array)
- data[name].push(element.value);
- else {
- var elements = [data[name]];
- elements.push(element.value);
- data[name] = elements;
- }
- }
- else {
- data[name] = element.value;
- }
- }
- }
-
- var intent = new Intent(action, enctype, data);
-
- window.navigator.startActivity(intent);
-
- return false;
- }
- };
-
- var onIntentDOMAdded = function(e) {
- if(e.target.tagName == "INTENT") {
- parseIntentTag(e.target)
- }
- };
-
- var init = function () {
- var intents = new Intents();
-
- window.Intent = Intent;
- window.navigator.startActivity = intents.startActivity;
-
- if(window.name != "") {
- loadIntentData(JSON.parse(window.atob(window.name.replace(/_/g, "="))));
- window.name = "";
- }
-
- if(!!window.postMessage) {
- // We can handle postMessage.
- iframe = document.createElement("iframe");
- iframe.style.display = "none";
-
-
- addEventListener(iframe, "load", function() {
- if(iframe.src != serverSource) {
- iframe.src = serverSource;
- }
- parseIntentsDocument();
- }, false);
-
- // Listen to new "intent" nodes.
- var heads = document.getElementsByTagName("HEAD");
- if(heads.length > 0) {
- var head = heads[0];
- addEventListener(head, "DOMNodeInserted", onIntentDOMAdded, false);
- head.appendChild(iframe);
- iframe.src = serverSource;
- }
- }
-
- addEventListener(window, "submit", handleFormSubmit, false);
- };
-
- init();
-})();
-/*
- http://www.JSON.org/json2.js
- 2011-02-23
-
- Public Domain.
-
- NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
-
- See http://www.JSON.org/js.html
-
-
- This code should be minified before deployment.
- See http://javascript.crockford.com/jsmin.html
-
- USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
- NOT CONTROL.
-
-
- This file creates a global JSON object containing two methods: stringify
- and parse.
-
- JSON.stringify(value, replacer, space)
- value any JavaScript value, usually an object or array.
-
- replacer an optional parameter that determines how object
- values are stringified for objects. It can be a
- function or an array of strings.
-
- space an optional parameter that specifies the indentation
- of nested structures. If it is omitted, the text will
- be packed without extra whitespace. If it is a number,
- it will specify the number of spaces to indent at each
- level. If it is a string (such as '\t' or '&nbsp;'),
- it contains the characters used to indent at each level.
-
- This method produces a JSON text from a JavaScript value.
-
- When an object value is found, if the object contains a toJSON
- method, its toJSON method will be called and the result will be
- stringified. A toJSON method does not serialize: it returns the
- value represented by the name/value pair that should be serialized,
- or undefined if nothing should be serialized. The toJSON method
- will be passed the key associated with the value, and this will be
- bound to the value
-
- For example, this would serialize Dates as ISO strings.
-
- Date.prototype.toJSON = function (key) {
- function f(n) {
- // Format integers to have at least two digits.
- return n < 10 ? '0' + n : n;
- }
-
- return this.getUTCFullYear() + '-' +
- f(this.getUTCMonth() + 1) + '-' +
- f(this.getUTCDate()) + 'T' +
- f(this.getUTCHours()) + ':' +
- f(this.getUTCMinutes()) + ':' +
- f(this.getUTCSeconds()) + 'Z';
- };
-
- You can provide an optional replacer method. It will be passed the
- key and value of each member, with this bound to the containing
- object. The value that is returned from your method will be
- serialized. If your method returns undefined, then the member will
- be excluded from the serialization.
-
- If the replacer parameter is an array of strings, then it will be
- used to select the members to be serialized. It filters the results
- such that only members with keys listed in the replacer array are
- stringified.
-
- Values that do not have JSON representations, such as undefined or
- functions, will not be serialized. Such values in objects will be
- dropped; in arrays they will be replaced with null. You can use
- a replacer function to replace those with JSON values.
- JSON.stringify(undefined) returns undefined.
-
- The optional space parameter produces a stringification of the
- value that is filled with line breaks and indentation to make it
- easier to read.
-
- If the space parameter is a non-empty string, then that string will
- be used for indentation. If the space parameter is a number, then
- the indentation will be that many spaces.
-
- Example:
-
- text = JSON.stringify(['e', {pluribus: 'unum'}]);
- // text is '["e",{"pluribus":"unum"}]'
-
-
- text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
- // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
-
- text = JSON.stringify([new Date()], function (key, value) {
- return this[key] instanceof Date ?
- 'Date(' + this[key] + ')' : value;
- });
- // text is '["Date(---current time---)"]'
-
-
- JSON.parse(text, reviver)
- This method parses a JSON text to produce an object or array.
- It can throw a SyntaxError exception.
-
- The optional reviver parameter is a function that can filter and
- transform the results. It receives each of the keys and values,
- and its return value is used instead of the original value.
- If it returns what it received, then the structure is not modified.
- If it returns undefined then the member is deleted.
-
- Example:
-
- // Parse the text. Values that look like ISO date strings will
- // be converted to Date objects.
-
- myData = JSON.parse(text, function (key, value) {
- var a;
- if (typeof value === 'string') {
- a =
-/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
- if (a) {
- return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
- +a[5], +a[6]));
- }
- }
- return value;
- });
-
- myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
- var d;
- if (typeof value === 'string' &&
- value.slice(0, 5) === 'Date(' &&
- value.slice(-1) === ')') {
- d = new Date(value.slice(5, -1));
- if (d) {
- return d;
- }
- }
- return value;
- });
-
-
- This is a reference implementation. You are free to copy, modify, or
- redistribute.
-*/
-
-/*jslint evil: true, strict: false, regexp: false */
-
-/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
- call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
- getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
- lastIndex, length, parse, prototype, push, replace, slice, stringify,
- test, toJSON, toString, valueOf
-*/
-
-
-// Create a JSON object only if one does not already exist. We create the
-// methods in a closure to avoid creating global variables.
-
-var JSON;
-if (!JSON) {
- JSON = {};
-}
-
-(function () {
- "use strict";
-
- function f(n) {
- // Format integers to have at least two digits.
- return n < 10 ? '0' + n : n;
- }
-
- if (typeof Date.prototype.toJSON !== 'function') {
-
- Date.prototype.toJSON = function (key) {
-
- return isFinite(this.valueOf()) ?
- this.getUTCFullYear() + '-' +
- f(this.getUTCMonth() + 1) + '-' +
- f(this.getUTCDate()) + 'T' +
- f(this.getUTCHours()) + ':' +
- f(this.getUTCMinutes()) + ':' +
- f(this.getUTCSeconds()) + 'Z' : null;
- };
-
- String.prototype.toJSON =
- Number.prototype.toJSON =
- Boolean.prototype.toJSON = function (key) {
- return this.valueOf();
- };
- }
-
- var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
- escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
- gap,
- indent,
- meta = { // table of character substitutions
- '\b': '\\b',
- '\t': '\\t',
- '\n': '\\n',
- '\f': '\\f',
- '\r': '\\r',
- '"' : '\\"',
- '\\': '\\\\'
- },
- rep;
-
-
- function quote(string) {
-
-// If the string contains no control characters, no quote characters, and no
-// backslash characters, then we can safely slap some quotes around it.
-// Otherwise we must also replace the offending characters with safe escape
-// sequences.
-
- escapable.lastIndex = 0;
- return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
- var c = meta[a];
- return typeof c === 'string' ? c :
- '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
- }) + '"' : '"' + string + '"';
- }
-
-
- function str(key, holder) {
-
-// Produce a string from holder[key].
-
- var i, // The loop counter.
- k, // The member key.
- v, // The member value.
- length,
- mind = gap,
- partial,
- value = holder[key];
-
-// If the value has a toJSON method, call it to obtain a replacement value.
-
- if (value && typeof value === 'object' &&
- typeof value.toJSON === 'function') {
- value = value.toJSON(key);
- }
-
-// If we were called with a replacer function, then call the replacer to
-// obtain a replacement value.
-
- if (typeof rep === 'function') {
- value = rep.call(holder, key, value);
- }
-
-// What happens next depends on the value's type.
-
- switch (typeof value) {
- case 'string':
- return quote(value);
-
- case 'number':
-
-// JSON numbers must be finite. Encode non-finite numbers as null.
-
- return isFinite(value) ? String(value) : 'null';
-
- case 'boolean':
- case 'null':
-
-// If the value is a boolean or null, convert it to a string. Note:
-// typeof null does not produce 'null'. The case is included here in
-// the remote chance that this gets fixed someday.
-
- return String(value);
-
-// If the type is 'object', we might be dealing with an object or an array or
-// null.
-
- case 'object':
-
-// Due to a specification blunder in ECMAScript, typeof null is 'object',
-// so watch out for that case.
-
- if (!value) {
- return 'null';
- }
-
-// Make an array to hold the partial results of stringifying this object value.
-
- gap += indent;
- partial = [];
-
-// Is the value an array?
-
- if (Object.prototype.toString.apply(value) === '[object Array]') {
-
-// The value is an array. Stringify every element. Use null as a placeholder
-// for non-JSON values.
-
- length = value.length;
- for (i = 0; i < length; i += 1) {
- partial[i] = str(i, value) || 'null';
- }
-
-// Join all of the elements together, separated with commas, and wrap them in
-// brackets.
-
- v = partial.length === 0 ? '[]' : gap ?
- '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' :
- '[' + partial.join(',') + ']';
- gap = mind;
- return v;
- }
-
-// If the replacer is an array, use it to select the members to be stringified.
-
- if (rep && typeof rep === 'object') {
- length = rep.length;
- for (i = 0; i < length; i += 1) {
- if (typeof rep[i] === 'string') {
- k = rep[i];
- v = str(k, value);
- if (v) {
- partial.push(quote(k) + (gap ? ': ' : ':') + v);
- }
- }
- }
- } else {
-
-// Otherwise, iterate through all of the keys in the object.
-
- for (k in value) {
- if (Object.prototype.hasOwnProperty.call(value, k)) {
- v = str(k, value);
- if (v) {
- partial.push(quote(k) + (gap ? ': ' : ':') + v);
- }
- }
- }
- }
-
-// Join all of the member texts together, separated with commas,
-// and wrap them in braces.
-
- v = partial.length === 0 ? '{}' : gap ?
- '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' :
- '{' + partial.join(',') + '}';
- gap = mind;
- return v;
- }
- }
-
-// If the JSON object does not yet have a stringify method, give it one.
-
- if (typeof JSON.stringify !== 'function') {
- JSON.stringify = function (value, replacer, space) {
-
-// The stringify method takes a value and an optional replacer, and an optional
-// space parameter, and returns a JSON text. The replacer can be a function
-// that can replace values, or an array of strings that will select the keys.
-// A default replacer method can be provided. Use of the space parameter can
-// produce text that is more easily readable.
-
- var i;
- gap = '';
- indent = '';
-
-// If the space parameter is a number, make an indent string containing that
-// many spaces.
-
- if (typeof space === 'number') {
- for (i = 0; i < space; i += 1) {
- indent += ' ';
- }
-
-// If the space parameter is a string, it will be used as the indent string.
-
- } else if (typeof space === 'string') {
- indent = space;
- }
-
-// If there is a replacer, it must be a function or an array.
-// Otherwise, throw an error.
-
- rep = replacer;
- if (replacer && typeof replacer !== 'function' &&
- (typeof replacer !== 'object' ||
- typeof replacer.length !== 'number')) {
- throw new Error('JSON.stringify');
- }
-
-// Make a fake root object containing our value under the key of ''.
-// Return the result of stringifying the value.
-
- return str('', {'': value});
- };
- }
-
-
-// If the JSON object does not yet have a parse method, give it one.
-
- if (typeof JSON.parse !== 'function') {
- JSON.parse = function (text, reviver) {
-
-// The parse method takes a text and an optional reviver function, and returns
-// a JavaScript value if the text is a valid JSON text.
-
- var j;
-
- function walk(holder, key) {
-
-// The walk method is used to recursively walk the resulting structure so
-// that modifications can be made.
-
- var k, v, value = holder[key];
- if (value && typeof value === 'object') {
- for (k in value) {
- if (Object.prototype.hasOwnProperty.call(value, k)) {
- v = walk(value, k);
- if (v !== undefined) {
- value[k] = v;
- } else {
- delete value[k];
- }
- }
- }
- }
- return reviver.call(holder, key, value);
- }
-
-
-// Parsing happens in four stages. In the first stage, we replace certain
-// Unicode characters with escape sequences. JavaScript handles many characters
-// incorrectly, either silently deleting them, or treating them as line endings.
-
- text = String(text);
- cx.lastIndex = 0;
- if (cx.test(text)) {
- text = text.replace(cx, function (a) {
- return '\\u' +
- ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
- });
- }
-
-// In the second stage, we run the text against regular expressions that look
-// for non-JSON patterns. We are especially concerned with '()' and 'new'
-// because they can cause invocation, and '=' because it can cause mutation.
-// But just to be safe, we want to reject all unexpected forms.
-
-// We split the second stage into 4 regexp operations in order to work around
-// crippling inefficiencies in IE's and Safari's regexp engines. First we
-// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
-// replace all simple value tokens with ']' characters. Third, we delete all
-// open brackets that follow a colon or comma or that begin the text. Finally,
-// we look to see that the remaining characters are only whitespace or ']' or
-// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
-
- if (/^[\],:{}\s]*$/
- .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
- .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
- .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
-
-// In the third stage we use the eval function to compile the text into a
-// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
-// in JavaScript: it can begin a block or an object literal. We wrap the text
-// in parens to eliminate the ambiguity.
-
- j = eval('(' + text + ')');
-
-// In the optional fourth stage, we recursively walk the new structure, passing
-// each name/value pair to a reviver function for possible transformation.
-
- return typeof reviver === 'function' ?
- walk({'': j}, '') : j;
- }
-
-// If the text is not JSON parseable, then a SyntaxError is thrown.
-
- throw new SyntaxError('JSON.parse');
- };
- }
-}());
-/*
- * base64.js - Base64 encoding and decoding functions
- *
- * See: http://developer.mozilla.org/en/docs/DOM:window.btoa
- * http://developer.mozilla.org/en/docs/DOM:window.atob
- *
- * Copyright (c) 2007, David Lindquist <david.lindquist@gmail.com>
- * Released under the MIT license
- */
-
-if (typeof btoa == 'undefined') {
- function btoa(str) {
- var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
- var encoded = [];
- var c = 0;
- while (c < str.length) {
- var b0 = str.charCodeAt(c++);
- var b1 = str.charCodeAt(c++);
- var b2 = str.charCodeAt(c++);
- var buf = (b0 << 16) + ((b1 || 0) << 8) + (b2 || 0);
- var i0 = (buf & (63 << 18)) >> 18;
- var i1 = (buf & (63 << 12)) >> 12;
- var i2 = isNaN(b1) ? 64 : (buf & (63 << 6)) >> 6;
- var i3 = isNaN(b2) ? 64 : (buf & 63);
- encoded[encoded.length] = chars.charAt(i0);
- encoded[encoded.length] = chars.charAt(i1);
- encoded[encoded.length] = chars.charAt(i2);
- encoded[encoded.length] = chars.charAt(i3);
- }
- return encoded.join('');
- }
-}
-
-if (typeof atob == 'undefined') {
- function atob(str) {
- var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
- var invalid = {
- strlen: (str.length % 4 != 0),
- chars: new RegExp('[^' + chars + ']').test(str),
- equals: (/=/.test(str) && (/=[^=]/.test(str) || /={3}/.test(str)))
- };
- if (invalid.strlen || invalid.chars || invalid.equals)
- throw new Error('Invalid base64 data');
- var decoded = [];
- var c = 0;
- while (c < str.length) {
- var i0 = chars.indexOf(str.charAt(c++));
- var i1 = chars.indexOf(str.charAt(c++));
- var i2 = chars.indexOf(str.charAt(c++));
- var i3 = chars.indexOf(str.charAt(c++));
- var buf = (i0 << 18) + (i1 << 12) + ((i2 & 63) << 6) + (i3 & 63);
- var b0 = (buf & (255 << 16)) >> 16;
- var b1 = (i2 == 64) ? -1 : (buf & (255 << 8)) >> 8;
- var b2 = (i3 == 64) ? -1 : (buf & 255);
- decoded[decoded.length] = String.fromCharCode(b0);
- if (b1 >= 0) decoded[decoded.length] = String.fromCharCode(b1);
- if (b2 >= 0) decoded[decoded.length] = String.fromCharCode(b2);
- }
- return decoded.join('');
- }
-}
View
828 examples/lib/webintents.js
<
@@ -1,828 +0,0 @@
-/*
- Copyright 2011 Google Inc.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-(function() {
- if(!!window.Intent) return;
-
- var addEventListener = function(obj, type, func, capture) {
- if(!!window.addEventListener) {
- obj.addEventListener(type, func, capture);
- }
- else {
- obj.attachEvent("on" + type, func);
- }
- };
-
- /* Copyright 2011 Google Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ var __WEBINTENTS_ROOT = "http://webintents.org/";
-
- var server = __WEBINTENTS_ROOT;
- var serverSource = server + "intents.html";
- var pickerSource = server + "picker.html";
- var iframe;
- var channels = {};
- var intents = {};
-
- var encodeNameTransport = function(data) {
- return window.btoa(unescape(encodeURIComponent(JSON.stringify(data)))).replace(/=/g, "_");
- };
-
- var decodeNameTransport = function(str) {
- return JSON.parse(window.atob(str.replace(/_/g, "=")));
- };
-
- var Intents = function() {
- };
-
- /*
- * Starts an activity.
- */
- Intents.prototype.startActivity = function (intent, onResult) {
- var id = "intent" + new Date().valueOf();
- var params = "directories=no,menubar=no,status=0,location=0,fullscreen=no,width=300,height=300";
-
- intent._id = id;
- intents[id] = { intent: intent };
-
- var w = window.open(pickerSource, encodeNameTransport(intent), params);
-
- if(onResult) {
- iframe.contentWindow.postMessage(
- _str({"request": "registerCallback", "id": id }),
- serverSource );
- intents[id].callback = onResult;
- }
- };
-
- var _str = function(obj) {
- return JSON.stringify(obj);
- };
-
- var handler = function(e) {
- try {
- var data = JSON.parse(e.data);
- if(!!intents[data.intent._id] == true &&
- data.request &&
- data.request == "response") {
-
- intents[data.intent._id].callback(data.intent);
- }
- } catch (err) {
- // TODO(tpayne): filter on the origin. For now, just swallow JSON parse
- // errors that get thrown.
- }
- };
-
- addEventListener(window, "message", handler, false);
-
- var loadIntentData = function(data) {
- var intent = new Intent();
- intent._id = data._id;
- intent.action = data.action;
- intent.type = data.type;
- intent.data = data.data;
- // This will recieve the intent data.
- window.intent = intent;
- };
-
- var register = function(action, type, url, title, icon) {
- if(!!url == false) url = document.location.toString();
- if(url.substring(0, 7) != "http://" &&
- url.substring(0, 8) != "https://") {
- if(url.substring(0,1) == "/") {
- // absolute path
- url = document.location.origin + url;
- }
- else {
- // relative path
- path = document.location.href;
- path = path.substring(0, path.lastIndexOf('/') + 1);
- url = path + url;
- }
- }
-
- iframe.contentWindow.postMessage(
- _str({
- request: "register",
- intent: { action: action, type: type, url: url, title: title, icon: icon, domain: window.location.host }
- }),
- serverSource);
- };
-
- var Intent = function(action, type, data) {
- var me = this;
- var closed = false;
- this.action = action;
- this.type = type;
- this.data = data;
-
- this.postResult = function (data) {
- if(closed) return;
-
- var returnIntent = new Intent();
- returnIntent._id = me._id;
- returnIntent.action = me.action;
- returnIntent.data = data;
-
- iframe.contentWindow.postMessage(
- _str({
- request: "intentResponse",
- intent: returnIntent
- }),
- serverSource);
-
- closed = true;
- };
- };
-
- Intent.SHARE = "http://webintents.org/share";
- Intent.SEND = "http://webintents.org/send";
- Intent.EDIT = "http://webintents.org/edit";
- Intent.VIEW = "http://webintents.org/view";
- Intent.PICK = "http://webintents.org/pick";
-
- var getFavIcon = function() {
- var links = document.getElementsByTagName("link");
- var link;
- for(var i = 0; link = links[i]; i++) {
- if((link.rel == "icon" || link.rel == "shortcut") && !!link.href ) {
- var url = link.href;
- if(url.substring(0, 7) != "http://" &&
- url.substring(0, 8) != "https://") {
- if(url.substring(0,1) == "/") {
- // absolute path
- return document.location.origin + url;
- }
- else {
- // relative path
- path = document.location.href;
- path = path.substring(0, path.lastIndexOf('/') + 1);
- url = path + url;
- }
- }
- else {
- return url;
- }
- }
- }
-
- return window.location.origin + "/favicon.ico";
- };
-
- var parseIntentTag = function(intent) {
- var title = intent.getAttribute("title") || document.title;
- var href = intent.getAttribute("href") || document.location.href;
- var action = intent.getAttribute("action");
- var type = intent.getAttribute("type");
- var icon = intent.getAttribute("icon") || getFavIcon();
-
- if(!!action == false) return;
-
- register(action, type, href, title, icon);
- };
-
- var parseIntentsDocument = function() {
- var intents = document.getElementsByTagName("intent");
- var intent;
- for(var i = 0; intent = intents[i]; i++) {
- parseIntentTag(intent);
- }
- };
-
- var handleFormSubmit = function(e) {
- var form = e.target;
-
- if(form.method.toLowerCase() == "intent") {
- if(!!e.preventDefault)
- e.preventDefault();
- else
- e.returnValue = false;
- var action = form.action;
- var enctype = form.getAttribute("enctype");
- var data = {};
- var element;
-
- for(var i = 0; element = form.elements[i]; i++) {
- if(!!element.name) {
- var name = element.name;
- if(!!data[name]) {
- // If the element make it an array
- if(data[name] instanceof Array)
- data[name].push(element.value);
- else {
- var elements = [data[name]];
- elements.push(element.value);
- data[name] = elements;
- }
- }
- else {
- data[name] = element.value;
- }
- }
- }
-
- var intent = new Intent(action, enctype, data);
-
- window.navigator.startActivity(intent);
-
- return false;
- }
- };
-
- var onIntentDOMAdded = function(e) {
- if(e.target.tagName == "INTENT") {
- parseIntentTag(e.target)
- }
- };
-
- var init = function () {
- var intents = new Intents();
-
- window.Intent = Intent;
- window.navigator.startActivity = intents.startActivity;
-
- if(window.name != "") {
- loadIntentData(JSON.parse(window.atob(window.name.replace(/_/g, "="))));
- window.name = "";
- }
-
- if(!!window.postMessage) {
- // We can handle postMessage.
- iframe = document.createElement("iframe");
- iframe.style.display = "none";
-
-
- addEventListener(iframe, "load", function() {
- if(iframe.src != serverSource) {
- iframe.src = serverSource;
- }
- parseIntentsDocument();
- }, false);
-
- // Listen to new "intent" nodes.
- var heads = document.getElementsByTagName("HEAD");
- if(heads.length > 0) {
- var head = heads[0];
- addEventListener(head, "DOMNodeInserted", onIntentDOMAdded, false);
- head.appendChild(iframe);
- iframe.src = serverSource;
- }
- }
-
- addEventListener(window, "submit", handleFormSubmit, false);
- };
-
- init();
-})();
-/*
- http://www.JSON.org/json2.js
- 2011-02-23
-
- Public Domain.
-
- NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
-
- See http://www.JSON.org/js.html
-
-
- This code should be minified before deployment.
- See http://javascript.crockford.com/jsmin.html
-
- USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
- NOT CONTROL.
-
-
- This file creates a global JSON object containing two methods: stringify
- and parse.
-
- JSON.stringify(value, replacer, space)
- value any JavaScript value, usually an object or array.
-
- replacer an optional parameter that determines how object
- values are stringified for objects. It can be a
- function or an array of strings.
-
- space an optional parameter that specifies the indentation
- of nested structures. If it is omitted, the text will
- be packed without extra whitespace. If it is a number,
- it will specify the number of spaces to indent at each
- level. If it is a string (such as '\t' or '&nbsp;'),
- it contains the characters used to indent at each level.
-
- This method produces a JSON text from a JavaScript value.
-
- When an object value is found, if the object contains a toJSON
- method, its toJSON method will be called and the result will be
- stringified. A toJSON method does not serialize: it returns the
- value represented by the name/value pair that should be serialized,
- or undefined if nothing should be serialized. The toJSON method
- will be passed the key associated with the value, and this will be
- bound to the value
-
- For example, this would serialize Dates as ISO strings.
-
- Date.prototype.toJSON = function (key) {
- function f(n) {
- // Format integers to have at least two digits.
- return n < 10 ? '0' + n : n;
- }
-
- return this.getUTCFullYear() + '-' +
- f(this.getUTCMonth() + 1) + '-' +
- f(this.getUTCDate()) + 'T' +
- f(this.getUTCHours()) + ':' +
- f(this.getUTCMinutes()) + ':' +
- f(this.getUTCSeconds()) + 'Z';
- };
-
- You can provide an optional replacer method. It will be passed the
- key and value of each member, with this bound to the containing
- object. The value that is returned from your method will be
- serialized. If your method returns undefined, then the member will
- be excluded from the serialization.
-
- If the replacer parameter is an array of strings, then it will be
- used to select the members to be serialized. It filters the results
- such that only members with keys listed in the replacer array are
- stringified.
-
- Values that do not have JSON representations, such as undefined or
- functions, will not be serialized. Such values in objects will be
- dropped; in arrays they will be replaced with null. You can use
- a replacer function to replace those with JSON values.
- JSON.stringify(undefined) returns undefined.
-
- The optional space parameter produces a stringification of the
- value that is filled with line breaks and indentation to make it
- easier to read.
-
- If the space parameter is a non-empty string, then that string will
- be used for indentation. If the space parameter is a number, then
- the indentation will be that many spaces.
-
- Example:
-
- text = JSON.stringify(['e', {pluribus: 'unum'}]);
- // text is '["e",{"pluribus":"unum"}]'
-
-
- text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
- // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
-
- text = JSON.stringify([new Date()], function (key, value) {
- return this[key] instanceof Date ?
- 'Date(' + this[key] + ')' : value;
- });
- // text is '["Date(---current time---)"]'
-
-
- JSON.parse(text, reviver)
- This method parses a JSON text to produce an object or array.
- It can throw a SyntaxError exception.
-
- The optional reviver parameter is a function that can filter and
- transform the results. It receives each of the keys and values,
- and its return value is used instead of the original value.
- If it returns what it received, then the structure is not modified.
- If it returns undefined then the member is deleted.
-
- Example:
-
- // Parse the text. Values that look like ISO date strings will
- // be converted to Date objects.
-
- myData = JSON.parse(text, function (key, value) {
- var a;
- if (typeof value === 'string') {
- a =
-/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
- if (a) {
- return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
- +a[5], +a[6]));
- }
- }
- return value;
- });
-
- myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
- var d;
- if (typeof value === 'string' &&
- value.slice(0, 5) === 'Date(' &&
- value.slice(-1) === ')') {
- d = new Date(value.slice(5, -1));
- if (d) {
- return d;
- }
- }
- return value;
- });
-
-
- This is a reference implementation. You are free to copy, modify, or
- redistribute.
-*/
-
-/*jslint evil: true, strict: false, regexp: false */
-
-/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
- call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
- getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
- lastIndex, length, parse, prototype, push, replace, slice, stringify,
- test, toJSON, toString, valueOf
-*/
-
-
-// Create a JSON object only if one does not already exist. We create the
-// methods in a closure to avoid creating global variables.
-
-var JSON;
-if (!JSON) {
- JSON = {};
-}
-
-(function () {
- "use strict";
-
- function f(n) {
- // Format integers to have at least two digits.
- return n < 10 ? '0' + n : n;
- }
-
- if (typeof Date.prototype.toJSON !== 'function') {
-
- Date.prototype.toJSON = function (key) {
-
- return isFinite(this.valueOf()) ?
- this.getUTCFullYear() + '-' +
- f(this.getUTCMonth() + 1) + '-' +
- f(this.getUTCDate()) + 'T' +
- f(this.getUTCHours()) + ':' +
- f(this.getUTCMinutes()) + ':' +
- f(this.getUTCSeconds()) + 'Z' : null;
- };
-
- String.prototype.toJSON =
- Number.prototype.toJSON =
- Boolean.prototype.toJSON = function (key) {
- return this.valueOf();
- };
- }
-
- var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
- escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
- gap,
- indent,
- meta = { // table of character substitutions
- '\b': '\\b',
- '\t': '\\t',
- '\n': '\\n',
- '\f': '\\f',
- '\r': '\\r',
- '"' : '\\"',
- '\\': '\\\\'
- },
- rep;
-
-
- function quote(string) {
-
-// If the string contains no control characters, no quote characters, and no
-// backslash characters, then we can safely slap some quotes around it.
-// Otherwise we must also replace the offending characters with safe escape
-// sequences.
-
- escapable.lastIndex = 0;
- return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
- var c = meta[a];
- return typeof c === 'string' ? c :
- '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
- }) + '"' : '"' + string + '"';
- }
-
-
- function str(key, holder) {
-
-// Produce a string from holder[key].
-
- var i, // The loop counter.
- k, // The member key.
- v, // The member value.
- length,
- mind = gap,
- partial,
- value = holder[key];
-
-// If the value has a toJSON method, call it to obtain a replacement value.
-
- if (value && typeof value === 'object' &&
- typeof value.toJSON === 'function') {
- value = value.toJSON(key);
- }
-
-// If we were called with a replacer function, then call the replacer to
-// obtain a replacement value.
-
- if (typeof rep === 'function') {
- value = rep.call(holder, key, value);
- }
-
-// What happens next depends on the value's type.
-
- switch (typeof value) {
- case 'string':
- return quote(value);
-
- case 'number':
-
-// JSON numbers must be finite. Encode non-finite numbers as null.
-
- return isFinite(value) ? String(value) : 'null';
-
- case 'boolean':
- case 'null':
-
-// If the value is a boolean or null, convert it to a string. Note:
-// typeof null does not produce 'null'. The case is included here in
-// the remote chance that this gets fixed someday.
-
- return String(value);
-
-// If the type is 'object', we might be dealing with an object or an array or
-// null.
-
- case 'object':
-
-// Due to a specification blunder in ECMAScript, typeof null is 'object',
-// so watch out for that case.
-
- if (!value) {
- return 'null';
- }