Skip to content

Commit

Permalink
First set of commits for getting webintents to work in an extension - #…
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulKinlan committed Sep 9, 2011
1 parent 35f1151 commit 1efe2ad
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
6 changes: 6 additions & 0 deletions server/script/webintents-server.js
Expand Up @@ -219,6 +219,12 @@ attachEventListener(window, "message", msgHandler.handler, false);
attachEventListener(window, "storage", msgHandler.handler, false);
attachEventListener(document, "storage", msgHandler.handler, false);

attachEventListener(window, "load", function() {
// Tell the app we are loaded.
var message = JSON.stringify({ request: "ready" });
window.parent.postMessage(message, "*");
}, false);

if(!!window.onstorage) {
// we don't have storage events, so lets poll.

Expand Down
7 changes: 6 additions & 1 deletion src/webintents.js
Expand Up @@ -71,12 +71,17 @@

var handler = function(e) {
var data = JSON.parse(e.data);
if(!!intents[data.intent._id] == true &&
if(
!!data.intent == true &&
!!intents[data.intent._id] == true &&
data.request &&
data.request == "response") {

intents[data.intent._id].callback(data.intent);
}
else if (data.request == "ready") {
console.log("Webintents frame ready");
}
};

addEventListener(window, "message", handler, false);
Expand Down
8 changes: 7 additions & 1 deletion tools/chrome/extensions/share/background.html
@@ -1,12 +1,18 @@
<!doctype html>
<script src="webintents.js"></script>
<intent
action="http://webintents.org/share"
type="text/*"
href="/handler/twitter.html"
title="Twitter"
/>
<script>

function clickHandler(info, tab) {
console.log(info);
if(info.mediaType == "image" ||
info.mediaType == "video" ||
info.meditType == "audio") {
info.mediaType == "audio") {
var intent = new Intent();
intent.action = "http://webintents.org/share";
intent.type = info.mediaType + "/*";
Expand Down
18 changes: 18 additions & 0 deletions tools/chrome/extensions/share/handlers/twitter.html
@@ -0,0 +1,18 @@
<!doctype html>
<html>
<head>
<script src="webintents.js"></script>
<script>
document.addEventListener("load", function() {
if(window.intent) {
if(window.intent.type.indexOf("text/") {
var href = "https://twitter.com/intent/tweet?" +
encodeURI(window.intent.data);
window.location = href;
}
}
});
</script>
</head>

</html>

0 comments on commit 1efe2ad

Please sign in to comment.