diff --git a/phantomweb/static/js/exceptional.js b/phantomweb/static/js/exceptional.js new file mode 100644 index 0000000..b135265 --- /dev/null +++ b/phantomweb/static/js/exceptional.js @@ -0,0 +1,69 @@ +var Exceptional = { + KEY : null, + HOST : 'api.getexceptional.com', + action : '', + handle: function (msg,url,line) { + if (Exceptional.KEY) { + var request = document.createElement('iframe'); + var protocol_version = 5; + request.style.width = '1px'; + request.style.height = '1px'; + request.style.display = 'none'; + var api_url = document.location.protocol + '//' + Exceptional.HOST + '/api/errors/new?protocol_version=' + protocol_version + '&msg=' + Exceptional.customEscape(msg) + '&url=' + Exceptional.customEscape(url) + '&line=' + Exceptional.customEscape(line) + '&api_key=' + Exceptional.KEY + '&customaction=' + Exceptional.customEscape(Exceptional.action); + request.src = api_url; + if (document.body) { + document.body.appendChild(request); + } else{ + addLoadEvent(function() { + document.body.appendChild(request); + }); + }; + + }; + return api_url; + }, + setKey: function (key) { + Exceptional.KEY = key; + }, + setHost: function (host) { + Exceptional.HOST = host; + }, + setAction: function (action) { + Exceptional.action = action; + }, + customEscape: function (escape_me) { + if (typeof(escape_me) == "object") { + return(escape(JSON.stringify(escape_me))); + } else{ + return(escape(escape_me)); + }; + } +}; + +window.onerror = function(msg, url, line) { + Exceptional.handle(msg,url,line); +}; + +// nice way to register the execution of some code when the page has finished loading - from http://simonwillison.net/2004/May/26/addLoadEvent/ +function addLoadEvent(func) { + var oldonload = window.onload; + if (typeof window.onload != 'function') { + window.onload = func; + } else { + window.onload = function() { + if (oldonload) { + oldonload(); + } + func(); + }; + } +} + +// add JSON support - from here https://github.com/douglascrockford/JSON-js +if(!this.JSON)this.JSON={}; +(function(){function k(a){return a<10?"0"+a:a}if(typeof Date.prototype.toJSON!=="function"){Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+k(this.getUTCMonth()+1)+"-"+k(this.getUTCDate())+"T"+k(this.getUTCHours())+":"+k(this.getUTCMinutes())+":"+k(this.getUTCSeconds())+"Z":null};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(){return this.valueOf()}}var n=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,o= +/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,f,l,q={"\u0008":"\\b","\t":"\\t","\n":"\\n","\u000c":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},i;function p(a){o.lastIndex=0;return o.test(a)?'"'+a.replace(o,function(c){var d=q[c];return typeof d==="string"?d:"\\u"+("0000"+c.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function m(a,c){var d,g,j=f,e,b=c[a];if(b&&typeof b==="object"&&typeof b.toJSON==="function")b=b.toJSON(a); +if(typeof i==="function")b=i.call(c,a,b);switch(typeof b){case "string":return p(b);case "number":return isFinite(b)?String(b):"null";case "boolean":case "null":return String(b);case "object":if(!b)return"null";f+=l;e=[];if(Object.prototype.toString.apply(b)==="[object Array]"){g=b.length;for(a=0;a - +