@@ -22,8 +22,6 @@ var TK = TraceKit.noConflict();
22
22
// Disable Tracekit's remote fetching by default
23
23
TK . remoteFetching = false ;
24
24
25
- var ravenCallbacks = { } ;
26
-
27
25
/*
28
26
* The core Raven singleton
29
27
*
@@ -216,108 +214,34 @@ var Raven = {
216
214
globalUser = user ;
217
215
218
216
return Raven ;
219
- } ,
220
-
221
- on : function ( eventType , eventCallback , eventContext ) {
222
- var eventCallbacks ;
223
-
224
- if ( ! eventType || typeof eventType !== "string" ) {
225
- throw new TypeError ( "Unknown Event: " + eventType ) ;
226
- }
227
-
228
- if ( ! isFunction ( eventCallback ) ) {
229
- throw new TypeError ( "Cannot attach non-function as a callback: " + eventCallback ) ;
230
- }
231
-
232
- eventCallbacks = ravenCallbacks [ eventType ] || ( ravenCallbacks [ eventType ] = [ ] ) ;
233
-
234
- eventCallbacks . push ( {
235
- callback : eventCallback ,
236
- context : eventContext
237
- } ) ;
238
-
239
- return Raven ;
240
- } ,
241
-
242
- off : function ( eventType , eventFunction , eventContext ) {
243
- var eventCallbacks , matches , key ;
244
-
245
- if ( typeof eventType !== "string" && eventType != null ) {
246
- throw new TypeError ( "Event must be null or a string to remove: " + eventType ) ;
247
- }
248
-
249
- if ( eventFunction == null && eventContext == null ) {
250
- matches = callbackMatchesAlways ;
251
- } else if ( eventFunction == null && eventContext != null ) {
252
- matches = callbackMatchesContext ;
253
- } else if ( eventFunction != null && eventContext == null ) {
254
- matches = callbackMatchesFunction ;
255
- } else {
256
- matches = callbackMatchesBoth ;
257
- }
258
-
259
- eventCallbacks = ravenCallbacks [ eventType ] ;
260
-
261
- if ( eventType == null ) {
262
- for ( key in ravenCallbacks ) {
263
- if ( ravenCallbacks . hasOwnProperty ( key ) ) {
264
- eventCallbacks = ravenCallbacks [ key ] ;
265
- removeCallbacks ( eventCallbacks , matches , eventFunction , eventContext ) ;
266
- }
267
- }
268
- } else {
269
- removeCallbacks ( eventCallbacks , matches , eventFunction , eventContext ) ;
270
- }
271
-
272
- return Raven ;
273
217
}
274
218
} ;
275
219
276
- function callbackMatchesFunction ( callback , func , ctx ) {
277
- return callback . callback === func ;
278
- }
279
-
280
- function callbackMatchesContext ( callback , func , ctx ) {
281
- return callback . context === ctx ;
282
- }
283
-
284
- function callbackMatchesBoth ( callback , func , ctx ) {
285
- return callbackMatchesFunction . apply ( null , arguments ) && callbackMatchesContext . apply ( null , arguments ) ;
286
- }
287
-
288
- function callbackMatchesAlways ( ) {
289
- return true ;
290
- }
220
+ function triggerEvent ( eventType , options ) {
221
+ var event , key ;
291
222
292
- function removeCallbacks ( callbacks , matches , func , ctx ) {
293
- var i , callback , len ;
223
+ eventType = 'raven' + eventType [ 0 ] . toUpperCase ( ) + eventType . substr ( 1 ) ;
294
224
295
- if ( ! callbacks ) {
296
- return ;
225
+ if ( document . createEvent ) {
226
+ event = document . createEvent ( "HTMLEvents" ) ;
227
+ event . initEvent ( eventType , true , true ) ;
228
+ } else {
229
+ event = document . createEventObject ( ) ;
230
+ event . eventType = eventType ;
297
231
}
298
232
299
- for ( i = 0 , len = callbacks . length ; i < len ; ) {
300
- callback = callbacks [ i ] ;
301
- if ( callback && matches ( callback , func , ctx ) ) {
302
- callbacks . splice ( i , 1 ) ;
303
- len -= 1 ;
304
- } else {
305
- i += 1 ;
306
- }
233
+ if ( typeof options !== "object" ) {
234
+ options = { }
307
235
}
308
- }
309
236
310
- function triggerEvent ( eventType , args ) {
311
- var eventCallbacks = ravenCallbacks [ eventType ] ,
312
- len ,
313
- i ;
314
-
315
- if ( ! eventCallbacks ) {
316
- return ;
237
+ for ( key in options ) if ( options . hasOwnProperty ( key ) ) {
238
+ event [ key ] = options [ key ]
317
239
}
318
240
319
- for ( i = 0 , len = eventCallbacks . length ; i < len ; ++ i ) {
320
- eventCallbacks [ i ] . callback . apply ( eventCallbacks [ i ] . context , args ) ;
241
+ if ( document . createEvent ) {
242
+ document . dispatchEvent ( event ) ;
243
+ } else {
244
+ document . fireEvent ( "on" + event . eventType . toLowerCase ( ) , event ) ;
321
245
}
322
246
}
323
247
@@ -391,7 +315,10 @@ function handleStackInfo(stackInfo, options) {
391
315
} ) ;
392
316
}
393
317
394
- triggerEvent ( 'handle' , [ stackInfo , options ] ) ;
318
+ triggerEvent ( 'handle' , {
319
+ stackInfo : stackInfo ,
320
+ options : options
321
+ } ) ;
395
322
396
323
processException (
397
324
stackInfo . name ,
@@ -569,11 +496,17 @@ function makeRequest(data) {
569
496
var img , src ;
570
497
571
498
function success ( ) {
572
- triggerEvent ( 'success' , [ data , src ] ) ;
499
+ triggerEvent ( 'success' , {
500
+ data : data ,
501
+ src : src
502
+ } ) ;
573
503
}
574
504
575
505
function failure ( ) {
576
- triggerEvent ( 'failure' , [ data , src ] ) ;
506
+ triggerEvent ( 'failure' , {
507
+ data : data ,
508
+ src : src
509
+ } ) ;
577
510
}
578
511
579
512
src = globalServer + getAuthQueryString ( ) + '&sentry_data=' + encodeURIComponent ( JSON . stringify ( data ) ) ;
0 commit comments