Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,27 @@
* This is the flinger client library.
*/
;
(function () {
(function(window, $) {
window.flingerAdditionalClientData = function () {
return "";
}
};

window.flingerFormatter = function (x) {
return x.toLocaleString();
}
};

var arrayMap = Array.prototype.map;
//debounce used to throttle sending to the server
var debounce = function(func, wait, immediate) {
var result;
var timeout = null;
var result, timeout;
return function() {
var context = this, args = arguments;
var args = arguments;
var callNow = immediate && !timeout;
var context = this;
var later = function() {
timeout = null;
if (!immediate) result = func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) result = func.apply(context, args);
Expand All @@ -33,18 +34,18 @@
//enqueue up for transmission
var enqueue = function(logArguments, kind, stack) {
if (!console[kind].on) return;
message = {
arguments: Array.prototype.slice.call(logArguments).map(function (x) { return flingerFormatter(x); }),
var message = {
arguments: arrayMap.call(logArguments, function (x) { return flingerFormatter(x); }),
kind: kind,
stack: stack,
stack: stack
};
message.user = flingerAdditionalClientData(message);
sendBuffer.push(message);
send();
}
};
//send along to the server
var send = debounce(function(){
jQuery.ajax({
var send = debounce(function() {
$.ajax({
type: "POST",
url: "/",
contentType: 'application/flinger',
Expand All @@ -53,7 +54,7 @@
sendBuffer = [];
}, 1000);
//ancient browsers may lack a console
window.console = window.console || {};
var console = window.console || {};
//patch console log, saving the original
var originalConsoleLog = console.log || function(){};
console.log = function() {
Expand Down Expand Up @@ -82,8 +83,7 @@
};
console.error.on = true;
//now, this is a different trick, monkey patch Error
var originalError = Error;
Error = function() {
window.Error = function() {
try {
enbarf();
} catch(e) {
Expand All @@ -92,4 +92,4 @@
};
console.exception = Error;
console.exception.on = true;
})();
})(this, this.jQuery);