diff --git a/.gitignore b/.gitignore index fb913ad8..e54256f4 100644 --- a/.gitignore +++ b/.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* diff --git a/Makefile b/Makefile index f55a3233..2427f9bd 100644 --- a/Makefile +++ b/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 diff --git a/README.md b/README.md index 10f53312..ac7b488a 100644 --- a/README.md +++ b/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: + + + +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. - -
- - -
- 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 ======== diff --git a/assets/share.pxm b/assets/share.pxm new file mode 100644 index 00000000..deaf902d Binary files /dev/null and b/assets/share.pxm differ diff --git a/assets/share16.png b/assets/share16.png new file mode 100644 index 00000000..f24e61c4 Binary files /dev/null and b/assets/share16.png differ diff --git a/assets/share32.png b/assets/share32.png new file mode 100644 index 00000000..794f6432 Binary files /dev/null and b/assets/share32.png differ diff --git a/examples/css/embedbase.css b/examples/css/embedbase.css new file mode 100644 index 00000000..b6ca0ebf --- /dev/null +++ b/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; +} diff --git a/examples/favicon.ico b/examples/favicon.ico index aafa9e7d..e18d5125 100644 Binary files a/examples/favicon.ico and b/examples/favicon.ico differ diff --git a/examples/index.html b/examples/index.html index a4fb0b99..dce2b1d5 100644 --- a/examples/index.html +++ b/examples/index.html @@ -14,6 +14,7 @@

Examples

Specification Examples Use Cases + FAQ
@@ -28,7 +43,20 @@

Share intent example

applications that request Share functionality.

- +
+

Share Intent Registration

+
<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" />
+

Any application that launches a startActivity with an action of "http://webintents.org/share" will see these applications listed.

+
diff --git a/examples/intents/share/register.html b/examples/intents/share/register.html deleted file mode 100644 index 84c6cc1b..00000000 --- a/examples/intents/share/register.html +++ /dev/null @@ -1,35 +0,0 @@ - - - - Share Intent Registration Page - - - - - - -

Service

-

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.

-

Share Intent Registration

-
<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" />
- -

Any application that launches a startActivity with an action of "http://webintents.org/share" will see these applications listed.

- - diff --git a/examples/intents/share/shareimage.html b/examples/intents/share/shareimage.html index 26ff2974..3681b70e 100644 --- a/examples/intents/share/shareimage.html +++ b/examples/intents/share/shareimage.html @@ -1,7 +1,13 @@ Share Link - + + + + + diff --git a/examples/intents/shorten/index.html b/examples/intents/shorten/index.html index 0c61d329..cb83b412 100644 --- a/examples/intents/shorten/index.html +++ b/examples/intents/shorten/index.html @@ -2,14 +2,13 @@ Intent: Shorten - + @@ -45,11 +44,12 @@
-

Example: Shorten

+

Shorten intent example

