/
webintents.min.js
15 lines (12 loc) · 8.23 KB
/
webintents.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*
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){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=function(a){return window.btoa(unescape(encodeURIComponent(JSON.stringify(a)))).replace(/=/g,"_")},i=function(a){return JSON.parse(window.atob(a.replace(/_/g,"=")))},j=function(){};j.prototype.startActivity=function(a,b){var c="intent"+(new Date).valueOf(),f="directories=no,menubar=no,status=0,location=0,fullscreen=no,width=300,height=300",i=document.getElementById("webintents_channel");a._id=c,g[c]={intent:a};var j=window.open(e,h(a),f);b&&(i.contentWindow.postMessage(k({request:"registerCallback",id:c}),d),g[c].callback=b)};var k=function(a){return JSON.stringify(a)},l=function(a){var b=JSON.parse(a.data);!!g[b.intent._id]==!0&&b.request&&b.request=="response"&&g[b.intent._id].callback(b.intent)};a(window,"message",l,!1);var m=function(a){var b=new o;b._id=a._id,b.action=a.action,b.type=a.type,b.data=a.data,window.intent=b},n=function(a,b,c,e,f){var g=document.getElementById("webintents_channel");!!c==!1&&(c=document.location.toString()),c.substring(0,7)!="http://"&&c.substring(0,8)!="https://"&&(c.substring(0,1)=="/"?c=window.location.protocol+"//"+window.location.host+"/"+c:(path=document.location.href,path=path.substring(0,path.lastIndexOf("/")+1),c=path+c)),g.contentWindow.postMessage(k({request:"register",intent:{action:a,type:b,url:c,title:e,icon:f,domain:window.location.host}}),d)},o=function(a,b,c){var e=this,f=!1;this.action=a,this.type=b,this.data=c,this.postResult=function(a){if(!f){var b=document.getElementById("webintents_channel"),c=new o;c._id=e._id,c.action=e.action,c.data=a,b.contentWindow.postMessage(k({request:"intentResponse",intent:c}),d),f=!0}}};o.SHARE="http://webintents.org/share",o.SEND="http://webintents.org/send",o.EDIT="http://webintents.org/edit",o.VIEW="http://webintents.org/view",o.PICK="http://webintents.org/pick";var p=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 window.location.protocol+"//"+window.location.host+"/"+d;path=document.location.href,path=path.substring(0,path.lastIndexOf("/")+1),d=path+d}return window.location.protocol+"//"+window.location.host+"/favicon.ico"},q=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")||p();!!d!=!1&&n(d,e,c,b,f)},r=function(){var a=document.getElementsByTagName("intent"),b;for(var c=0;b=a[c];c++)q(b)},s=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 o(c,d,e);window.navigator.startActivity(j);return!1}},t=function(a){a.target.tagName=="INTENT"&&q(a.target)},u=function(){var b=new j;window.Intent=o,window.navigator.startActivity=b.startActivity;if(window.name!=""){var c=!1;c=window.history.length==1?!0:!1,c&&(m(JSON.parse(window.atob(window.name.replace(/_/g,"=")))),window.name="")}if(!!window.postMessage){var e=document.createElement("iframe");e.style.display="none",e.id="webintents_channel",a(e,"load",function(){e.src!=d?e.src=d:r()},!1);var f=document.getElementsByTagName("HEAD");if(f.length>0){var g=f[0];a(g,"DOMNodeInserted",t,!1),g.appendChild(e),e.src=d}}a(window,"submit",s,!1)};u()}})();var JSON;JSON||(JSON={}),function(){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<f;c+=1)h[c]=str(c,i)||"null";e=h.length===0?"[]":gap?"[\n"+gap+h.join(",\n"+gap)+"\n"+g+"]":"["+h.join(",")+"]",gap=g;return e}if(rep&&typeof rep=="object"){f=rep.length;for(c=0;c<f;c+=1)typeof rep[c]=="string"&&(d=rep[c],e=str(d,i),e&&h.push(quote(d)+(gap?": ":":")+e))}else for(d in i)Object.prototype.hasOwnProperty.call(i,d)&&(e=str(d,i),e&&h.push(quote(d)+(gap?": ":":")+e));e=h.length===0?"{}":gap?"{\n"+gap+h.join(",\n"+gap)+"\n"+g+"}":"{"+h.join(",")+"}",gap=g;return e}}function quote(a){escapable.lastIndex=0;return 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 f(a){return a<10?"0"+a:a}"use strict",typeof Date.prototype.toJSON!="function"&&(Date.prototype.toJSON=function(a){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(a){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={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;typeof JSON.stringify!="function"&&(JSON.stringify=function(a,b,c){var d;gap="",indent="";if(typeof c=="number")for(d=0;d<c;d+=1)indent+=" ";else typeof c=="string"&&(indent=c);rep=b;if(!b||typeof b=="function"||typeof b=="object"&&typeof b.length=="number")return str("",{"":a});throw new Error("JSON.stringify")}),typeof JSON.parse!="function"&&(JSON.parse=function(text,reviver){function walk(a,b){var c,d,e=a[b];if(e&&typeof e=="object")for(c in e)Object.prototype.hasOwnProperty.call(e,c)&&(d=walk(e,c),d!==undefined?e[c]=d:delete e[c]);return reviver.call(a,b,e)}var j;text=String(text),cx.lastIndex=0,cx.test(text)&&(text=text.replace(cx,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)}));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,""))){j=eval("("+text+")");return typeof reviver=="function"?walk({"":j},""):j}throw new SyntaxError("JSON.parse")})}();if(typeof btoa=="undefined")function btoa(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",c=[],d=0;while(d<a.length){var e=a.charCodeAt(d++),f=a.charCodeAt(d++),g=a.charCodeAt(d++),h=(e<<16)+((f||0)<<8)+(g||0),i=(h&63<<18)>>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<a.length){var f=b.indexOf(a.charAt(e++)),g=b.indexOf(a.charAt(e++)),h=b.indexOf(a.charAt(e++)),i=b.indexOf(a.charAt(e++)),j=(f<<18)+(g<<12)+((h&63)<<6)+(i&63),k=(j&255<<16)>>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("")}