summaryrefslogtreecommitdiff
path: root/scripts/history.js
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2014-10-20 13:25:32 +0300
committerAlon Levy <alon@pobox.com>2014-10-20 21:36:37 +0300
commitc919c4bfef4ad9e2dc25d040c0727dd29ad541ae (patch)
treedd6394603680976c48801b53321e8085b0db1505 /scripts/history.js
parentf1f4e937932f52c630831d0d501f8f8756b37531 (diff)
introduce require.js and rewrite tests
Yes, I'm being lazy. The purpose of require.js is to allow writing modules, i.e. individual smaller then the whole files with clear dependencies. This is achieved by using a new api provided by require.js: define, require, requirejs Read more at [requirejs] (http://requirejs.org) Tests have been rewritten to work correctly with require.js; they still use jsdom. Test output is now stored in the repository, all tests are run via run_tests.js; This is a hack - once a good harness (with assertions, suites - unittest like) presents itself it will be used. Hidden here is also using FileSaver for history saving, so history is saved to history.json instead to a random name. Plus dropping some dead code.
Diffstat (limited to 'scripts/history.js')
-rw-r--r--scripts/history.js16
1 files changed, 13 insertions, 3 deletions
diff --git a/scripts/history.js b/scripts/history.js
index 02ca8b0f..a3127c75 100644
--- a/scripts/history.js
+++ b/scripts/history.js
@@ -15,6 +15,8 @@
// ReferenceError: __commandLineAPI is not defined
//var ActionEnum = Enum();
+define('history', ['FileSaver'], function(saveAs) {
+
function History(user) {
this.records = [];
this.user = user;
@@ -41,9 +43,9 @@ History.prototype.record = function(d)
History.prototype.save_to_file = function()
{
- // TODO: filename and chrome support (grep json;base64 for other locations)
- // perhaps has to wait for FileWriter api?
- location.href = 'data:text/json;base64,' + window.btoa(JSON.stringify(this.records, function (k, v) { return v; }, 2));
+ var json = JSON.stringify(this.records, function (k, v) { return v; }, 2);
+
+ saveAs(new Blob([json], {type: 'application/json'}), 'history.json');
};
History.prototype.clear_history = function()
@@ -96,3 +98,11 @@ History.prototype.record_keystrokes = function(where, keys)
'where': where
});
}
+
+return {
+ History:History,
+ KEYSTROKE_WHERE_TEXTANALYSIS:KEYSTROKE_WHERE_TEXTANALYSIS,
+ KEYSTROKE_WHERE_DOCUMENT:KEYSTROKE_WHERE_DOCUMENT,
+ KEYSTROKE_WHERE_EDIT_NODE:KEYSTROKE_WHERE_EDIT_NODE
+};
+}); // define