diff options
| author | Alon Levy <alon@pobox.com> | 2014-10-20 13:25:32 +0300 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2014-10-20 21:36:37 +0300 |
| commit | c919c4bfef4ad9e2dc25d040c0727dd29ad541ae (patch) | |
| tree | dd6394603680976c48801b53321e8085b0db1505 /scripts/buttons.js | |
| parent | f1f4e937932f52c630831d0d501f8f8756b37531 (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/buttons.js')
| -rw-r--r-- | scripts/buttons.js | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/scripts/buttons.js b/scripts/buttons.js index 1543b4cc..bbde2d45 100644 --- a/scripts/buttons.js +++ b/scripts/buttons.js @@ -1,18 +1,19 @@ "use strict" +define('buttons', ['jquery', 'FileSaver', 'rhizicore'], function ($, saveAs, RZ) { $('.tutorial').click(function(){}); var key="#47989379"; $('.save').click(function(){ - var json = graph.save_to_json(); + var json = RZ.graph.save_to_json(); console.log(json); localStorage.setItem(key, json); }); $('.saveToFile').click(function() { - var json = graph.save_to_json(); + var json = RZ.graph.save_to_json(); var filename = 'graph.json'; var blob = new Blob([json], {type: 'application/json'}); console.log('saving ' + json.length + ' bytes to ' + filename); @@ -20,7 +21,7 @@ $('.saveToFile').click(function() { }); var really_load = function() { - if (nodes.length > 0){ + if (!RZ.graph.empty()) { return confirm('All unsaved changes will be deleted, are you sure?'); } return true; @@ -44,7 +45,7 @@ $('.file-load').on('change', function(event) { if (e.target.readyState === FileReader.DONE) { console.log('done reading ' + theFile.name); console.log('got #' + result.length + ' bytes in ' + typeof(result)); - graph.load_from_json(result); + RZ.graph.load_from_json(result); } } })(file); @@ -55,10 +56,8 @@ $('.local-storage-load').click(function(){ if (!really_load()) { return; } - links=[]; // TODO - not global - nodes=[]; // TODO - not global var json_blob = localStorage.getItem(key) - graph.load_from_json(json_blob); + RZ.graph.load_from_json(json_blob); }); $('.set-user').click(function() { @@ -66,7 +65,7 @@ $('.set-user').click(function() { $('.set-user-form').show(); $('.set-user-form').submit(function() { var user = $('.set-user-input').val(); - graph.set_user(user); + RZ.graph.set_user(user); $('.set-user').html('user: ' + user); $('.set-user').show(); $('.set-user-form').hide(); @@ -76,8 +75,10 @@ $('.set-user').click(function() { }); $('.save-history').click(function() { - if (graph.history === undefined) { + if (RZ.graph.history === undefined) { throw "History is undefined"; } - graph.history.save_to_file(); + RZ.graph.history.save_to_file(); }); +return {'buttons': 'nothing here'}; +}); // define |