diff --git a/examples/intents/shorten/shorten.html b/examples/intents/shorten/shorten.html index 689b01b7..e1f4d494 100644 --- a/examples/intents/shorten/shorten.html +++ b/examples/intents/shorten/shorten.html @@ -1,7 +1,12 @@ Kinlan's Link Shortener - + + diff --git a/examples/lib/webintents.debug.js b/examples/lib/webintents.debug.js deleted file mode 100644 index db8d8d8d..00000000 --- a/examples/lib/webintents.debug.js +++ /dev/null @@ -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 ' '), - 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 - * 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(''); - } -} diff --git a/examples/lib/webintents.js b/examples/lib/webintents.js deleted file mode 100644 index 6d3646ab..00000000 --- a/examples/lib/webintents.js +++ /dev/null @@ -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 ' '), - 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 - * 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(''); - } -} diff --git a/examples/lib/webintents.min.js b/examples/lib/webintents.min.js deleted file mode 100644 index df4bba28..00000000 --- a/examples/lib/webintents.min.js +++ /dev/null @@ -1,15 +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 a=function(a,b,c,d){window.addEventListener?a.addEventListener(b,c,d):a.attachEvent("on"+b,c)},b="http://webintents.org/",c=b,d=c+"intents.html",e=c+"picker.html",f,g={},h={},i=function(a){return window.btoa(unescape(encodeURIComponent(JSON.stringify(a)))).replace(/=/g,"_")},j=function(a){return JSON.parse(window.atob(a.replace(/_/g,"=")))},k=function(){};k.prototype.startActivity=function(a,b){var c="intent"+(new Date).valueOf(),g="directories=no,menubar=no,status=0,location=0,fullscreen=no,width=300,height=300";a._id=c,h[c]={intent:a};var j=window.open(e,i(a),g);b&&(f.contentWindow.postMessage(l({request:"registerCallback",id:c}),d),h[c].callback=b)};var l=function(a){return JSON.stringify(a)},m=function(a){try{var b=JSON.parse(a.data);!!h[b.intent._id]==!0&&b.request&&b.request=="response"&&h[b.intent._id].callback(b.intent)}catch(c){}};a(window,"message",m,!1);var n=function(a){var b=new p;b._id=a._id,b.action=a.action,b.type=a.type,b.data=a.data,window.intent=b},o=function(a,b,c,e,g){!!c==!1&&(c=document.location.toString()),c.substring(0,7)!="http://"&&c.substring(0,8)!="https://"&&(c.substring(0,1)=="/"?c=document.location.origin+c:(path=document.location.href,path=path.substring(0,path.lastIndexOf("/")+1),c=path+c)),f.contentWindow.postMessage(l({request:"register",intent:{action:a,type:b,url:c,title:e,icon:g,domain:window.location.host}}),d)},p=function(a,b,c){var e=this,g=!1;this.action=a,this.type=b,this.data=c,this.postResult=function(a){if(g)return;var b=new p;b._id=e._id,b.action=e.action,b.data=a,f.contentWindow.postMessage(l({request:"intentResponse",intent:b}),d),g=!0}};p.SHARE="http://webintents.org/share",p.SEND="http://webintents.org/send",p.EDIT="http://webintents.org/edit",p.VIEW="http://webintents.org/view",p.PICK="http://webintents.org/pick";var q=function(){var a=document.getElementsByTagName("link"),b;for(var c=0;b=a[c];c++)if((b.rel=="icon"||b.rel=="shortcut")&&!!b.href){var d=b.href;if(d.substring(0,7)=="http://"||d.substring(0,8)=="https://")return d;if(d.substring(0,1)=="/")return document.location.origin+d;path=document.location.href,path=path.substring(0,path.lastIndexOf("/")+1),d=path+d}return window.location.origin+"/favicon.ico"},r=function(a){var b=a.getAttribute("title")||document.title,c=a.getAttribute("href")||document.location.href,d=a.getAttribute("action"),e=a.getAttribute("type"),f=a.getAttribute("icon")||q();if(!!d==!1)return;o(d,e,c,b,f)},s=function(){var a=document.getElementsByTagName("intent"),b;for(var c=0;b=a[c];c++)r(b)},t=function(a){var b=a.target;if(b.method.toLowerCase()=="intent"){a.preventDefault?a.preventDefault():a.returnValue=!1;var c=b.action,d=b.getAttribute("enctype"),e={},f;for(var g=0;f=b.elements[g];g++)if(!!f.name){var h=f.name;if(!e[h])e[h]=f.value;else if(e[h]instanceof Array)e[h].push(f.value);else{var i=[e[h]];i.push(f.value),e[h]=i}}var j=new p(c,d,e);return window.navigator.startActivity(j),!1}},u=function(a){a.target.tagName=="INTENT"&&r(a.target)},v=function(){var b=new k;window.Intent=p,window.navigator.startActivity=b.startActivity,window.name!=""&&(n(JSON.parse(window.atob(window.name.replace(/_/g,"=")))),window.name="");if(!!window.postMessage){f=document.createElement("iframe"),f.style.display="none",a(f,"load",function(){f.src!=d&&(f.src=d),s()},!1);var c=document.getElementsByTagName("HEAD");if(c.length>0){var e=c[0];a(e,"DOMNodeInserted",u,!1),e.appendChild(f),f.src=d}}a(window,"submit",t,!1)};v()})();var JSON;JSON||(JSON={}),function(){function f(a){return a<10?"0"+a:a}function quote(a){return escapable.lastIndex=0,escapable.test(a)?'"'+a.replace(escapable,function(a){var b=meta[a];return typeof b=="string"?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function str(a,b){var c,d,e,f,g=gap,h,i=b[a];i&&typeof i=="object"&&typeof i.toJSON=="function"&&(i=i.toJSON(a)),typeof rep=="function"&&(i=rep.call(b,a,i));switch(typeof i){case"string":return quote(i);case"number":return isFinite(i)?String(i):"null";case"boolean":case"null":return String(i);case"object":if(!i)return"null";gap+=indent,h=[];if(Object.prototype.toString.apply(i)==="[object Array]"){f=i.length;for(c=0;c>18,j=(h&258048)>>12,k=isNaN(f)?64:(h&4032)>>6,l=isNaN(g)?64:h&63;c[c.length]=b.charAt(i),c[c.length]=b.charAt(j),c[c.length]=b.charAt(k),c[c.length]=b.charAt(l)}return c.join("")}if(typeof atob=="undefined")function atob(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",c={strlen:a.length%4!=0,chars:(new RegExp("[^"+b+"]")).test(a),equals:/=/.test(a)&&(/=[^=]/.test(a)||/={3}/.test(a))};if(c.strlen||c.chars||c.equals)throw new Error("Invalid base64 data");var d=[],e=0;while(e>16,l=h==64?-1:(j&65280)>>8,m=i==64?-1:j&255;d[d.length]=String.fromCharCode(k),l>=0&&(d[d.length]=String.fromCharCode(l)),m>=0&&(d[d.length]=String.fromCharCode(m))}return d.join("")} \ No newline at end of file diff --git a/examples/usage/declarativeRegister/index.html b/examples/usage/declarativeRegister/index.html index 1cf74322..c0806892 100644 --- a/examples/usage/declarativeRegister/index.html +++ b/examples/usage/declarativeRegister/index.html @@ -2,7 +2,7 @@ Declartive Registration - + startActivity - + - -
- - -
-

