diff options
author | obscuren <geffobscura@gmail.com> | 2014-05-10 08:00:18 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-05-10 08:00:18 +0800 |
commit | f73a5f067a3f135fa87f887606939ff52afd9258 (patch) | |
tree | 976d23ec43adefe54b75c53eff1f64c3e636ba77 /ethereal/assets/ext/pre.js | |
parent | 1471585af082632b33eae5bf489d0ae0b277b369 (diff) | |
download | go-tangerine-f73a5f067a3f135fa87f887606939ff52afd9258.tar go-tangerine-f73a5f067a3f135fa87f887606939ff52afd9258.tar.gz go-tangerine-f73a5f067a3f135fa87f887606939ff52afd9258.tar.bz2 go-tangerine-f73a5f067a3f135fa87f887606939ff52afd9258.tar.lz go-tangerine-f73a5f067a3f135fa87f887606939ff52afd9258.tar.xz go-tangerine-f73a5f067a3f135fa87f887606939ff52afd9258.tar.zst go-tangerine-f73a5f067a3f135fa87f887606939ff52afd9258.zip |
fxed
Diffstat (limited to 'ethereal/assets/ext/pre.js')
-rw-r--r-- | ethereal/assets/ext/pre.js | 58 |
1 files changed, 58 insertions, 0 deletions
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 += "<br>" + 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; +} |