From f73a5f067a3f135fa87f887606939ff52afd9258 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 10 May 2014 02:00:18 +0200 Subject: fxed --- ethereal/assets/ext/pre.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 ethereal/assets/ext/pre.js (limited to 'ethereal/assets/ext/pre.js') diff --git a/ethereal/assets/ext/pre.js b/ethereal/assets/ext/pre.js new file mode 100644 index 000000000..ca520f152 --- /dev/null +++ b/ethereal/assets/ext/pre.js @@ -0,0 +1,58 @@ +function debug(/**/) { + var args = arguments; + var msg = "" + for(var i = 0; i < args.length; i++){ + if(typeof args[i] === "object") { + msg += " " + JSON.stringify(args[i]) + } else { + msg += " " + args[i] + } + } + + postData({call:"debug", args:[msg]}) + document.getElementById("debug").innerHTML += "
" + msg +} + +// Helper function for generating pseudo callbacks and sending data to the QML part of the application +function postData(data, cb) { + data._seed = Math.floor(Math.random() * 1000000) + if(cb) { + eth._callbacks[data._seed] = cb; + } + + if(data.args === undefined) { + data.args = []; + } + + navigator.qt.postMessage(JSON.stringify(data)); +} + +navigator.qt.onmessage = function(ev) { + var data = JSON.parse(ev.data) + + if(data._event !== undefined) { + eth.trigger(data._event, data.data); + } else { + if(data._seed) { + var cb = eth._callbacks[data._seed]; + if(cb) { + // Figure out whether the returned data was an array + // array means multiple return arguments (multiple params) + if(data.data instanceof Array) { + cb.apply(this, data.data) + } else { + cb.call(this, data.data) + } + + // Remove the "trigger" callback + delete eth._callbacks[ev._seed]; + } + } + } +} + +window.onerror = function(message, file, lineNumber, column, errorObj) { + debug(file, message, lineNumber+":"+column, errorObj); + + return false; +} -- cgit