Skip to content

Commit

Permalink
Merge pull request #84 from bisrael/master
Browse files Browse the repository at this point in the history
RFC: Add Events to Raven
  • Loading branch information
mattrobenolt committed Apr 18, 2013
2 parents ab0a723 + 930d908 commit 9b2887b
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,34 @@ var Raven = {
}
};

function triggerEvent(eventType, options) {
var event, key;

eventType = 'raven' + eventType[0].toUpperCase() + eventType.substr(1);

if (document.createEvent) {
event = document.createEvent("HTMLEvents");
event.initEvent(eventType, true, true);
} else {
event = document.createEventObject();
event.eventType = eventType;
}

if (typeof options !== "object") {
options = {}
}

for (key in options) if (options.hasOwnProperty(key)) {
event[key] = options[key]
}

if (document.createEvent) {
document.dispatchEvent(event);
} else {
document.fireEvent("on" + event.eventType.toLowerCase(), event);
}
}

var uriKeys = 'source protocol authority userInfo user password host port relative path directory file query anchor'.split(' '),
uriPattern = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;

Expand Down Expand Up @@ -300,6 +328,11 @@ function handleStackInfo(stackInfo, options) {
});
}

triggerEvent('handle', {
stackInfo: stackInfo,
options: options
});

processException(
stackInfo.name,
stackInfo.message,
Expand Down Expand Up @@ -471,8 +504,30 @@ function send(data) {
makeRequest(data);
}


function makeRequest(data) {
new Image().src = globalServer + getAuthQueryString() + '&sentry_data=' + encodeURIComponent(JSON.stringify(data));
var img, src;

function success() {
triggerEvent('success', {
data: data,
src: src
});
}

function failure() {
triggerEvent('failure', {
data: data,
src: src
});
}

src = globalServer + getAuthQueryString() + '&sentry_data=' + encodeURIComponent(JSON.stringify(data));
img = new Image();
img.onload = success;
img.onerror = failure;
img.onabort = failure;
img.src = src;
}

function isSetup() {
Expand Down

0 comments on commit 9b2887b

Please sign in to comment.