The Code

-
<form method="intent" action="http://webintents.org/share" enctype="text/uri-list">
-  <input type="url" name="uris" placeholder="Enter a URL to share" />
-  <input type="submit" />
-</form>
- - - diff --git a/examples/usage/startActivityHandleInputData/index.html b/examples/usage/startActivityHandleInputData/index.html index ec89fb6e..392c85e6 100644 --- a/examples/usage/startActivityHandleInputData/index.html +++ b/examples/usage/startActivityHandleInputData/index.html @@ -1,7 +1,7 @@ startActivity Handle Input Data - + + + + + + diff --git a/tools/chrome/extensions/share/manifest.json b/tools/chrome/extensions/share/manifest.json index 77df2c8c..14fd072f 100644 --- a/tools/chrome/extensions/share/manifest.json +++ b/tools/chrome/extensions/share/manifest.json @@ -7,13 +7,19 @@ "https://*/*" ], "icons": { - "16": "16.png" + "16": "openshareicon-16x16.png", + "48": "openshareicon-48x48.png", + "128": "openshareicon-128x128.png" }, - "version": "0.0.0.1", + "browser_action": { + "default_icon": "openshareicon-16x16.png", + "default_title": "Share this page" + }, + "version": "0.0.0.2", "background_page": "background.html", "content_scripts" : [{ "matches" : ["http://*/*", "https://*/*"], - "js" : ["startActivity.js"] + "js" : ["webintents-inject.js", "webintents.js", "startActivity.js"] }, { "matches" : ["https://plus.google.com/*"], diff --git a/tools/chrome/extensions/share/openshareicon-128x128.png b/tools/chrome/extensions/share/openshareicon-128x128.png new file mode 100644 index 00000000..929ffb84 Binary files /dev/null and b/tools/chrome/extensions/share/openshareicon-128x128.png differ diff --git a/tools/chrome/extensions/share/openshareicon-16x16.png b/tools/chrome/extensions/share/openshareicon-16x16.png new file mode 100644 index 00000000..5be2b46c Binary files /dev/null and b/tools/chrome/extensions/share/openshareicon-16x16.png differ diff --git a/tools/chrome/extensions/share/openshareicon-48x48.png b/tools/chrome/extensions/share/openshareicon-48x48.png new file mode 100644 index 00000000..dcd3ae8b Binary files /dev/null and b/tools/chrome/extensions/share/openshareicon-48x48.png differ diff --git a/tools/chrome/extensions/share/plus.js b/tools/chrome/extensions/share/plus.js index f4b313a5..e63bf8bb 100644 --- a/tools/chrome/extensions/share/plus.js +++ b/tools/chrome/extensions/share/plus.js @@ -1,27 +1,28 @@ -var shareElement = document.getElementById(":3r.f"); - -if(window.intent) { - shareElement.innerText = window.intent.data; -} - var addIntent = function() { // Always add the intent in. var intentEl = document.createElement("intent"); intentEl.setAttribute("action", "http://webintents.org/share"); intentEl.setAttribute("type", "text/uri-list"); + intentEl.setAttribute("href", document.location.href); document.head.appendChild(intentEl); }; var checkIntent = function() { - setTimeout(function() { - var script = document.createElement("script"); - var scriptText = "if (window.intent) {"; - scriptText += "alert(window.intent.data);"; - scriptText += "}"; - script.textContent = scriptText; - document.head.appendChild(script); - }, 0); -}; + var interval = setInterval(function() { + debugger; + if (!!window.intent == false) return; + clearInterval(interval); + var share = document.querySelector(".c-i-f-C"); + var ev = document.createEvent("MouseEvent"); + ev.initMouseEvent("click"); + share.dispatchEvent(ev); + setTimeout(function() { + var se = document.querySelector(".m-n-f-ba-rd"); + se.textContent = window.intent.data; + }, 1000); + + }, 1000); +} if(document.readyState == "complete") { addIntent(); diff --git a/tools/chrome/extensions/share/startActivity.js b/tools/chrome/extensions/share/startActivity.js index b718b71c..48d8d1b5 100644 --- a/tools/chrome/extensions/share/startActivity.js +++ b/tools/chrome/extensions/share/startActivity.js @@ -1,17 +1,3 @@ -var port = chrome.extension.connect(); -port.onMessage.addListener(function(intent) { - // There has been a share intent calle - var startActivityScript = document.createElement("script"); - var sa = "var intentObj = new Intent();"; - sa += "intentObj.action = '" + intent.action + "';"; - sa += "intentObj.type = '" + intent.type + "';"; - sa += "intentObj.data = '" + intent.data + "';"; - sa += "window.navigator.startActivity(intentObj);" - startActivityScript.textContent = sa; - document.head.appendChild(startActivityScript); +chrome.extension.onRequest.addListener(function(intent) { + window.navigator.startActivity(intent); }); - -var intentsScript = document.createElement("script"); -intentsScript.src = "https://127.0.0.1:8080/webintents.js"; - -document.head.appendChild(intentsScript); diff --git a/tools/chrome/extensions/share/twitter.js b/tools/chrome/extensions/share/twitter.js index 3ccf6913..d1d314b4 100644 --- a/tools/chrome/extensions/share/twitter.js +++ b/tools/chrome/extensions/share/twitter.js @@ -1,5 +1,3 @@ - - var addIntent = function() { // Always add the intent in. var intentEl = document.createElement("intent"); @@ -10,15 +8,12 @@ var addIntent = function() { }; var checkIntent = function() { - setTimeout(function() { - var script = document.createElement("script"); - var scriptText = "if (window.intent) {"; - scriptText += "var se = document.getElementsByClassName('twitter-anywhere-tweet-box-editor')[0];"; - scriptText += "se.value = window.intent.data;"; - scriptText += "se.focus(); }"; - script.textContent = scriptText; - document.head.appendChild(script); - }, 2000); + setTimeout(function() { + if (!!window.intent == false) return; + var se = document.getElementsByClassName('twitter-anywhere-tweet-box-editor')[0]; + se.value = window.intent.data; + se.focus(); + }, 1000); } if(document.readyState == "complete") { diff --git a/tools/chrome/extensions/share/webintents-inject.js b/tools/chrome/extensions/share/webintents-inject.js new file mode 100644 index 00000000..f238f393 --- /dev/null +++ b/tools/chrome/extensions/share/webintents-inject.js @@ -0,0 +1,11 @@ +(function() { + var xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function() { + if(xhr.readyState != 4 || xhr.status != 200) return; + var script = document.createElement("script"); + script.textContent = xhr.responseText; + document.head.appendChild(script); + }; + xhr.open("GET", chrome.extension.getURL('/webintents.js'), true); + xhr.send(); +})(); diff --git a/tools/chrome/extensions/share/webintents.js b/tools/chrome/extensions/share/webintents.js deleted file mode 100644 index 6d3646ab..00000000 --- a/tools/chrome/extensions/share/webintents.js +++ /dev/null @@ -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 ' '), - 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 - * 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(''); - } -} diff --git a/webintents.debug.js b/webintents.debug.js deleted file mode 100644 index db8d8d8d..00000000 --- a/webintents.debug.js +++ /dev/null @@ -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 ' '), - 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 - * 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(''); - } -} diff --git a/webintents.js b/webintents.js deleted file mode 100644 index 6d3646ab..00000000 --- a/webintents.js +++ /dev/null @@ -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 ' '), - 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 - * 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(''); - } -} diff --git a/webintents.min.js b/webintents.min.js deleted file mode 100644 index df4bba28..00000000 --- a/webintents.min.js +++ /dev/null @@ -1,15 +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 a=function(a,b,c,d){window.addEventListener?a.addEventListener(b,c,d):a.attachEvent("on"+b,c)},b="http://webintents.org/",c=b,d=c+"intents.html",e=c+"picker.html",f,g={},h={},i=function(a){return window.btoa(unescape(encodeURIComponent(JSON.stringify(a)))).replace(/=/g,"_")},j=function(a){return JSON.parse(window.atob(a.replace(/_/g,"=")))},k=function(){};k.prototype.startActivity=function(a,b){var c="intent"+(new Date).valueOf(),g="directories=no,menubar=no,status=0,location=0,fullscreen=no,width=300,height=300";a._id=c,h[c]={intent:a};var j=window.open(e,i(a),g);b&&(f.contentWindow.postMessage(l({request:"registerCallback",id:c}),d),h[c].callback=b)};var l=function(a){return JSON.stringify(a)},m=function(a){try{var b=JSON.parse(a.data);!!h[b.intent._id]==!0&&b.request&&b.request=="response"&&h[b.intent._id].callback(b.intent)}catch(c){}};a(window,"message",m,!1);var n=function(a){var b=new p;b._id=a._id,b.action=a.action,b.type=a.type,b.data=a.data,window.intent=b},o=function(a,b,c,e,g){!!c==!1&&(c=document.location.toString()),c.substring(0,7)!="http://"&&c.substring(0,8)!="https://"&&(c.substring(0,1)=="/"?c=document.location.origin+c:(path=document.location.href,path=path.substring(0,path.lastIndexOf("/")+1),c=path+c)),f.contentWindow.postMessage(l({request:"register",intent:{action:a,type:b,url:c,title:e,icon:g,domain:window.location.host}}),d)},p=function(a,b,c){var e=this,g=!1;this.action=a,this.type=b,this.data=c,this.postResult=function(a){if(g)return;var b=new p;b._id=e._id,b.action=e.action,b.data=a,f.contentWindow.postMessage(l({request:"intentResponse",intent:b}),d),g=!0}};p.SHARE="http://webintents.org/share",p.SEND="http://webintents.org/send",p.EDIT="http://webintents.org/edit",p.VIEW="http://webintents.org/view",p.PICK="http://webintents.org/pick";var q=function(){var a=document.getElementsByTagName("link"),b;for(var c=0;b=a[c];c++)if((b.rel=="icon"||b.rel=="shortcut")&&!!b.href){var d=b.href;if(d.substring(0,7)=="http://"||d.substring(0,8)=="https://")return d;if(d.substring(0,1)=="/")return document.location.origin+d;path=document.location.href,path=path.substring(0,path.lastIndexOf("/")+1),d=path+d}return window.location.origin+"/favicon.ico"},r=function(a){var b=a.getAttribute("title")||document.title,c=a.getAttribute("href")||document.location.href,d=a.getAttribute("action"),e=a.getAttribute("type"),f=a.getAttribute("icon")||q();if(!!d==!1)return;o(d,e,c,b,f)},s=function(){var a=document.getElementsByTagName("intent"),b;for(var c=0;b=a[c];c++)r(b)},t=function(a){var b=a.target;if(b.method.toLowerCase()=="intent"){a.preventDefault?a.preventDefault():a.returnValue=!1;var c=b.action,d=b.getAttribute("enctype"),e={},f;for(var g=0;f=b.elements[g];g++)if(!!f.name){var h=f.name;if(!e[h])e[h]=f.value;else if(e[h]instanceof Array)e[h].push(f.value);else{var i=[e[h]];i.push(f.value),e[h]=i}}var j=new p(c,d,e);return window.navigator.startActivity(j),!1}},u=function(a){a.target.tagName=="INTENT"&&r(a.target)},v=function(){var b=new k;window.Intent=p,window.navigator.startActivity=b.startActivity,window.name!=""&&(n(JSON.parse(window.atob(window.name.replace(/_/g,"=")))),window.name="");if(!!window.postMessage){f=document.createElement("iframe"),f.style.display="none",a(f,"load",function(){f.src!=d&&(f.src=d),s()},!1);var c=document.getElementsByTagName("HEAD");if(c.length>0){var e=c[0];a(e,"DOMNodeInserted",u,!1),e.appendChild(f),f.src=d}}a(window,"submit",t,!1)};v()})();var JSON;JSON||(JSON={}),function(){function f(a){return a<10?"0"+a:a}function quote(a){return escapable.lastIndex=0,escapable.test(a)?'"'+a.replace(escapable,function(a){var b=meta[a];return typeof b=="string"?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function str(a,b){var c,d,e,f,g=gap,h,i=b[a];i&&typeof i=="object"&&typeof i.toJSON=="function"&&(i=i.toJSON(a)),typeof rep=="function"&&(i=rep.call(b,a,i));switch(typeof i){case"string":return quote(i);case"number":return isFinite(i)?String(i):"null";case"boolean":case"null":return String(i);case"object":if(!i)return"null";gap+=indent,h=[];if(Object.prototype.toString.apply(i)==="[object Array]"){f=i.length;for(c=0;c>18,j=(h&258048)>>12,k=isNaN(f)?64:(h&4032)>>6,l=isNaN(g)?64:h&63;c[c.length]=b.charAt(i),c[c.length]=b.charAt(j),c[c.length]=b.charAt(k),c[c.length]=b.charAt(l)}return c.join("")}if(typeof atob=="undefined")function atob(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",c={strlen:a.length%4!=0,chars:(new RegExp("[^"+b+"]")).test(a),equals:/=/.test(a)&&(/=[^=]/.test(a)||/={3}/.test(a))};if(c.strlen||c.chars||c.equals)throw new Error("Invalid base64 data");var d=[],e=0;while(e>16,l=h==64?-1:(j&65280)>>8,m=i==64?-1:j&255;d[d.length]=String.fromCharCode(k),l>=0&&(d[d.length]=String.fromCharCode(l)),m>=0&&(d[d.length]=String.fromCharCode(m))}return d.join("")} \ No newline at end of file diff --git a/widgets/embed/share.html b/widgets/embed/share.html index 07699450..843035f9 100644 --- a/widgets/embed/share.html +++ b/widgets/embed/share.html @@ -11,6 +11,8 @@ // The data returned by the request. if(!!data) { localStorage[parentUrl] = "1"; + window.document.body.className = "shared"; + share.title = "Shared"; } }); }); @@ -25,8 +27,8 @@ // In this imlementation there might be a race. var script = document.createElement("script"); - script.src = "http://webintents.org/webintents.min.js"; - + script.src = "/lib/webintents.js"; + document.head.appendChild(script); } }); @@ -44,6 +46,6 @@ - + diff --git a/widgets/favicon.ico b/widgets/favicon.ico index aafa9e7d..e18d5125 100644 Binary files a/widgets/favicon.ico and b/widgets/favicon.ico differ diff --git a/widgets/images/share.png b/widgets/images/share.png deleted file mode 100755 index dfa95904..00000000 Binary files a/widgets/images/share.png and /dev/null differ diff --git a/widgets/images/share16.png b/widgets/images/share16.png new file mode 100644 index 00000000..f24e61c4 Binary files /dev/null and b/widgets/images/share16.png differ diff --git a/widgets/images/share32.png b/widgets/images/share32.png new file mode 100644 index 00000000..794f6432 Binary files /dev/null and b/widgets/images/share32.png differ diff --git a/widgets/share.js b/widgets/share.js index 1c2728cd..2bb563f4 100644 --- a/widgets/share.js +++ b/widgets/share.js @@ -1,3 +1,3 @@ (function(intentName) { - document.writeln(""); + document.writeln(""); })();